VIS2 SS2013 CVD DVR
 All Classes Namespaces Functions Enumerations Properties
TFWeightsShader.cs
1 #region Using Statements
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using Microsoft.Xna.Framework;
7 using Microsoft.Xna.Framework.Content;
8 using Microsoft.Xna.Framework.Graphics;
9 using Microsoft.Xna.Framework.Input;
10 #endregion
11 
12 namespace visLU.Effects
13 {
18  class TFWeightsShader : Effect
19  {
20  GraphicsDevice device;
21  Effect effect;
22 
23  private EffectParameter worldViewProjection;
24  public EffectParameter world;
25  public EffectParameter cameraPosition;
26  private EffectParameter frontFaces;
27  private EffectParameter backFaces;
28  private EffectParameter transferValues;
29  private EffectParameter transferValuesAlpha;
30  private EffectParameter volumeTexture;
31  private EffectParameter directLightPosition;
32  private EffectParameter stepSize;
33  private EffectParameter baseSampleDist;
34  private EffectParameter sampleDist;
35  private EffectParameter iterations;
36  private EffectParameter side;
37  private EffectParameter scaleFactor;
38  private EffectParameter texSize; //correct the texture coordinates
39  private EffectParameter slice;
40  private EffectParameter prevControlPoint;
41  private EffectParameter currControlPoint;
42  private EffectParameter nextControlPoint;
43  //boolean parameters
44  private EffectParameter frontToBack;
45  private EffectParameter shading;
46 
47  private EffectParameter useAlpha;
48  private EffectParameter useTransferColors;
49 
50  private EffectParameter selectedPos;
51 
52 
53  private Texture3D volume;
54  private Texture2D front;
55  private Texture2D back;
56  private Texture2D transfer;
57  private Texture2D alpha;
58 
65  public TFWeightsShader(GraphicsDevice _device, Effect _effect)
66  : base(_effect)
67  {
68  device = _device;
69  effect = _effect;
70 
71  // WorldViewProjection
72  worldViewProjection = this.Parameters["myWorldViewProjectionMatrix"];
73 
74  // WorldProjection
75  world = this.Parameters["myWorldMatrix"];
76 
77  // Position of Camera
78  cameraPosition = this.Parameters["CameraPosition"];
79 
80  // Texture for FrontFaces
81  frontFaces = this.Parameters["Front"];
82 
83  // Texture for Backfaces
84  backFaces = this.Parameters["Back"];
85 
86  // Texture for Transferfunction
87  transferValues = this.Parameters["Transfer"];
88 
89  // Texture for Transferfunction
90  transferValuesAlpha = this.Parameters["TransferAlpha"];
91 
92  // 3D Texture Volume
93  volumeTexture = this.Parameters["Volume"];
94 
95  //direct light position
96  directLightPosition = this.Parameters["DirectLightVector"];
97 
98  // stepSize
99  stepSize = this.Parameters["StepSize"];
100 
101  //base sample distance for the dataset
102  baseSampleDist = this.Parameters["baseSampleDist"];
103 
104  //current sample distance tha we use
105  sampleDist = this.Parameters["sampleDist"];
106 
107  // number of iterations to be done
108  iterations = this.Parameters["Iterations"];
109 
110  // side TODO: find better name
111  side = this.Parameters["Side"];
112 
113  // scaleFactor
114  scaleFactor = this.Parameters["ScaleFactor"];
115 
116  //texture size
117  texSize = this.Parameters["textureSize"];
118 
119  // slice
120  slice = this.Parameters["Slice"];
121 
122  currControlPoint = this.Parameters["currentControlPoint"];
123  prevControlPoint = this.Parameters["prevControlPoint"];
124  nextControlPoint = this.Parameters["nextControlPoint"];
125 
126  frontToBack = this.Parameters["frontToBack"];
127 
128  shading = this.Parameters["shading"];
129 
130  useAlpha = this.Parameters["useAlpha"];
131 
132  useTransferColors = this.Parameters["useTransferColors"];
133 
134  selectedPos = this.Parameters["selectedPositions"];
135 
136  if (GameProperties.Instance.debugOutput)
137  {
138  Console.WriteLine("TFWeights Shader Created");
139  }
140  }
141 
145  public Texture3D VolumeTexture
146  {
147  get { return volume; }
148  set { volume = value; }
149  }
150 
154  public Texture2D FrontFacesTexture
155  {
156  get { return front; }
157  set
158  {
159  front = value; if (GameProperties.Instance.debugOutput)
160  { Console.WriteLine("frontfacetexture set"); }
161  }
162  }
163 
167  public Texture2D BackFacesTexture
168  {
169  get { return back; }
170  set { back = value; }
171  }
172 
176  public Texture2D TransferTexture
177  {
178  get { return transfer; }
179  set { transfer = value; }
180  }
181 
185  public Texture2D TransferTextureAlpha
186  {
187  get { return alpha; }
188  set { alpha = value; }
189  }
190 
191  #region SetEffectParameter
192  //set by the engine:
198  public void SetEffectParameter(Matrix _worldViewProjection, Matrix _world)
199  {
200  this.worldViewProjection.SetValue(_worldViewProjection);
201  this.world.SetValue(_world);
202  }
203 
208  public void SetEffectParameter(Vector3 _cameraPosition)
209  {
210  this.cameraPosition.SetValue(_cameraPosition);
211  }
212 
217  public void SetEffectParameter(float _currControlPoint, float _prevControlPoint, float _nextControlPoint)
218  {
219  this.currControlPoint.SetValue(_currControlPoint);
220  this.prevControlPoint.SetValue(_prevControlPoint);
221  this.nextControlPoint.SetValue(_nextControlPoint);
222  }
223 
228  public void SetEffectParameter(Texture2D _selectedPos)
229  {
230  this.selectedPos.SetValue(_selectedPos);
231  }
232 
233  //set by the data itself
243  public void SetEffectParameter(Texture3D _volumeTexture,
244  Vector3 _directLightPosition,
245  Vector3 _stepSize,
246  float _baseSampleDist,
247  float _sampleDist,
248  int _iterations,
249  int _side,
250  Vector4 _scaleFactor,
251  Vector2 _texSize,
252  float _slice)
253  {
254  this.volumeTexture.SetValue(_volumeTexture);
255  this.stepSize.SetValue(_stepSize);
256  this.iterations.SetValue(_iterations);
257  this.side.SetValue(_side);
258  this.scaleFactor.SetValue(_scaleFactor);
259  this.frontToBack.SetValue(GameProperties.Instance.enableFrontToBackBlend);
260  this.shading.SetValue(GameProperties.Instance.enableShading);
261  this.useAlpha.SetValue(GameProperties.Instance.enableTransferAlphaValues);
262  this.useTransferColors.SetValue(GameProperties.Instance.enableTransferFunction);
263 
264  if (front != null)
265  {
266  this.frontFaces.SetValue(front);
267  }
268  if (back != null)
269  {
270  this.backFaces.SetValue(back);
271  }
272  if (transfer != null)
273  {
274  this.transferValues.SetValue(transfer);
275  }
276  if (alpha != null)
277  {
278  this.transferValuesAlpha.SetValue(alpha);
279  }
280  this.slice.SetValue(_slice);
281  //extended
282  this.directLightPosition.SetValue(_directLightPosition);
283  this.baseSampleDist.SetValue(_baseSampleDist);
284  this.sampleDist.SetValue(_sampleDist);
285  this.texSize.SetValue(_texSize);
286  }
287  #endregion
288  }
289 }