Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PhongPS
- // Pixel Shader (ps_4_0_level_9_1)
- //
- // Built with Odyssey Shader Generator v0.1.5045.27441
- // 25/10/2013 14:55:42
- //------------------------------------------------------------------------------
- // Input/Output Structs
- //------------------------------------------------------------------------------
- struct VSOut
- {
- float4 Position: SV_POSITION0;
- float4 WorldPosition: POSITION0;
- float3 Normal: NORMAL0;
- float2 TextureUV: TEXCOORD0;
- };
- struct PSOut
- {
- float4 Color: SV_Target0;
- };
- //------------------------------------------------------------------------------
- // Custom Struct Definition
- //------------------------------------------------------------------------------
- struct Material
- {
- float kA;
- float kD;
- float kS;
- float SpecularPower;
- float4 Ambient;
- float4 Diffuse;
- float4 Specular;
- };
- struct PointLight
- {
- float Intensity;
- float Radius;
- float4 Diffuse;
- float3 Position;
- };
- //------------------------------------------------------------------------------
- // ConstantBuffers
- //------------------------------------------------------------------------------
- cbuffer cbStatic : register(b0)
- {
- Material material;
- PointLight lPoint;
- };
- cbuffer cbFrame : register(b1)
- {
- float3 vCameraPosition;
- };
- //------------------------------------------------------------------------------
- // Required methods
- //------------------------------------------------------------------------------
- float4 PhongLighting(PointLight light, Material material, float3 vViewDirection, float3 vLightDirection, float3 vNormal)
- {
- float3 L = -normalize(vLightDirection);
- float3 V = normalize(vViewDirection);
- float3 N = normalize(vNormal);
- float NdotL = saturate(dot(N, L));
- float fSelfShadow = saturate(4 * NdotL);
- float4 cDiffuse = material.kD * NdotL * material.Diffuse * light.Diffuse;
- float4 cAmbient = material.kA * material.Ambient;
- float3 R = reflect(-L, N);
- float RdotV = dot(R,V);
- float fSpecular = pow(max(RdotV, 0.0f), material.SpecularPower);
- float4 cSpecular = material.kS * fSpecular * material.Specular;
- float4 color = cAmbient + fSelfShadow *(cDiffuse + cSpecular);
- return color;
- }
- //------------------------------------------------------------------------------
- // Pixel Shader
- //------------------------------------------------------------------------------
- PSOut PhongPS(VSOut input) : SV_Target
- {
- float3 vWorldPos = input.WorldPosition.xyz;
- float3 vViewDirection = vCameraPosition - vWorldPos;
- float3 vLightDirection = vWorldPos - lPoint.Position;
- float4 cFinal = PhongLighting(lPoint, material, vViewDirection, vLightDirection, input.Normal);
- PSOut output;
- output.Color = cFinal;
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement