Difference between revisions of "ShaderTerrain"
From SimsWiki
(EP2-NL) |
(EP3-OFB) |
||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | + | EP3-OFB | |
0xCD7FE87A | 0xCD7FE87A | ||
0x1C0532FA | 0x1C0532FA |
Revision as of 05:12, 14 April 2007
EP3-OFB 0xCD7FE87A 0x1C0532FA 0x4CE399AB 0xFF1AFA1C # terrain # # Shaders for terrain tiles # # setf waterbumpMapScale 4.0 setv3 thumbnailMatDiffCoef (0.75, 0.93, 0.75) seti terrainMatLayer -2 # multiplier on terrain (grass/paints) both on the lot and # lot skirts. (See lotSkirt.matShad.) setc terrainMatDiffCoef (0.9, 0.9, 0.9) # Specifies the number of tiles over which the paint & bump textures should be applied. setf canvasDetailTextureScale 4 setf canvasBaseTextureScale 20 setf paintTextureScale 20 setf paintDetailTextureScale 4.0 #============================================================================== define TerrainCanvasShaderShader() shader -layer (($terrainMatLayer - 3) * 8) vertexFormatPred position 0 true vertexFormatPred normal 0 true vertexFormatPred texcoord 0 true vertexFormatPred blendindices 0 false vertexFormatPred targetindices 0 false viewerRenderTypePred viewerRenderType pass -fixedFunction create LightingStatesNoStdLights() fillmode $stdMatFillMode if ($stdMatLightingDebug) stage texture $stdMatBaseTextureName ${stdMatBaseTextureParam} textureBlend multiply(texture outRegister) select(outRegister) end else stage texture "${texture}" textureAddressing tile tile ffTextureMatrix -scalev ($canvasBaseTextureScale, $canvasBaseTextureScale) -invert ffTextureCoordsSource 0 textureBlend multiply(texture outRegister) select(outRegister) end stage texture "${texture}_detail" textureAddressing tile tile ffTextureMatrix -scalev ($canvasDetailTextureScale, $canvasDetailTextureScale) -invert ffTextureCoordsSource 0 textureBlend lerpTextureAlpha(texture outRegister) select(outRegister) end endif end end enddef define TerrainCanvasShader() material if ($stdMatLightingDebug) create LightingDebugStandardMaterialOverrides() endif create TerrainCanvasShaderShader() shader end end enddef #============================================================================== define TerrainPaintShader(addDetail) shader -layer (($terrainMatLayer - 2) * 8) vertexFormatPred position 0 true vertexFormatPred normal 0 true vertexFormatPred texcoord 0 true vertexFormatPred blendindices 0 false vertexFormatPred targetindices 0 false #viewerRenderTypePred viewerRenderType pass -fixedFunction create LightingStatesNoStdLights() fillmode $stdMatFillMode alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) alphaTest true 10 alphaTestFunction acceptIfGreater if ($stdMatLightingDebug) stage texture $stdMatBaseTextureName ${stdMatBaseTextureParam} textureBlend multiply(texture outRegister) select(outRegister) end else if (&addDetail) stage texture $paintTexture textureAddressing tile tile ffTextureMatrix -scalev ($paintTextureScale, $paintTextureScale) -invert textureTransformType vector2 ffTextureCoordsSource 0 textureBlend select(texture) select(outRegister) end stage texture "${paintTexture}_detail" textureAddressing tile tile ffTextureMatrix -scalev ($paintDetailTextureScale, $paintDetailTextureScale) -invert textureTransformType vector2 ffTextureCoordsSource 0 textureBlend lerpTextureAlpha(texture outRegister) select(outRegister) end else stage texture $paintTexture textureAddressing tile tile ffTextureMatrix -scalev ($paintTextureScale, $paintTextureScale) -invert textureTransformType vector2 ffTextureCoordsSource 0 textureBlend select(texture) select(outRegister) end endif endif stage texture $alphaMap textureAddressing clamp clamp ffTextureMatrix -scalev ($alphaMapScaleU, $alphaMapScaleV) ffTextureCoordsSource 0 textureBlend select(outRegister) select(texture) end end end enddef define TerrainPaint() material if ($stdMatLightingDebug) create LightingDebugStandardMaterialOverrides() endif create TerrainPaintShader(true) create TerrainPaintShader(false) shader end end enddef #============================================================================== define TerrainLighting() material create DetermineHardwareSupport() shader -layer (($terrainMatLayer - 1) * 8) vertexFormatPred position 0 true vertexFormatPred normal 0 true vertexFormatPred texcoord 0 true vertexFormatPred blendindices 0 false vertexFormatPred targetindices 0 false pass -fixedFunction create LightingStatesNoStdLights() fillmode $stdMatFillMode alphaBlend srcFactor(destColor) add dstFactor(zero) colorScalar $terrainMatDiffCoef 1 # important that alpha be one for ARGB capture. ffDepthOffset 0 depthTest true -enableDepthWrite false stage texture "floorLightMap_0" # at the moment is deterministically mapped to page 0 # A page holds 64x64 tiles. A tile is one world unit wide. ffTextureMatrix -scalev (1/64, 1/64) textureTransformType vector2 ffTextureCoordsSource 0 textureBlend multiplyScale2(texture colorScalar) select(colorScalar) end end if ($lmIntegratedShadows) pass -fixedFunction create LightingStatesNoStdLights() fillmode $stdMatFillMode alphaBlend srcFactor(destColor) add dstFactor(zero) depthTest true -enableDepthWrite true depthTestFunction acceptIfLess alphaTest true 100 alphaTestFunction acceptIfGreater colorScalar (0.61, 0.61, 0.61) # needs to be set by tsUserEtc ffDepthOffset 1 stage texture "floorLightMap_0" ffTextureMatrix -scalev (1/64, 1/64) textureTransformType vector2 ffTextureCoordsSource 0 textureBlend select(colorScalar) select(texture) end end elseif (not ($useHWShader2Path or $useHWShader1Path)) # must match condition in OverlayShadowMaterialDef pass -fixedFunction create LightingStatesNoStdLights() fillmode $stdMatFillMode alphaBlend srcFactor(zero) add dstFactor(one) ffDepthOffset 1 depthTest true -enableDepthWrite true alphaTest true 100 alphaTestFunction acceptIfLess stage texture "floorLightMap_0" # at the moment is deterministically mapped to page 0 ffTextureMatrix -scalev (1/64, 1/64) textureTransformType vector2 ffTextureCoordsSource 0 textureBlend select(texture) select(texture) end end endif end end enddef #============================================================================== define TerrainToolThumbnail() material shader -layer ($terrainMatLayer * 8) vertexFormatPred position 0 true vertexFormatPred normal 0 true vertexFormatPred texcoord 0 true vertexFormatPred blendindices 0 false vertexFormatPred targetindices 0 false pass -fixedFunction create LightingStates() alphaBlend srcFactor(srcAlpha) add dstFactor(zero) colorScalar $thumbnailMatDiffCoef fillmode $stdMatFillMode stage texture $paintTexture textureAddressing tile tile textureBlend multiplyScale2(texture diffuse) select(texture) end end end end enddef define TerrainWaterShader(withBumpMap) shader -layer 1 vertexFormatPred position 0 true vertexFormatPred normal 0 true vertexFormatPred color 0 true vertexFormatPred texcoord 0 true vertexFormatPred blendindices 0 false vertexFormatPred targetindices 0 false viewerRenderTypePred viewerRenderType setb cubeMapSupport (queryBooleanGraphicsDeviceCap(hasCubeMapSupport)) create DetermineHardwareSupport() pass -fixedFunction # disable lighting, disable normalize normals, enable local viewer if ($useSWVertexShaderPath) create LightingStatesNoStdLights() else create LightingStatesNoStdLightsParam(false true) endif alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) fillmode $stdMatFillMode colorScalar (1, 1, 1) -applyTextureLightColor 0 0 stage if ($cubeMapSupport) texture reflectionoutdoorwater-envcube textureMIPFilterHint disabled ffTextureCoordsSource fromReflectionVector textureTransformType vector3 ffTextureMatrix -orientCameraToGlobal textureAddressing clamp clamp clamp textureBlend multiply(texture colorScalar) select(diffuse) else colorScalar (0.3,0.5,1.0) -applyTextureLightColor 0 0 textureBlend select(colorScalar) select(diffuse) endif end end if (&withBumpMap) pass -fixedFunction create LightingStatesNoStdLights() alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) fillmode $stdMatFillMode colorScalar (1.0, 1.0, 1.0, 0.3) -applyTextureLightColor 0 0 stage texture "water-1-bump" textureAddressing tile tile # -atrans waveformType cycles/sec offset (startU, startV) (endU, endV) textureMatrixAnimation -targetType fixedFunction -aorigin (0, 0) -atrans sine 0.04 0 (0, 0) (1, 0) -ascale sawtooth 1 0 ($waterbumpMapScale, $waterbumpMapScale) textureTransformType vector2 ffTextureCoordsSource 0 textureBlend select(texture) select(texture) end stage texture "water-2-bump" textureAddressing tile tile # -atrans waveformType cycles/sec offset (startU, startV) (endU, endV) textureMatrixAnimation -targetType fixedFunction -aorigin (0, 0) -atrans sine 0.04 0 (1, 0) (0, 0) -ascale sawtooth 1 0 ($waterbumpMapScale, $waterbumpMapScale) textureTransformType vector2 ffTextureCoordsSource 0 textureBlend multiply(texture outRegister) select(texture) end stage # does this work out on GF2 due to reg combiners? textureBlend multiply(outRegister colorScalar) select(colorScalar) end end endif end enddef #============================================================================== define TerrainWater() material # only activate the water w/ bump shader for pixel shader capable HW if (queryIntegerGraphicsDeviceCap(maxPixelProgramVersionMajor) != 0) create TerrainWaterShader(true) endif create TerrainWaterShader(false) # fallback without bumps end enddef #============================================================================== materialDefinition terrainLightingMaterial setDefinition TerrainLighting end materialDefinition waterOnTerrain setDefinition TerrainWater end #endshader