Advertisement
AvengerDr

Shader definition

Oct 25th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. [DataContract]
  2. [PixelShader(PixelShaderFlags.Diffuse)]
  3. [PixelShader(PixelShaderFlags.Specular)]
  4. public class PhongPS : Shader
  5. {
  6.     public PhongPS()
  7.     {
  8.         Name = "PhongPS";
  9.         Type = ShaderType.Pixel;
  10.         FeatureLevel = Odyssey.Graphics.Materials.FeatureLevel.PS_4_0_Level_9_1;
  11.         EnableSeparators = true;
  12.         var input = PhongVS.VSOut;
  13.         input.Name = "input";
  14.         InputStruct = input;
  15.         OutputStruct = Struct.PixelShaderOutput;
  16.  
  17.         ConstantBuffer cbStatic = CBStatic;
  18.         ConstantBuffer cbFrame= CBFrame;
  19.  
  20.         Struct pointLight = (Struct)cbStatic[Param.Struct.PointLight];
  21.         Struct material = (Struct)cbStatic[Param.Struct.Material];
  22.  
  23.         Add(cbStatic);
  24.         Add(cbFrame);
  25.  
  26.         CastNode vWorldPos = new CastNode
  27.         {
  28.             Input = new ConstantNode { Value = InputStruct[Param.SemanticVariables.WorldPosition] },
  29.             Output = new Vector { Type = Shaders.Type.Float3, Name = "vWorldPos", Swizzle = new[] { Swizzle.X, Swizzle.Y, Swizzle.Z } },
  30.             IsVerbose = true
  31.         };
  32.  
  33.         SubtractionNode vLightDirection = new SubtractionNode
  34.         {
  35.             Input1 =vWorldPos,
  36.             Input2 = new ConstantNode { Value = pointLight[Param.Light.Position] },
  37.             Output = new Vector { Type = Shaders.Type.Float3, Name="vLightDirection"},
  38.             IsVerbose = true,
  39.         };
  40.         SubtractionNode vViewDirection = new SubtractionNode
  41.         {
  42.             Input1 = new ConstantNode { Value = cbFrame[Param.Vectors.CameraPosition] },
  43.             Input2 = vWorldPos,
  44.             Output = new Vector { Type = Shaders.Type.Float3, Name="vViewDirection"},
  45.             IsVerbose = true,
  46.         };
  47.  
  48.         PhongLightingNode nPhong = new PhongLightingNode
  49.         {
  50.             Light = new ConstantNode { Value = pointLight },
  51.             Material = new ConstantNode { Value = material },
  52.             ViewDirection = vViewDirection,
  53.             Normal = new ConstantNode {Value= InputStruct[Param.SemanticVariables.Normal] },
  54.             LightDirection = vLightDirection,
  55.             Specular = true,
  56.         };
  57.  
  58.         Result = new PSOutputNode()
  59.         {
  60.             FinalColor = nPhong,
  61.             Output = OutputStruct
  62.         };
  63.     }
  64. [...]
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement