DangerOnTheRanger

shadow.sha

Sep 21st, 2011
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. //Cg
  2.  
  3. void vshader(float4 vtx_position : POSITION,
  4.              float2 vtx_texcoord0: TEXCOORD0,
  5.              float3 vtx_normal: NORMAL,
  6.  
  7.              uniform float4x4 trans_model_to_clip_of_light,
  8.              uniform float4x4 mat_modelproj,
  9.              uniform float4 mspos_light,
  10.              uniform float4 k_ambient,
  11.              uniform float4 k_scale,
  12.              uniform float4 k_push,
  13.  
  14.              out float4 l_position : POSITION,
  15.              out float2 l_texcoord0 : TEXCOORD0,
  16.              out float4 l_shadowcoord : TEXCOORD1,
  17.          out float  l_smooth : TEXCOORD2,
  18.          out float4 l_lightclip : TEXCOORD3
  19.              )
  20.  
  21. {
  22. float4 position = vtx_position * k_scale;
  23.  
  24. // vertex position
  25. l_position = mul(mat_modelproj, position);
  26.  
  27. // Pass through texture coordinate for main texture.
  28. l_texcoord0 = vtx_texcoord0;
  29.  
  30. // Calculate the surface lighting factor.
  31. l_smooth = saturate(dot(vtx_normal, normalize(mspos_light - position)));
  32.  
  33. // Calculate light-space clip position.
  34. float4 pushed = position + float4(vtx_normal * k_push, 0);
  35. l_lightclip = mul(trans_model_to_clip_of_light, pushed);
  36.  
  37. // Calculate shadow-map texture coordinates.
  38. l_shadowcoord = l_lightclip * float4(0.5,0.5,0.5,1.0) + l_lightclip.w * float4(0.5,0.5,0.5,0.0);
  39. }
  40.  
  41.  
  42. void fshader(in float2 l_texcoord0 : TEXCOORD0,
  43.              in float4 l_shadowcoord : TEXCOORD1,
  44.              in float  l_smooth : TEXCOORD2,
  45.              in float4 l_lightclip : TEXCOORD3,
  46.              uniform float4 attr_color,
  47.              uniform sampler2D tex_0 : TEXUNIT0,
  48.              uniform sampler2D k_Ldepthmap : TEXUNIT1,
  49.              uniform float4 k_ambient,
  50.          uniform float4 k_texDisable,
  51.              out float4 o_color:COLOR)
  52. {
  53.   float3 circleoffs = float3(l_lightclip.xy / l_lightclip.w, 0);
  54.   float falloff = saturate(1.0 - dot(circleoffs, circleoffs));
  55.   float4 baseColor = saturate(tex2D(tex_0, l_texcoord0) + k_texDisable);
  56.   float shade=tex2D(k_Ldepthmap, l_shadowcoord.xy/l_shadowcoord.w).x;
  57.   shade=step((l_shadowcoord.z/l_shadowcoord.w), shade);
  58.   /* The attr_color parameter is only necessary if you use/want to use
  59.   vertex colors in your scene */
  60.   o_color =  attr_color * baseColor * ( falloff * shade * l_smooth + k_ambient.x );
  61.   o_color.a = attr_color.a;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment