2 # part of the Irrlicht Engine Shader example.
\r
3 # Please note that these example shaders don't do anything really useful.
\r
4 # They only demonstrate that shaders can be used in Irrlicht.
\r
7 ATTRIB InPos = vertex.position;
\r
8 ATTRIB InColor = vertex.color;
\r
9 ATTRIB InNormal = vertex.normal;
\r
10 ATTRIB InTexCoord = vertex.texcoord;
\r
13 OUTPUT OutPos = result.position;
\r
14 OUTPUT OutColor = result.color;
\r
15 OUTPUT OutTexCoord = result.texcoord;
\r
17 PARAM MVP[4] = { state.matrix.mvp }; # modelViewProjection matrix.
\r
23 #transform position to clip space
\r
24 DP4 Temp.x, MVP[0], InPos;
\r
25 DP4 Temp.y, MVP[1], InPos;
\r
26 DP4 Temp.z, MVP[2], InPos;
\r
27 DP4 Temp.w, MVP[3], InPos;
\r
30 DP3 TempNormal.x, InNormal.x, program.local[0];
\r
31 DP3 TempNormal.y, InNormal.y, program.local[1];
\r
32 DP3 TempNormal.z, InNormal.z, program.local[2];
\r
35 DP3 TempNormal.w, TempNormal, TempNormal;
\r
36 RSQ TempNormal.w, TempNormal.w;
\r
37 MUL TempNormal, TempNormal, TempNormal.w;
\r
39 # calculate light vector
\r
40 DP4 TempPos.x, InPos, program.local[10]; # vertex into world position
\r
41 DP4 TempPos.y, InPos, program.local[11];
\r
42 DP4 TempPos.z, InPos, program.local[12];
\r
43 DP4 TempPos.w, InPos, program.local[13];
\r
45 ADD TempPos, program.local[8], -TempPos; # vtxpos - lightpos
\r
47 # normalize light vector
\r
48 DP3 TempPos.w, TempPos, TempPos;
\r
49 RSQ TempPos.w, TempPos.w;
\r
50 MUL TempPos, TempPos, TempPos.w;
\r
52 # calculate light color
\r
53 DP3 TempColor, TempNormal, TempPos; # dp3 with negative light vector
\r
54 LIT OutColor, TempColor; # clamp to zero if r3 < 0, r5 has diffuce component in r5.y
\r
55 MUL OutColor, TempColor.y, program.local[9]; # ouput diffuse color
\r
56 MOV OutColor.w, 1.0; # we want alpha to be always 1
\r
57 MOV OutTexCoord, InTexCoord; # store texture coordinate
\r