Advertisement
Guest User

Untitled

a guest
Mar 16th, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 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))) * 10;
  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 sampler2D tex_0 : TEXUNIT0,
  47. uniform sampler2D k_Ldepthmap : TEXUNIT1,
  48. uniform float4 k_ambient,
  49. uniform float4 k_texDisable,
  50. out float4 o_color:COLOR)
  51. {
  52. float3 circleoffs = float3(l_lightclip.xy / l_lightclip.w, 0);
  53. float falloff = saturate(1.0 - dot(circleoffs, circleoffs));
  54. float4 baseColor = saturate(tex2D(tex_0, l_texcoord0) + k_texDisable);
  55. float shade = tex2Dproj(k_Ldepthmap,l_shadowcoord);
  56. o_color = baseColor * ( falloff * shade * l_smooth + k_ambient.x );
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement