/*ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ*\ File: Program for shadow mapping Author: Magnus Högdahl Copyright: Starbreeze AB 2007 History: \*____________________________________________________________________________________________*/ *flags { *sample1x1 0x0001 *sample2x2 0x0002 *sample3x3 0x0004 *sample4x4 0x0008 } *generate { *gen sample1x1 *gen sample2x2 *gen sample3x3 *gen sample4x4 } *program { *do0 "!!ARBfp1.0 OPTION ARB_fragment_program_shadow; #----------------------------------------- OUTPUT oCol = result.color; ATTRIB v0 = fragment.color; ATTRIB tc0 = fragment.texcoord[0]; ATTRIB tc1 = fragment.texcoord[1]; ATTRIB tc2 = fragment.texcoord[2]; ATTRIB tc3 = fragment.texcoord[3]; PARAM VPParam = program.env[0]; # { F, B, 1/B, ... } PARAM VPConst = program.env[1]; # { 2B, B+F, 2BF, 2(B-F) } PARAM VPScale = program.env[2]; # { scale } PARAM V2SMat0 = program.env[3]; PARAM V2SMat1 = program.env[4]; PARAM V2SMat2 = program.env[5]; PARAM V2SMat3 = program.env[6]; PARAM VPParamSM = program.env[7]; PARAM VPConstSM = program.env[8]; @PARAM16 SMPixelUV = program.env[9]; # { scale } @PARAM16 const_val = { 1.0, 1.0, 1.0, 1.0 }; @PARAM16 const_val2 = { 0.5, 0.0005, 0.0, 0.0 }; PARAM const_depthdot = { 0.0039062502328306575316582639013686, 0.000015258789971994755983040093364721, 0.000000059604648328104515558750364705942, 0 }; @if platform_pc @PARAM16 const_vpmul = { 2, -2, 0, 0 }; @PARAM16 const_vpadd = { -1, 1, 0, 0 }; # PARAM const_smscale = { 0.001953125, 0.001953125, 0, 0 }; @else @PARAM16 const_vpmul = { 2, 2, 0, 0 }; @PARAM16 const_vpadd = { -1, -1, 0, 0 }; # PARAM const_smscale = { 0.001953125, -0.001953125, 0, 0 }; @endif " *if_sample2x2 " @PARAM16 const_smofs2x2_0 = { -0.5, -0.5, 0, 0 }; @PARAM16 const_smofs2x2_1 = { -0.5, 0.5, 0, 0 }; @PARAM16 const_smofs2x2_2 = { 0.5, -0.5, 0, 0 }; @PARAM16 const_smofs2x2_3 = { 0.5, 0.5, 0, 0 }; " *if_sample3x3 " @ifnot xenon @PARAM16 const_smofs3x3_0 = { -1.0, -1.0, 0, 0 }; @PARAM16 const_smofs3x3_1 = { 0.0, -1.0, 0, 0 }; @PARAM16 const_smofs3x3_2 = { 1.0, -1.0, 0, 0 }; @PARAM16 const_smofs3x3_3 = { -1.0, 0.0, 0, 0 }; @PARAM16 const_smofs3x3_4 = { 0.0, 0.0, 0, 0 }; @PARAM16 const_smofs3x3_5 = { 1.0, 0.0, 0, 0 }; @PARAM16 const_smofs3x3_6 = { -1.0, 1.0, 0, 0 }; @PARAM16 const_smofs3x3_7 = { 0.0, 1.0, 0, 0 }; @PARAM16 const_smofs3x3_8 = { 1.0, 1.0, 0, 0 }; @endif " *if_sample4x4 " @PARAM16 const_smofs4x4_0 = { -1.5, -1.5, 0, 0 }; @PARAM16 const_smofs4x4_1 = { -1.5, -0.5, 0, 0 }; @PARAM16 const_smofs4x4_2 = { -1.5, 0.5, 0, 0 }; @PARAM16 const_smofs4x4_3 = { -1.5, 1.5, 0, 0 }; @PARAM16 const_smofs4x4_4 = { -0.5, -1.5, 0, 0 }; @PARAM16 const_smofs4x4_5 = { -0.5, -0.5, 0, 0 }; @PARAM16 const_smofs4x4_6 = { -0.5, 0.5, 0, 0 }; @PARAM16 const_smofs4x4_7 = { -0.5, 1.5, 0, 0 }; @PARAM16 const_smofs4x4_8 = { 0.5, -1.5, 0, 0 }; @PARAM16 const_smofs4x4_9 = { 0.5, -0.5, 0, 0 }; @PARAM16 const_smofs4x4_10 = { 0.5, 0.5, 0, 0 }; @PARAM16 const_smofs4x4_11 = { 0.5, 1.5, 0, 0 }; @PARAM16 const_smofs4x4_12 = { 1.5, -1.5, 0, 0 }; @PARAM16 const_smofs4x4_13 = { 1.5, -0.5, 0, 0 }; @PARAM16 const_smofs4x4_14 = { 1.5, 0.5, 0, 0 }; @PARAM16 const_smofs4x4_15 = { 1.5, 1.5, 0, 0 }; " *do3 " @TEMP16 t0; @TEMP16 t1; TEMP r0; TEMP PixelPosV; # View space pixel position TEMP PixelPosSM; TEMP tc0p; #----------------------------------------- RCP tc0p.w, tc0.w; MUL tc0p, tc0, tc0p.w; TEX r0, tc0p, texture[1], 2D; #----------------------------------------- @if xenon SUB r0.a, const_val.w, r0.r; @else MAD r0, r0, 255, 0.5; FLR r0, r0; DP3 r0.a, r0, const_depthdot; MAD r0.a, r0.a, 2, -1; @endif # Convert depth to linear z MAD r0.y, r0.a, VPConst.w, -VPConst.x; RCP r0.y, r0.y; MUL PixelPosV.z, r0.y, -VPConst.z; MAD PixelPosV.xy, tc0p, const_vpmul, const_vpadd; MUL PixelPosV.x, PixelPosV, VPScale.z; MUL PixelPosV.y, PixelPosV, VPScale.w; MUL PixelPosV.xy, PixelPosV, PixelPosV.z; MOV PixelPosV.w, 1; DP4 PixelPosSM.x, PixelPosV, V2SMat0; DP4 PixelPosSM.y, PixelPosV, V2SMat1; DP4 PixelPosSM.z, PixelPosV, V2SMat2; DP4 PixelPosSM.w, PixelPosV, V2SMat3; KIL PixelPosSM.wwww; RCP PixelPosSM.w, PixelPosSM.w; MUL PixelPosSM.xyz, PixelPosSM, PixelPosSM.w; @ifnot platform_pc MUL PixelPosSM.y, PixelPosSM, -1; @endif ADD PixelPosSM.xy, PixelPosSM, 0.5; # MIN PixelPosSM.xy, PixelPosSM, 1; # MAX PixelPosSM.xy, PixelPosSM, 0; @if xenon SUB PixelPosSM.z, 1, PixelPosSM.z; @else MAD PixelPosSM.z, PixelPosSM.z, 0.5, 0.5; @endif " *if_sample1x1 " @if xenon TEX t0.x, PixelPosSM, texture[0], PCF2X22D; @else TEX t0.x, PixelPosSM, texture[0], SHADOW2D; @endif " *if_sample2x2 " @if xenon TEX t0.x, PixelPosSM, texture[0], PCF2X22D; @else MAD r0.xyzw, SMPixelUV, const_smofs2x2_0, PixelPosSM; TEX t0.x, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs2x2_1, PixelPosSM; TEX t0.y, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs2x2_2, PixelPosSM; TEX t0.z, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs2x2_3, PixelPosSM; TEX t0.w, r0, texture[0], SHADOW2D; DP4_SAT t0.x, t0, 0.25; @endif " *if_sample3x3 " @if xenon TEX t0.x, PixelPosSM, texture[0], PCF3X32D; @else MAD r0.xyzw, SMPixelUV, const_smofs3x3_0, PixelPosSM; TEX t0.x, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs3x3_1, PixelPosSM; TEX t0.y, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs3x3_2, PixelPosSM; TEX t0.z, r0, texture[0], SHADOW2D; DP3 t1.x, t0, 1.0; MAD r0.xyzw, SMPixelUV, const_smofs3x3_3, PixelPosSM; TEX t0.x, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs3x3_4, PixelPosSM; TEX t0.y, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs3x3_5, PixelPosSM; TEX t0.z, r0, texture[0], SHADOW2D; DP3 t1.y, t0, 1.0; MAD r0.xyzw, SMPixelUV, const_smofs3x3_6, PixelPosSM; TEX t0.x, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs3x3_7, PixelPosSM; TEX t0.y, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs3x3_8, PixelPosSM; TEX t0.z, r0, texture[0], SHADOW2D; DP3 t1.z, t0, 1.0; DP3_SAT t0.x, t1, 0.11111111111111111111111111111111; @endif " *if_sample4x4 " @if xenon TEX t0.x, PixelPosSM, texture[0], PCF4X42D; @else MAD r0.xyzw, SMPixelUV, const_smofs4x4_0, PixelPosSM; TEX t0.x, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_1, PixelPosSM; TEX t0.y, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_2, PixelPosSM; TEX t0.z, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_3, PixelPosSM; TEX t0.w, r0, texture[0], SHADOW2D; DP4 t1.x, t0, 1.0; MAD r0.xyzw, SMPixelUV, const_smofs4x4_4, PixelPosSM; TEX t0.x, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_5, PixelPosSM; TEX t0.y, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_6, PixelPosSM; TEX t0.z, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_7, PixelPosSM; TEX t0.w, r0, texture[0], SHADOW2D; DP4 t1.y, t0, 1.0; MAD r0.xyzw, SMPixelUV, const_smofs4x4_8, PixelPosSM; TEX t0.x, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_9, PixelPosSM; TEX t0.y, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_10, PixelPosSM; TEX t0.z, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_11, PixelPosSM; TEX t0.w, r0, texture[0], SHADOW2D; DP4 t1.z, t0, 1.0; MAD r0.xyzw, SMPixelUV, const_smofs4x4_12, PixelPosSM; TEX t0.x, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_13, PixelPosSM; TEX t0.y, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_14, PixelPosSM; TEX t0.z, r0, texture[0], SHADOW2D; MAD r0.xyzw, SMPixelUV, const_smofs4x4_15, PixelPosSM; TEX t0.w, r0, texture[0], SHADOW2D; DP4 t1.w, t0, 1.0; DP4_SAT t0.x, t1, 0.0625; @endif " *do5 " @ifnot xenon SUB t0.x, 1, t0.x; @endif MOV t0.gba, 0; SUB t0.a, 1, t0.r; MOV oCol, t0; END " }