Advertisement
Guest User

genshader1

a guest
May 31st, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. //Cg
  2. void vshader(
  3.      uniform float4x4 trans_model_to_view,
  4.      out float4 l_eye_position : TEXCOORD0,
  5.      uniform float4x4 tpose_view_to_model,
  6.      out float4 l_eye_normal : TEXCOORD1,
  7.      in float4 vtx_normal : TEXCOORD0,
  8.      float4 vtx_position : POSITION,
  9.      out float4 l_position : POSITION,
  10.      uniform float4x4 mat_modelproj
  11. ) {
  12.      l_position = mul(mat_modelproj, vtx_position);
  13.      l_eye_position = mul(trans_model_to_view, vtx_position);
  14.      l_eye_normal.xyz = mul((float3x3)tpose_view_to_model, vtx_normal.xyz);
  15.      l_eye_normal.w = 0;
  16. }
  17.  
  18. void fshader(
  19.      in float4 l_eye_position : TEXCOORD0,
  20.      in float4 l_eye_normal : TEXCOORD1,
  21.      uniform float4 alight_alight0,
  22.      uniform float4x4 dlight_dlight0_rel_view,
  23.      uniform float4x4 dlight_dlight1_rel_view,
  24.      uniform float4x4 dlight_dlight2_rel_view,
  25.      uniform float4x4 dlight_dlight3_rel_view,
  26.      uniform float4x4 attr_material,
  27.      uniform float4 row1_view_to_model,
  28.      out float4 o_color : COLOR0,
  29.      uniform float4 attr_color,
  30.      uniform float4 attr_colorscale
  31. ) {
  32.      float4 result;
  33.      // Fetch all textures.
  34.      // Correct the surface normal for interpolation effects
  35.      l_eye_normal.xyz = normalize(l_eye_normal.xyz);
  36.      // Begin view-space light calculations
  37.      float ldist,lattenv,langle;
  38.      float4 lcolor,lspec,lvec,lpoint,latten,ldir,leye,lhalf;     float4 tot_specular = float4(0,0,0,0);
  39.      float shininess = attr_material[3].w;
  40.      // Ambient Light 0
  41.      lcolor = alight_alight0;
  42.      // Directional Light 0
  43.      lcolor = dlight_dlight0_rel_view[0];
  44.      lspec  = dlight_dlight0_rel_view[1];
  45.      lvec   = dlight_dlight0_rel_view[2];
  46.      lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
  47.      lhalf = dlight_dlight0_rel_view[3];
  48.      lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
  49.      tot_specular += lspec;
  50.      // Directional Light 1
  51.      lcolor = dlight_dlight1_rel_view[0];
  52.      lspec  = dlight_dlight1_rel_view[1];
  53.      lvec   = dlight_dlight1_rel_view[2];
  54.      lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
  55.      lhalf = dlight_dlight1_rel_view[3];
  56.      lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
  57.      tot_specular += lspec;
  58.      // Directional Light 2
  59.      lcolor = dlight_dlight2_rel_view[0];
  60.      lspec  = dlight_dlight2_rel_view[1];
  61.      lvec   = dlight_dlight2_rel_view[2];
  62.      lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
  63.      lhalf = dlight_dlight2_rel_view[3];
  64.      lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
  65.      tot_specular += lspec;
  66.      // Directional Light 3
  67.      lcolor = dlight_dlight3_rel_view[0];
  68.      lspec  = dlight_dlight3_rel_view[1];
  69.      lvec   = dlight_dlight3_rel_view[2];
  70.      lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
  71.      lhalf = dlight_dlight3_rel_view[3];
  72.      lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
  73.      tot_specular += lspec;
  74.      // Begin view-space light summation
  75.      result = float4(0,0,0,0);
  76.      result = saturate(result);
  77.      // End view-space light calculations
  78.      result *= attr_colorscale;
  79.      tot_specular *= attr_material[3];
  80.      result.rgb = result.rgb + tot_specular.rgb;
  81.      o_color = result * 1.000001;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement