Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. void ps( in v2p input, out float4 final_color : SV_TARGET )
  2. {
  3. float3 ambient_intensity = float3( 0.3f, 0.3f, 0.3f );
  4. float3 diffuse_color = float3( 0.8f, 0.8f, 0.8f);
  5. float3 specular_color = float3( 1.0f, 1.0f , 1.0f );
  6.  
  7. float3 tmp_light;
  8. tmp_light.x = light_vector.x;
  9. tmp_light.y = light_vector.y;
  10. tmp_light.z = light_vector.z;
  11.  
  12. float3 norm_light = normalize( tmp_light );
  13.  
  14. float3 tmp_pos;
  15. tmp_pos.x = input.pos.x;
  16. tmp_pos.y = input.pos.y;
  17. tmp_pos.z = input.pos.z;
  18.  
  19. float3 tmp_norm;
  20. tmp_norm.x = input.norm.x;
  21. tmp_norm.y = input.norm.y;
  22. tmp_norm.z = input.norm.z;
  23.  
  24. float3 tmp_cam = float3( 0.0f, 0.0f, -20.0f ); // todo: make this stuff work right in cbuffer
  25.  
  26. // light intensity
  27. float d = distance( tmp_light, tmp_pos );
  28.  
  29. float attenuation = 1.0f / d*d;
  30. float3 pointlight = attenuation*light_color;
  31.  
  32. // diffuse lighting
  33. float diffuse = max( dot( tmp_norm, norm_light) , 0.0f );
  34. float3 diffuse_final = diffuse_color*ambient_intensity + diffuse_color*pointlight*diffuse;
  35.  
  36. // specular lighting
  37. float3 reflect_vect = 2*dot( tmp_norm, norm_light )*tmp_norm - norm_light;
  38. float ref_max = max( dot( reflect_vect, normalize(tmp_cam) ), 0.0f );
  39. float spec_exponent = pow ( ref_max, 1.0f );
  40.  
  41. float3 spec_final;
  42. if( dot( tmp_norm, norm_light ) <= 0 )
  43. {
  44. spec_final = float3( 0.0f, 0.0f, 0.0f );
  45. }
  46. if( dot( tmp_norm, norm_light ) > 0 )
  47. {
  48. spec_final = specular_color*pointlight*spec_exponent;
  49. }
  50.  
  51. final_color = float4( diffuse_final + spec_final, 1.0f );
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement