1 | // material constants
|
---|
2 | const float3 ambientMaterial= float3(0.5, 0.5, 0.5);
|
---|
3 | const float3 diffuseMaterial = float3(1.0, 1.0, 1.0);
|
---|
4 | const float3 specularMaterial = float3(0.3, 0.3, 0.3);
|
---|
5 |
|
---|
6 | //------------------------------------------
|
---|
7 | // a fényerõt számító fv.
|
---|
8 | // l = light vector, r = reciprok négyzet radius: 1.0/(r*r)
|
---|
9 | //------------------------------------------
|
---|
10 | float SQR(float x) { return x*x; }
|
---|
11 | float Attenuation(float3 Light)
|
---|
12 | {
|
---|
13 | return 10.0 / dot(Light, Light);
|
---|
14 | }
|
---|
15 |
|
---|
16 | //-----------------------------------------------------------------------------
|
---|
17 | // Illumination function used in shading: all input vectors are normalized
|
---|
18 | //-----------------------------------------------------------------------------
|
---|
19 | float4 Illumination(float3 Light, float3 Normal, float3 View, float2 TexCoord, float Attenuation)
|
---|
20 | {
|
---|
21 | // Blinn lighting
|
---|
22 | float3 Half = normalize(Light + View);
|
---|
23 | float Diffuse = dot(Normal, Light);
|
---|
24 | float Specular = dot(Normal, Half);
|
---|
25 | float4 Lighting = lit(Diffuse, Specular, 16);
|
---|
26 | float4 Color= tex2D(ColorMapSampler, TexCoord);
|
---|
27 |
|
---|
28 | return float4(
|
---|
29 | Lighting.x * ambientMaterial * Color +
|
---|
30 | (Lighting.y * diffuseMaterial * Color +
|
---|
31 | Lighting.z * specularMaterial) * Attenuation, 1);
|
---|
32 | } |
---|