Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float4x4 World;
- float4x4 View;
- float4x4 Projection;
- float4 AmbientColor = float4(1, 1, 1, 1);
- float AmbientIntensity = 0.1;
- float4x4 WorldInverseTranspose;
- float3 DiffuseLightDirection = float3(1, 0, 0);
- float4 DiffuseColor = float4(1, 1, 1, 1);
- float DiffuseIntensity = 1.0;
- float Shininess = 200;
- float4 SpecularColor = float4(1, 1, 1, 1);
- float SpecularIntensity = 1;
- float3 ViewVector = float3(1, 0, 0);
- struct VertexShaderInput
- {
- float4 Position : SV_POSITION;
- float4 Normal : NORMAL0;
- };
- struct VertexShaderOutput
- {
- float4 Position : SV_POSITION;
- float4 Color : COLOR0;
- float3 Normal : TEXCOORD0;
- };
- VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
- {
- VertexShaderOutput output;
- float4 worldPosition = mul(input.Position, World);
- float4 viewPosition = mul(worldPosition, View);
- output.Position = mul(viewPosition, Projection);
- float4 normal = normalize(mul(input.Normal, WorldInverseTranspose));
- float lightIntensity = dot(normal.xyz, DiffuseLightDirection);
- output.Color = saturate(DiffuseColor * DiffuseIntensity * lightIntensity);
- output.Normal = normal.xyz;
- return output;
- }
- float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET0
- {
- float3 light = normalize(DiffuseLightDirection);
- float3 normal = normalize(input.Normal);
- float3 r = normalize(2 * dot(light, normal) * normal - light);
- float3 v = normalize(mul(normalize(ViewVector), (float3x3) World));
- float dotProduct = dot(r, v);
- float4 specular = SpecularIntensity * SpecularColor * max(pow(abs(dotProduct), Shininess), 0) * length(input.Color);
- return saturate(input.Color + AmbientColor * AmbientIntensity + specular);
- }
- technique Specular
- {
- pass Pass1
- {
- VertexShader = compile vs_4_0 VertexShaderFunction();
- PixelShader = compile ps_4_0 PixelShaderFunction();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement