Advertisement
Guest User

Untitled

a guest
Mar 16th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. //Cg
  2. //Cg profile arbvp1 arbfp1
  3.  
  4. // shader loosely based on pro-rsoft's from the panda3d forums
  5. // shader assumes 6 texture stages:
  6. // 0-2 textures
  7. // 3-5 alpha maps
  8. // vertex shader accepts unit 0 and 3 texture coords as input
  9. // and outputs unit 0 scaled and unit 3 unchanged
  10. // fragment shader uses unit 0 coordinates to access textures
  11. // and unit 3 coordinates (un-scaled) to access alpha maps
  12. // gsk, june-2008
  13.  
  14. void vshader( in float4 vtx_position : POSITION,
  15. in float3 vtx_normal : NORMAL,
  16. in float2 vtx_texcoord0 : TEXCOORD0,
  17. in float2 vtx_texcoord3 : TEXCOORD3,
  18. in uniform float4x4 mat_modelproj,
  19. in uniform float4x4 trans_model_to_world,
  20. in uniform float3 k_lightvec,
  21. in uniform float4 k_lightcolor,
  22. in uniform float4 k_ambientlight,
  23. in uniform float4 k_tscale,
  24. in uniform float k_zscale,
  25. out float4 l_brightness,
  26. out float4 l_lightcolor,
  27. out float4 l_mpos,
  28. out float2 l_texcoord0 : TEXCOORD0,
  29. out float2 l_texcoord3 : TEXCOORD3,
  30. out float4 l_position : POSITION)
  31. {
  32.  
  33. // worldspace position, for clipping in the fragment shader
  34. l_mpos = mul(trans_model_to_world, vtx_position);
  35.  
  36. l_position=mul(mat_modelproj,vtx_position);
  37. l_texcoord0=vtx_texcoord0*k_tscale;
  38. l_texcoord3=vtx_texcoord3;
  39. vtx_normal.z /= k_zscale;
  40.  
  41. // lighting
  42. float3 N = normalize( vtx_normal );
  43. float3 L = normalize( k_lightvec );
  44. l_brightness = (max( dot( -N, L ), 0.0f )*k_lightcolor)+k_ambientlight;
  45.  
  46.  
  47. }
  48.  
  49. void fshader( in float4 l_position : POSITION,
  50. in float2 l_texcoord0 : TEXCOORD0,
  51. in float2 l_texcoord3 : TEXCOORD3,
  52. in float4 l_brightness,
  53. in float4 l_lightcolor,
  54. in float4 l_mpos,
  55. in uniform float4 k_waterlevel,
  56. in uniform sampler2D tex_0 : TEXUNIT0,
  57. in uniform sampler2D tex_1 : TEXUNIT1,
  58. in uniform sampler2D tex_2 : TEXUNIT2,
  59. in uniform sampler2D tex_3 : TEXUNIT3,
  60. in uniform sampler2D tex_4 : TEXUNIT4,
  61. in uniform sampler2D tex_5 : TEXUNIT5,
  62. out float4 o_color : COLOR )
  63. {
  64. // clipping
  65. if ( l_mpos.z < k_waterlevel.z) discard;
  66.  
  67. // alpha splatting and lighting
  68. float4 tex1=tex2D(tex_0,l_texcoord0);
  69. float4 tex2=tex2D(tex_1,l_texcoord0);
  70. float4 tex3=tex2D(tex_2,l_texcoord0);
  71. float alpha1=tex2D(tex_3,l_texcoord3).z;
  72. float alpha2=tex2D(tex_4,l_texcoord3).z;
  73. float alpha3=tex2D(tex_5,l_texcoord3).z;
  74. o_color =tex1*alpha1;
  75. o_color+=tex2*alpha2;
  76. o_color+=tex3*alpha3;
  77. //o_color *= 0.5;
  78. //o_color
  79. o_color=o_color*(l_brightness);
  80. //o_color=l_lightcolor;
  81. o_color.a=1.0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement