1 |
|
---|
2 |
|
---|
3 | struct vertOUT
|
---|
4 | {
|
---|
5 | float4 hPos :POSITION;
|
---|
6 | float4 hPosition :TEXCOORD4;
|
---|
7 | float3 wPos :TEXCOORD1;
|
---|
8 | float2 texCoord :TEXCOORD0;
|
---|
9 | float3 mNormal :TEXCOORD2;
|
---|
10 | };
|
---|
11 |
|
---|
12 | vertOUT PhongVS(float4 position : POSITION,
|
---|
13 | float3 normal : NORMAL,
|
---|
14 | half3 tangent : TEXCOORD1,
|
---|
15 | float2 texCoord : TEXCOORD0,
|
---|
16 | uniform float4x4 worldViewProj,
|
---|
17 | uniform float4x4 world)
|
---|
18 | {
|
---|
19 | vertOUT OUT;
|
---|
20 | OUT.hPos = OUT.hPosition = mul(worldViewProj, position);
|
---|
21 | OUT.wPos = mul(world, position).xyz;
|
---|
22 | OUT.mNormal = mul(world, normal);
|
---|
23 | //OUT.mNormal = normal;
|
---|
24 | OUT.texCoord = texCoord;
|
---|
25 | return OUT;
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 | float4 PhongPS( vertOUT IN,
|
---|
31 | uniform float3 cameraPos,
|
---|
32 | uniform float3 lightpos1,
|
---|
33 | uniform float3 lightpos2,
|
---|
34 | uniform float3 lightpos3,
|
---|
35 | uniform float3 lightpos4,
|
---|
36 | uniform float3 lightpos5,
|
---|
37 | uniform float3 lightpos6,
|
---|
38 | uniform float3 lightpos7,
|
---|
39 | uniform float3 lightpos8,
|
---|
40 | uniform float4 lightcol1,
|
---|
41 | uniform float4 lightcol2,
|
---|
42 | uniform float4 lightcol3,
|
---|
43 | uniform float4 lightcol4,
|
---|
44 | uniform float4 lightcol5,
|
---|
45 | uniform float4 lightcol6,
|
---|
46 | uniform float4 lightcol7,
|
---|
47 | uniform float4 lightcol8,
|
---|
48 | uniform float4 ambientLight,
|
---|
49 | uniform float shininess,
|
---|
50 | uniform float4 specular,
|
---|
51 | uniform float4 diffuse,
|
---|
52 | uniform float4 ambient
|
---|
53 |
|
---|
54 | ) : COLOR0
|
---|
55 | {
|
---|
56 |
|
---|
57 |
|
---|
58 | float3 N = IN.mNormal;
|
---|
59 | N = normalize( N );
|
---|
60 | float3 pos = IN.wPos;
|
---|
61 |
|
---|
62 | float M = 1;
|
---|
63 |
|
---|
64 | float3 lightpositions[8];
|
---|
65 | float4 lightcolors[8];
|
---|
66 |
|
---|
67 | lightpositions[0] = lightpos1;
|
---|
68 | lightpositions[1] = lightpos2;
|
---|
69 | lightpositions[2] = lightpos3;
|
---|
70 | lightpositions[3] = lightpos4;
|
---|
71 | lightpositions[4] = lightpos5;
|
---|
72 | lightpositions[5] = lightpos6;
|
---|
73 | lightpositions[6] = lightpos7;
|
---|
74 | lightpositions[7] = lightpos8;
|
---|
75 |
|
---|
76 | lightcolors[0] = lightcol1;
|
---|
77 | lightcolors[1] = lightcol2;
|
---|
78 | lightcolors[2] = lightcol3;
|
---|
79 | lightcolors[3] = lightcol4;
|
---|
80 | lightcolors[4] = lightcol5;
|
---|
81 | lightcolors[5] = lightcol6;
|
---|
82 | lightcolors[6] = lightcol7;
|
---|
83 | lightcolors[7] = lightcol8;
|
---|
84 |
|
---|
85 | float4 I = ambientLight * ambient;
|
---|
86 |
|
---|
87 | for(int i=0; i< M; i++)
|
---|
88 | {
|
---|
89 | float3 V = normalize(cameraPos - pos);
|
---|
90 | float3 L = lightpositions[i] - pos;
|
---|
91 | float d = length(L);
|
---|
92 | L = normalize(L);
|
---|
93 | float3 H = normalize(L + V);
|
---|
94 | float lightscale = 1.0;
|
---|
95 | float4 spec = specular * lightcolors[i] * pow(dot(H, N), shininess) * lightscale;
|
---|
96 | float4 diff = diffuse * lightcolors[i] * abs(dot(L, N)) * lightscale;
|
---|
97 | float range = 4.0;
|
---|
98 | I += 1.0 / d * (spec + diff);
|
---|
99 | }
|
---|
100 |
|
---|
101 | //return 1;
|
---|
102 | return I;
|
---|
103 |
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | float4 PhongPlaneReflectPS( vertOUT IN,
|
---|
108 | uniform float3 cameraPos,
|
---|
109 | uniform float3 lightpos1,
|
---|
110 | uniform float3 lightpos2,
|
---|
111 | uniform float3 lightpos3,
|
---|
112 | uniform float3 lightpos4,
|
---|
113 | uniform float3 lightpos5,
|
---|
114 | uniform float3 lightpos6,
|
---|
115 | uniform float3 lightpos7,
|
---|
116 | uniform float3 lightpos8,
|
---|
117 | uniform float4 lightcol1,
|
---|
118 | uniform float4 lightcol2,
|
---|
119 | uniform float4 lightcol3,
|
---|
120 | uniform float4 lightcol4,
|
---|
121 | uniform float4 lightcol5,
|
---|
122 | uniform float4 lightcol6,
|
---|
123 | uniform float4 lightcol7,
|
---|
124 | uniform float4 lightcol8,
|
---|
125 | uniform float4 ambientLight,
|
---|
126 | uniform float shininess,
|
---|
127 | uniform float4 specular,
|
---|
128 | uniform float4 diffuse,
|
---|
129 | uniform float4 ambient,
|
---|
130 | uniform sampler2D reflectionTex,
|
---|
131 | uniform float reflectionAmount
|
---|
132 |
|
---|
133 | ) : COLOR0
|
---|
134 | {
|
---|
135 |
|
---|
136 |
|
---|
137 | float3 N = IN.mNormal;
|
---|
138 | N = normalize( N );
|
---|
139 | float3 pos = IN.wPos;
|
---|
140 |
|
---|
141 | float M = 4;
|
---|
142 |
|
---|
143 | float3 lightpositions[8];
|
---|
144 | float4 lightcolors[8];
|
---|
145 |
|
---|
146 | lightpositions[0] = lightpos1;
|
---|
147 | lightpositions[1] = lightpos2;
|
---|
148 | lightpositions[2] = lightpos3;
|
---|
149 | lightpositions[3] = lightpos4;
|
---|
150 | lightpositions[4] = lightpos5;
|
---|
151 | lightpositions[5] = lightpos6;
|
---|
152 | lightpositions[6] = lightpos7;
|
---|
153 | lightpositions[7] = lightpos8;
|
---|
154 |
|
---|
155 | lightcolors[0] = lightcol1;
|
---|
156 | lightcolors[1] = lightcol2;
|
---|
157 | lightcolors[2] = lightcol3;
|
---|
158 | lightcolors[3] = lightcol4;
|
---|
159 | lightcolors[4] = lightcol5;
|
---|
160 | lightcolors[5] = lightcol6;
|
---|
161 | lightcolors[6] = lightcol7;
|
---|
162 | lightcolors[7] = lightcol8;
|
---|
163 |
|
---|
164 | float4 I = ambientLight * ambient;
|
---|
165 |
|
---|
166 | for(int i=0; i< M; i++)
|
---|
167 | {
|
---|
168 | float3 V = normalize(cameraPos - pos);
|
---|
169 | float3 L = lightpositions[i] - pos;
|
---|
170 | float d = length(L);
|
---|
171 | L = normalize(L);
|
---|
172 | float3 H = normalize(L + V);
|
---|
173 | float lightscale = 3;
|
---|
174 | float4 spec = specular * lightcolors[i] * pow(dot(H, N), shininess) * lightscale;
|
---|
175 | float4 diff = diffuse * lightcolors[i] * abs(dot(L, N)) * lightscale;
|
---|
176 | float range = 4.0;
|
---|
177 | I += 1.0 / d * (spec + diff);
|
---|
178 | }
|
---|
179 |
|
---|
180 | float2 uv = (IN.hPosition.xy/IN.hPosition.w + 1.0) * 0.5;
|
---|
181 | uv.y = 1.0 - uv.y;
|
---|
182 | float4 reflection = tex2D(reflectionTex, uv);
|
---|
183 | I *= reflectionAmount * reflection + (1 - reflectionAmount);
|
---|
184 |
|
---|
185 | //I = reflection;
|
---|
186 | //return 1;
|
---|
187 | return I;
|
---|
188 |
|
---|
189 | }
|
---|