Advertisement
Guest User

genshader0

a guest
May 31st, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.31 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_ambient = float4(0,0,0,0);
  39.      float4 tot_diffuse = float4(0,0,0,0);
  40.      float4 tot_specular = float4(0,0,0,0);
  41.      float shininess = attr_material[3].w;
  42.      // Ambient Light 0
  43.      lcolor = alight_alight0;
  44.      tot_ambient += lcolor;
  45.      // Directional Light 0
  46.      lcolor = dlight_dlight0_rel_view[0];
  47.      lspec  = dlight_dlight0_rel_view[1];
  48.      lvec   = dlight_dlight0_rel_view[2];
  49.      lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
  50.      tot_diffuse += lcolor;
  51.      lhalf = dlight_dlight0_rel_view[3];
  52.      lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
  53.      tot_specular += lspec;
  54.      // Directional Light 1
  55.      lcolor = dlight_dlight1_rel_view[0];
  56.      lspec  = dlight_dlight1_rel_view[1];
  57.      lvec   = dlight_dlight1_rel_view[2];
  58.      lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
  59.      tot_diffuse += lcolor;
  60.      lhalf = dlight_dlight1_rel_view[3];
  61.      lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
  62.      tot_specular += lspec;
  63.      // Directional Light 2
  64.      lcolor = dlight_dlight2_rel_view[0];
  65.      lspec  = dlight_dlight2_rel_view[1];
  66.      lvec   = dlight_dlight2_rel_view[2];
  67.      lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
  68.      tot_diffuse += lcolor;
  69.      lhalf = dlight_dlight2_rel_view[3];
  70.      lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
  71.      tot_specular += lspec;
  72.      // Directional Light 3
  73.      lcolor = dlight_dlight3_rel_view[0];
  74.      lspec  = dlight_dlight3_rel_view[1];
  75.      lvec   = dlight_dlight3_rel_view[2];
  76.      lcolor *= saturate(dot(l_eye_normal.xyz, lvec.xyz));
  77.      tot_diffuse += lcolor;
  78.      lhalf = dlight_dlight3_rel_view[3];
  79.      lspec *= pow(saturate(dot(l_eye_normal.xyz, lhalf.xyz)), shininess);
  80.      tot_specular += lspec;
  81.      // Begin view-space light summation
  82.      result = float4(0,0,0,0);
  83.      result += tot_ambient * attr_material[0];
  84.      result += tot_diffuse * attr_material[1];
  85.      result = saturate(result);
  86.      // End view-space light calculations
  87.      result *= attr_colorscale;
  88.      tot_specular *= attr_material[3];
  89.      result.rgb = result.rgb + tot_specular.rgb;
  90.      o_color = result * 1.000001;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement