Ellesar

Untitled

Apr 10th, 2011
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float4x4 invProj;
  2. float4x4 invView;
  3.  
  4. float3 lightPos;
  5. float3 lightColor;
  6. float lightIntensity;
  7. float3 cameraPos;
  8.  
  9. void VS_light(in  float4 inPosition            : POSITION,
  10.               out float4 outPosition           : POSITION,
  11.               out float4 outWorldPosition      : TEXCOORD0) {
  12.     outPosition = inPosition;
  13.     outWorldPosition = mul(invView, mul(invProj, inPosition));
  14. }
  15.  
  16. void PS_light(in  float4 inWorldPosition       : TEXCOORD0,
  17.               out float4 outColor              : COLOR)
  18. {
  19.     float4 value;
  20.     outColor = float4(0, 0, 0, 0);
  21.     float3 position = inWorldPosition.xyz;
  22.     float distance = length(lightPos - position);
  23.     const float stepSize = distance / 250.0;
  24.     const float3 rayStep = normalize(position - cameraPos) * stepSize; 
  25.    
  26.     [unroll(2)]
  27.     for (int i = 0; i < 250; i++) {
  28.         float lightAttenuation = 1 / pow(distance, 3);
  29.         float shadow = 1.0;//shadow(position);
  30.         float opacity = 1.0;
  31.         value.rgb = (1.0 - outColor.a) * (lightColor * lightIntensity * lightAttenuation * shadow);
  32.         value.a = (1.0 - outColor.a) * opacity;
  33.         outColor += value;
  34.         position += rayStep;
  35.         distance -= stepSize;
  36.     }  
  37. }
  38.  
  39. technique light
  40. {
  41.     pass
  42.     {
  43.         VertexShader = compile vs_2_0 VS_light();
  44.         PixelShader = compile ps_2_0 PS_light();
  45.     }
  46. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×