📄 vertexlitgeneric_diffbumptimesbase.vsh
字号:
dp3 $tmp2.z, $worldBumpBasis3, $lightDirection
dp3 $tmp2.w, $worldNormal, $lightDirection ; unbumped normal in world space ( [0 0 1] in tangent space )
free $lightDirection
alloc $attenuation # was r1
max $attenuation.xyzw, $tmp2.xyzw, c0.x ; clamp to zero
mul $tmp.xyz, $distAttenuation.w, c[a0.x] ; calculate light color times distance attenuation
mul $tmp.xyz, $tmp, $tmp.w ; * angular attenuation
mad $linearColor1.xyz, $attenuation.x, $tmp, $linearColor1 ; mult by color
mad $linearColor2.xyz, $attenuation.y, $tmp, $linearColor2 ; mult by color
mad $linearColor3.xyz, $attenuation.z, $tmp, $linearColor3 ; mult by color
mad $linearColorNormal.xyz, $attenuation.w, $tmp, $linearColorNormal ; mult by color
free $attenuation # was r1
free $tmp # was r2
free $tmp2 # was r0
free $distAttenuation # was r6
}
sub DoBumpedLight
{
local( $lightType ) = shift;
local( $worldPos ) = shift;
local( $worldTangentS ) = shift;
local( $worldTangentT ) = shift;
local( $worldNormal ) = shift;
local( $worldBumpBasis1 ) = shift;
local( $worldBumpBasis2 ) = shift;
local( $worldBumpBasis3 ) = shift;
local( $linearColor1 ) = shift; # was r3
local( $linearColor2 ) = shift; # was r4
local( $linearColor3 ) = shift; # was r5
local( $linearColorNormal ) = shift;# was r6
if( $lightType eq "spot" )
{
&BumpedSpotLight( $worldTangentS, $worldTangentT, $worldNormal,
$worldBumpBasis1, $worldBumpBasis2, $worldBumpBasis3,
$linearColor1, $linearColor2, $linearColor3, $linearColorNormal );
}
elsif( $lightType eq "point" )
{
&BumpedPointLight( $worldPos, $worldTangentS, $worldTangentT, $worldNormal,
$linearColor1, $linearColor2, $linearColor3, $linearColorNormal );
}
elsif( $lightType eq "directional" )
{
&BumpedDirectionalLight( $worldTangentS, $worldTangentT, $worldNormal,
$linearColor1, $linearColor2, $linearColor3, $linearColorNormal );
}
else
{
die "don't know about light type \"$lightType\"\n";
}
}
sub BumpedLightingPostfix
{
; BUMPED LIGHTING POSTFIX
local( $linearColor1 ) = shift;
local( $linearColor2 ) = shift;
local( $linearColor3 ) = shift;
local( $linearColorNormal ) = shift;
;; gamma correct the unbumped normal
; OPTIMIZE?: Either use a cubic or quintic to approximate
; the gamma curve
alloc $gammaColorNormal # was r0
&LinearToGamma( $linearColorNormal, $gammaColorNormal );
mul $gammaColorNormal.xyz, $gammaColorNormal.xyz, $cOverbrightFactor ; overbrighting factor
; &ColorClamp( $gammaColorNormal, $gammaColorNormal );
alloc $averageLinearColor
; OPTIMIZE: build overbright factor into something similar to $cOneThird
; compute the average of the three colors for the three vects
mul $averageLinearColor.xyz, $linearColor1.xyz, $cOOSqrt3 ; mult by 1/sqrt(3)
mad $averageLinearColor.xyz, $linearColor2.xyz, $cOOSqrt3, $averageLinearColor.xyz
mad $averageLinearColor.xyz, $linearColor3.xyz, $cOOSqrt3, $averageLinearColor.xyz
; compute a scale value to multiply all three vec colors by so
; that the flat normal will match the gamma corrected normal
rcp $averageLinearColor.x, $averageLinearColor.x
rcp $averageLinearColor.y, $averageLinearColor.y
rcp $averageLinearColor.z, $averageLinearColor.z
mul $averageLinearColor.xyz, $gammaColorNormal, $averageLinearColor
; $averageLinearColor is now a scale value to get from linear to gamma approximately.
; is exact for the normal
if( 1 )
{
mul oT2.xyz, $linearColor1, $averageLinearColor
mul oT3.xyz, $linearColor2, $averageLinearColor
mul oD0.xyz, $linearColor3, $averageLinearColor
; mul oT2.xyz, $cOOSqrt3, $gammaColorNormal
; mul oT3.xyz, $cOOSqrt3, $gammaColorNormal
; mul oD0.xyz, $cOOSqrt3, $gammaColorNormal
}
else
{
mul $linearColor1.xyz, $linearColor1, $averageLinearColor
mul $linearColor2.xyz, $linearColor2, $averageLinearColor
mul $linearColor3.xyz, $linearColor3, $averageLinearColor
&ColorClamp( $linearColor1, "oT2" );
&ColorClamp( $linearColor2, "oT3" );
&ColorClamp( $linearColor3, "oD0" );
}
free $gammaColorNormal
free $averageLinearColor
}
sub DoBumpedLighting
{
local( $staticLightType ) = shift;
local( $ambientLightType ) = shift;
local( $localLightType1 ) = shift;
local( $localLightType2 ) = shift;
local( $worldPos ) = shift;
local( $worldTangentS ) = shift;
local( $worldTangentT ) = shift;
local( $worldNormal ) = shift;
alloc $worldBumpBasis1
alloc $worldBumpBasis2
alloc $worldBumpBasis3
&CalculateWorldBumpBasis( $worldTangentS, $worldTangentT, $worldNormal,
$worldBumpBasis1, $worldBumpBasis2, $worldBumpBasis3 );
alloc $linearColor1
alloc $linearColor2
alloc $linearColor3
alloc $linearColorNormal
&BumpedAmbientLight( $worldBumpBasis1, $worldBumpBasis2, $worldBumpBasis3,
$linearColor1, $linearColor2, $linearColor3, $linearColorNormal );
# mov $linearColor1, $cZero
# mov $linearColor2, $cZero
# mov $linearColor3, $cZero
# mov $linearColorNormal, $cZero
if( $localLightType1 ne "none" )
{
mov a0.x, $cLight0Offset
&DoBumpedLight( $localLightType1, $worldPos, $worldTangentS, $worldTangentT, $worldNormal,
$worldBumpBasis1, $worldBumpBasis2, $worldBumpBasis3,
$linearColor1, $linearColor2, $linearColor3, $linearColorNormal );
}
if( $localLightType2 ne "none" )
{
mov a0.x, $cLight1Offset
&DoBumpedLight( $localLightType2, $worldPos, $worldTangentS, $worldTangentT, $worldNormal,
$worldBumpBasis1, $worldBumpBasis2, $worldBumpBasis3,
$linearColor1, $linearColor2, $linearColor3, $linearColorNormal );
}
&BumpedLightingPostfix( $linearColor1, $linearColor2, $linearColor3, $linearColorNormal );
free $worldBumpBasis1
free $worldBumpBasis2
free $worldBumpBasis3
free $linearColor1
free $linearColor2
free $linearColor3
free $linearColorNormal
}
;------------------------------------------------------------------------------
; Vertex blending (whacks everything? positions in r7, normals in r8, tangentS in r9,
; tangentT in r10)
;------------------------------------------------------------------------------
alloc $worldTangentS # was r0
alloc $worldTangentT # was r10
; hard code to zero bones and use software skinning
; would normally do skinning here.
mov $worldTangentS, $vUserData ; have to do this since we can't use two "v" registers in the same instruction
; Calculate tangentT
&Cross( $worldTangentT, $vNormal, $worldTangentS );
; flip direction if necessary
mul $worldTangentT.xyz, $vUserData.w, $worldTangentT.xyz
free $worldTangentS
;------------------------------------------------------------------------------
; Transform the position from world to proj space
;------------------------------------------------------------------------------
alloc $projPos
#$projPos = "r0";
dp4 $projPos.x, $vPos, $cViewProj0
dp4 $projPos.y, $vPos, $cViewProj1
dp4 $projPos.z, $vPos, $cViewProj2
dp4 $projPos.w, $vPos, $cViewProj3
mov oPos, $projPos
;------------------------------------------------------------------------------
; Fog
;------------------------------------------------------------------------------
alloc $worldPos
if( $g_fogType eq "heightfog" )
{
; Get the worldpos z component only since that's all we need for height fog
dp4 $worldPos.z, $vPos, $cModel2
}
&CalcFog( $worldPos, $projPos );
free $worldPos
free $projPos
;------------------------------------------------------------------------------
; Lighting
; whacks: r3, r4, r5, r6, ???
; output:
; oT2 - color on first bump axis in tangent space
; oT3 - color on second bump axis in tangent space
; oD0 - color on third bump axis in tangent space
;------------------------------------------------------------------------------
; c[x] : light color (r,g,b,magnitude) - not normalized here, but is in pixel shader.
; c[x+1] : light direction (world space)
; c[x+2] : light point (world space)
; c[x+3] : exponent, stopdot, stopdot2, 1 / (stopdot - stopdot2)
; c[x+4] : attenuation0, attenuation1, attenuation2
if( 1 )
{
&DoBumpedLighting( $g_staticLightType, $g_ambientLightType, $g_localLightType1, $g_localLightType2,
$vPos, $vUserData, $worldTangentT, $vNormal );
}
else
{
$worldNormal = $vNormal;
$worldPos = $vPos;
&DoLighting( $g_staticLightType, $g_ambientLightType, $g_localLightType1,
$g_localLightType2, $worldPos, $worldNormal );
}
;------------------------------------------------------------------------------
; Texture coordinates
;------------------------------------------------------------------------------
if( 0 )
{
; base texture texcoords + offset
dp4 oT0.x, $vTexCoord0, c93 ; FIXME
dp4 oT0.y, $vTexCoord0, c94 ; FIXME
; normal map texcoords + offset
add oT1, $vTexCoord0, c95
}
else
{
; base texture texcoords + offset
mov oT0, $vTexCoord0
; normal map texcoords + offset
mov oT1, $vTexCoord0
}
free $worldTangentT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -