ShaderWallPS
From SimsWiki
EP3-OFB
0xCD7FE87A
0x1C0532FA
0x3035AF69
0xFFDE6F3E
# pixelshaderwalls
define PS2WallRendering(wallBumpMaps)
#PS2.0
# Pass 1:
# Basemap * (LightMap * (normal dot incidence))
# TexKill = cutout - 0.5
shader -layer $wallLayer
validateRenderShaderContext -vertexFormat position 0 required
validateRenderShaderContext -vertexFormat normal 0 required
validateRenderShaderContext -vertexFormat texcoord 0 required
validateRenderShaderContext -vertexFormat texcoord 1 required
validateRenderShaderContext -vertexFormat texcoord 2 required
if ($caustics)
pass -modifiedEachFrameHint
else
pass
endif
fillmode $stdMatFillMode
create FirstPassWallVertexShader($caustics)
shaderProgram -target pixelProgram -method assemble
bindConstants 1 -bindingID immediateData -data ($wallHighlightIntensity)
shaderSource
ps_2_0
def c0, 0,0.5,1,2
endShaderSource
if ($wallMaskOK)
shaderSource "dcl_2d s0 ; cutout"
endif
shaderSource
dcl_2d s1 ; base
dcl t0.xy ; base mapping
dcl t1.xy ; light map space
endShaderSource
if ($lightMapping)
shaderSource
dcl_2d s2 ; lightmap
dcl t2.xy ; also incidence space.
endShaderSource
endif
if (&wallBumpMaps)
shaderSource
dcl_2d s3 ; normalmap
dcl_2d s4 ; incidence
endShaderSource
endif
if ($wallHighlightOn)
shaderSource "dcl_2d s5 ; highlight texture"
endif
if ($caustics)
shaderSource
dcl_2d s6 ; caustics texture
dcl t3.xy ; caustics projection
dcl v0 ; wall height, so caustics can fade off in a pool
endShaderSource
endif
if ($wallMaskOK)
shaderSource
texld r11, t0, s0
sub r10, r11.a, c0.y ; any values under 127 become clip pixels.
texkill r10
endShaderSource
endif
shaderSource
texld r0, t1, s1 ; base map
endShaderSource
if ($lightMapping)
shaderSource
texld r1, t2, s2 ; light map
mul r2.rgb, r0, r1
endShaderSource
else
shaderSource "mul r2, r0, c0.y"
endif
shaderSource
mul r2.rgb, r2, c0.w ; result * 2
endShaderSource
if (&wallBumpMaps)
shaderSource
texld r3, t1, s3
texld r4, t2, s4
mad r5, r3, c0.w, -c0.z ; 2x-1
mad r6, r4, c0.w, -c0.z ; 2x-1
dp3_sat r2.a, r5, r6 ; incidence dot normal
mul r2, r2, r2.a ; roll this into the lightmap.
endShaderSource
endif
if ($caustics)
shaderSource
texld r8, t3, s6
mad r2.rgb, v0, r8, r2
endShaderSource
endif
if ($wallHighlightOn)
shaderSource
texld r7, t0, s5
mad r2.rgb, r2, r7.a, c1
endShaderSource
endif
shaderSource
mov r2.a, c0.z
mov oC0, r2
endShaderSource
end #shader program
if ($wallMaskOK)
sampler 0
textureAddressing clamp clamp
texture ${wallMaskTextureName}
end
endif
sampler 1
texture ${wallpaperTextureName}
textureAddressing tile tile
end
if ($lightMapping)
sampler 2
texture "wallLightMap_${page}"
end
if (&wallBumpMaps)
sampler 3
texture "${wallpaperNormalMapTextureName}"
end
sampler 4
texture "wallIncidenceMap_${page}"
end
endif
endif
if ($wallHighlightOn)
sampler 5
texture "wall_selection_colors"
textureAddressing clamp clamp
end
endif
if ($caustics)
sampler 6
texture causticsTile
textureAddressing tile tile
end
endif
end #pass
end #shader
enddef
# Handles:
# PS2 case
# PS1.4 case
# no bumpmap PS1.1 case
# the 'glowy reflection map' gizmo is applied to the wall gradient multiplier here in the VS, which saves cycles.
define FirstPassWallVertexShader(caustics)
shaderProgram -target vertexProgram -method assemble
bindConstants 0 -bindingID geomToClip -constantCount 4
if ($wallMaskMirrorFlag)
bindConstants 4 -bindingID immediateData -data (-1,1,1,0)
else
bindConstants 4 -bindingID immediateData -data (1,1,0,0)
endif
seti textureLights (numLightsOfType(environmentCube))
if ($caustics)
bindConstants 5 -bindingID geomToGlobal -constantCount 3
if ($textureLights)
bindConstants 10 -bindingID allTextureLights -constantCount 1
endif
endif
shaderSource
vs_1_1
; matrix for caustics projection
def c11, 1, -2.5, 0, 0.3
def c12, 1, 1, 1, 0
def c13, 0, 0, 0, 0 ; This won't be used
dcl_position v0
dcl_normal v1
dcl_texcoord0 v2 ; base, normal maps
dcl_texcoord1 v3 ; mask
dcl_texcoord2 v4 ; lightmaps, incidence maps
m4x4 oPos, v0, c0
mad oT0.xy, v3, c4.xy, c4.zw ; cutout
mov oT1.xy, v2 ; texcoords 0 = base texture, normal maps
mov oT2.xy, v4 ; texcoords 2 = lightmap/incidence map
endShaderSource
if ($wallHighlightOn)
shaderSource "mov oT3.xy, v2"
else
if ($caustics)
shaderSource
m4x3 r0, v0, c5 ; object to world space.
mul r0.xyz, r0.xyz, c11.w ; mul by 0.3
m3x3 oT3, r0, c11 ; project and emit.
endShaderSource
if ($textureLights)
shaderSource "mul oD0, v2.y, c10 ; scale by the 'night light"
else
shaderSource "mov oD0, v2.y"
endif
endif
endif
end #vertex program
enddef
define PS1WallRendering(wallBumps)
if ($wallMaskOK = false)
# generally an error condition, so only do the basics
create PS1MasklessWallRendering(lightMapping)
else
if (&wallBumps)
create PS1BumpMapWallRendering()
else
create PS1BasicWallRendering( )
endif
endif
enddef
# bumpmaps for PS 1.1
# first pass does:
# RGB =(Incidence dot Normal)
# Alpha = Cutout
# Second pass does:
# Base * lightmap * 2
# multiplies by dest color
define BasePassWallVertexShader()
shaderProgram -target vertexProgram -method assemble
bindConstants 0 -bindingID geomToClip -constantCount 4
if ($wallMaskMirrorFlag)
bindConstants 4 -bindingID immediateData -data (-1,1,1,0)
else
bindConstants 4 -bindingID immediateData -data (1,1,0,0)
endif
shaderSource
vs_1_1
dcl_position v0
dcl_texcoord0 v1 ; base map
dcl_texcoord2 v2 ; light map
m4x4 oPos, v0, c0
mov oT0.xy, v1 ; texcoords 0 = base Map
mov oT1.xy, v2 ; tc 2 = light maps
mov oT3.xy, v1 ; for the highlight
endShaderSource
end #vertex program
enddef
define PS1BumpMapWallRendering()
shader -layer $wallLayer
validateRenderShaderContext -vertexFormat position 0 required
validateRenderShaderContext -vertexFormat texcoord 0 required
validateRenderShaderContext -vertexFormat texcoord 1 required
validateRenderShaderContext -vertexFormat texcoord 2 required
validateRenderShaderContext -viewerRenderType viewerRenderType
pass
alphaTest true 127
alphaTestFunction acceptIfGreater
create FirstPassWallVertexShader($caustics)
shaderProgram -target pixelProgram -method assemble
shaderSource
ps_1_1
tex t0
tex t1
tex t2
dp3_sat r0.rgb, t1_bx2, t2_bx2
mov r0.a, t0.a
endShaderSource
end
sampler 0
textureAddressing clamp clamp
texture $wallMaskTextureName ${wallMaskTextureParam}
end
sampler 1
texture "${wallpaperNormalMapTextureName}"
end
sampler 2
texture "wallIncidenceMap_${page}"
end
end
pass
fillmode $stdMatFillMode
alphaBlend srcFactor(destColor) add dstFactor(zero)
depthTest true -enableDepthWrite false
depthTestFunction acceptIfEqual
create BasePassWallVertexShader()
shaderProgram -target pixelProgram -method assemble
shaderSource
ps_1_1
tex t0
tex t1
mul_x2 r0, t0, t1
endShaderSource
end
sampler 0
texture $wallpaperTextureName ${wallpaperTextureParam}
textureAddressing tile tile
end
sampler 1
texture "wallLightMap_${page}"
end
end #pass
end #shader
enddef
define PS1BasicWallRendering()
# only handles Base * lightmap.
shader -layer $wallLayer
validateRenderShaderContext -vertexFormat position 0 required
validateRenderShaderContext -vertexFormat normal 0 required
validateRenderShaderContext -vertexFormat texcoord 0 required
validateRenderShaderContext -vertexFormat texcoord 1 required
validateRenderShaderContext -vertexFormat texcoord 2 required
if ($caustics)
pass -modifiedEachFrameHint
else
pass
endif
alphaTest true 127
alphaTestFunction acceptIfGreater
fillmode $stdMatFillMode
create FirstPassWallVertexShader($caustics)
if ($lightMapping)
shaderProgram -target pixelProgram -method assemble
bindConstants 0 -bindingID immediateData -data ($wallHighlightIntensity)
shaderSource
ps_1_1
tex t0
tex t1
tex t2
endShaderSource
if ($caustics)
shaderSource "tex t3"
endif
shaderSource
mul_x2 r0.rgb, t1, t2
+mov r0.a, t0.a
endShaderSource
if ($caustics)
shaderSource "mad r0.rgb, t3, v0, r0"
endif
end
else
shaderProgram -target pixelProgram -method assemble
bindConstants 0 -bindingID immediateData -data ($wallHighlightIntensity)
shaderSource
ps_1_1
tex t0 ; mask
tex t1 ; texture
endShaderSource
# if ($caustics or $wallHighlightOn)
shaderSource "tex t3"
#endif
shaderSource
mov_x2 r0.rgb, t1
+mov r0.a, t0.a
endShaderSource
if ($wallHighlightOn)
shaderSource
mad r0.rgb, t1, t3.a, c0
endShaderSource
else
if ($caustics)
shaderSource "add r0.rgb, r0, t3"
endif
endif
end
endif
sampler 0
textureAddressing clamp clamp
texture $wallMaskTextureName ${wallMaskTextureParam}
end
sampler 1
texture $wallpaperTextureName ${wallpaperTextureParam}
textureAddressing tile tile
end
if ($lightMapping)
sampler 2
texture "wallLightMap_${page}"
end
endif
if ($wallHighlightOn)
sampler 3
texture "wall_selection_colors"
textureAddressing clamp clamp
end
else
if ($caustics)
sampler 3
texture causticsTile
textureAddressing tile tile
end
endif
endif
end #pass
end #shader
enddef
# no mask case, should be rare, but can happen in some situations.
define PS1MasklessWallRendering(lightMapping)
shader -layer $wallLayer
pass
create BasePassWallVertexShader()
shaderProgram -target pixelProgram -method assemble
bindConstants 0 -bindingID immediateData -data ($wallHighlightIntensity)
shaderSource
ps_1_1
tex t1
endShaderSource
if (&lightMapping)
shaderSource "tex t2"
endif
if ($wallHighlightOn)
shaderSource "tex t3"
endif
if (&lightMapping)
shaderSource "mul_x2 r0, t1, t2"
else
shaderSource "mov r0, t1"
endif
if ($wallHighlightOn)
shaderSource
mad r0.rgb, r0, t3.a, c0
endShaderSource
endif
end
sampler 1
texture $wallpaperTextureName ${wallpaperTextureParam}
textureAddressing tile tile
end
if (&lightMapping)
sampler 2
texture "wallLightMap_${page}"
end
endif
if ($wallHighlightOn)
sampler 3
texture "wall_selection_colors"
textureAddressing clamp clamp
end
else
end
end
enddef
#Empricially, only used to render a thumbnail
define PixelShaderWallTextureShader()
shader -layer $wallLayer
validateRenderShaderContext -vertexFormat position 0 required
validateRenderShaderContext -vertexFormat normal 0 required
validateRenderShaderContext -vertexFormat texcoord 2 required
pass
depthTestFunction accept
fillmode $stdMatFillMode
shaderProgram -target vertexProgram -method assemble
bindConstants 0 -bindingID geomToClip -constantCount 4
shaderSource
vs_1_1
dcl_position v0
dcl_texcoord0 v1 ; base map
m4x4 oPos, v0, c0
mov oT0.xy, v1
mov oT1.xy, v1
endShaderSource
end #vertex program
shaderProgram -target pixelProgram -method assemble
shaderSource
ps_1_1
def c0,1,1,1,1
tex t0
endShaderSource
if ($lightMapping)
shaderSource
tex t1
mul_x2 r0.rgb, t0, t1
mov r0.a, c0
endShaderSource
else
shaderSource
mov r0.rgb, t0
mov r0.a, c0
endShaderSource
endif
end
sampler 0
texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
textureAddressing tile tile
end
if ($lightMapping)
sampler 1
texture "wallLightMap_${page}"
end
endif
end
end
enddef
define DebugPixelShaderWalls()
shader -layer $wallLayer
validateRenderShaderContext -vertexFormat position 0 required
validateRenderShaderContext -vertexFormat normal 0 required
validateRenderShaderContext -vertexFormat texcoord 0 required
validateRenderShaderContext -vertexFormat texcoord 1 required
validateRenderShaderContext -vertexFormat texcoord 2 required
pass
fillmode $stdMatFillMode
alphaTest true 127
alphaTestFunction acceptIfGreater
create FirstPassWallVertexShader($caustics)
# mov oT1.xy, v2 ; texcoords 0 = base texture, normal maps
# mov oT2.xy, v4 ; texcoords 2 = lightmap/incidence map
shaderProgram -target pixelProgram -method assemble
shaderSource
ps_1_1
tex t0
tex t1
tex t2
mov r0, t0
endShaderSource
if ($lightMapping and $debugShowWallLightmap)
shaderSource "mov_x2 r0, t2"
endif
if ($debugShowWallIncidence)
shaderSource "mov r0, t2"
endif
if ($debugShowWallNormalMap)
shaderSource "mov r0, t1"
endif
if ($debugWallLighting)
shaderSource "dp3 r0.rgb, t1_bx2, t2_bx2"
endif
end
if ($lightMapping and $debugShowWallLightmap)
sampler 2
texture "wallLightMap_${page}"
end
endif
if (($debugShowWallIncidence or $debugWallLighting) and $lightMapping)
sampler 2
texture "wallIncidenceMap_${page}"
end
endif
if (($debugShowWallNormalMap or $debugWallLighting) and $wallBumps)
sampler 1
texture "${wallpaperNormalMapTextureName}"
end
endif
end
end
enddef