2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
10 namespace visLU.Effects
21 GraphicsDevice device;
24 private EffectParameter worldViewProjection;
25 public EffectParameter world;
26 public EffectParameter cameraPosition;
27 private EffectParameter frontFaces;
28 private EffectParameter backFaces;
29 private EffectParameter transferValues;
30 private EffectParameter transferValuesAlpha;
31 private EffectParameter CVDtransferValues;
32 private EffectParameter volumeTexture;
33 private EffectParameter gradientTexture;
34 private EffectParameter directLightPosition;
35 private EffectParameter stepSize;
36 private EffectParameter baseSampleDist;
37 private EffectParameter sampleDist;
38 private EffectParameter iterations;
39 private EffectParameter side;
40 private EffectParameter scaleFactor;
41 private EffectParameter texSize;
42 private EffectParameter slice;
44 private EffectParameter frontToBack;
45 private EffectParameter shading;
46 private EffectParameter useAlpha;
47 private EffectParameter useTransferColors;
48 private EffectParameter useCVDTransferColors;
51 private EffectParameter ep_RGBtoXYZmatrix;
52 private EffectParameter ep_rotation;
55 private EffectParameter ep_rotationBack;
56 private EffectParameter ep_XYZtoRGBmatrix;
58 private Texture3D volume;
59 private Texture3D gradients;
60 private Texture2D front;
61 private Texture2D back;
62 private Texture2D transfer;
63 private Texture2D cvdTransfer;
64 private Texture2D alpha;
66 private Matrix rgbToXYZ;
67 private Matrix xyzToRGB;
76 public Texture3D VolumeTexture
78 get {
return volume; }
79 set { volume = value; }
85 public Texture3D GradientTexture
87 get {
return gradients; }
88 set { gradients = value; }
94 public Texture2D FrontFacesTexture
97 set { front = value; Console.WriteLine(
"frontfacetexture set"); }
103 public Texture2D BackFacesTexture
106 set { back = value; }
112 public Texture2D TransferTexture
114 get {
return transfer; }
115 set { transfer = value; }
121 public Texture2D TransferTextureAlpha
123 get {
return alpha; }
124 set { alpha = value; }
130 public Texture2D CVDTransferTexture
132 get {
return cvdTransfer; }
133 set { cvdTransfer = value; }
145 public VolumeShader(GraphicsDevice _device, Effect _effect,
bool CVDon)
150 #region create normal volume shader
152 Console.WriteLine(
"creating shader");
157 worldViewProjection = this.Parameters[
"myWorldViewProjectionMatrix"];
160 world = this.Parameters[
"myWorldMatrix"];
163 cameraPosition = this.Parameters[
"CameraPosition"];
166 frontFaces = this.Parameters[
"Front"];
169 backFaces = this.Parameters[
"Back"];
172 transferValues = this.Parameters[
"Transfer"];
175 transferValuesAlpha = this.Parameters[
"TransferAlpha"];
178 CVDtransferValues = this.Parameters[
"CVDTransfer"];
181 volumeTexture = this.Parameters[
"Volume"];
184 gradientTexture = this.Parameters[
"Gradients"];
187 directLightPosition = this.Parameters[
"DirectLightVector"];
190 stepSize = this.Parameters[
"StepSize"];
193 baseSampleDist = this.Parameters[
"baseSampleDist"];
196 sampleDist = this.Parameters[
"sampleDist"];
199 iterations = this.Parameters[
"Iterations"];
202 side = this.Parameters[
"Side"];
205 scaleFactor = this.Parameters[
"ScaleFactor"];
208 texSize = this.Parameters[
"textureSize"];
211 slice = this.Parameters[
"Slice"];
213 frontToBack = this.Parameters[
"frontToBack"];
215 shading = this.Parameters[
"shading"];
217 useAlpha = this.Parameters[
"useAlpha"];
219 useTransferColors = this.Parameters[
"useTransferColors"];
221 useCVDTransferColors = this.Parameters[
"useCVDTransferColors"];
223 Console.WriteLine(
"SHADER CREATED");
228 #region create CVD volume shader
230 Console.WriteLine(
"creating shader");
235 worldViewProjection = this.Parameters[
"myWorldViewProjectionMatrix"];
238 world = this.Parameters[
"myWorldMatrix"];
241 cameraPosition = this.Parameters[
"CameraPosition"];
244 frontFaces = this.Parameters[
"Front"];
247 backFaces = this.Parameters[
"Back"];
250 transferValuesAlpha = this.Parameters[
"TransferAlpha"];
253 CVDtransferValues = this.Parameters[
"CVDTransfer"];
256 volumeTexture = this.Parameters[
"Volume"];
259 gradientTexture = this.Parameters[
"Gradients"];
262 directLightPosition = this.Parameters[
"DirectLightVector"];
265 stepSize = this.Parameters[
"StepSize"];
268 baseSampleDist = this.Parameters[
"baseSampleDist"];
271 sampleDist = this.Parameters[
"sampleDist"];
274 iterations = this.Parameters[
"Iterations"];
277 scaleFactor = this.Parameters[
"ScaleFactor"];
280 texSize = this.Parameters[
"textureSize"];
282 frontToBack = this.Parameters[
"frontToBack"];
284 shading = this.Parameters[
"shading"];
286 useAlpha = this.Parameters[
"useAlpha"];
288 useCVDTransferColors = this.Parameters[
"useCVDTransferColors"];
293 rgbToXYZ =
new Matrix(0.6097559f, 0.2052401f, 0.1492240f, 0.0f,
294 0.3111242f, 0.6256560f, 0.0632197f, 0.0f,
295 0.0194811f, 0.0608902f, 0.7448387f, 0.0f,
296 0.0f, 0.0f, 0.0f, 1.0f);
298 ep_RGBtoXYZmatrix = this.Parameters[
"mRGBtoXYZ"];
299 ep_rotation = this.Parameters[
"rotmat"];
304 xyzToRGB =
new Matrix(1.9624274f, -0.6105343f, -0.3413404f, 0.0f,
305 -0.9787684f, 1.9161415f, 0.0334540f, 0.0f,
306 0.0286869f, -0.1406752f, 1.3487655f, 0.0f,
307 0.0f, 0.0f, 0.0f, 1.0f);
309 ep_rotationBack = this.Parameters[
"rotmatBack"];
310 ep_XYZtoRGBmatrix = this.Parameters[
"mXYZtoRGB"];
312 Console.WriteLine(
"CVD SHADER CREATED");
319 #region SetEffectParameter
330 this.worldViewProjection.SetValue(_worldViewProjection);
331 this.world.SetValue(_world);
340 this.cameraPosition.SetValue(_cameraPosition);
343 public void SetEffectParameter_CVD(Texture3D _volumeTexture,
344 Texture3D _gradientTexture,
347 Vector4 _scaleFactor,
350 Matrix _rotateFromLMS)
352 this.volumeTexture.SetValue(_volumeTexture);
353 this.gradientTexture.SetValue(_gradientTexture);
354 this.stepSize.SetValue(_stepSize);
355 this.iterations.SetValue(_iterations);
356 this.scaleFactor.SetValue(_scaleFactor);
357 this.texSize.SetValue(_texSize);
359 this.frontToBack.SetValue(
GameProperties.Instance.enableFrontToBackBlend);
361 this.useAlpha.SetValue(
GameProperties.Instance.enableTransferAlphaValues);
363 this.directLightPosition.SetValue(
GameProperties.Instance.directLightPos);
366 this.ep_RGBtoXYZmatrix.SetValue(rgbToXYZ);
367 this.ep_rotation.SetValue(_rotateToLMS);
370 this.ep_rotationBack.SetValue(_rotateFromLMS);
371 this.ep_XYZtoRGBmatrix.SetValue(xyzToRGB);
376 this.frontFaces.SetValue(front);
380 this.backFaces.SetValue(back);
384 this.transferValuesAlpha.SetValue(alpha);
386 if (cvdTransfer != null)
388 this.CVDtransferValues.SetValue(cvdTransfer);
404 Texture3D _gradientTexture,
408 Vector4 _scaleFactor,
411 this.volumeTexture.SetValue(_volumeTexture);
412 this.gradientTexture.SetValue(_gradientTexture);
413 this.stepSize.SetValue(_stepSize);
414 this.iterations.SetValue(_iterations);
415 this.side.SetValue(_side);
416 this.scaleFactor.SetValue(_scaleFactor);
417 this.frontToBack.SetValue(
GameProperties.Instance.enableFrontToBackBlend);
419 this.useAlpha.SetValue(
GameProperties.Instance.enableTransferAlphaValues);
420 this.useTransferColors.SetValue(
GameProperties.Instance.enableTransferFunction);
426 this.frontFaces.SetValue(front);
430 this.backFaces.SetValue(back);
432 if (transfer != null)
434 this.transferValues.SetValue(transfer);
438 this.transferValuesAlpha.SetValue(alpha);
440 if (cvdTransfer != null)
442 this.CVDtransferValues.SetValue(cvdTransfer);
444 this.slice.SetValue(_slice);
462 Texture3D _gradientTexture,
463 Vector3 _directLightPosition,
465 float _baseSampleDist,
469 Vector4 _scaleFactor,
473 this.volumeTexture.SetValue(_volumeTexture);
474 this.gradientTexture.SetValue(_gradientTexture);
475 this.stepSize.SetValue(_stepSize);
476 this.iterations.SetValue(_iterations);
477 this.side.SetValue(_side);
478 this.scaleFactor.SetValue(_scaleFactor);
479 this.frontToBack.SetValue(
GameProperties.Instance.enableFrontToBackBlend);
481 this.useAlpha.SetValue(
GameProperties.Instance.enableTransferAlphaValues);
482 this.useTransferColors.SetValue(
GameProperties.Instance.enableTransferFunction);
488 this.frontFaces.SetValue(front);
492 this.backFaces.SetValue(back);
494 if (transfer != null)
496 this.transferValues.SetValue(transfer);
500 this.transferValuesAlpha.SetValue(alpha);
502 if (cvdTransfer != null)
504 this.CVDtransferValues.SetValue(cvdTransfer);
506 this.slice.SetValue(_slice);
509 this.directLightPosition.SetValue(_directLightPosition);
510 this.baseSampleDist.SetValue(_baseSampleDist);
511 this.sampleDist.SetValue(_sampleDist);
512 this.texSize.SetValue(_texSize);