diff options
Diffstat (limited to 'libraries/irrlicht-1.8.1/media/d3d9.hlsl')
-rw-r--r-- | libraries/irrlicht-1.8.1/media/d3d9.hlsl | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/media/d3d9.hlsl b/libraries/irrlicht-1.8.1/media/d3d9.hlsl new file mode 100644 index 0000000..e3f3e42 --- /dev/null +++ b/libraries/irrlicht-1.8.1/media/d3d9.hlsl | |||
@@ -0,0 +1,84 @@ | |||
1 | // part of the Irrlicht Engine Shader example. | ||
2 | // These simple Direct3D9 pixel and vertex shaders will be loaded by the shaders | ||
3 | // example. Please note that these example shaders don't do anything really useful. | ||
4 | // They only demonstrate that shaders can be used in Irrlicht. | ||
5 | |||
6 | //----------------------------------------------------------------------------- | ||
7 | // Global variables | ||
8 | //----------------------------------------------------------------------------- | ||
9 | float4x4 mWorldViewProj; // World * View * Projection transformation | ||
10 | float4x4 mInvWorld; // Inverted world matrix | ||
11 | float4x4 mTransWorld; // Transposed world matrix | ||
12 | float3 mLightPos; // Light position | ||
13 | float4 mLightColor; // Light color | ||
14 | |||
15 | |||
16 | // Vertex shader output structure | ||
17 | struct VS_OUTPUT | ||
18 | { | ||
19 | float4 Position : POSITION; // vertex position | ||
20 | float4 Diffuse : COLOR0; // vertex diffuse color | ||
21 | float2 TexCoord : TEXCOORD0; // tex coords | ||
22 | }; | ||
23 | |||
24 | |||
25 | VS_OUTPUT vertexMain(in float4 vPosition : POSITION, | ||
26 | in float3 vNormal : NORMAL, | ||
27 | float2 texCoord : TEXCOORD0 ) | ||
28 | { | ||
29 | VS_OUTPUT Output; | ||
30 | |||
31 | // transform position to clip space | ||
32 | Output.Position = mul(vPosition, mWorldViewProj); | ||
33 | |||
34 | // transform normal | ||
35 | float3 normal = mul(float4(vNormal,0.0), mInvWorld); | ||
36 | |||
37 | // renormalize normal | ||
38 | normal = normalize(normal); | ||
39 | |||
40 | // position in world coodinates | ||
41 | float3 worldpos = mul(mTransWorld, vPosition); | ||
42 | |||
43 | // calculate light vector, vtxpos - lightpos | ||
44 | float3 lightVector = worldpos - mLightPos; | ||
45 | |||
46 | // normalize light vector | ||
47 | lightVector = normalize(lightVector); | ||
48 | |||
49 | // calculate light color | ||
50 | float3 tmp = dot(-lightVector, normal); | ||
51 | tmp = lit(tmp.x, tmp.y, 1.0); | ||
52 | |||
53 | tmp = mLightColor * tmp.y; | ||
54 | Output.Diffuse = float4(tmp.x, tmp.y, tmp.z, 0); | ||
55 | Output.TexCoord = texCoord; | ||
56 | |||
57 | return Output; | ||
58 | } | ||
59 | |||
60 | |||
61 | // Pixel shader output structure | ||
62 | struct PS_OUTPUT | ||
63 | { | ||
64 | float4 RGBColor : COLOR0; // Pixel color | ||
65 | }; | ||
66 | |||
67 | |||
68 | sampler2D myTexture; | ||
69 | |||
70 | PS_OUTPUT pixelMain(float2 TexCoord : TEXCOORD0, | ||
71 | float4 Position : POSITION, | ||
72 | float4 Diffuse : COLOR0 ) | ||
73 | { | ||
74 | PS_OUTPUT Output; | ||
75 | |||
76 | float4 col = tex2D( myTexture, TexCoord ); // sample color map | ||
77 | |||
78 | // multiply with diffuse and do other senseless operations | ||
79 | Output.RGBColor = Diffuse * col; | ||
80 | Output.RGBColor *= 4.0; | ||
81 | |||
82 | return Output; | ||
83 | } | ||
84 | |||