.. | .. |
---|
206 | 206 | |
---|
207 | 207 | SetCamera(cam); |
---|
208 | 208 | |
---|
209 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 209 | + // Warning: not used. |
---|
| 210 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
210 | 211 | |
---|
211 | 212 | object = o; |
---|
212 | 213 | |
---|
.. | .. |
---|
12402 | 12403 | String program = |
---|
12403 | 12404 | // Min shader |
---|
12404 | 12405 | "!!ARBfp1.0\n" + |
---|
12405 | | - "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" + |
---|
| 12406 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
12406 | 12407 | "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
12407 | 12408 | "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
12408 | 12409 | "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
12409 | 12410 | "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12411 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12412 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12413 | + "PARAM light2cam2 = program.env[12];" + |
---|
12410 | 12414 | "TEMP temp;" + |
---|
12411 | 12415 | "TEMP light;" + |
---|
12412 | 12416 | "TEMP ndotl;" + |
---|
12413 | 12417 | "TEMP normal;" + |
---|
12414 | 12418 | "TEMP depth;" + |
---|
| 12419 | + "TEMP eye;" + |
---|
| 12420 | + "TEMP pos;" + |
---|
12415 | 12421 | |
---|
12416 | 12422 | "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
12417 | | - |
---|
| 12423 | + Normalize("normal") + |
---|
12418 | 12424 | "MOV light, state.light[0].position;" + |
---|
12419 | 12425 | "DP3 ndotl.x, light, normal;" + |
---|
12420 | 12426 | |
---|
12421 | 12427 | // shadow |
---|
12422 | | - "MOV temp, fragment.texcoord[1];" + |
---|
12423 | | - TextureFetch("depth", "temp", "1") + |
---|
| 12428 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12429 | + "MOV temp, pos;" + |
---|
| 12430 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
12424 | 12431 | //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
12425 | | - "SLT temp.x, fragment.texcoord[1].z, depth.z;" + |
---|
12426 | | - |
---|
| 12432 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
12427 | 12433 | |
---|
12428 | 12434 | // No shadow when out of frustum |
---|
12429 | 12435 | //"SGE temp.y, depth.z, zero123.y;" + |
---|
12430 | 12436 | //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
12431 | 12437 | |
---|
12432 | | - "MUL ndotl.x, ndotl.x, temp.x;" + |
---|
12433 | | - "MAX ndotl.x, ndotl.x, pow2.y;" + |
---|
| 12438 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
12434 | 12439 | |
---|
| 12440 | + // Backlit |
---|
| 12441 | + "MOV pos.w, zero123.y;" + |
---|
| 12442 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12443 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12444 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12445 | + Normalize("eye") + |
---|
| 12446 | + |
---|
| 12447 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12448 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12449 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12450 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12451 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12452 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12453 | + |
---|
| 12454 | + "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12455 | + |
---|
| 12456 | + // Pigment |
---|
12435 | 12457 | "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12436 | 12458 | "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
12437 | 12459 | "MUL temp, temp, ndotl.x;" + |
---|
12438 | 12460 | |
---|
12439 | 12461 | "MUL temp, temp, zero123.z;" + |
---|
12440 | 12462 | |
---|
12441 | | - "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12463 | + //"MUL temp, temp, ndotl.y;" + |
---|
12442 | 12464 | |
---|
| 12465 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
12443 | 12466 | "MOV result.color, temp;" + |
---|
12444 | 12467 | "END"; |
---|
12445 | 12468 | |
---|
.. | .. |
---|
12581 | 12604 | "MUL temp, floor, mapgrid.x;" + |
---|
12582 | 12605 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12583 | 12606 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12584 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12607 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12585 | 12608 | "") + |
---|
12586 | 12609 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12587 | 12610 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12588 | 12611 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12589 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12612 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12590 | 12613 | "") + |
---|
12591 | 12614 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12592 | 12615 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12593 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12616 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12594 | 12617 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12595 | 12618 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12596 | 12619 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12597 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12620 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12598 | 12621 | "") + |
---|
12599 | 12622 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12600 | 12623 | //"MOV params, material;" + |
---|
.. | .. |
---|
13392 | 13415 | return out; |
---|
13393 | 13416 | } |
---|
13394 | 13417 | |
---|
13395 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13418 | + // Also does frustum culling |
---|
| 13419 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13396 | 13420 | { |
---|
13397 | 13421 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13398 | 13422 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|