Advertisement
Ember

flat shading

Feb 20th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. //-----------------------------------------------------------------------------------------
  2. // Pixel Shader
  3. //-----------------------------------------------------------------------------------------
  4. float4 ColorPS(
  5.     float4 position : TEXCOORD0) : SV_Target
  6. {
  7.     // Hardcode a generic directional light
  8.     float3 L = normalize(float3(0.5, 0.25, -1.0));
  9.  
  10.     // Compute the surface normal
  11.     float3 dx = ddx(position);
  12.     float3 dy = ddy(position);
  13.     float3 dn = normalize(cross(dx, dy));
  14.  
  15.     // Calculate a half-lambert diffuse factor
  16.     float NdotL = saturate(-dot(dn, L) * 0.5 + 0.5);
  17.  
  18.     // Basic colouring
  19.     float4 color = float4(1, 1, 1, 1);
  20.     float3 diffuse = color.xyz * NdotL;
  21.  
  22.     // Return the result
  23.     return float4(diffuse, 1.0f);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement