Changeset 1525 for GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs
- Timestamp:
- 09/28/06 11:21:44 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Diffuse.hlsl
r1519 r1525 3 3 float4 readCubeMap(samplerCUBE cm, float3 coord) 4 4 { 5 float4 color = texCUBE( cm, float3(coord.xy, - 5 float4 color = texCUBE( cm, float3(coord.xy, -coord.z) ); 6 6 color.a = 1; 7 7 return color; … … 48 48 /////////////////// 49 49 50 float4 GetContibution(float3 L, float3 pos, float3 N, float3 V, samplerCUBE SmallEnvMapSampler, samplerCUBE DistanceEnvMapSampler) // Phong-Blinn 51 // L: a hossza lényeges (az egységkocka faláig ér) 52 { 53 REDUCED_CUBEMAP_SIZE = 4; 50 float4 GetContibution(float3 L1, float3 L2, float3 L3, float3 L4, float3 pos, float3 N, samplerCUBE SmallEnvMapSampler, float d) 51 { 52 /* 53 L1 = readDistanceCubeMap(DistanceEnvMapSampler, L1) * normalize(L1); 54 L2 = readDistanceCubeMap(DistanceEnvMapSampler, L2) * normalize(L2); 55 L3 = readDistanceCubeMap(DistanceEnvMapSampler, L3) * normalize(L3); 56 L4 = readDistanceCubeMap(DistanceEnvMapSampler, L4) * normalize(L4); 57 */ 58 59 L1 = d * normalize(L1); 60 L2 = d * normalize(L2); 61 L3 = d * normalize(L3); 62 L4 = d * normalize(L4); 63 64 65 float3 r1 = normalize(L1 - pos); 66 float3 r2 = normalize(L2 - pos); 67 float3 r3 = normalize(L3 - pos); 68 float3 r4 = normalize(L4 - pos); 69 54 70 55 71 float kd = 0.3; // 0.3 56 float ks = 0.0; // 0.5 57 float shininess = 10; 58 59 float l = length(L); 60 L = normalize(L); 61 62 //dw 63 float dw = 4 / (REDUCED_CUBEMAP_SIZE*REDUCED_CUBEMAP_SIZE*l*l*l + 4/3.1416f); 64 //Lin 65 float4 Lin = readCubeMap(SmallEnvMapSampler, L); 66 //r 67 float doy = readDistanceCubeMap(DistanceEnvMapSampler, L); 68 float dxy = length(L * doy - pos); 69 70 //dws 71 float dws = (doy*doy * dw) / (dxy*dxy*(1 - dw/3.1416f) + doy*doy*dw/3.1416f); // localization: 72 //float dws = dw; 73 74 //L = L * doy - pos; // L: x->y, az objektumtól induljon, ne a középpontból 75 L = normalize(L); 76 float3 H = normalize(L + V); // felezõvektor 77 78 float a = kd * max(dot(N,L),0) + 79 ks * pow(max(dot(N,H),0), shininess); // diffuse + specular 80 81 // 1.: eddigi 82 //return Lin * a * dws; 83 84 float ctheta_in = dot(N,L); 85 float ctheta_out = dot(N,V); 86 87 return Lin * a * dws; 72 73 float tri1 = acos(dot(r1, r2)) * dot(cross(r1, r2), N); 74 float tri2 = acos(dot(r2, r3)) * dot(cross(r2, r3), N); 75 float tri3 = acos(dot(r3, r4)) * dot(cross(r3, r4), N); 76 float tri4 = acos(dot(r4, r1)) * dot(cross(r4, r1), N); 77 78 return max(tri1 + tri2 + tri3 + tri4, 0); 88 79 } 89 80 … … 122 113 { 123 114 REDUCED_CUBEMAP_SIZE = 4; 124 115 float width = 1.0 /REDUCED_CUBEMAP_SIZE; 116 125 117 //V = /*-*/normalize( V ); 126 118 float3 V = normalize(IN.wPos - cameraPos); // 127 119 float3 N = mul( float4(IN.mNormal,1), world_IT).xyz; 128 120 //float3 N = IN.mNormal; 129 121 N = normalize( N ); … … 132 124 133 125 float4 intens = 0; 134 //intens = readCubeMap(SmallEnvMapSampler, pos);126 //intens = readCubeMap(SmallEnvMapSampler, pos); 135 127 136 for (int x = 0; x < REDUCED_CUBEMAP_SIZE; x++) // az envmap minden texelére 137 for (int y = 0; y < REDUCED_CUBEMAP_SIZE; y++) 138 { 139 // intenzitás kiolvasása az adott texelbol 140 141 float2 p, tpos; 142 tpos.x = x/(float)REDUCED_CUBEMAP_SIZE; // 0..1 143 tpos.y = y/(float)REDUCED_CUBEMAP_SIZE; // 0..1 144 tpos.xy += float2(0.5/REDUCED_CUBEMAP_SIZE, 0.5/REDUCED_CUBEMAP_SIZE); // az adott texel középpont uv koordinátái 145 146 p.x = tpos.x; 147 p.y = 1-tpos.y; 148 p.xy = 2*p.xy - 1; // -1..1 // az adott texel középpont pozíciója 149 150 float3 L; 151 128 float3 L1, L2, L3, L4, L; 129 float4 Le; 130 float d; 131 132 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 133 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 134 { 135 float2 p, tpos; 136 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 137 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 138 139 p.x = tpos.x; 140 p.y = 1-tpos.y; 141 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 142 143 L1 = float3(p.x - width, p.y - width, 1); 144 L2 = float3(p.x + width, p.y - width, 1); 145 L3 = float3(p.x + width, p.y + width, 1); 146 L4 = float3(p.x - width, p.y + width, 1); 152 147 L = float3(p.x, p.y, 1); 153 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 154 148 Le = readCubeMap(SmallEnvMapSampler, L); 149 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 150 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 151 } 152 153 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 154 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 155 { 156 float2 p, tpos; 157 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 158 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 159 160 p.x = tpos.x; 161 p.y = 1-tpos.y; 162 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 163 164 L4 = float3(p.x - width, p.y - width, -1); 165 L3 = float3(p.x + width, p.y - width, -1); 166 L2 = float3(p.x + width, p.y + width, -1); 167 L1 = float3(p.x - width, p.y + width, -1); 155 168 L = float3(p.x, p.y, -1); 156 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 157 169 Le = readCubeMap(SmallEnvMapSampler, L); 170 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 171 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 172 } 173 174 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 175 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 176 { 177 float2 p, tpos; 178 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 179 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 180 181 p.x = tpos.x; 182 p.y = 1-tpos.y; 183 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 184 185 L4 = float3(p.x - width, 1, p.y - width); 186 L3 = float3(p.x + width, 1, p.y - width); 187 L2 = float3(p.x + width, 1, p.y + width); 188 L1 = float3(p.x - width, 1, p.y + width); 158 189 L = float3(p.x, 1, p.y); 159 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 160 190 Le = readCubeMap(SmallEnvMapSampler, L); 191 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 192 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 193 } 194 195 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 196 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 197 { 198 float2 p, tpos; 199 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 200 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 201 202 p.x = tpos.x; 203 p.y = 1-tpos.y; 204 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 205 206 L1 = float3(p.x - width, -1, p.y - width); 207 L2 = float3(p.x + width, -1, p.y - width); 208 L3 = float3(p.x + width, -1, p.y + width); 209 L4 = float3(p.x - width, -1, p.y + width); 161 210 L = float3(p.x, -1, p.y); 162 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 163 211 Le = readCubeMap(SmallEnvMapSampler, L); 212 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 213 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 214 } 215 216 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 217 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 218 { 219 float2 p, tpos; 220 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 221 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 222 223 p.x = tpos.x; 224 p.y = 1-tpos.y; 225 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 226 227 L1 = float3(1, p.x - width, p.y - width); 228 L2 = float3(1, p.x + width, p.y - width); 229 L3 = float3(1, p.x + width, p.y + width); 230 L4 = float3(1, p.x - width, p.y + width); 164 231 L = float3(1, p.x, p.y); 165 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 166 232 Le = readCubeMap(SmallEnvMapSampler, L); 233 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 234 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 235 } 236 237 for (int x = 0; x < REDUCED_CUBEMAP_SIZE - 1; x++) // az envmap minden texelére 238 for (int y = 0; y < REDUCED_CUBEMAP_SIZE - 1; y++) 239 { 240 float2 p, tpos; 241 tpos.x = (x + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 242 tpos.y = (y + 0.5) /(float)REDUCED_CUBEMAP_SIZE; // 0..1 243 244 p.x = tpos.x; 245 p.y = 1-tpos.y; 246 p.xy = 2 * p.xy - 1; // -1..1 // az adott texel középpont pozíciója 247 248 L4 = float3(-1, p.x - width, p.y - width); 249 L3 = float3(-1, p.x + width, p.y - width); 250 L2 = float3(-1, p.x + width, p.y + width); 251 L1 = float3(-1, p.x - width, p.y + width); 167 252 L = float3(-1, p.x, p.y); 168 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); 169 } 170 253 Le = readCubeMap(SmallEnvMapSampler, L); 254 d = readDistanceCubeMap(DistanceEnvMapSampler, L); 255 intens += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, SmallEnvMapSampler, d); 256 } 257 258 171 259 //return float4(pos, 1); 172 260 return intens; -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Localized_EnvMap.hlsl
r1487 r1525 362 362 363 363 float3 L; 364 364 365 365 L = float3(p.x, p.y, 1); 366 366 intens += GetContibution( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler); … … 382 382 } 383 383 384 return intens +0.0001*lastCenter.x;385 } 384 return intens; 385 }
Note: See TracChangeset
for help on using the changeset viewer.