home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GameStar 2005 February
/
Gamestar_70_2005-02_dvd.iso
/
DVDStar
/
Editace
/
ogierinstall_103.exe
/
XRShader_FP20_NDSEATP_DV.fp
< prev
next >
Wrap
Text File
|
2004-12-21
|
9KB
|
280 lines
!!ARBfp1.0
#/*»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*\
# File: Program for CXR_Shader::RenderShading_FP20
#
# Author: Magnus H÷gdahl
#
# Copyright: Starbreeze AB 2004
#
# History:
#
#\*____________________________________________________________________________________________*/
# LightIntensity = ((Diffuse.rgb + FresnelFactor * Specular.rgb) * SilkFactor + Transmission.rgb) * DistanceAttenuation * Projection
# Diffuse = DiffuseMap.rgb * DiffuseColor.rgb * Max(0, N*L)
# Specular = SpecularMap.rgb * SpecColor.rgb * (Max(0, H*N)^(SpecularMap.a * SpecColor.a) + Environment);
# Environment = EnvironmentMap.rgb * EnvColor.rgb * Max(0, N*L)
# Transmission = TransmissionMap.rgb * (TransmissionMap.a * Max(0, -N*L) + AttribMap.a * (1 - Abs(L*N - HSCenter))^HSExp )
# FresnelFactor = (1 - AttribMap.r) + AttribMap.r * (1 - H*V)^5
# SilkFactor = (1 - AttribMap.g) + AttribMap.g*(1 - V*N);
# Projection = DistanceAttenuation * ProjectionMap1.rgb + (1 - DistanceAttenuation) * ProjectionMap2.rgb
# DistanceAttenuation = (1 - |LightPos - PixelPos| / LightRange^2)^2
# N = Normal
# L = Light vector
# H = Half angle vector
# V = Eye vector
#-----------------------------------------
# Texture0 = Diffuse Map // Default = 1,1,1,1
# Texture1 = Specular Map // Default = 1,1,1,1
# Texture2 = Normal map // Default = 1, 0.5, 0.5
# Texture3 = Attribute Map // r = Fresnel, g = Silkness, b = ?, a = ?, Default = 0,0,0,0
# Texture4 = Transmission Diffuse Map // Default = 0,0,0,0
# Texture5 = Projection Map 1 // Default = 1,1,1
# Texture6 = Projection Map 2 // Default = 1,1,1
# Texture7 = Environment Map // Default = 0,0,0
#-----------------------------------------
# TexCoord0 = Mapping tex coord
# TexCoord1 = Animated model space pixel position
# TexCoord2 = Interpolated tangent space light vector (IPTSLV)
# TexCoord3 = Interpolated tangent space eye vector (IPTSEV)
# TexCoord4 = ProjMap tex coord
# TexCoord5 = Tangentspace-2-world transform, row 0
# TexCoord6 = Tangentspace-2-world transform, row 1
# TexCoord7 = Tangentspace-2-world transform, row 2
#-----------------------------------------
OUTPUT oCol = result.color;
ATTRIB vCol = fragment.color;
ATTRIB MappingTexCoord = fragment.texcoord[0];
ATTRIB PixelPosition = fragment.texcoord[1];
ATTRIB IPTSLV = fragment.texcoord[2];
ATTRIB IPTSEV = fragment.texcoord[3];
ATTRIB ProjMapTexCoord = fragment.texcoord[4];
ATTRIB TS2W_Mat_0 = fragment.texcoord[5];
ATTRIB TS2W_Mat_1 = fragment.texcoord[6];
ATTRIB TS2W_Mat_2 = 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 SpecColor = program.env[3]; # { R, G, B, SpecPower } (0-2 range)
PARAM AttribScale = program.env[4];
PARAM EnvMapColor = program.env[5];
PARAM NoiseOffset = program.env[6];
PARAM const_val = { 0.5, 1.0, 2.0, 4.0 };
PARAM const_val2 = { 0, 0.25, 4, 0 };
TEMP DiffuseTexel;
TEMP SpecularTexel;
TEMP ProjMapTexel1;
TEMP ProjMapTexel2;
TEMP NormalMapTexel;
TEMP AttribTexel;
TEMP TransmissionTexel;
TEMP EnvMapTexel;
TEMP TSLV; # Tangent space light vector
TEMP TSEV; # Tangent space eye vector
TEMP H;
TEMP R;
TEMP r0;
TEMP r1;
TEMP r2;
TEMP Attenuation;
TEMP Noise;
TEMP F;
TEMP u; # u = H * TSEV
TEMP t; # t = H * N
TEMP v; # v = TSEV * N
TEMP v_nosat;
TEMP l; # l = TSLV * N
TEMP lt;
#-----------------------------------------
# Fetch Textures
TEX DiffuseTexel, MappingTexCoord, texture[0], 2D; # Sample diffusemap
TEX SpecularTexel, MappingTexCoord, texture[1], 2D; # Sample diffusemap
TEX NormalMapTexel, MappingTexCoord, texture[2], 2D; # Sample normalmap
TEX AttribTexel, MappingTexCoord, texture[3], 2D;
TEX TransmissionTexel, MappingTexCoord, texture[4], 2D;
TEX ProjMapTexel1, ProjMapTexCoord, texture[5], CUBE;
TEX ProjMapTexel2, ProjMapTexCoord, texture[6], CUBE;
#TEX TSLV, IPTSLV, texture[3], CUBE; # Normalize TSLV
#TEX TSEV, IPTSEV, texture[3], CUBE; # Normalize TSLV
#MAD TSLV.rgb, TSLV, const_val.b, -const_val.g;# Bias and scale the normalmap texel (only rgb) (from 0->1, -1->1)
#MAD TSEV.rgb, TSEV, const_val.b, -const_val.g;# Bias and scale the normalmap texel (only rgb) (from 0->1, -1->1)
#MAD NormalMapTexel.rgb, NormalMapTexel, const_val.b, -const_val.g;# Bias and scale the normalmap texel (only rgb) (from 0->1, -1->1)
#TEX NormalMapTexel.rgb, NormalMapTexel, texture[3], CUBE; # Normalize normal
#MAD NormalMapTexel.rgb, NormalMapTexel, const_val.b, -const_val.g;# Bias and scale the normalmap texel (only rgb) (from 0->1, -1->1)
MUL AttribTexel.rgba, AttribTexel, AttribScale;
#-----------------------------------------
# Attenuation
SUB r1, LightPosition, PixelPosition;
DP3 r1.w, r1, r1;
#DP3 r1.w, IPTSLV, IPTSLV;
MUL_SAT r1.w, r1.w, LightRange.z;
ADD r1.w, const_val.g, -r1.w;
MUL Attenuation.w, r1.w, r1.w;
#-----------------------------------------
# Noise function
MUL r2, PixelPosition, 0.00125;
SWZ r1, r2, x, y, 0, 0;
ADD r1, r1, NoiseOffset.x;
TEX r0, r1, texture[9], 2D; # Sample rand map
SWZ r1, r2, y, z, 0, 0;
ADD r1, r1, NoiseOffset.y;
TEX r1, r1, texture[9], 2D; # Sample rand map
ADD r0.rgb, r1, r0;
SWZ r1, r2, z, x, 0, 0;
ADD r1, r1, -NoiseOffset.z;
TEX r1, r1, texture[9], 2D; # Sample rand map
ADD r0.rgb, r1, r0;
#MUL Noise.rgb, r0, 1;
#MUL r0.y, r0.x, 0.25;
#TEX r1, r0, texture[9], 2D; # Sample rand map
TEX r0, r0, texture[9], 2D; # Sample rand map
MUL_SAT r1.x, r0.g, r0.g;
MUL r0.b, r0.g, 2;
MUL r0.r, r0.r, r0.r;
MUL r0.g, r0.g, r0.g;
MUL r0.r, r0.r, 0.5;
MUL r1.x, r1.x, r1.x;
ADD r0.r, r0.r, r1.x;
SWZ r0.rgb, r0, b, g, r, 0;
#MOV r0.b, r1.x;
#MOV r0.g, r1.x;
MUL Noise.rgb, r0, 0.75;
#LRP Noise.rgb, Noise, 1, 0.5;
#-----------------------------------------
# Normalize normal
MAD NormalMapTexel.rgb, NormalMapTexel, const_val.b, -const_val.g;# Bias and scale the normalmap texel (only rgb) (from 0->1, -1->1)
DP3 r0.a, NormalMapTexel, NormalMapTexel;
RSQ r0.a, r0.a;
MUL NormalMapTexel.rgb, NormalMapTexel, r0.a;
#-----------------------------------------
# Normalize TSLV
DP3 TSLV.a, IPTSLV, IPTSLV;
RSQ TSLV.a, TSLV.a;
MUL TSLV.xyz, IPTSLV, TSLV.a;
#-----------------------------------------
# Normalize TSEV
DP3 TSEV.a, IPTSEV, IPTSEV;
RSQ TSEV.a, TSEV.a;
MUL TSEV.xyz, IPTSEV, TSEV.a;
#-----------------------------------------
# Calc halfangle vector
ADD H.xyz, TSEV, TSLV;
DP3 H.a, H, H;
RSQ H.a, H.a;
MUL H.xyz, H, H.a;
#-----------------------------------------
DP3_SAT u.a, H, TSEV;
DP3_SAT t.a, H, NormalMapTexel;
DP3 v_nosat.a, TSEV, NormalMapTexel;
DP3_SAT l.a, TSLV, NormalMapTexel;
DP3_SAT lt.a, TSLV, -NormalMapTexel;
MOV_SAT v.a, v_nosat.a;
#-----------------------------------------
# Calc reflection vector
ADD r0.a, v_nosat.a, v_nosat.a;
MAD R.xyz, NormalMapTexel, r0.a, -TSEV;
#-----------------------------------------
# Environment mapping
DP3 r0.r, R, TS2W_Mat_0; # Transform reflection vector to world space
DP3 r0.g, R, TS2W_Mat_1;
DP3 r0.b, R, TS2W_Mat_2;
TEX EnvMapTexel, r0, texture[7], CUBE;
#-----------------------------------------
# Self shadowing
SUB r0.a, const_val2.y, -TSLV.x;
MUL_SAT Attenuation.r, r0.a, const_val2.z;
#-----------------------------------------
# Fresnel
# MOV AttribTexel.r, 0.0;
SUB_SAT r0.a, 1, u.a;
MUL r0.r, r0.a, r0.a;
#MUL r0.r, r0.r, r0.r;
#MUL r0.a, r0.r, r0.a;
LRP F.a, AttribTexel.r, r0.r, 1;
#-----------------------------------------
# Silkness factor
SUB r0.a, 1, v.a;
LRP r0.a, AttribTexel.g, r0.a, 1;
MUL Attenuation.r, Attenuation.r, r0.a;
#-----------------------------------------
# Diffuse
MUL r1.rgb, LightColor, DiffuseTexel; # Multiply diffusemap with light color
MUL r1.rgb, r1, const_val.b; # Scale by 2 for correct brightness
MUL r0.rgb, l.a, r1; # Diffuse color * Diffuse dotprod
#-----------------------------------------
# Specular + EnvMap
MUL SpecularTexel.a, SpecularTexel.a, SpecColor.a;
#MOV SpecularTexel.a, 128;
POW r1.a, t.a, SpecularTexel.a;
MAD r1.rgb, EnvMapTexel, EnvMapColor, r1.a;
MUL r1.rgb, r1, F.a; # Mul specular with fresnel factor
#MUL r1.rgb, r1, DiffuseTexel; # Mul specular with specular map
MUL r1.rgb, r1, SpecularTexel; # Mul specular with specular map
MAD r0.rgb, SpecColor, r1, r0; # Mul specular with specular color, add to final fragment
#-----------------------------------------
MUL r0.rgb, r0, Attenuation.r; # Multiply final fragment by geometric attenuation and silkness
#-----------------------------------------
# Transmitted light
MAD r0.rgb, lt.a, TransmissionTexel, r0;
#-----------------------------------------
MUL r0.rgb, r0, Attenuation.w; # Multiply final fragment by distance attenuation
MUL r0.rgb, r0, Noise; # Multiply final fragment by distance attenuation
#-----------------------------------------
# Projection map
#LRP ProjMapTexel1.rgb, Attenuation.w, ProjMapTexel1, ProjMapTexel2;
MUL r0.rgb, r0, ProjMapTexel1; # Multiply final fragment by projmap
# Alpha from diffuse texture
MOV r0.a, DiffuseTexel.a;
#MOV r0.rgb, l.a;
#MUL r0.rgb, 0.25, t.a;
# Write result
MOV oCol, r0;
END