Difference between revisions of "ShaderImposters"
From SimsWiki
(EP0-TS2) |
(EP2-NL) |
||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | + | EP2-NL | |
0xCD7FE87A | 0xCD7FE87A | ||
0x1C0532FA | 0x1C0532FA | ||
Line 26: | Line 26: | ||
seti nhoodCanvasLayer -8 | seti nhoodCanvasLayer -8 | ||
+ | setb isQuad false | ||
# Used for double-sided slices, which are assumed to be | # Used for double-sided slices, which are assumed to be | ||
Line 38: | Line 39: | ||
pass -fixedFunction | pass -fixedFunction | ||
create LightingStatesNoStdLights() | create LightingStatesNoStdLights() | ||
− | |||
− | |||
− | |||
# the imposters are saved with pre-multiplied alpha. | # the imposters are saved with pre-multiplied alpha. | ||
Line 74: | Line 72: | ||
shader -layer (($nhoodCanvasLayer + 5)* 8) | shader -layer (($nhoodCanvasLayer + 5)* 8) | ||
vertexFormatPred position 0 true | vertexFormatPred position 0 true | ||
− | numLightsPred $kShadeLight (numLightsOfType(${kShadeLight})) | + | numLightsPred $kShadeLight (numLightsOfType(${kShadeLight})) |
+ | |||
+ | setb isTypeQuad ($isQuad) | ||
if ($includeLightMap) | if ($includeLightMap) | ||
Line 84: | Line 84: | ||
alphaTest true 0 | alphaTest true 0 | ||
− | alphaTestFunction acceptIfGreater | + | alphaTestFunction acceptIfGreater |
− | + | ||
+ | |||
+ | if ($isTypeQuad) | ||
+ | #always accept it as we its alpha and we are writing over terrain | ||
+ | depthTest true -enableDepthWrite false | ||
+ | ffDepthOffset 100 | ||
+ | depthTestFunction acceptIfLessOrEqual | ||
+ | endif | ||
+ | |||
+ | |||
colorScalar $lightMapTint 1 | colorScalar $lightMapTint 1 | ||
stage | stage | ||
− | texture "terrainLmap" | + | if ($isTypeQuad) |
+ | texture $lmapTexture | ||
+ | else | ||
+ | texture "terrainLmap" | ||
+ | endif | ||
− | textureFilterHint | + | textureFilterHint bilinear bilinear |
textureAddressing tile tile | textureAddressing tile tile | ||
ffTextureCoordsSource $textureCoordSet | ffTextureCoordsSource $textureCoordSet | ||
Line 105: | Line 118: | ||
alphaTest true 0 | alphaTest true 0 | ||
− | alphaTestFunction acceptIfGreater | + | alphaTestFunction acceptIfGreater |
+ | |||
+ | if ($isTypeQuad) | ||
+ | #always accept it as its alpha and we are writing over terrain | ||
+ | ffDepthOffset 100 | ||
+ | depthTest true -enableDepthWrite false | ||
+ | depthTestFunction acceptIfLessOrEqual | ||
+ | endif | ||
− | create | + | # use shape light only in neighborhood mode |
+ | # we don't want to make the terrain fade as it looks bad | ||
+ | create ImposterColorScalarWithTextureLight(tsIsInNeighborhood) | ||
stage | stage | ||
− | texture "terrain" | + | if ($isTypeQuad) |
+ | texture $terrainTexture | ||
+ | else | ||
+ | texture "terrain" | ||
+ | endif | ||
textureFilterHint bilinear bilinear | textureFilterHint bilinear bilinear | ||
Line 117: | Line 143: | ||
textureBlend multiply(texture colorScalar) multiply(texture colorScalar) | textureBlend multiply(texture colorScalar) multiply(texture colorScalar) | ||
end | end | ||
− | end | + | end |
if ($includeHighlight) | if ($includeHighlight) | ||
Line 127: | Line 153: | ||
alphaTest true 0 | alphaTest true 0 | ||
alphaTestFunction acceptIfGreater | alphaTestFunction acceptIfGreater | ||
− | + | ||
colorScalar (0.2, 1, 0.2) 0.3 | colorScalar (0.2, 1, 0.2) 0.3 | ||
Line 147: | Line 173: | ||
pass -fixedFunction | pass -fixedFunction | ||
create NonStandardLighting() | create NonStandardLighting() | ||
− | + | ||
− | + | ||
+ | if (numLightsOfType(${kShapeColorLight}) > 0 and not tsIsInNeighborhood) | ||
+ | alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) | ||
+ | depthTest true -enableDepthWrite false | ||
+ | else | ||
+ | alphaBlend srcFactor(one) add dstFactor(invSrcAlpha) | ||
+ | depthTest true -enableDepthWrite true | ||
+ | depthTestFunction acceptIfLessOrEqual | ||
+ | endif | ||
+ | |||
alphaTest true 64 | alphaTest true 64 | ||
alphaTestFunction acceptIfGreater | alphaTestFunction acceptIfGreater | ||
− | + | ||
− | + | ||
fillmode $stdMatFillMode | fillmode $stdMatFillMode | ||
cullmode cullClockwise | cullmode cullClockwise | ||
− | create | + | create ImposterColorScalarWithTextureLight(true) |
stage | stage | ||
Line 182: | Line 215: | ||
shaderProgram -target vertexProgram -method assemble | shaderProgram -target vertexProgram -method assemble | ||
− | |||
bindConstants 0 -bindingID geomToClip -constantCount 4 | bindConstants 0 -bindingID geomToClip -constantCount 4 | ||
+ | |||
setf invRoofTextureTiles (1 / 64) | setf invRoofTextureTiles (1 / 64) | ||
Line 190: | Line 223: | ||
def c4, $invRoofTextureTiles, -$invRoofTextureTiles, 0, 1 | def c4, $invRoofTextureTiles, -$invRoofTextureTiles, 0, 1 | ||
dcl_position v0 | dcl_position v0 | ||
− | + | ||
− | m4x4 oPos, | + | m4x4 oPos, v0, c0 |
mad oT0.xy, v0, c4.xy, c4.zw | mad oT0.xy, v0, c4.xy, c4.zw | ||
endShaderSource | endShaderSource | ||
end | end | ||
− | + | ||
fillmode $stdMatFillMode | fillmode $stdMatFillMode | ||
− | cullmode none | + | cullmode none |
+ | |||
+ | if (numLightsOfType(${kShapeColorLight}) > 0 and not tsIsInNeighborhood) | ||
+ | alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) | ||
+ | depthTest true -enableDepthWrite false | ||
+ | else | ||
+ | alphaBlend srcFactor(one) add dstFactor(zero) | ||
+ | endif | ||
+ | |||
+ | create ImposterColorScalarWithTextureLight(true) | ||
− | |||
stage | stage | ||
Line 213: | Line 254: | ||
end | end | ||
end | end | ||
+ | enddef | ||
+ | |||
+ | define ImposterColorScalarWithTextureLight(useShapeColor) | ||
+ | # Allow shade colour, but only if we're not being highlighted. | ||
+ | if (&useShapeColor) | ||
+ | colorScalar (1, 1, 1, 1) -applyShapeColor 0 -applyTextureLightColor 0 0 | ||
+ | else | ||
+ | colorScalar (1, 1, 1, 1) -applyTextureLightColor 0 0 | ||
+ | endif | ||
+ | |||
+ | if (numLightsOfType(${kShadeLight}) != 0 and numLightsOfType(${kShapeColorLight}) = 0) | ||
+ | tsUserLight shadeLight 0 | ||
+ | endif | ||
enddef | enddef | ||
define ImposterColorScalar() | define ImposterColorScalar() | ||
# Allow shade colour, but only if we're not being highlighted. | # Allow shade colour, but only if we're not being highlighted. | ||
− | colorScalar (1, 1, 1, 1) -applyShapeColor 0 | + | colorScalar (1, 1, 1, 1) -applyShapeColor 0 |
if (numLightsOfType(${kShadeLight}) != 0 and numLightsOfType(${kShapeColorLight}) = 0) | if (numLightsOfType(${kShadeLight}) != 0 and numLightsOfType(${kShapeColorLight}) = 0) | ||
tsUserLight shadeLight 0 | tsUserLight shadeLight 0 |
Revision as of 04:50, 16 July 2008
EP2-NL 0xCD7FE87A 0x1C0532FA 0xA335F05F 0xFFD7EBE7 # imposters # # Shaders for imposters # # NOTE: because imposters are generated by # rendering the lot to textures, all imposter # textures effectively have pre-multiplied alpha. # This parameter gets used for lots saved prior to ~12/20/03. For the # new lots, this parameter gets set in code. This parameter is used to # slightly tint the imposter terrain surface to make it slightly stand out # in the neighborhood terrain. setc lightMapTint (1.0, 1.0, 1.0) #layer ID of neighborhood terrain canvas seti nhoodCanvasLayer -8 setb isQuad false # Used for double-sided slices, which are assumed to be # drawn in correct front/back order. define ImposterDualPackedSliceMaterial() # params: page material shader -layer (($stdMatLayer * 8)) vertexFormatPred position 0 true numLightsPred $kShadeLight (numLightsOfType(${kShadeLight})) pass -fixedFunction create LightingStatesNoStdLights() # the imposters are saved with pre-multiplied alpha. alphaBlend srcFactor(one) add dstFactor(invSrcAlpha) alphaTest true 127 alphaTestFunction acceptIfGreater fillmode $stdMatFillMode create ImposterColorScalar() stage texture "slices_${page}" textureMIPFilterHint disabled textureFilterHint point point textureBlend multiply(texture colorScalar) multiply(texture colorScalar) end end end end enddef setb includeLightMap false setb includeHighlight false set textureCoordSet 0 define ImposterTerrainMaterial() material shader -layer (($nhoodCanvasLayer + 5)* 8) vertexFormatPred position 0 true numLightsPred $kShadeLight (numLightsOfType(${kShadeLight})) setb isTypeQuad ($isQuad) if ($includeLightMap) pass -fixedFunction create NonStandardLighting() alphaBlend srcFactor(destColor) add dstFactor(invSrcAlpha) fillmode $stdMatFillMode alphaTest true 0 alphaTestFunction acceptIfGreater if ($isTypeQuad) #always accept it as we its alpha and we are writing over terrain depthTest true -enableDepthWrite false ffDepthOffset 100 depthTestFunction acceptIfLessOrEqual endif colorScalar $lightMapTint 1 stage if ($isTypeQuad) texture $lmapTexture else texture "terrainLmap" endif textureFilterHint bilinear bilinear textureAddressing tile tile ffTextureCoordsSource $textureCoordSet textureBlend multiply(texture colorScalar) select(texture) end end endif pass -fixedFunction create NonStandardLighting() alphaBlend srcFactor(one) add dstFactor(invSrcAlpha) fillmode $stdMatFillMode alphaTest true 0 alphaTestFunction acceptIfGreater if ($isTypeQuad) #always accept it as its alpha and we are writing over terrain ffDepthOffset 100 depthTest true -enableDepthWrite false depthTestFunction acceptIfLessOrEqual endif # use shape light only in neighborhood mode # we don't want to make the terrain fade as it looks bad create ImposterColorScalarWithTextureLight(tsIsInNeighborhood) stage if ($isTypeQuad) texture $terrainTexture else texture "terrain" endif textureFilterHint bilinear bilinear textureAddressing clamp clamp textureBlend multiply(texture colorScalar) multiply(texture colorScalar) end end if ($includeHighlight) pass -fixedFunction create NonStandardLighting() alphaBlend srcFactor(srcAlpha) add dstFactor(one) fillmode $stdMatFillMode alphaTest true 0 alphaTestFunction acceptIfGreater colorScalar (0.2, 1, 0.2) 0.3 stage textureBlend select(colorScalar) select(colorScalar) end end endif end end enddef define ImposterWallMaterial() material shader -layer ($stdMatLayer * 8) vertexFormatPred position 0 true numLightsPred $kShadeLight (numLightsOfType(${kShadeLight})) pass -fixedFunction create NonStandardLighting() if (numLightsOfType(${kShapeColorLight}) > 0 and not tsIsInNeighborhood) alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) depthTest true -enableDepthWrite false else alphaBlend srcFactor(one) add dstFactor(invSrcAlpha) depthTest true -enableDepthWrite true depthTestFunction acceptIfLessOrEqual endif alphaTest true 64 alphaTestFunction acceptIfGreater fillmode $stdMatFillMode cullmode cullClockwise create ImposterColorScalarWithTextureLight(true) stage texture "walls_${page}" textureMIPFilterHint disabled textureFilterHint point point textureBlend multiply(texture colorScalar) multiply(texture colorScalar) end end end end enddef define ImposterRoofMaterial() material shader -layer ($stdMatLayer * 8) vertexFormatPred position 0 true numLightsPred $kShadeLight (numLightsOfType(${kShadeLight})) pass create NonStandardLighting() shaderProgram -target vertexProgram -method assemble bindConstants 0 -bindingID geomToClip -constantCount 4 setf invRoofTextureTiles (1 / 64) shaderSource vs_1_1 def c4, $invRoofTextureTiles, -$invRoofTextureTiles, 0, 1 dcl_position v0 m4x4 oPos, v0, c0 mad oT0.xy, v0, c4.xy, c4.zw endShaderSource end fillmode $stdMatFillMode cullmode none if (numLightsOfType(${kShapeColorLight}) > 0 and not tsIsInNeighborhood) alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) depthTest true -enableDepthWrite false else alphaBlend srcFactor(one) add dstFactor(zero) endif create ImposterColorScalarWithTextureLight(true) stage texture "roofs" textureFilterHint bilinear bilinear textureAddressing clamp clamp textureBlend multiply(texture colorScalar) select(colorScalar) end end end end enddef define ImposterColorScalarWithTextureLight(useShapeColor) # Allow shade colour, but only if we're not being highlighted. if (&useShapeColor) colorScalar (1, 1, 1, 1) -applyShapeColor 0 -applyTextureLightColor 0 0 else colorScalar (1, 1, 1, 1) -applyTextureLightColor 0 0 endif if (numLightsOfType(${kShadeLight}) != 0 and numLightsOfType(${kShapeColorLight}) = 0) tsUserLight shadeLight 0 endif enddef define ImposterColorScalar() # Allow shade colour, but only if we're not being highlighted. colorScalar (1, 1, 1, 1) -applyShapeColor 0 if (numLightsOfType(${kShadeLight}) != 0 and numLightsOfType(${kShapeColorLight}) = 0) tsUserLight shadeLight 0 endif enddef