!!ARBfp1.0 #/*ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ*\ # File: Program for CXR_Shader::RenderShading_FP20 # # Author: Magnus Högdahl # # Copyright: Starbreeze AB 2004 # # History: # #\*____________________________________________________________________________________________*/ #----------------------------------------- #Texture0 = Diffuse Map #Texture1 = Specular map #Texture2 = Normal map #Texture3 = Normalization cube Map #Texture4 = Projection Map #TexCoord0 = Diffuse/Normal/Specular tex coord #TexCoord1 = Animated model space pixel position #TexCoord3 = Interpolated tangent space light vector (IPTSLV) #TexCoord4 = Interpolated tangent space eye vector (IPTSEV) #TexCoord7 = ProjMap tex coord #----------------------------------------- OUTPUT oCol = result.color; ATTRIB vCol = fragment.color; ATTRIB TexCoord = fragment.texcoord[0]; ATTRIB PixelPosition = fragment.texcoord[1]; ATTRIB IPTSLV = fragment.texcoord[3]; ATTRIB IPTSEV = fragment.texcoord[4]; #ATTRIB ProjMapTexCoord = fragment.texcoord[7]; PARAM LightPosition = program.env[0]; # { X, Y, Z, 0 } PARAM LightRange = program.env[1]; # { 1.0 / Range, Range, 1.0 / Range^2, Range^2 } PARAM LightColor = program.env[2]; # { R, G, B, 0 } (0-2 range) PARAM SpecColor1 = program.env[3]; # { R, G, B, SpecPower } (0-2 range) PARAM const_val = { 0.5, 1.0, 2.0, 4.0 }; PARAM const_val2 = { 0, 0.25, 4, 0 }; TEMP DiffuseTexel; TEMP SpecularTexel; TEMP NormalMapTexel; TEMP TSLV; # Tangent space light vector TEMP TSEV; # Tangent space eye vector TEMP Reflection; TEMP r0; TEMP r1; #----------------------------------------- # Attenuation SUB r1, LightPosition, PixelPosition; DP3 r1.w, r1, r1; MUL_SAT r1.w, r1.w, LightRange.z; ADD r1.w, const_val.g, -r1.w; MUL r1.w, r1.w, r1.w; #----------------------------------------- # Normalize TSLV @if support_normalize NRM TSLV.xyz, IPTSLV.xyz; @else DP3 TSLV.a, IPTSLV, IPTSLV; RSQ TSLV.a, TSLV.a; MUL TSLV.xyz, IPTSLV, TSLV.a; @endif #----------------------------------------- # Self shadowing SUB r0.a, const_val2.y, -TSLV.x; MUL_SAT r0.a, r0.a, const_val2.z; MUL r1.w, r1.w, r0.a; #----------------------------------------- # Cull #SUB r1.w, r1.w, 0.00001; #KIL r1.w; #MOV oCol, const_val; #----------------------------------------- # Fetch Textures @if dynmip TEXDYN DiffuseTexel, TexCoord, texture[0], 2D; # Sample diffusemap TEXDYN SpecularTexel, TexCoord, texture[1], 2D; # Sample diffusemap TEXDYN NormalMapTexel, TexCoord, texture[2], 2D; # Sample normalmap @else TEX DiffuseTexel, TexCoord, texture[0], 2D; # Sample diffusemap TEX SpecularTexel, TexCoord, texture[1], 2D; # Sample diffusemap TEX NormalMapTexel, TexCoord, texture[2], 2D; # Sample normalmap @endif #----------------------------------------- # Reconstruct normal from g,b components MAD NormalMapTexel.rgba, NormalMapTexel, const_val.b, -const_val.g;# Bias and scale the normalmap texel (only rgb) (from 0->1, -1->1) SWZ NormalMapTexel.rgb, NormalMapTexel, 0, a, g, 0; DP3 NormalMapTexel.r, NormalMapTexel, NormalMapTexel; # r = g^2 + b^2 SUB NormalMapTexel.r, const_val.y, NormalMapTexel.r; # r = 1 - r; RSQ NormalMapTexel.r, NormalMapTexel.r; # r = 1/sqrt(r) RCP NormalMapTexel.r, NormalMapTexel.r; # r = 1/r = sqrt(1 - g^2 - b^2) #----------------------------------------- # Normalize TSEV @if support_normalize NRM TSEV.xyz, IPTSEV.xyz; @else DP3 TSEV.a, IPTSEV, IPTSEV; RSQ TSEV.a, TSEV.a; MUL TSEV.xyz, IPTSEV, TSEV.a; @endif #----------------------------------------- # Calc reflection vector DP3 r0.a, NormalMapTexel, TSEV; ADD r0.a, r0.a, r0.a; MAD Reflection.xyz, NormalMapTexel, r0.a, -TSEV; #----------------------------------------- # Diffuse MUL r1.rgb, LightColor, DiffuseTexel; # Multiply diffusemap with light color DP3_SAT r0.rgb, NormalMapTexel, TSLV; MUL r0.rgb, r0, r1; # Diffuse color * Diffuse dotprod #----------------------------------------- # Specular MUL SpecularTexel.rgb, SpecularTexel, SpecColor1; DP3_SAT r1.x, TSLV, Reflection; POW r1.x, r1.x, SpecColor1.a; MAD r0.rgb, r1.x, SpecularTexel, r0; # Mul specular with specular map #----------------------------------------- MUL r0.rgb, r0, r1.w; # Multiply final fragment by attenuation+projmap #MOV r0.rgb, r1.w; #MOV r0, { 0.25,0,0,0 }; # Write result MOV oCol, r0; END