This page is located on the SimsWiki. To view it in it's original form, click here.

In TS2 terminology, Terrain paint == Ground cover.

This page presently forces on the general structures of a HCP-custom terrain paint package and its moddings.

structures

Terrainpaint001-intro.png

<p>

Commonly, a new custom terrain paint package by HCP consists of 5 contents as shown in the resource tree in simpe (the top left box).

  • the Directory of Compressed Files (CLST) is to list out all the files compressed with TS2 build-in compression
  • the Floor XML file is to link the text list file and the 2 texr files together for the game-engine recognition.
  • the text list file is to store the UI catelogue infos (name, description, cost) equivalent to the same infos in the Floor XML file (highlit in cyan rectangle lining in the above picture Terrainpaint001-intro.png)

Terrainpaint002-intro.png

  • the 2 texture (txtr) files named as "${texture}" and "${texture}_detail" where {texture} are the given texture names. Basically, they're graphically identical but functionally different for the terrain rendering by the terrain shader. Although LIFO files can store the mutual texture for both txtr files as suggested here
define TerrainPaintShaderVS_PS()
   shader -layer (($terrainMatLayer - 2) * 8)
      vertexFormatPred position      0 true
      vertexFormatPred texcoord      0 true
      pass
         fillmode $stdMatFillMode
         alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
         
         alphaTest true 10
         alphaTestFunction acceptIfGreater
         
         depthTest true -enableDepthWrite false
         
         if (viewerRenderType = $kRenderTypeImposter)
            depthTestFunction acceptIfLessOrEqual
         else
            depthTestFunction acceptIfEqual
         endif
         
         shaderProgram -target vertexProgram -method compile -version 1_1
            bindConstants 0 -bindingID geomToClip -constantCount 4			
			   bindConstants 4 -bindingID immediateData -data (1/$canvasBaseTextureScale, 1/$canvasDetailTextureScale, $alphaMapScaleU, $alphaMapScaleV)
   			
			   shaderSource
			      float4x4 clipSpaceMatrix  : register(c0);
			      float4   textureConstants : register(c4);
   			
			   struct InputVertex
				   {
					   float3 position: POSITION0;
					   float2 texcoord : TEXCOORD0;
				   };
   				
				   struct OutputVertex
				   {
					   float4 clipPosition : POSITION;
					   float2 txBase  : TEXCOORD0;
					   float2 txDetail: TEXCOORD1;
					   float2 txAlpha : TEXCOORD2;
				   };
   				
				   OutputVertex VertexMain( InputVertex i)
				   {
				      OutputVertex o;
				      o.clipPosition = mul(float4(i.position, 1), clipSpaceMatrix);
				      o.txBase   = i.texcoord * textureConstants.x;
				      o.txDetail = i.texcoord * textureConstants.y;				   
				      o.txAlpha  = i.texcoord.xy * textureConstants.zw;
				      return o;
				   }
			   endShaderSource  
         end # end shader program
         
         
         shaderProgram -target pixelProgram -method compile -version 1_1      
            shaderSource                            
               sampler base;
               sampler detail;
               sampler alphaMap;
               struct cInputPixel
               {               
                  float2 tcBase : TEXCOORD0;
                  float2 tcDetail : TEXCOORD1;
                  float2 tcAlpha  : TEXCOORD2;
               };
               
               float4 PixelMain(cInputPixel pi) : COLOR
               {         
                  float4 baseColor   = tex2D(base, pi.tcBase);                                                
                  float4 detailColor = tex2D(detail, pi.tcDetail);                              
                  float4 alphaColor  = tex2D(alphaMap, pi.tcAlpha);
                  float4 result = (detailColor.a * detailColor) + ((1 - detailColor.a) * baseColor);               
                  result.a = alphaColor.a;
                  return result;                        
               }
            endShaderSource
         end # end shader program      
            
         sampler base
            texture $paintTexture
            textureAddressing tile tile
         end
         
         sampler detail
            texture "${paintTexture}_detail"
            textureAddressing tile tile
         end
         
         sampler alphaMap
            texture $alphaMap
            textureAddressing clamp clamp
         end      
      end
   end
enddef

define TerrainPaintShader(addDetail)
   shader -layer (($terrainMatLayer - 2) * 8)
      vertexFormatPred position      0 true
      vertexFormatPred texcoord      0 true
      
      pass -fixedFunction         
         fillmode $stdMatFillMode

         alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
         
         alphaTest true 10
         alphaTestFunction acceptIfGreater
         
         depthTest true -enableDepthWrite false
         if (viewerRenderType = $kRenderTypeImposter)
            depthTestFunction acceptIfLessOrEqual
         else
            depthTestFunction acceptIfEqual
         endif
         
         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
         stage
            texture $alphaMap
            textureAddressing clamp clamp
            ffTextureMatrix -scalev ($alphaMapScaleU, $alphaMapScaleV)
            ffTextureCoordsSource 0
            textureBlend select(outRegister) select(texture)
         end 
      end       
   end
enddef


define TerrainPaint()
   material
      create DetermineHardwareSupport()
      
      if (viewerRenderType != $kRenderTypeShadowMap)   
         if ($useHWShader1Path or $useHWShader2Path)	
		      create TerrainPaintShaderVS_PS()
	      else            
            create TerrainPaintShader(true)
            create TerrainPaintShader(false)
            shader
            end
         endif      
      endif      
   end
enddef