!!ARBfp1.0 OPTION ARB_precision_hint_fastest; #----------------------------------- # # EffectSystem Shader Object: # # All effect systems shaders has predefines reserved in # program.env[0 - 2]. Some of the predefines can be controled # by setting flags in the effect object such as no animation etc. # # # Reserved texture coordinates: # texcoord[1] Generated coords for screen space calc. # # Texture coordinates: # texcoord[0] Object texture coordinates # # Textures: # texture[0] Framebuffer # texture[1] Distortion map # texture[2] Mask # # Predefines program parameters: # program.env[0] { 1/ScrW, 1/ScrH, (ScrW-1)/ScrTexW, (ScrH-1)/ScrTexH } # program.env[1] { MinX, MinY, MaxX, MaxY } # program.env[2] { Time, FrontPlane, BackPlane, SysFade } # # Register controled parameters: # program.env[3] { Speed, Frequency, _, _ } # #----------------------------------- OUTPUT oCol = result.color; # Texture coordinates ATTRIB tc0 = fragment.texcoord[0]; ATTRIB tc1 = fragment.texcoord[1]; # Predefines PARAM c0 = program.env[0]; PARAM c1 = program.env[1]; PARAM c2 = program.env[2]; PARAM c3 = program.env[3]; PARAM c4 = program.env[4]; # Program parameters PARAM p0 = program.env[5]; # { Speed, Frequency, Max, Min } PARAM p1 = program.env[6]; # { 1/BlendValue, _, _, _ } # Constants PARAM const_val0 = { 0, 0.5, 1, 2 }; # Used (xyzw) PARAM const_val1 = { 0.99609375, 0.00390625, 0, 0 }; # Used (xy__) # Registers TEMP t0; TEMP t2; TEMP t3; TEMP r0; TEMP r1; TEMP r2; TEMP r3; TEMP r4; TEMP r5; TEMP r6; #------------------------------------------------ # Calculate screen texcoord in 0-1 range RCP r0.w, tc1.w; MUL r0.xyz, tc1, r0.w; @if xenon #MOV r6.w, r0.z; MAD r0.xyz, r0.xyzw, c0.xyzw, const_val0.yyxx; @else MAD r0, r0.xyzw, c0.xyzw, const_val0.yyxx; @endif # Create vector 1,0,tc1.z,1 MAD r2, const_val0.xxzx, tc1.zzzz, const_val0.zxxz; DP4 r3, r2, c3; DP4 r4, r2, c4; MAX r4, r4, p0.z; RCP r4, r4.w; MUL r3, r3, r4; MIN r3, r3, p0.w; MUL r3, r3, p0.y; # Load normal map, mask and depth mask texel TEX r1, tc0, texture[1], 2D; # Normal map texel TEX t2, tc0, texture[2], 2D; # Mask texel TEX t3, r0, texture[3], 2D; # Depth mask texel # Reconstruct normal from b,g component MAD r1.rgba, r1, const_val0.w, -const_val0.z; SWZ r1.rgb, r1, 0, a, r, 0; DP3 r1.r, r1, r1; SUB r1.r, const_val0.z, r1.r; RSQ r1.r, r1.r; RCP r1.r, r1.r; # Apply fade scale MUL r1, r1, c2.wwww; # Apply mask #TEX t2, tc0, texture[2], 2D; MUL r1, r1, t2.xxxx; # Apply depth mask @if xenon @else # Calc raw depth value MUL t3.rgb, t3, const_val1.xxxx; MAD t3.a, t3.g, const_val1.y, t3.r; @endif # Move these calculations to parameters perhaps? SUB r6.x, c2.z, c2.y; # BackPlane - FrontPlane MUL r6.z, c2.z, c2.y; # BackPlane * FrontPlane # Convert depth buffer to z @if xenon SUB t3.w, const_val0.y, t3.x; @endif MAD r2.x, t3.a, r6.x, -c2.z; RCP r2.y, -r2.x; MUL r2.z, r2.y, r6.z; # Convert fragment to z RCP r5.y, tc1.w; MUL r5.y, r5.y, tc1.z; @if xenon MAD r5.z, r5.y, r6.x, -c2.z; RCP r5.z, -r5.z; MUL r5.w, r5.z, r6.z; @else MAD r5.y, r5.y, const_val0.y, const_val0.y; MAD r5.y, r5.y, r6.x, -c2.z; RCP r5.z, -r5.y; MAD r5.w, r5.z, r6.z, -const_val1.y; @endif # Calculate z difference SUB r2.w, r2.z, r5.w; # Make sure z difference is positive and linearly interpolate it between 0 and "radius" ABS r4.x, r2.w; # MAX r4.x, r2.w, const_val0.x; MUL_SAT r4.x, r4.x, p1.x; MUL r1, r1, r4.xxxx; # End apply depth mask # Offset MAD_SAT r0, r1, r3, r0; # Clamp inside framebuffer coordinates LRP r0.xy, r0.xyxy, c1.zwxy, c1.xyzw; # Load final texel TEX t0, r0, texture[0], 2D; MOV oCol, t0; MOV oCol.a, const_val0.z; # Debug color #;MAD oCol, r0, const_val0.zzxx, const_val0.xxxz; #;MOV oCol.rgba, const_val0.zxxz; END #------------------------------------------------