• Main Page
  • Packages
  • Classes
  • Files
  • File List

trunk/visLU/Effects/VolumeShader.cs

Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005 using Microsoft.Xna.Framework;
00006 using Microsoft.Xna.Framework.Content;
00007 using Microsoft.Xna.Framework.Graphics;
00008 using Microsoft.Xna.Framework.Input;
00009 
00010 namespace visLU2.Effects
00011 {
00016     class VolumeShader: Effect
00017     {
00018         Game game;
00019         GraphicsDevice device;
00020         Effect effect;
00021 
00022         private EffectParameter worldViewProjection;
00023         public EffectParameter world;
00024         public EffectParameter cameraPosition;
00025         private EffectParameter frontFaces;
00026         private EffectParameter backFaces;
00027         private EffectParameter transferValues;
00028         private EffectParameter transferValuesAlpha;
00029         private EffectParameter volumeTexture;
00030         private EffectParameter stepSize;
00031         private EffectParameter iterations;
00032         private EffectParameter side;
00033         private EffectParameter scaleFactor;
00034         private EffectParameter slice;
00035         // boolean parameters
00036         private EffectParameter frontToBack; 
00037         private EffectParameter shading;
00038         private EffectParameter useAlpha;
00039         private EffectParameter useTransferColors;
00040 
00041         private Texture3D volume;
00042         private Texture2D front;
00043         private Texture2D back;
00044         private Texture2D transfer;
00045         private Texture2D alpha;
00046 
00047         /*Vector3 stepSize;
00048         int iterations;
00049         int side;
00050         Vector4 scaleFactor;*/
00057         public VolumeShader(Game _game, GraphicsDevice _device, Effect _effect)
00058             : base(_device, _effect)
00059         {
00060             game = _game;
00061             device = _device;
00062             effect = _effect;
00063 
00064             // WorldViewProjection
00065             worldViewProjection = this.Parameters["myWorldViewProjectionMatrix"];
00066 
00067             // WorldProjection
00068             world = this.Parameters["myWorldMatrix"];
00069 
00070             // Position of Camera
00071             cameraPosition = this.Parameters["CameraPosition"];
00072 
00073             // Texture for FrontFaces
00074             frontFaces = this.Parameters["Front"];
00075 
00076             // Texture for Backfaces
00077             backFaces = this.Parameters["Back"];
00078 
00079             // Texture for Transferfunction
00080             transferValues = this.Parameters["Transfer"];
00081 
00082             // Texture for Transferfunction
00083             transferValuesAlpha = this.Parameters["TransferAlpha"];
00084 
00085             // 3D Texture Volume
00086             volumeTexture = this.Parameters["Volume"];
00087 
00088             // stepSize
00089             stepSize = this.Parameters["StepSize"];
00090 
00091             // number of iterations to be done
00092             iterations = this.Parameters["Iterations"];
00093 
00094             // side TODO: find better name
00095             side = this.Parameters["Side"];
00096 
00097             // scaleFactor
00098             scaleFactor = this.Parameters["ScaleFactor"];
00099 
00100             // slice
00101             slice = this.Parameters["Slice"];
00102 
00103             frontToBack = this.Parameters["frontToBack"];
00104 
00105             shading = this.Parameters["shading"];
00106 
00107             useAlpha = this.Parameters["useAlpha"];
00108 
00109             useTransferColors = this.Parameters["useTransferColors"];
00110 
00111         }
00112 
00116         public Texture3D VolumeTexture
00117         {
00118             get { return volume; }
00119             set { volume = value; }
00120         }
00121 
00125         public Texture2D FrontFacesTexture
00126         {
00127             get { return front; }
00128             set { front = value; }
00129         }
00130 
00134         public Texture2D BackFacesTexture
00135         {
00136             get { return back; }
00137             set { back = value; }
00138         }
00139 
00143         public Texture2D TransferTexture
00144         {
00145             get { return transfer; }
00146             set { transfer = value; }
00147         }
00148 
00152         public Texture2D TransferTextureAlpha
00153         {
00154             get { return alpha; }
00155             set { alpha = value; }
00156         }
00157 
00158         #region SetEffectParameter
00159         
00160 
00161         //set by the engine:
00167         public void SetEffectParameter(Matrix _worldViewProjection, Matrix _world)
00168         {
00169             this.worldViewProjection.SetValue(_worldViewProjection);
00170             this.world.SetValue(_world);
00171         }
00172 
00177         public void SetEffectParameter(Vector3 _cameraPosition)
00178         {
00179             this.cameraPosition.SetValue(_cameraPosition);
00180         }
00181 
00182         //set by the data itself
00192         public void SetEffectParameter(Texture3D _volumeTexture,
00193             Vector3 _stepSize,
00194             int _iterations,
00195             int _side,
00196             Vector4 _scaleFactor,
00197             float _slice)
00198         {
00199             this.volumeTexture.SetValue(_volumeTexture);
00200             this.stepSize.SetValue(_stepSize);
00201             this.iterations.SetValue(_iterations);
00202             this.side.SetValue(_side);
00203             this.scaleFactor.SetValue(_scaleFactor);
00204             this.frontToBack.SetValue(GameProperties.Instance.enableFrontToBackBlend);
00205             this.shading.SetValue(GameProperties.Instance.enableShading);
00206             this.useAlpha.SetValue(GameProperties.Instance.enableTransferAlphaValues);
00207             this.useTransferColors.SetValue(GameProperties.Instance.enableTransferFunction);
00208 
00209             if (front != null)
00210             {
00211                 this.frontFaces.SetValue(front);
00212             }
00213             if (back != null)
00214             {
00215                 this.backFaces.SetValue(back);
00216             }
00217             if (transfer != null)
00218             {
00219                 this.transferValues.SetValue(transfer);
00220             }
00221             if (alpha != null)
00222             {
00223                 this.transferValuesAlpha.SetValue(alpha);
00224             }
00225             this.slice.SetValue(_slice);
00226         }
00227         #endregion
00228     }
00229 }

Generated on Wed Jan 19 2011 21:59:17 for flowvis-2 by  doxygen 1.7.2