Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
Line 1: Line 1:
 
#
 
#
# Shaders for terrain tiles
+
# Shaders for neighborhood
 
#
 
#
 
#
 
#
  
setf  waterbumpMapScale    4.0
+
# layers
setv3 thumbnailMatDiffCoef (0.75, 0.93, 0.75)
+
# normal shadows are layer 2 (after opaques), tree shadows are moved to -2 to make them
seti terrainMatLayer -2
+
#  render to the first buffer. Tree shadows (-2) do not show up on fields (7).
 +
seti nhoodWaterLayer            1
 +
seti nhoodCanvasLayer          -8
 +
seti nhoodTreeShadowLayer      -2
  
# multiplier on terrain (grass/paints) both on the lot and
+
setf  neighborhoodMaterialScaleU 8.0  # defaults for neighborhood materials without these defined
# lot skirts. (See lotSkirt.matShad.)
+
setf  neighborhoodMaterialScaleV 8.0 # defaults for neighborhood materials without these defined
setc terrainMatDiffCoef (0.9, 0.9, 0.9)
+
  
# Specifies the number of tiles over which the paint & bump textures should be applied.
+
setf  nhoodWaterMap1Scale    7.0
setf  canvasDetailTextureScale            4
+
setf  nhoodWaterMap1Speed    0.5
setf  canvasBaseTextureScale            20
+
setf  nhoodWaterMap2Scale    5.0
 +
setf  nhoodWaterMap2Speed    0.3
  
setf  paintTextureScale                  20
 
setf  paintDetailTextureScale            4.0
 
setb  hasCutout false
 
  
#==============================================================================
+
setv2 baseTexOffset (0.5, 0.5)
 +
setv3 nhoodDiffCoef (0.75, 0.93, 0.75)
  
define TerrainCanvasShaderShaderVS_PS()
+
 
   pass
+
setf  nhoodPaintTextureScale  13      #Repeat distance of neighborhood textures in tiles.
      fillmode $stdMatFillMode     
+
                                    #NOTE: There is a related parameter called "TextureVariantGridSize" in
      depthTest true -enableDepthWrite true                 
+
                                    #NeighborhoodTerrain.ini. You would normally (though not necessarily) want it to be
     
+
                                    #the same as this number.
       if ($hasCutout)                        
+
setf  waterEdgeTextureScale  250.0  #Repeat distance in meters
         depthTestFunction acceptIfEqual
+
setf  terrainEdgeTextureScale 100.0  #Repeat distance in meters
      else
+
 
         depthTestFunction acceptIfLessOrEqual
+
 
 +
# Reflective water
 +
setc  nhoodWaterReflColour  (0.55, .6, 0.65)
 +
setc  lotSkirtWaterReflColour (0.65, 0.7, 0.85)
 +
setf  nhoodWaterReflStrength  0.75
 +
setf  nhoodWaterReflOffset    0.0020
 +
 
 +
# Standard water
 +
setf nhoodWaterbumpMapScale 8.0
 +
setf nhoodWaterAlpha        0.35
 +
 
 +
setb isDay true
 +
setb isTerrainConcrete false
 +
 
 +
# water clipping plane
 +
setf waterHeight 312.45
 +
 
 +
# underwater gradient texture
 +
set  waterGradientTexture neighborhood-underwater-gradient
 +
set  waterGradientTextureAdditive neighborhood-underwater-gradient-with-black
 +
# depth at which the gradient starts to take effect
 +
setf waterGradientZoneStart 0
 +
# how far down the gradient goes from that point.
 +
setf waterGradientZoneSize 40
 +
 
 +
set skyboxCubeMap neighborhood-sky2-envcube
 +
 
 +
# bump mapping
 +
setv3 nhoodSunDir (-0.5, 1, 0.5)  # default -- should be set by code from the lighting.txt value
 +
# overall kind-of brightness booster for bump map.
 +
setf  bumpMapBoost 1.5
 +
 
 +
# ==============================================================================
 +
# derived bump map quantities
 +
define BiasedNormal(n bn)
 +
   setf  nLen (sqrt(sqr($&{n}.x) + sqr($&{n}.y) + sqr($&{n}.z)))
 +
  setv3 &{bn} ((0.5,0.5,0.5) * (($&{n} / $nLen.xxx) + (1,1,1)))
 +
enddef
 +
 
 +
create BiasedNormal(nhoodSunDir nhoodSunDirBiased)
 +
setv3 nhoodSunDirBiased ($nhoodSunDirBiased * $bumpMapBoost.xxx)
 +
 
 +
set terrainType "unset"
 +
 
 +
# defaults off, can be turned on at startup.
 +
setb simpleTerrain false
 +
setb isImposter false
 +
 
 +
include neighborhoodSWVS.matShad
 +
 
 +
# ==============================================================================
 +
 
 +
define NeighborhoodCanvas()
 +
 
 +
# this material does nothing but prep the z-buffer, and render black.
 +
 
 +
material
 +
       if ($simpleTerrain)
 +
         shader
 +
         end
 
       endif
 
       endif
     
+
 
       shaderProgram -target vertexProgram -method compile -version 1_1
+
       shader -layer (($nhoodCanvasLayer) * 8)
        bindConstants 0 -bindingID geomToClip -constantCount 4
+
       
bindConstants 4 -bindingID immediateData -data (1/$canvasBaseTextureScale, 1/$canvasDetailTextureScale, 0, 0)
+
        validateRenderShaderContext -vertexFormat position     0 required
+
        validateRenderShaderContext -vertexFormat normal        0 required
shaderSource
+
       
  float4x4 clipSpaceMatrix : register(c0);
+
        if (not $isImposter)        
  float4  textureConstants : register(c4);
+
            validateRenderShaderContext -vertexFormat  texcoord      0 required
+
         endif
struct InputVertex
+
        viewerRenderTypePred viewerRenderType
{
+
float3 position: POSITION0;
+
float2 texcoord : TEXCOORD0;
+
};
+
+
struct OutputVertex
+
{
+
float4 clipPosition : POSITION;
+
float2 txBase : TEXCOORD0;
+
float2 txDetail: TEXCOORD1;
+
};
+
+
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;  
+
  return o;
+
}
+
endShaderSource 
+
      end # end shader program
+
     
+
     
+
      shaderProgram -target pixelProgram -method compile -version 1_1      
+
         shaderSource                           
+
            sampler base;
+
            sampler detail;
+
            struct cInputPixel
+
            {             
+
              float2 tcBase : TEXCOORD0;
+
              float2 tcDetail : TEXCOORD1;
+
            };
+
 
              
 
              
             float4 PixelMain(cInputPixel pi) : COLOR
+
        create DetermineHardwareSupport()
             {       
+
       
               float4 baseColor  = tex2D(base, pi.tcBase);                                               
+
        if (strcmp("Concrete", "${terrainType}") = 0)
               float4 detailColor = tex2D(detail, pi.tcDetail);                             
+
             setb isTerrainConcrete true
              float4 result = (detailColor.a * detailColor) + ((1 - detailColor.a) * baseColor);             
+
        endif
               return result;                       
+
 
             }
+
        if (not $isUnderWater or viewerRenderType != $kRenderTypeReflection)
         endShaderSource
+
             if ($useSWVertexShaderPath)
      end # end shader program     
+
               create NeighborhoodTerrainPrepWorkSWVS()
 +
            else
 +
               pass -fixedFunction
 +
                  create LightingStatesNoStdLights()
 +
                 
 +
                  cullmode none # so that reflections don't "creep under" edge of terrain
 +
                  colorScalar (0.0, 0.0, 0.0, 1.0)
 +
                                   
 +
                  if ($isImposter and $isTerrainConcrete)
 +
                    ffDepthOffset -1
 +
                  endif
 +
 
 +
                  stage
 +
                    if (not $isImposter)
 +
                        ffTextureCoordsSource fromPosition
 +
                    endif
 +
                    textureBlend select(colorScalar) select(outRegister)
 +
                  end
 +
               end
 +
            endif
 +
              
 +
         endif
 
          
 
          
      sampler base
 
        texture "${texture}"
 
        textureAddressing tile tile
 
 
       end
 
       end
     
 
      sampler detail
 
        texture "${texture}_detail"
 
        textureAddressing tile tile
 
      end     
 
 
   end
 
   end
 
enddef
 
enddef
  
define TerrainCanvasShaderShaderFF()
+
 
  pass -fixedFunction       
+
# ==============================================================================
       fillmode $stdMatFillMode
+
# Used for those triangles in the canvas which are partially under water.
 +
#
 +
define NeighborhoodCanvasStraddle()
 +
material
 +
 
 +
       if ($simpleTerrain)
 +
        shader
 +
        end
 +
      endif
 +
 
 +
# material for reflection camera
 +
 
 +
      shader -layer (($nhoodCanvasLayer) * 8)
 
        
 
        
      depthTest true -enableDepthWrite true                
+
validateRenderShaderContext -vertexFormat  position      0 required
 +
validateRenderShaderContext -vertexFormat  normal        0 required
 +
validateRenderShaderContext -vertexFormat  texcoord      0 required
 +
viewerRenderTypePred $kRenderTypeReflection
 +
       
 +
#Render the portion that is above water only
 +
       
 +
create DetermineHardwareSupport()
 +
       
 +
if ($useSWVertexShaderPath)
 +
 +
create NeighborhoodWaterlineStraddleSWVS()
 +
 +
else
 +
       
 +
pass -fixedFunction
 +
create LightingStatesNoStdLights()
 +
alphaBlend srcFactor(one) add dstFactor(zero)
 +
cullmode none # so that reflections don't "creep under" edge of terrain
 +
colorScalar (0.0, 0.0, 0.0, 1.0)
 +
 
 +
alphaTest true 128
 +
alphaTestFunction acceptIfGreater
 +
 
 +
stage
 +
# above water -- clip by using depth-based 0/1 texture.
 +
texture blackWhite
 +
textureAddressing clamp clamp
 +
textureFilterHint point point
 +
textureMIPFilterHint disabled
 +
                 
 +
ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
 +
ffTextureCoordsSource fromPosition
 +
textureBlend select(colorScalar) select(texture)
 +
end
 +
end
 +
endif
 +
 +
end
 
        
 
        
       if ($hasCutout)                       
+
        
        depthTestFunction acceptIfEqual
+
     
       else
+
       #material for standard camera 
        depthTestFunction acceptIfLessOrEqual
+
       #shader -layer (-128)     
       endif
+
shader -layer (-128)
             
+
      stage
+
validateRenderShaderContext -vertexFormat  position      0 required
        texture "${texture}"
+
validateRenderShaderContext -vertexFormat  normal        0 required
        textureAddressing tile tile
+
validateRenderShaderContext -vertexFormat  texcoord      0 required
        ffTextureMatrix -scalev ($canvasBaseTextureScale, $canvasBaseTextureScale) -invert
+
viewerRenderTypePred $kRenderTypeNormal
        ffTextureCoordsSource 0
+
       
        textureBlend select(texture) select(texture)
+
create DetermineHardwareSupport()
      end
+
       
      stage
+
if ($useSWVertexShaderPath)
        texture "${texture}_detail"
+
create NeighborhoodWaterlineStraddleStandardCameraSWVS()
        textureAddressing tile tile
+
else
        ffTextureMatrix -scalev ($canvasDetailTextureScale, $canvasDetailTextureScale) -invert
+
       
        ffTextureCoordsSource 0
+
#Render the portion that is above water only
        textureBlend lerpTextureAlpha(texture outRegister) select(outRegister)
+
pass -fixedFunction
      end  
+
create LightingStatesNoStdLights()
  end       
+
alphaBlend srcFactor(one) add dstFactor(zero)
 +
cullmode none # so that reflections don't "creep under" edge of terrain
 +
colorScalar (0.0, 0.0, 0.0, 1.0)
 +
 
 +
stage
 +
textureBlend select(colorScalar) select(outRegister)
 +
end  
 +
end
 +
endif
 +
 +
end
 +
        
 +
end
 
enddef
 
enddef
  
define TerrainCanvasShader()
+
# ==============================================================================
  material
+
# Material for terrain geometry that is partially or completely under water.
       shader -layer (($terrainMatLayer - 3) * 8)
+
define NeighborhoodWaterTerrain()
         vertexFormatPred position      0 true
+
material
         vertexFormatPred normal        0 true
+
 
        vertexFormatPred texcoord      0 true
+
       if ($simpleTerrain)
        viewerRenderTypePred viewerRenderType
+
         shader
       
+
         end
        create DetermineHardwareSupport()
+
      endif
        if (viewerRenderType = $kRenderTypeShadowMap)
+
        create ShadowMapVS_PS()
+
      else
+
            if ($useHWShader1Path or $useHWShader2Path)
+
        create TerrainCanvasShaderShaderVS_PS()
+
        else 
+
              create TerrainCanvasShaderShaderFF()
+
            endif
+
        endif
+
      end
+
 
        
 
        
      shader
+
shader -layer (($nhoodCanvasLayer + 2) * 8)
      end
+
validateRenderShaderContext -vertexFormat  position      0 required
  end
+
validateRenderShaderContext -vertexFormat  normal        0 required
 +
validateRenderShaderContext -vertexFormat  texcoord      0 required
 +
viewerRenderTypePred viewerRenderType
 +
 
 +
 +
create DetermineHardwareSupport()
 +
 +
if (viewerRenderType != $kRenderTypeReflection)       
 +
 +
if ($useSWVertexShaderPath)
 +
create NeighborhoodUnderWaterTerrainSWVS()
 +
 +
else
 +
 +
pass -fixedFunction
 +
 +
 +
create LightingStatesNoStdLights()
 +
 +
alphaBlend srcFactor(destColor) add dstFactor(zero)
 +
cullmode none # so that reflections don't "creep under" edge of terrain
 +
# apply depth-based gradient texture to terrain that is under water.
 +
stage
 +
texture $waterGradientTexture
 +
 +
if ($cubeMapSupport)
 +
  textureAddressing tile clamp
 +
else
 +
  textureAddressing clamp clamp
 +
endif
 +
                   
 +
set d ($waterHeight - $waterGradientZoneStart)
 +
set s (-$waterGradientZoneSize)
 +
ffTextureMatrix -cameraToGlobal -order xzyw -scale $s -trans (0, $d) -invert
 +
ffTextureCoordsSource fromPosition
 +
textureBlend select(texture) select(outRegister)
 +
end
 +
end
 +
 +
endif
 +
 +
endif
 +
 +
end
 +
end
 
enddef
 
enddef
  
#==============================================================================
+
# ==============================================================================
  
define TerrainPaintShaderVS_PS()
+
define NeighborhoodTerrainPaintShader()
   shader -layer (($terrainMatLayer - 2) * 8)
+
   shader -layer (($nhoodCanvasLayer + 1) * 8)
       vertexFormatPred position      0 true
+
       validateRenderShaderContext -vertexFormat  position      0 required
       vertexFormatPred texcoord      0 true
+
       validateRenderShaderContext -vertexFormat  normal        0 required
      pass
+
           
        fillmode $stdMatFillMode
+
         if (not $isImposter)
        alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
             validateRenderShaderContext -vertexFormat  texcoord      0 required
       
+
        alphaTest true 10
+
        alphaTestFunction acceptIfGreater
+
       
+
        depthTest true -enableDepthWrite false
+
       
+
         if (viewerRenderType = $kRenderTypeImposter)
+
             depthTestFunction acceptIfLessOrEqual
+
        else
+
            depthTestFunction acceptIfEqual
+
 
         endif
 
         endif
       
+
 
        shaderProgram -target vertexProgram -method compile -version 1_1
+
  create DetermineHardwareSupport()
            bindConstants 0 -bindingID geomToClip -constantCount 4
+
 
  bindConstants 4 -bindingID immediateData -data (1/$canvasBaseTextureScale, 1/$canvasDetailTextureScale, $alphaMapScaleU, $alphaMapScaleV)
+
  if (strcmp("Concrete", "${terrainType}") = 0)
 +
            setb isTerrainConcrete true
 +
        endif
 +
 
 +
  if ($useSWVertexShaderPath)
 +
  create NeighborhoodMainTerrainShaderSWVS()
 
  
 
  
  shaderSource
+
  else
      float4x4 clipSpaceMatrix  : register(c0);
+
 
      float4  textureConstants : register(c4);
+
  pass -fixedFunction
 
  
 
  
  struct InputVertex
+
  create LightingStatesNoStdLights()
  {
+
  alphaBlend srcFactor(srcAlpha) add dstFactor(one)
  float3 position: POSITION0;
+
  cullmode none # so that reflections don't "creep under" edge of terrain
  float2 texcoord : TEXCOORD0;
+
 
  };
+
  if ($isImposter and $isTerrainConcrete)
 +
                  ffDepthOffset -1
 +
              endif
 +
                     
 +
  colorScalar $nhoodSunDirBiased
 +
         
 +
  depthTest true -enableDepthWrite false
 +
  depthTestFunction acceptIfEqual
 
  
 
  
  struct OutputVertex
+
  seti snowLevel (tsHasSnow)
  {
+
  float4 clipPosition : POSITION;
+
  float2 txBase  : TEXCOORD0;
+
  float2 txDetail: TEXCOORD1;
+
  float2 txAlpha : TEXCOORD2;
+
  };
+
 
  
 
  
  OutputVertex VertexMain( InputVertex i)
+
  if ($snowLevel = 1)
  {
+
      set weatherSuffix "-LSNOW"
      OutputVertex o;
+
  elseif ($snowLevel = 2)
      o.clipPosition = mul(float4(i.position, 1), clipSpaceMatrix);
+
                  set weatherSuffix "-HSNOW"
      o.txBase  = i.texcoord * textureConstants.x;
+
               else
      o.txDetail = i.texcoord * textureConstants.y;  
+
                   set weatherSuffix ""
      o.txAlpha  = i.texcoord.xy * textureConstants.zw;
+
               endif
      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
+
  stage
              {       
+
  texture $alphaMap
                  float4 baseColor  = tex2D(base, pi.tcBase);                                               
+
  textureAddressing clamp clamp
                  float4 detailColor = tex2D(detail, pi.tcDetail);                             
+
 
                   float4 alphaColor  = tex2D(alphaMap, pi.tcAlpha);
+
                   if ($isImposter)
                  float4 result = (detailColor.a * detailColor) + ((1 - detailColor.a) * baseColor);             
+
  ffTextureMatrix -cameraToGlobal -scalev ((0.1 * $alphaMapScaleU), (0.1 * $alphaMapScaleV))
                  result.a = alphaColor.a;
+
  ffTextureCoordsSource fromPosition
                  return result;                       
+
  else
              }
+
      ffTextureMatrix -scalev ($alphaMapScaleU, $alphaMapScaleV)
            endShaderSource
+
      ffTextureCoordsSource 0
        end # end shader program     
+
  endif
           
+
  textureBlend select(outRegister) select(texture)
        sampler base
+
  end  
            texture $paintTexture
+
 
            textureAddressing tile tile
+
  stage  
        end
+
  texture "${paintTexture}${weatherSuffix}"
       
+
  textureAddressing tile tile
        sampler detail
+
  if ($isImposter)
            texture "${paintTexture}_detail"
+
  ffTextureMatrix -cameraToGlobal -scalev ((10.0 * $nhoodPaintTextureScale), (10.0 * $nhoodPaintTextureScale)) -invert
            textureAddressing tile tile
+
  ffTextureCoordsSource fromPosition
        end
+
  else
       
+
      ffTextureMatrix -scalev ($nhoodPaintTextureScale, $nhoodPaintTextureScale) -invert
        sampler alphaMap
+
      ffTextureCoordsSource 0
            texture $alphaMap
+
  endif
            textureAddressing clamp clamp
+
  textureBlend select(texture outRegister) select(outRegister)
        end    
+
  end  
      end
+
  end      
  end
+
        endif
 +
 +
end
 
enddef
 
enddef
  
define TerrainPaintShader(addDetail)
+
define NeighborhoodTerrainPaint()
   shader -layer (($terrainMatLayer - 2) * 8)
+
   material
      vertexFormatPred position      0 true
+
      vertexFormatPred texcoord      0 true
+
 
        
 
        
       pass -fixedFunction       
+
       if ($simpleTerrain)
        fillmode $stdMatFillMode
+
         shader
 
+
         end
        alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
      endif
       
+
     
        alphaTest true 10
+
      create NeighborhoodTerrainPaintShader()
        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
 
   end
 
enddef
 
enddef
 +
  
 +
# ==============================================================================
  
define TerrainPaint()
+
set ratioH 1  # default material parameter value
 +
set ratioW 1  # default material parameter value
 +
set useReflection 1 # default material parameter value
 +
define NeighborhoodWater()
 
   material
 
   material
       create DetermineHardwareSupport()
+
       # never draw water in its reflection.  Already handled by code.
     
+
 
       if (viewerRenderType != $kRenderTypeShadowMap)  
+
       if ($simpleTerrain)
         if ($useHWShader1Path or $useHWShader2Path)
+
         shader -layer $nhoodWaterLayer
      create TerrainPaintShaderVS_PS()
+
            pass -fixedFunction
      else           
+
              colorScalar (0.3, 0.4,0.8) 1.0
            create TerrainPaintShader(true)
+
              stage
            create TerrainPaintShader(false)
+
                  textureBlend select(colorScalar) select(colorScalar)
            shader
+
              end
 
             end
 
             end
         endif     
+
         end
       endif    
+
       endif
  end
+
enddef
+
  
  
#==============================================================================
+
      # First option: reflection mapped water.
define TerrainLightingVS_PS()
+
      if ($useReflection)
  pass
+
 
      fillmode $stdMatFillMode
+
        shader -layer $nhoodWaterLayer
      alphaBlend srcFactor(destColor) add dstFactor(zero)          
+
            validateRenderShaderContext -vertexFormat  position      0 required
      depthTest true -enableDepthWrite false          
+
            validateRenderShaderContext -vertexFormat  normal        0 required
       depthTestFunction acceptIfEqual
+
            validateRenderShaderContext -vertexFormat  texcoord      0 required
 +
            viewerRenderTypePred viewerRenderType
 +
 
 +
            ################################################################################
 +
            # Three pass/2 texture rippled reflection -- does not run on GeF2 only 2 stages (for GeF4+)
 +
            pass -fixedFunction -modifiedEachFrameHint
 +
           
 +
           
 +
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
              colorScalar $nhoodWaterReflColour $nhoodWaterReflStrength
 +
              depthTest true -enableDepthWrite false
 +
             
 +
              stage
 +
                  ffTextureCoordsSource fromPosition
 +
                  ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
 +
                  textureAddressing clamp clamp
 +
                  texture "ScreenReflection"
 +
                 
 +
                  textureBlend multiply(texture colorScalar) select(outRegister) tempRegister
 +
              end
 +
              stage
 +
                  ffTextureCoordsSource fromPosition
 +
                  ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5 + $nhoodWaterReflOffset, 0.5 + $nhoodWaterReflOffset)
 +
                  textureAddressing clamp clamp
 +
                 
 +
                  texture "ScreenReflection"
 +
                  textureBlend multiply(texture colorScalar) select(outRegister)
 +
              end           
 +
              stage
 +
                  texture "neighborhood-water-1"
 +
                  textureAddressing tile tile
 +
                  # -atrans waveformType cycles/sec offset (startU, startV)  (endU, endV)
 +
                  textureMatrixAnimation -targetType fixedFunction -atrans sawtooth ($nhoodWaterMap1Speed / $nhoodWaterMap1Scale) 0 (0, 0) ($nhoodWaterMap1Scale, 0) -ascale sawtooth 1 0 ($nhoodWaterMap1Scale, $nhoodWaterMap1Scale)
 +
                  ffTextureCoordsSource 0
 +
                  textureBlend lerpTextureAlpha(tempRegister outRegister) select(colorScalar)
 +
              end
 +
            end
 +
        end
 +
       
 +
        shader -layer $nhoodWaterLayer
 +
            validateRenderShaderContext -vertexFormat  position      0 required
 +
            validateRenderShaderContext -vertexFormat  normal        0 required
 +
            validateRenderShaderContext -vertexFormat  texcoord      0 required
 +
            viewerRenderTypePred viewerRenderType
 +
 
 +
            ################################################################################
 +
            # Two stage case since the three stage case above fails on most low end hardware because of its third stage (GF2).
 +
            pass -fixedFunction -modifiedEachFrameHint
 +
           
 +
           
 +
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
              colorScalar $nhoodWaterReflColour $nhoodWaterReflStrength
 +
              depthTest true -enableDepthWrite false
 +
             
 +
              stage
 +
                  ffTextureCoordsSource fromPosition
 +
                  ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
 +
                  textureAddressing clamp clamp
 +
                  texture "ScreenReflection"
 +
                 
 +
                  textureBlend multiply(texture colorScalar) select(outRegister)
 +
              end
 +
             
 +
              stage
 +
                  texture "neighborhood-water-1"
 +
                  textureAddressing tile tile
 +
                  # -atrans waveformType cycles/sec offset (startU, startV)  (endU, endV)
 +
                  #textureMatrixAnimation -targetType fixedFunction -atrans sawtooth ($nhoodWaterMap1Speed / $nhoodWaterMap1Scale) 0 (0, 0) ($nhoodWaterMap1Scale, 0) -ascale sawtooth 1 0 ($nhoodWaterMap1Scale, $nhoodWaterMap1Scale)
 +
                  ffTextureCoordsSource 0
 +
                  textureBlend lerpTextureAlpha(outRegister outRegister) select(colorScalar)
 +
              end
 +
             
 +
            end
 +
        end
 +
       
 +
       endif
 
        
 
        
       shaderProgram -target vertexProgram -method compile -version 1_1
+
       ################################################################################
         bindConstants 0 -bindingID geomToClip -constantCount 4
+
      # fallback: no reflection.
bindConstants 4 -bindingID immediateData -data (1/64, 0, 0, 0)
+
      shader -layer ($nhoodWaterLayer)
 +
         viewerRenderTypePred viewerRenderType
 +
       
 +
        create DetermineHardwareSupport()
 +
       
 +
        pass -fixedFunction
 +
  # For now, we are diabling the lighting since we simply want to use the vertex colors.
 +
  create LightingStatesNoStdLightsParam(false true)
 +
  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
 
 +
            colorScalar (.4, .6, .9, .6)    
 +
           
 +
            fillmode $stdMatFillMode
 +
            stage
 +
              #texture reflectionoutdoorwater-envcube
 +
              if ($cubeMapSupport)
 +
                  texture $skyboxCubeMap
 +
                  textureMIPFilterHint disabled
 +
 
 +
                  ffTextureCoordsSource fromReflectionVector
 +
                  ffTextureMatrix -orientCameraToGlobal
 +
 
 +
                  textureAddressing clamp clamp clamp
 +
                  textureBlend multiply(texture colorScalar) select(colorScalar)
 +
              else
 +
                  textureBlend select(colorScalar) select(colorScalar)
 +
              endif
 +
            end 
 +
        end 
 +
 +
      end
 +
 +
 +
      ################################################################################
 +
      # Final fallback.
 +
#<shader -layer ($nhoodWaterLayer)
 +
viewerRenderTypePred viewerRenderType
 
 
shaderSource
+
pass -fixedFunction
  float4x4 clipSpaceMatrix  : register(c0);
+
  float4  textureConstants : register(c4);  
+
+
struct InputVertex
+
{
+
float3 position: POSITION0;
+
float2 texcoord : TEXCOORD0;
+
};
+
 
 
struct OutputVertex
+
fillmode $stdMatFillMode
{
+
create LightingStatesNoStdLights()
float4 clipPosition : POSITION;
+
alphaBlend srcFactor(one) add dstFactor(srcAlpha)
float2 txBase  : TEXCOORD0;
+
colorScalar (.2, .3, .5, .05)     
};
+
stage
+
textureBlend select(colorScalar) select(colorScalar)
OutputVertex VertexMain( InputVertex i)
+
end
{
+
end
  OutputVertex o;
+
  o.clipPosition = mul(float4(i.position, 1), clipSpaceMatrix);
+
  o.txBase  = i.texcoord * textureConstants.xx;  
+
end#>
  return o;
+
}
+
        create NeighborhoodWaterSWVS()
endShaderSource 
+
               
      end # end shader program
+
     
+
 
        
 
        
      shaderProgram -target pixelProgram -method compile -version 1_1
+
end
        bindConstants 0 -bindingID immediateData -data ($terrainMatDiffCoef.x, $terrainMatDiffCoef.y, $terrainMatDiffCoef.z, 1)       
+
       
+
        shaderSource 
+
            float4  terrainDiffCoef  : register(c0);
+
                                   
+
            sampler base;           
+
            struct cInputPixel
+
            {             
+
              float2 tcBase : TEXCOORD0;             
+
            };
+
           
+
            float4 PixelMain(cInputPixel pi) : COLOR
+
            {       
+
              float4 baseColor  = tex2D(base, pi.tcBase);                                                             
+
              float4 result = 2.0*(baseColor*terrainDiffCoef);             
+
              result.a = terrainDiffCoef.w;
+
              return result;                       
+
            }
+
        endShaderSource
+
      end # end shader program     
+
       
+
      sampler base
+
        texture "floorLightMap_0"  # at the moment is deterministically mapped to page 0
+
        textureAddressing tile tile
+
      end           
+
  end 
+
 
enddef
 
enddef
  
define TerrainLighting()
 
  material
 
  create DetermineHardwareSupport()
 
 
      shader -layer (($terrainMatLayer - 1) * 8)
 
        vertexFormatPred position      0 true
 
        vertexFormatPred texcoord      0 true
 
        if (viewerRenderType != $kRenderTypeShadowMap)           
 
            if ($useHWShader2Path or $useHWShader1Path)
 
              create TerrainLightingVS_PS()
 
            else
 
              pass -fixedFunction           
 
                  fillmode $stdMatFillMode
 
  
                  alphaBlend srcFactor(destColor) add dstFactor(zero)
+
# ==============================================================================
 +
# The layer ID for this should be lower than "nhoodWaterLayer" Id because we want the farther side of the water box should be
 +
# drawn as well.
 +
# the layer ID of any under-water objects (so
 +
define NeighborhoodWaterEdge()
  
                  colorScalar $terrainMatDiffCoef 1  # important that alpha be one for ARGB capture.
+
  material
 
+
      if ($simpleTerrain)
                  ffDepthOffset 0
+
        shader
                  depthTest true -enableDepthWrite false           
+
        end
                  depthTestFunction acceptIfEqual
+
      endif
 
+
                  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                   
+
                         
+
              pass -fixedFunction
+
                  create LightingStatesNoStdLights()
+
                  fillmode $stdMatFillMode
+
 
+
                  alphaBlend srcFactor(zero) add dstFactor(one)
+
 
        
 
        
                  ffDepthOffset 0
 
                  depthTest true -enableDepthWrite false
 
                  alphaTest true 100
 
                  alphaTestFunction acceptIfLess
 
 
        
 
        
                  stage
+
      shader -layer (($nhoodWaterLayer - 1) * 8)
                    texture "floorLightMap_0" # at the moment is deterministically mapped to page 0
+
        validateRenderShaderContext -vertexFormat position      0 required
                    ffTextureMatrix -scalev (1/64, 1/64)
+
        validateRenderShaderContext -vertexFormat  texcoord      0 required
                    textureTransformType vector2
+
       
                    ffTextureCoordsSource 0
+
        pass -fixedFunction
                    textureBlend select(texture) select(texture)
+
            create LightingStates()
                  end  
+
            alphaBlend srcFactor(one) add dstFactor(zero)
              end            
+
            cullmode cullCounterClockwise
            endif       
+
 
        endif
+
            stage
 +
              texture $waterEdgeTexture
 +
              textureAddressing tile tile
 +
              ffTextureMatrix -scalev (1/$waterEdgeTextureScale, 1/$waterEdgeTextureScale)
 +
              ffTextureCoordsSource 0
 +
              textureBlend select(texture) select(diffuse)
 +
            end  
 +
        end  
 +
         
 
       end
 
       end
 
   end
 
   end
 +
 
 
enddef
 
enddef
  
#==============================================================================
+
# ==============================================================================
define TerrainToolThumbnail()
+
define NeighborhoodTerrainEdge()
 
   material
 
   material
       shader -layer ($terrainMatLayer * 8)
+
 
         vertexFormatPred position      0 true
+
      if ($simpleTerrain)
         vertexFormatPred normal        0 true
+
        shader
         vertexFormatPred texcoord      0 true
+
        end
        vertexFormatPred blendindices  0 false
+
      endif
        vertexFormatPred targetindices 0 false
+
     
 +
       shader -layer (($nhoodCanvasLayer + 13) * 8)
 +
         validateRenderShaderContext -vertexFormat  position      0 required
 +
         validateRenderShaderContext -vertexFormat  normal        0 required
 +
         validateRenderShaderContext -vertexFormat  texcoord      0 required
  
 
         pass -fixedFunction
 
         pass -fixedFunction
 
             create LightingStates()
 
             create LightingStates()
             alphaBlend srcFactor(srcAlpha) add dstFactor(zero)
+
             alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
            colorScalar $thumbnailMatDiffCoef
+
            fillmode $stdMatFillMode
+
           
+
 
             stage
 
             stage
               texture $paintTexture
+
               texture $terrainEdgeTexture
 
               textureAddressing tile tile
 
               textureAddressing tile tile
               textureBlend multiplyScale2(texture diffuse) select(texture)
+
              ffTextureMatrix -scalev (1/$terrainEdgeTextureScale, 1/$terrainEdgeTextureScale)
 +
              ffTextureCoordsSource 0
 +
               textureBlend multiply(texture diffuse) select(texture)
 
             end  
 
             end  
 
         end       
 
         end       
 +
       
 
       end
 
       end
 
   end
 
   end
 
enddef
 
enddef
  
define TerrainWaterShader(withBumpMap)
+
#==============================================================================
  shader -layer 1
+
define NHoodTerrainLighting()
      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
+
  set terrainRepresentativeTexture "lottexture-test-01_detail"
        colorScalar (1, 1, 1) -applyTextureLightColor 0 0                         
+
                 
+
        stage
+
            if ($cubeMapSupport)
+
              texture reflectionoutdoorwater-envcube
+
              textureMIPFilterHint disabled
+
  
              ffTextureCoordsSource fromReflectionVector
+
material
              textureTransformType vector3
+
shader -layer (($nhoodCanvasLayer + 3) * 8)
              ffTextureMatrix -orientCameraToGlobal
+
validateRenderShaderContext -vertexFormat  position      0 required
 +
validateRenderShaderContext -vertexFormat  normal        0 required
 +
 +
if (not $isImposter)
 +
  validateRenderShaderContext -vertexFormat  texcoord      0 required
 +
endif
 +
  
              textureAddressing clamp clamp clamp
+
        if (strcmp("Concrete", "${terrainType}") = 0)
              textureBlend multiply(texture colorScalar) select(diffuse)
+
             setb isTerrainConcrete true
            else
+
         endif
              colorScalar (0.3,0.5,1.0) -applyTextureLightColor 0 0   
+
              textureBlend select(colorScalar) select(diffuse)
+
             endif
+
         end         
+
      end 
+
 
        
 
        
      if (&withBumpMap)       
+
        if ($simpleTerrain)
        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
+
             if (strcmp("Desert", "${terrainType}") = 0)
               texture "water-1-bump"
+
               set terrainRepresentativeTexture "lottexture-canvas-desert"
              textureAddressing tile tile
+
            endif
               # -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)
+
            shader
              textureTransformType vector2
+
               pass -fixedFunction                 
              ffTextureCoordsSource 0
+
  ffDepthOffset -1                
              textureBlend select(texture) select(texture)
+
 
            end  
+
                  stage
 
+
    texture "nhoodLightMap"   
            stage
+
    if ($isImposter)
              texture "water-2-bump"
+
      ffTextureMatrix -cameraToGlobal -scalev (1280, 1280) -invert
              textureAddressing tile tile
+
      ffTextureCoordsSource fromPosition
              # -atrans waveformType cycles/sec offset (startU, startV)  (endU, endV)
+
  else
              textureMatrixAnimation -targetType fixedFunction -aorigin (0, 0) -atrans sine 0.04 0 (1, 0) (0, 0) -ascale sawtooth 1 0 ($waterbumpMapScale, $waterbumpMapScale)
+
      ffTextureMatrix -scalev (128, 128) -invert
              textureTransformType vector2
+
      ffTextureCoordsSource 0
              ffTextureCoordsSource 0
+
  endif
              textureBlend multiply(texture outRegister) select(texture)
+
                       
             end  
+
                    textureBlend select(texture) select(texture)
 +
                  end  
 +
                 
 +
                  stage  
 +
    texture $terrainRepresentativeTexture   
 +
    if ($isImposter)
 +
      ffTextureMatrix -cameraToGlobal -scalev (160, 160) -invert
 +
      ffTextureCoordsSource fromPosition
 +
  else
 +
      ffTextureMatrix -scalev (16, 16) -invert
 +
      ffTextureCoordsSource 0
 +
  endif
 +
   
 +
                    #textureBlend multiply(texture outRegister) select(outRegister)
 +
                    textureBlend select(texture outRegister) select(outRegister)
 +
                  end
 +
              end
 +
             end
 
              
 
              
            stage
+
        endif
              # does this work out on GF2 due to reg combiners?
+
     
              textureBlend multiply(outRegister colorScalar) select(colorScalar)
+
 
            end  
+
create DetermineHardwareSupport()
        end
+
      endif
+
if ($useSWVertexShaderPath)
  end
+
create NeighborhoodTerrainLightingSWVS()
 +
else
 +
pass -fixedFunction
 +
 +
create LightingStatesNoStdLights()
 +
 +
# standard Lightmap * dest
 +
alphaBlend srcFactor(destColor) add dstFactor(zero)
 +
 +
# if the outbound 'clip' texture has 0 in it, don't emit those pixels.
 +
alphaTest true 127
 +
alphaTestFunction acceptIfGreater
 +
 +
 +
fillmode $stdMatFillMode
 +
 +
if ($isImposter and $isTerrainConcrete)
 +
  ffDepthOffset -1        
 +
      endif
 +
           
 +
depthTestFunction acceptIfEqual
 +
            # emit the lightmap
 +
stage
 +
texture "nhoodLightMap"
 +
if ($isImposter)
 +
  ffTextureMatrix -cameraToGlobal -scalev (1280, 1280) -invert
 +
  ffTextureCoordsSource fromPosition
 +
else
 +
  ffTextureMatrix -scalev (128, 128) -invert
 +
  ffTextureCoordsSource 0
 +
endif
 +
 +
if (tsHasSnow >= 1)
 +
  colorScalar (0.3, 0.3, 0.35, 0)
 +
  else
 +
      colorScalar (0, 0, 0, 0)
 +
  endif
 +
 +
textureBlend add(texture colorScalar) select(texture)
 +
end 
 +
 +
# modulate by the 'above water' texture, which is a 2x1 texture with black and white in it.
 +
 +
stage
 +
# above water -- clip by using depth-based 0/1 texture.
 +
texture blackWhite
 +
textureAddressing clamp clamp
 +
textureFilterHint point point
 +
textureMIPFilterHint disabled
 +
                 
 +
if ( $isImposter)
 +
  ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 10, 0) -invert
 +
              else
 +
  ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
 +
endif
 +
ffTextureCoordsSource fromPosition
 +
textureBlend multiply(texture:alphaReplicate outRegister) select(texture)
 +
end  
 +
end
 +
endif  
 +
end
 +
end
 +
 
enddef
 
enddef
  
  
#==============================================================================
+
# ==============================================================================
define TerrainWater()
+
 
 +
define NHoodTerrainHighlightMaterial()
 
   material
 
   material
       # only activate the water w/ bump shader for pixel shader capable HW     
+
       shader -layer (($nhoodCanvasLayer + 9) * 8)
      if (tsFrozenPond)
+
         validateRenderShaderContext -vertexFormat  position      0 required
        create TerrainWaterFrozen()
+
         validateRenderShaderContext -vertexFormat  normal        0 required
      else
+
         validateRenderShaderContext -vertexFormat texcoord      0 required
         if (queryIntegerGraphicsDeviceCap(maxPixelProgramVersionMajor) != 0)       
+
            create TerrainWaterShader(true)
+
         endif
+
         create TerrainWaterShader(false) # fallback without bumps       
+
      endif
+
  end
+
enddef
+
  
define TerrainWaterFrozen()
+
create DetermineHardwareSupport()
  shader -layer 1
+
      pass -fixedFunction
+
if ($useSWVertexShaderPath)
            create LightingStatesNoStdLightsParam(false false)                          
+
create NeighborhoodTerrainHighlightSWVS()
        alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
else
        fillmode $stdMatFillMode
+
pass -fixedFunction
        colorScalar (0.45, 0.45, 0.5, 0.475) -applyTextureLightColor 0 0
+
create LightingStates()
       
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
        stage
+
fillmode $stdMatFillMode
            texture "ice-pond-surface"
+
  colorScalar (1, 1, 1, $highlightAlpha)
            textureAddressing tile tile                                                  
+
           
            ffTextureCoordsSource fromPosition
+
stage
            ffTextureMatrix -cameraToGlobal -scale (5) -invert
+
texture $highlightTexture
            textureBlend multiply(texture colorScalar) select(colorScalar)
+
textureAddressing tile tile
        end                        
+
textureBlend select(texture) multiply(texture colorScalar)
       
+
end  
        stage
+
end   
            texture "ice-pond-surface"
+
endif
            textureAddressing tile tile                                                 
+
 
            ffTextureCoordsSource fromPosition
+
       end
            ffTextureMatrix -cameraToGlobal -scale (17) -invert                   
+
            textureBlend multiplyAdd(texture colorScalar outRegister) add(colorScalar outRegister)
+
        end
+
       end                      
+
 
   end
 
   end
enddef
 
 
#==============================================================================
 
 
define TerrainSnowShader() 
 
  create DetermineHardwareSupport()
 
  if ($useHWShader1Path or $useHWShader2Path)
 
create TerrainSnow()
 
else 
 
      create TerrainSnowFF()
 
  endif     
 
 
enddef
 
enddef
  
define TerrainSnowFF()
+
# ==============================================================================
 +
define NHoodTerrainOutlineHighlightMaterial()
 
   material
 
   material
       shader -layer 0
+
       shader -layer (($nhoodCanvasLayer + 10) * 8)
         pass -fixedFunction
+
         validateRenderShaderContext -vertexFormat  position      0 required
            depthTest true -enableDepthWrite true
+
        validateRenderShaderContext -vertexFormat  normal        0 required
            if (tsIsDay)
+
        validateRenderShaderContext -vertexFormat  texcoord      0 required
              colorScalar (0.5, 0.5, 0.52, 1)
+
 
            else
+
pass -fixedFunction
              colorScalar (0.15, 0.15, 0.375, 1)
+
  create LightingStatesNoStdLights()
            endif
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
             
+
fillmode $stdMatFillMode
              stage                                       
+
depthTest true -enableDepthWrite false
                  texture "snow-ground-diffuse"
+
           
                  textureAddressing tile tile 
+
stage
                  ffTextureCoordsSource fromPosition
+
texture $texture
                  ffTextureMatrix -cameraToGlobal -scalev (2, 2) -invert                           
+
textureAddressing clamp clamp
                  textureBlend multiply(texture colorScalar) select(colorScalar)
+
ffTextureCoordsSource 0
              end           
+
textureBlend select(texture) select(texture)
             
+
end  
              stage                                        
+
end    
                  texture "snow-ground-diffuse"
+
                  textureAddressing tile tile 
+
                  ffTextureCoordsSource fromPosition
+
                  ffTextureMatrix -cameraToGlobal -scalev (13, 13) -invert                           
+
                  textureBlend multiplyAdd(texture colorScalar outRegister) select(colorScalar)
+
              end          
+
        end
+
 
       end
 
       end
 
   end
 
   end
 
enddef
 
enddef
  
define TerrainSnowPS1() 
+
# ==============================================================================
  shaderProgram -target pixelProgram -method compile -version 1_1 # -disassemble "c:\sims2ep5\hlslPS1_1.txt"                           
+
setb nhoodIsPartlyUnderwater false
      bindConstants 0 -bindingID cursorTerrainPosition -constantCount 1 -constantType float
+
define PartiallyUnderWaterMaterial()
      if (tsIsDay)        
+
        bindConstants 1 -bindingID immediateData -data (1.1, 1.1, 1.175, 1)       
+
      else
+
        bindConstants 1 -bindingID immediateData -data (0.35, 0.35, 1.0, 1)       
+
      endif
+
           
+
      shaderSource
+
        sampler normmap;
+
                                                                                               
+
        float4 cursorPos : register(c0);
+
        float4 colorFactor : register(c1);
+
       
+
        struct v2f
+
        {
+
            float4 hpos : POSITION;                           
+
            float4 color : COLOR0;            
+
        float3 worldPos : COLOR1;              
+
        float3 bumpCoords : TEXCOORD0;
+
        float3 tanLightDir : TEXCOORD1;                                
+
        };
+
  
        float4 PixelMain(v2f pi) : COLOR
+
   seti vt viewerRenderType
        {     
+
            float4 normal = 2.0f * (tex2D(normmap, pi.bumpCoords) - 0.5f); 
+
            float3 diffuse = saturate(dot(pi.tanLightDir, normal.xyz))*colorFactor.xyz;           
+
            return float4(diffuse.xyz + pi.color, 1.0f);                       
+
        }
+
      endShaderSource                                                                                                           
+
   end                                           
+
 
    
 
    
  sampler normmap
+
## prevents the thumbnails of rocks and such from being 'under water', by punting to standard material.
      texture "snow-ground-bump"
+
   # thumbnails are rendered at 0,0,0, but water tends to be above them at 312 ft/yards whatever.
      textureAddressing tile tile
+
   end
+
 
    
 
    
 +
if (viewerRenderType = $kRenderTypeThumbnail)
 +
create StandardMaterial()     
 +
    else
 +
    create UnderWaterShadingMaterial()
 +
endif
 +
 
enddef
 
enddef
 +
 +
define UnderWaterShadingMaterial()
 +
 
 +
  material
 +
      shader -layer (($nhoodCanvasLayer + 4) * 8)
 +
        validateRenderShaderContext -vertexFormat  position 0 required
 +
        validateRenderShaderContext -vertexFormat  normal  0 required
 +
        validateRenderShaderContext -viewerRenderType viewerRenderType
 +
 
 +
        if ($stdMatBaseTextureEnabled)
 +
            validateRenderShaderContext -vertexFormat  texcoord 0 required
 +
        endif
 +
 
  
define TerrainSnowPS2() 
+
 
   shaderProgram -target pixelProgram -method compile -version ${psVersion}_0 # -disassemble "c:\sims2ep5\hlslPS1_1.txt"                           
+
        pass -fixedFunction
      bindConstants 0 -bindingID cursorTerrainPosition -constantCount 1 -constantType float                       
+
    
  if (tsIsDay)       
+
            ffMatCoef -amb $stdMatDiffCoef -ambAlpha $stdMatAlphaMultiplier -diff $stdMatDiffCoef -diffAlpha $stdMatAlphaMultiplier -emit $stdMatEmissiveCoef -emitAlpha $stdMatAlphaMultiplier -spec $stdMatSpecCoef -specPow $stdMatSpecPower
        bindConstants 1 -bindingID immediateData -data (1.1, 1.1, 1.175, 1)       
+
 
      else
+
            create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
        bindConstants 1 -bindingID immediateData -data (0.35, 0.35, 1.0, 1)        
+
            fillmode $stdMatFillMode
      endif
+
            cullmode $stdMatCullMode
 
+
 
      shaderSource                       
+
            create LightingStates()                      
       
+
                       
        sampler normmap;       
+
             stage
       
+
              create StandardShaderTextureState(Base)              
        float4 cursorPos : register(c0);
+
              textureBlend multiply(texture outRegister) multiply(texture outRegister)              
        float4 colorFactor : register(c1);
+
             end
       
+
        struct v2f
+
        {
+
             float4 hpos : POSITION;                           
+
        float4 color : COLOR0;                                        
+
        float3 worldPos : COLOR1;             
+
        float2 bumpCoords : TEXCOORD0;                                 
+
        float3 tanLightDir : TEXCOORD1;                                     
+
        };
+
 
+
        float4 PixelMain(v2f pi) : COLOR
+
        {                                                 
+
            float4 normal0 = 2.0f * (tex2D(normmap, pi.bumpCoords) - 0.5f);                       
+
            float4 normal1 = 2.0f * (tex2D(normmap, pi.bumpCoords*0.4f) - 0.5f);
+
             float4 normal = 0.5f*(normal0+normal1);
+
            float3 diffuse0 = saturate(dot(pi.tanLightDir, normal.xyz))*colorFactor.xyz;           
+
 
              
 
              
             float3 diffVec = cursorPos-pi.worldPos;           
+
             #################################################################
            diffVec *= 64.0f;
+
            if ($stdMatIsPartlyUnderwater and tsIsInNeighborhood)
            float blend = saturate(dot(diffVec, diffVec));                                                                                               
+
              if (viewerRenderType = $kRenderTypeReflection)
             return float4(saturate(float3(diffuse0.xyz + pi.color.xxx)), blend);                       
+
                  alphaTest true 128
         }
+
                  alphaTestFunction acceptIfGreater
      endShaderSource
+
                  stage
  end                                          
+
                    # above water -- clip by using depth-based 0/1 texture.
 +
                    texture blackWhite
 +
                    textureAddressing clamp clamp
 +
                    textureFilterHint point point
 +
                    textureMIPFilterHint disabled
 +
                       
 +
                    ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
 +
                    ffTextureCoordsSource fromPosition
 +
                    textureBlend multiply(texture outRegister) select(texture)
 +
                  end
 +
              else
 +
                  stage
 +
                    # would we want to source this from somewhere?
 +
                    texture $waterGradientTexture
 +
                    textureAddressing tile clamp
 +
                   
 +
                    set d ($waterHeight - $waterGradientZoneStart)
 +
                    set s (-$waterGradientZoneSize)
 +
                    ffTextureMatrix -cameraToGlobal -order xzyw -scale $s -trans (0, $d) -invert
 +
                    ffTextureCoordsSource fromPosition
 +
                    textureBlend multiply(texture outRegister) select(outRegister)
 +
                  end       
 +
              endif
 +
             else
 +
              # if we are in lot mode and we want to fade this shape
 +
              if (numLightsOfType(${kShapeColorLight}) != 0)
 +
                  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
                  depthTest true -enableDepthWrite false
 +
                  colorScalar (1, 1, 1, 1) -applyShapeColor 0
 +
                  stage
 +
                    textureBlend select(outRegister) select(colorScalar)
 +
                  end
 +
              endif
 +
            endif
 +
            #################################################################
 +
         end
 +
       
 +
        seti weatherLightCount (numLightsOfType(${kWeatherLight}))
 +
       
 +
      end
 +
     
 +
      # fallback shader, no darken by depth, since "FromPosition" tends to be totally FUBAR  in SWVP.
 +
      shader -layer (($nhoodCanvasLayer + 4) * 8)
 +
     
 +
pass -fixedFunction
 
    
 
    
  sampler normmap
+
            ffMatCoef -amb $stdMatDiffCoef -ambAlpha $stdMatAlphaMultiplier -diff $stdMatDiffCoef  -diffAlpha $stdMatAlphaMultiplier -emit $stdMatEmissiveCoef -emitAlpha $stdMatAlphaMultiplier -spec $stdMatSpecCoef -specPow $stdMatSpecPower
      texture "snow-ground-bump"
+
      textureAddressing tile tile
+
  end             
+
 
    
 
    
enddef
+
            create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
 
+
            fillmode $stdMatFillMode
define TerrainSnowVS1()
+
            cullmode $stdMatCullMode
  shaderProgram -target vertexProgram -method compile -version 1_1
+
 
      bindConstants 0 -bindingID  geomToClip    -constantCount 4       
+
            create LightingStates()
      bindConstants 4 -bindingID  geomToCamera  -constantCount 3
+
           
bindConstants 7 -bindingID  cameraToGeom  -constantCount 3
+
            stage
bindConstants 15 -bindingID ambientLight -constantCount 1 -constantType float                        
+
              create StandardShaderTextureState(Base)             
bindConstants 18 -bindingID allStandardLightData -constantCount 4 -constantType float      
+
              textureBlend multiply(texture outRegister) multiply(texture outRegister)
 +
            end
 +
           
 +
            # if we are in lot mode and we want to fade this shape
 +
            if (not tsIsInNeighborhood and numLightsOfType(${kShapeColorLight}) != 0)
 +
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
              depthTest true -enableDepthWrite false
 +
              colorScalar (1, 1, 1, 1) -applyShapeColor 0
 +
              stage
 +
                  textureBlend select(outRegister) select(colorScalar)
 +
              end
 +
            endif
 +
           
 +
end
 
 
if (tsIsDay)       
 
        bindConstants 10 -bindingID immediateData -data (1.2, 1.2, 1.2, 1)       
 
      else
 
        bindConstants 10 -bindingID immediateData -data (0.64, 0.64, 1.1, 1)       
 
      endif
 
 
        
 
        
       bindConstants 12 -bindingID geomToGlobal -constantCount 3
+
       end
                   
+
      bindConstants 22 -bindingID cameraToClipWithDepthOffset -constantCount 4 -data(0, 0, 0, 0)
+
+
shaderSource
+
float4x4 modelviewproj : register(c0);
+
float4x3 modelview : register(c4);
+
float4x3 modelviewInv : register(c7);            
+
        // light direction
+
float4 lightDir0 : register(c18);
+
float4 lightDir1 : register(c26);
+
float4x4 cameraToClipWithDOMatrix : register(c22);
+
        float4 ambient : register(c15);                                 
+
        float4x3 modelToWorld : register(c12);
+
     
+
struct a2v
+
        {
+
            float4 pos : POSITION;                   
+
            float3 normal : NORMAL;
+
            float2 tangent : TEXCOORD0;
+
            float2 bumpcoord : TEXCOORD1;                   
+
        };
+
  
        struct v2f
+
   end
        {
+
            float4 hpos : POSITION;                                         
+
        float4 color : COLOR0;                                    
+
        float3 worldPos : COLOR1;        
+
        float2 bumpCoords : TEXCOORD0;
+
        float3 tanLightDir : TEXCOORD1;                                                                                                                                       
+
        };
+
       
+
        v2f VertexMain(a2v IN)
+
        {
+
        v2f OUT;
+
 
+
        // vertex position in object space
+
        float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);  
+
       
+
        float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);
+
                         
+
        // compute binormal
+
        float3 binormal = normalize(cross(IN.normal, tangent));
+
       
+
        // tangent space matrix
+
        float3x3 tbn = float3x3(tangent, binormal, IN.normal);
+
       
+
        // light direction in object space                  
+
        float3 lt0 = mul(lightDir0, (float3x3)modelviewInv);
+
       
+
        // light 0 direction in tangent space                                    
+
        OUT.tanLightDir = normalize(mul(tbn, lt0));
+
                       
+
        OUT.bumpCoords = float2(IN.bumpcoord.x, IN.bumpcoord.y);
+
       
+
        // compute tangent space view vector
+
        // object space view point
+
        float3 viewPoint = mul(float4(0, 0, 0, 1), modelviewInv).xyz;
+
        float3 viewVecObj = normalize(viewPoint - IN.pos.xyz);
+
       
+
        // object space light
+
        float3 lightDirObj = normalize(mul(lightDir0, (float3x3)modelviewInv));
+
       
+
        // half angle vector in object space
+
        float3 halfWayVector = normalize(lightDirObj + viewVecObj);                  
+
       
+
        // transform half angle vector to tangent space
+
        //OUT.tanHalfAngle.xyz = normalize(mul(tbn, halfWayVector));
+
       
+
        // specular shadowing term
+
        //OUT.tanHalfAngle.w = max(dot(halfWayVector, IN.normal), 0);                  
+
       
+
        // vertex position in clip space
+
        float3 hposView = mul(pos, modelview);
+
            OUT.hpos = mul(float4(hposView, 1), cameraToClipWithDOMatrix);                                     
+
           
+
            // vertex position in world space
+
            OUT.worldPos = mul(pos, modelToWorld)/64.0f;                                           
+
                                                             
+
        OUT.color.xyz = ambient.xyz*0.3f;
+
        OUT.color.w = 1.0;        
+
        return OUT;
+
        }
+
                 
+
endShaderSource
+
   end # end shader program 
+
 
enddef
 
enddef
  
define TerrainSnow()
+
 
 +
 
 +
# ===================================================================================
 +
define ImposterArrowMaterial()
 
   material
 
   material
       shader -layer 1       
+
       shader -layer (($nhoodCanvasLayer + 11) * 8)
        validateRenderShaderContext -vertexFormat position 0 required
+
        validateRenderShaderContext -vertexFormat normal 0 required
+
        validateRenderShaderContext -vertexFormat texcoord 0 required
+
        validateRenderShaderContext -vertexFormat texcoord 1 required
+
 
          
 
          
         create DetermineHardwareSupport()
+
         validateRenderShaderContext -vertexFormat  position      0 required
                         
+
        validateRenderShaderContext -vertexFormat  normal        0 required
         pass
+
         validateRenderShaderContext -vertexFormat  texcoord      0 required
            alphaTest true 5
+
            alphaTestFunction acceptIfGreater
+
  
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
pass -fixedFunction
            depthTest true -enableDepthWrite true
+
  create LightingStatesNoStdLights()
           
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
            create TerrainSnowVS1()
+
fillmode $stdMatFillMode
           
+
             # TODO: change this, cannot turn off depth since that is used for dirty rect
            if ($useHWShader1Path)
+
depthTest false -enableDepthWrite false
              create TerrainSnowPS1()
+
           
            elseif ($useHWShader2Path)             
+
stage
              create TerrainSnowPS2()
+
texture $texture
            endif
+
textureAddressing tile tile
                                                 
+
ffTextureCoordsSource 0
        end # end pass
+
textureBlend select(texture) select(texture)
       
+
end  
      end #end shader
+
end    
  end # end material
+
enddef
+
 
+
define XRayCursorMaterial()
+
  material
+
      shader -layer (0)
+
        pass -fixedFunction -modifiedEachFrameHint
+
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
             depthTest true -enableDepthWrite false
+
                       
+
            colorScalar (1, 1, 0, 0.0)
+
            stage
+
              textureBlend select(colorScalar) select(colorScalar)
+
            end
+
        end
+
 
       end
 
       end
 
   end
 
   end
 
enddef
 
enddef
  
define LightSnowDayPS(psFullVersion)
+
# ===================================================================================
  shaderProgram -target pixelProgram -method compile -version &psFullVersion
+
      if ($singlePass)
+
        bindConstants 0 -bindingID immediateData -data (0, 0, 0, 0) -constantType float
+
      else
+
        bindConstants 0 -bindingID immediateData -data (1, 0, 0, 0) -constantType float
+
      endif
+
     
+
      shaderSource   
+
        float scale2Factor : register(c0);       
+
                               
+
        sampler base;           
+
        sampler base2;
+
        struct cInputPixel
+
        {             
+
            float2 txScale1  : TEXCOORD0;
+
float2 txScale2  : TEXCOORD1;
+
        };
+
       
+
        float4 PixelMain(cInputPixel pi) : COLOR
+
        {       
+
            float4 scale1Color = tex2D(base, pi.txScale1);                                               
+
            float4 scale2Color = tex2D(base2, pi.txScale2)*scale2Factor.x;                             
+
            float4 result = (scale1Color + scale2Color);           
+
            return result;                       
+
        }
+
      endShaderSource
+
  end # end shader program     
+
enddef
+
  
define LightSnowNightPS(psFullVersion)
+
define NeighborhoodTreeGUOBMaterial()
  shaderProgram -target pixelProgram -method compile -version &psFullVersion
+
      if ($singlePass)
+
        bindConstants 0 -bindingID immediateData -data (0, 0, 0, 0) -constantType float
+
      else
+
        bindConstants 0 -bindingID immediateData -data (1, 1, 0, 0) -constantType float
+
      endif
+
     
+
      shaderSource   
+
        float2 scale2Factor : register(c0);       
+
                               
+
        sampler base; 
+
        sampler base2;
+
        sampler lightMap;         
+
        struct cInputPixel
+
        {             
+
            float2 txScale1  : TEXCOORD0;
+
float2 txScale2  : TEXCOORD1;
+
float2 txltMap  : TEXCOORD2;
+
        };
+
       
+
        float4 PixelMain(cInputPixel pi) : COLOR
+
        {       
+
            float4 scale1Color = tex2D(base, pi.txScale1);                                               
+
            scale1color.xyz = scale1color.xyz;
+
            float4 scale2Color = tex2D(base2, pi.txScale2)*scale2Factor.x;
+
            float4 result = (scale1Color + scale2Color);             
+
            float4 lightMapColor = tex2D(lightMap, pi.txltMap);
+
            return float4(result.xyz*lightMapColor.xyz, result.w);                       
+
        }
+
      endShaderSource
+
  end # end shader program     
+
enddef
+
  
 +
# $stdMatTextureName
 +
# $stdMatAlphaMulitplier
  
define LightSnowVS_PS()
+
  # TODO: fix these so that they are not hardcoded, must be passed through content
  pass
+
   set textureName      "genericroundsoftguob-alpha"
      alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
   setf alphaMultiplier  0.65
      depthTest true -enableDepthWrite false     
+
      depthTestFunction acceptIfEqual
+
     
+
      shaderProgram -target vertexProgram -method compile -version 1_1
+
        bindConstants 0 -bindingID geomToClip -constantCount 4
+
        bindConstants 4 -bindingID geomToGlobal -constantCount 3
+
        bindConstants 8 -bindingID immediateData -data (1/(($scaleStage1).x), 1/(($scaleStage1).y), 1/(($scaleStage2).x), 1/(($scaleStage2).y)) -constantType float
+
+
shaderSource
+
  float4x4 clipSpaceMatrix  : register(c0);  
+
  float4x3 modelToWorld : register(c4);
+
  float4 scaleData : register(c8);
+
+
struct InputVertex
+
{
+
float3 position: POSITION0;
+
float2 txCoord : TEXCOORD0;
+
};
+
+
struct OutputVertex
+
{
+
float4 clipPosition : POSITION;
+
float2 txScale1  : TEXCOORD0;
+
float2 txScale2  : TEXCOORD1;
+
float2 txltMap    : TEXCOORD2;
+
};
+
+
OutputVertex VertexMain( InputVertex i)
+
{
+
  OutputVertex o;
+
  o.clipPosition = mul(float4(i.position, 1), clipSpaceMatrix);
+
  float3 worldPos = mul(float4(i.position.xyz, 1.0f), modelToWorld);
+
  o.txScale1   = worldPos.xy * scaleData.xy;
+
  o.txScale2  = worldPos.xy * scaleData.zw;
+
  o.txltMap = i.txCoord;
+
  return o;
+
}
+
endShaderSource 
+
      end # end shader program
+
     
+
      if (tsIsDay)
+
        if ($useHWShader1Path)
+
      create LightSnowDayPS("1_1")
+
      else    
+
            create LightSnowDayPS(${psVersion}_0)
+
        endif
+
      else
+
        if ($useHWShader1Path)
+
      create LightSnowNightPS("1_1")
+
      else 
+
            create LightSnowNightPS(${psVersion}_0)
+
        endif
+
      endif
+
       
+
      sampler base
+
        texture "${snowTexture}"
+
        textureAddressing tile tile
+
      end
+
     
+
      sampler base2
+
        texture "${snowTexture2}"
+
        textureAddressing tile tile
+
      end
+
     
+
      if (not tsIsDay)
+
        sampler lightMap
+
            texture "floorLightMap_${page}"
+
            textureAddressing tile tile
+
        end
+
      endif
+
  end
+
enddef
+
  
define LightSnowFF()
+
  # try using vs_2_sw on the trees since sw vs is not as susceptible to state changes
  pass -fixedFunction       
+
      alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
      fillmode $stdMatFillMode           
+
      depthTest true -enableDepthWrite false                       
+
     
+
      if ($kRaiseLightSnowFF)
+
        ffDepthOffset 2
+
        depthTestFunction acceptIfLessOrEqual     
+
      else
+
        depthTestFunction acceptIfEqual     
+
      endif     
+
             
+
      stage
+
        texture $snowTexture
+
        textureAddressing tile tile
+
        ffTextureCoordsSource fromPosition
+
        ffTextureMatrix -cameraToGlobal -scalev $scaleStage1 -invert             
+
        textureBlend select(texture) select(texture)
+
      end
+
     
+
      if (not $singlePass)         
+
        stage
+
            texture $snowTexture2
+
            textureAddressing tile tile
+
            ffTextureMatrix  -cameraToGlobal -scalev $scaleStage2 -invert
+
            ffTextureCoordsSource fromPosition
+
            textureBlend add(texture outRegister) add(outRegister texture)
+
        end
+
      else
+
        # a dummy stage so if the shader has to fail it should fail
+
        stage           
+
            texture "floorLightMap_${page}"
+
            textureBlend select(outRegister) select(outRegister)
+
        end
+
      endif     
+
  
     
+
  # this only handles tree GUOBs in the nhood.
      if (not tsIsDay)
+
  material
        stage
+
            texture "floorLightMap_${page}"
+
            textureAddressing tile tile
+
            ffTextureCoordsSource 0                                           
+
            textureBlend multiplyScale2(texture outRegister) select(outRegister)
+
        end
+
      endif
+
     
+
      # a dummy stage so if the shader has to fail it should fail
+
      stage           
+
        texture "floorLightMap_${page}"
+
        textureBlend select(outRegister) select(outRegister)
+
      end
+
 
    
 
    
  end     
+
      #the engine will try this shader first..
enddef
+
      shader -layer $nhoodTreeShadowLayer
 
+
        # shadows can never be seen in reflections (they're on the ground)
define LightSnowFFLowEnd()
+
         viewerRenderTypePred $kRenderTypeReflection false
  pass -fixedFunction          
+
     
      alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
        pass
      fillmode $stdMatFillMode            
+
          alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
      depthTest true -enableDepthWrite false                   
+
           depthTest true -enableDepthWrite false
      ffDepthOffset 1
+
         
      depthTestFunction acceptIfLessOrEqual     
+
            shaderProgram -target vertexProgram -method assemble
     
+
              bindConstants 0 -bindingID geomToClip -constantCount 4
      if (tsIsDay)       
+
              shaderSource
        colorScalar (1, 1, 1, 1)       
+
                 vs_1_1
      else
+
                dcl_position v0
        colorScalar (0.17, 0.17, 0.43, 1)       
+
                dcl_texcoord v1
      endif
+
                m4x4 oPos, v0, c0
             
+
                mov oT0, v1
      stage
+
               
        texture $snowTexture
+
              endShaderSource
        textureAddressing tile tile
+
            end
        ffTextureCoordsSource fromPosition
+
         
        ffTextureMatrix -cameraToGlobal -scalev $scaleStage1 -invert             
+
            shaderProgram -target pixelProgram -method assemble
        textureBlend multiply(texture colorScalar) select(texture)
+
              shaderSource
 +
                  ps_1_1
 +
                  def c0,1,1,1,$alphaMultiplier
 +
                  tex t0
 +
                  mul r0,t0, c0
 +
              endShaderSource
 +
             
 +
            end
 +
           
 +
            sampler 0
 +
              texture $textureName
 +
              textureAddressing clamp clamp clamp
 +
            end
 +
        end
 
       end
 
       end
 
        
 
        
      if (not $singlePass)          
+
  # and fall back to this one if it can't render the above.
        stage
+
  shader -layer $nhoodTreeShadowLayer
            texture $snowTexture
+
        # shadows can never be seen in reflections (they're on the ground)
            textureAddressing tile tile
+
        viewerRenderTypePred $kRenderTypeReflection false
            ffTextureMatrix  -cameraToGlobal -scalev $scaleStage2 -invert
+
     
            ffTextureCoordsSource fromPosition
+
        pass -fixedFunction
            textureBlend multiplyAdd(texture colorScalar outRegister) add(outRegister texture)
+
          alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
        end
+
          depthTest true -enableDepthWrite false
      else
+
         
        stage
+
          colorScalar (1,1,1, $alphaMultiplier)
            texture $snowTexture
+
         
            textureAddressing tile tile
+
          stage
            ffTextureCoordsSource fromPosition
+
              texture $textureName
            ffTextureMatrix -cameraToGlobal -scalev $scaleStage1 -invert                
+
              textureAddressing clamp clamp clamp
            textureBlend multiplyAdd(texture colorScalar outRegister) select(outRegister)
+
               textureBlend select(texture) multiply(texture colorScalar)
        end
+
          end
      endif     
+
        end
 +
  end
 +
   
 +
  end
  
  end     
 
 
enddef
 
enddef
  
define LightSnow()
+
#=======================================================================================
   material
+
define NeighborhoodBuildingMaterial()
       setv2 scaleStage1 (23, 23)
+
   material
      setv2 scaleStage2 (17, 17)
+
       shader -layer 0 
     
+
        setb isDay tsIsDay
      if (tsHasHail)
+
        setb shouldShow (($showOnDay and $isDay) or ((not $showOnDay) and (not $isDay)))
        set snowTexture "hail-ground-surface"
+
        if ($shouldShow)
        set snowTexture2 "hail-ground-surface"
+
            pass -fixedFunction   
        setv2 scaleStage1 (4, 4)
+
             
        setv2 scaleStage2 (3, 3)
+
              if (numLightsOfType(${kShapeColorLight}) > 0)             
      endif
+
                  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 
+
                  depthTest true -enableDepthWrite false             
      shader -layer (-1)
+
                  colorScalar (1, 1, 1, 1) -applyShapeColor 0
        create DetermineHardwareSupport()             
+
              else
        if ((not $kRaiseLightSnowFF and $useHWShader1Path) or $useHWShader2Path)
+
                  colorScalar (1, 1, 1, 1)
      create LightSnowVS_PS()
+
              endif    
      else  
+
             
            create LightSnowFF() # can use more than two stages
+
             
 +
              if ($isDay) #lighting is only applied at day time
 +
                  ffLighting -enable true -localViewer false -normalizeNormals false
 +
                  create NonStandardLighting()             
 +
                  ffMatCoef -amb (0.8,0.8,0.8) -ambAlpha 1.0 -diff (0.8,0.8,0.8) -diffAlpha 1.0 -spec (0,0,0) -specPow 0
 +
             
 +
                  stage
 +
                    ffTextureCoordsSource 0
 +
                    texture $texMaterial
 +
                    textureBlend multiply(texture diffuse) multiply(texture colorScalar)
 +
                  end
 +
              else
 +
                  stage
 +
                    ffTextureCoordsSource 0
 +
                    texture $texMaterial
 +
                    textureBlend select(texture) multiply(texture colorScalar)
 +
                  end
 +
              endif
 +
            end           
 
         endif
 
         endif
      end
 
     
 
      shader -layer (-1)      #if the above shader fails for some reason
 
        create LightSnowFFLowEnd()
 
 
       end
 
       end
 
   end   
 
   end   
 
enddef
 
enddef
 +
#============================================================================================
 +
 +
# make tree shadows render to an opaque (but blended layer) so they drop into the static layer
 +
# this overrides the texture name and alpha blend level.
  
materialDefinition TerrainSnowMaterial
+
materialDefinition neighborhood_roundshadow
   setDefinition TerrainSnowShader   
+
   setDefinition NeighborhoodTreeGUOBMaterial
 
end
 
end
  
materialDefinition RoadSnowMaterial
+
# rectangular shadows are used by the car shadows, until can pass the existing texture name onto the material,
  setDefinition LightSnow
+
# leave those shadows as transparent layer 7 that will get alpha sorted, etc.
  addParam snowTexture snow-light-pass2 
+
#materialDefinition neighborhood_rectangularshadow
  addParam snowTexture2 snow-light-pass1 
+
setDefinition NeighborhoodTreeGUOBMaterial
   addParam singlePass true
+
#end
   addParam page 0
+
 
 +
# forest
 +
materialDefinition forest_01_shadows
 +
   setDefinition NeighborhoodTreeGUOBMaterial
 +
end
 +
materialDefinition forest_02_shadows
 +
   setDefinition NeighborhoodTreeGUOBMaterial
 
end
 
end
  
materialDefinition LightSnowMaterial
 
  setDefinition LightSnow
 
  addParam snowTexture snow-light-pass2
 
  addParam snowTexture2 snow-light-pass1
 
  addParam singlePass false
 
  addParam page 0 
 
end
 
  
materialDefinition terrainLightingMaterial
+
# oak
   setDefinition TerrainLighting
+
materialDefinition treeoak01_shadows
 +
  setDefinition NeighborhoodTreeGUOBMaterial
 +
end
 +
materialDefinition treeoak02_shadows
 +
  setDefinition NeighborhoodTreeGUOBMaterial
 +
end
 +
materialDefinition treeoak03_shadows
 +
  setDefinition NeighborhoodTreeGUOBMaterial
 +
end
 +
materialDefinition treeoak04_shadows
 +
  setDefinition NeighborhoodTreeGUOBMaterial
 +
end
 +
materialDefinition treeoak05_shadows
 +
  setDefinition NeighborhoodTreeGUOBMaterial
 +
end
 +
materialDefinition treeoak06_shadows
 +
   setDefinition NeighborhoodTreeGUOBMaterial
 
end
 
end
  
materialDefinition waterOnTerrain
+
# scrub oak
   setDefinition TerrainWater
+
materialDefinition neighborhoodtreescruboak_shadows_alpha
 +
   setDefinition NeighborhoodTreeGUOBMaterial
 
end
 
end
  
materialDefinition XrayCursorBoxDirtyRectMaterial
+
# birch
   setDefinition XRayCursorMaterial
+
materialDefinition treebirch01_shadows
 +
   setDefinition NeighborhoodTreeGUOBMaterial
 +
 
 
end
 
end
 +
materialDefinition treebirch02_shadows
 +
  setDefinition NeighborhoodTreeGUOBMaterial
 +
 
 +
end
 +
materialDefinition treebirch03_shadows
 +
  setDefinition NeighborhoodTreeGUOBMaterial
  
define GeneralSnowMaterialFF()
+
end
   material     
+
materialDefinition treebirch04_shadows
      shader -layer ($stdMatLayer)
+
  setDefinition NeighborhoodTreeGUOBMaterial
        pass -fixedFunction           
+
end
            create LightingStatesParam(false false)    
+
materialDefinition treebirch05_shadows
            setv3 half (0.5,0.5,0.5)
+
  setDefinition NeighborhoodTreeGUOBMaterial
            if ($stdMatSpecPower != 0)
+
end
        ffMatCoef -amb ($stdMatDiffCoef * $half) -ambAlpha $stdMatAlphaMultiplier -diff ($stdMatDiffCoef * $half) -diffAlpha $stdMatAlphaMultiplier -spec $stdMatSpecCoef -specPow $stdMatSpecPower
+
materialDefinition treebirch06_shadows
        addSpecular true
+
  setDefinition NeighborhoodTreeGUOBMaterial
        else
+
end
        ffMatCoef -amb ($stdMatDiffCoef * $half) -ambAlpha $stdMatAlphaMultiplier -diff ($stdMatDiffCoef * $half) -diffAlpha $stdMatAlphaMultiplier -spec (0,0,0) -specPow 0
+
 
        endif
+
# TODO: need to redefine the tree shaders, at least skip in reflections
       
+
#  this is also causing massive batch count for main view (scrolling)
        create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
+
# all trees should be combined into a single part/texture atlas with their shadows
                       
+
# render them after the terrain
       
+
#materialDefinition treeoak01_diffuse
        stage
+
#  setDefinition StandardMaterial
            texture $stdMatBaseTextureName
+
#end
            textureBlend multiplyScale2(diffuse texture) select(texture)
+
 
        end          
+
 
       
+
# ===================================================================================
        if (tsIsDay)
+
 
        colorScalar $colorToAdd
+
materialDefinition neighborhood-canvas-outOfWater
            stage            
+
   setDefinition NeighborhoodCanvas
              textureBlend add(outRegister colorScalar) select(outRegister)
+
  addParam  isUnderWater false
            end                
+
end
        endif
+
 
       
+
materialDefinition neighborhood-canvas-underwater
      end
+
  setDefinition NeighborhoodCanvas
           
+
  addParam  isUnderWater true
      end
+
end
 +
 
 +
materialDefinition neighborhood-canvas-straddle
 +
  setDefinition NeighborhoodCanvasStraddle
 +
end
 +
 
 +
materialDefinition neighborhood-underwater-terrain
 +
  setDefinition NeighborhoodWaterTerrain
 +
end
 +
 
 +
materialDefinition waterEdgeBoxMaterial
 +
  setDefinition NeighborhoodWaterEdge
 +
  addParam waterEdgeTexture "neighborhood-sides-water"
 +
end
 +
 
 +
materialDefinition terrainEdgeBoxMaterial
 +
  setDefinition NeighborhoodTerrainEdge
 +
  addParam terrainEdgeTexture "neighborhood-sides-dirt"
 +
end
 +
 
 +
materialDefinition nhoodTerrainLightingMaterial
 +
  setDefinition NHoodTerrainLighting
 +
end
 +
 
 +
materialDefinition nhoodTerrainLightingMaterialImposter
 +
  setDefinition NHoodTerrainLighting
 +
  addParam isImposter true
 +
end
 +
 
 +
materialDefinition nhoodReflectionSkybox
 +
  setDefinition SkyboxCompositionPassMaterial
 +
  addParam skyboxCubeTexture $skyboxCubeMap
 +
end
 +
 
 +
materialDefinition lotSkirtReflectionSkybox
 +
  setDefinition SkyboxCompositionPassMaterial
 +
  addParam skyboxCubeTexture $skyboxCubeMap
 +
end
 +
 
 +
materialDefinition lotPlacementArrow
 +
  setDefinition ImposterArrowMaterial
 +
  addParam texture lot-placement-arrow
 +
end
 +
 
 +
# Material used in highlighting the terrain to depict a house for which no imposter exists yet.
 +
materialDefinition DefaultResidentialLotImposterMaterial
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lothighlight-residential"
 +
  addParam highlightAlpha 0.5
 +
end
 +
 
 +
materialDefinition DefaultCommunityLotImposterMaterial
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lothighlight-community"
 +
  addParam highlightAlpha 0.5
 +
end
 +
 
 +
 
 +
# Material used in creating a terrain thumbnail for a lot for which no imposter exists yet.
 +
materialDefinition DefaultLotThumbnailMaterial
 +
  setDefinition StandardMaterial
 +
  addParam stdMatBaseTextureEnabled "true"
 +
  addParam stdMatBaseTextureName "lotselection-done"
 +
  addParam stdMatLightingEnabled true
 +
  addParam stdMatDiffCoef (1, 1, 1)
 +
end
 +
 
 +
materialDefinition bridge_sides
 +
#  setDefinition StandardMaterial
 +
  setDefinition PartiallyUnderWaterMaterial
 +
  addParam stdMatAlphaBlendMode none
 +
  addParam stdMatBaseTextureEnabled true
 +
  addParam stdMatBaseTextureName bridge-sides
 +
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
 +
  addParam stdMatIsPartlyUnderwater true
 +
end
 +
 
 +
materialDefinition cliff_boulder_material
 +
#  setDefinition StandardMaterial
 +
  setDefinition PartiallyUnderWaterMaterial
 +
  addParam stdMatAlphaBlendMode none
 +
  addParam stdMatBaseTextureEnabled true
 +
  addParam stdMatBaseTextureName nh-test-cliff
 +
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
 +
  addParam stdMatIsPartlyUnderwater true
 +
end
 +
 
 +
materialDefinition plesiosaur_skin_material
 +
#  setDefinition StandardMaterial
 +
  setDefinition PartiallyUnderWaterMaterial
 +
  addParam stdMatAlphaBlendMode none
 +
  addParam stdMatBaseTextureEnabled true
 +
  addParam stdMatBaseTextureName plesiosaur-skin
 +
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
 +
  addParam stdMatIsPartlyUnderwater true
 +
 
 +
  # these are mvoing objects, need to be at or above layer 0
 +
  addParam nhoodCanvasLayer -4
 +
 
 +
end
 +
 
 +
materialDefinition neighborhood_bouyside_material
 +
#  setDefinition StandardMaterial
 +
  setDefinition PartiallyUnderWaterMaterial
 +
  addParam stdMatAlphaBlendMode none
 +
  addParam stdMatBaseTextureEnabled true
 +
  addParam stdMatBaseTextureName neighborhood_bouyside
 +
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
 +
  addParam stdMatIsPartlyUnderwater true
 +
 
 +
  # these are mvoing objects, need to be at or above layer 0
 +
  addParam nhoodCanvasLayer -4
 +
end
 +
 
 +
 
 +
materialDefinition RelationshipArchGreen
 +
  setDefinition StandardMaterial
 +
  addParam  stdMatSpecPower 20
 +
  addParam  stdMatDiffCoef (0.3, 1, 0.3)
 +
  addParam  stdMatSpecCoef (1, 1, 1)
 +
  addParam  stdMatAlphaMultiplier 0.6
 +
  addParam  stdMatAlphaBlendMode blend
 +
end
 +
 
 +
materialDefinition housePlacementOKHighlight
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lotselection-good"
 +
  addParam highlightAlpha 0.15
 +
end
 +
 +
materialDefinition housePlacementNotOKHighlight
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lotselection-bad"
 +
  addParam highlightAlpha 0.15
 +
end
 +
 
 +
materialDefinition roadIndicatorOK
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lothighlight-roadghost-good"
 +
  addParam highlightAlpha 0.75
 +
end
 +
 
 +
materialDefinition roadIndicatorNotOK
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lothighlight-roadghost-bad"
 +
  addParam highlightAlpha 0.75
 +
end
 +
 
 +
materialDefinition DefaultLotHighlight
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lotselection-good"
 +
  addParam highlightAlpha 0.25
 +
end
 +
 
 +
materialDefinition ResidentialLotHighlight
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lothighlight-residential"
 +
  addParam highlightAlpha 0.40
 +
end
 +
 
 +
materialDefinition CommunityLotHighlight
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lothighlight-community"
 +
  addParam highlightAlpha 0.40
 +
end
 +
 
 +
materialDefinition DormLotHighlight
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lothighlight-dorm"
 +
  addParam highlightAlpha 0.40
 +
end
 +
 
 +
materialDefinition NotOKLotHighlight
 +
  setDefinition NHoodTerrainHighlightMaterial
 +
  addParam highlightTexture "lotselection-bad"
 +
  addParam highlightAlpha 0.40
 +
end
 +
 
 +
materialDefinition neighborhoodbuildingres1_windows_night
 +
  setDefinition NeighborhoodBuildingMaterial
 +
  addParam texMaterial neighborhoodbuildingres1_repeat-surface-night
 +
  addParam showOnDay false
 +
end
 +
 
 +
materialDefinition neighborhoodbuildingres1_windows_day
 +
  setDefinition NeighborhoodBuildingMaterial
 +
  addParam texMaterial neighborhoodbuildingres1_repeat-surface
 +
  addParam showOnDay true
 +
end
 +
 
 +
# this is commented out because the UI renders this without use of the material
 +
#materialDefinition ZoomConePyramid
 +
#  setDefinition ZoomConeMaterial
 +
#  addParam baseColor (1.0, 1.0, 1.0, 0.5)
 +
#end
 +
 
 +
define LotSkirtPSWater()
 +
    shader -layer ($poolWaterLayer+1)
 +
        validateRenderShaderContext -vertexFormat position 0 required
 +
pass -clipAlways -modifiedEachFrameHint
 +
#fillmode wireframe
 +
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
seti textureLights (numLightsOfType(environmentCube)) 
 +
depthTest true -enableDepthWrite false         
 +
 
 +
shaderProgram -target vertexProgram -method compile -version 1_1
 +
 
 +
bindConstants 0 -bindingID geomToClip -constantCount 4
 +
bindConstants 4 -bindingID geomToCamera -constantCount 3
 +
 
 +
bindConstants 7 -bindingID frameInfo
 +
 
 +
bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed)
 +
bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed)
 +
 
 +
# pre-evaluate these
 +
setf xscale (-$wmXRepeat * $wmXWaveHeight)
 +
setf yscale (-$wmYRepeat * $wmYWaveHeight)
 +
bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
 +
bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
 +
bindConstants 18 -bindingID cameraToGlobal -constantCount 3
 +
bindConstants 21 -bindingID cameraToGeom -constantCount 3
 +
 +
if (tsIsDay)    
 +
bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)
 +
bindConstants 28 -bindingID immediateData -data (-0.3, 0.1, 0.1, 0.0)      
 +
else
 +
bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)
 +
bindConstants 28 -bindingID immediateData -data (-0.3, -0.2, -0.1, 0.0)     
 +
endif
 +
 
 +
shaderSource
 +
 
 +
float4 frameInfo : register(c7);
 +
float4 waveDataX : register(c11);
 +
float4 waveDataY : register(c12);
 +
float4 waveDataHelper : register(c13);
 +
float4x4 clipSpaceMatrix : register(c0);
 +
float4x3 cameraSpaceMatrix : register(c4);
 +
float4x3 cameraToGlobalMatrix : register(c18);
 +
float4x3 cameraToGeomMatrix : register(c21);
 +
 +
float4 nightColor: register(c25);
 +
float4 waterTint: register(c28);
 +
             
 +
float4 lightDirection : register(c14);
 +
float4 lightColor : register(c15);
 +
float4 lightSpecular : register(c16);
 +
 +
const static float4 refractionWeights={1,1,2,0};
 +
const static float4 layerBlue={1.0, 1.0, 1.0, 1.0};
 +
 +
struct InputVertex
 +
{
 +
float3 position: POSITION0;
 +
float3 normal : NORMAL0;
 +
float2 alpha  : TEXCOORD1;
 +
};
 +
 +
struct OutputVertex
 +
{
 +
float4 clipPosition : POSITION;
 +
float4 sPos        : TEXCOORD0;
 +
float2 Wave0        : TEXCOORD1;
 +
float2 Wave1        : TEXCOORD2;
 +
float2 Wave2        : TEXCOORD3;
 +
float2 Wave3        : TEXCOORD4;
 +
float3 Eye          : TEXCOORD5;
 +
float4 specular    : COLOR0; 
 +
float4 colorTint    : COLOR1;
 +
};
 +
             
 +
 +
 +
OutputVertex VertexMain( InputVertex inputVertex)
 +
{
 +
// Do Y-direction waves
 +
// r0 = (x, y, z, t)
 +
 +
OutputVertex outputVertex;
 +
 +
float4 posAndTime;
 +
posAndTime.xyz = inputVertex.position;
 +
posAndTime.w = frameInfo.w;
 +
 +
float temp = dot(posAndTime, waveDataX);
 +
float z = sin(temp) * waveDataX.z + inputVertex.position.z;
 +
temp = dot(posAndTime, waveDataY);
 +
posAndTime.z =  z + sin(temp) * waveDataY.z ;//-0.1f; //The -.01 is a fudge factor to remove some of the edge creep associated with moving the height of the wave. -tom
 +
posAndTime.w = 1.0f;
 +
 +
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix);
 +
outputVertex.sPos = float4(0.5f*(outputVertex.clipPosition.ww - outputVertex.clipPosition.xy), outputVertex.clipPosition.ww);
 +
 +
float3 waveNormal = normalize(inputVertex.normal + float3(cos(temp)*waveDataHelper.xy, 0));
 +
float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix));
 +
float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix);
 +
float3 viewVector = normalize(-cameraSpacePosition);
 +
 +
float3 halfVector = normalize(viewVector + lightDirection);
 +
outputVertex.specular = lightSpecular*pow(dot(cameraSpaceNormal, halfVector), 50)*nightColor*lightColor*0.5;
 +
 +
 +
float2 fTranslation=float2(fmod(frameInfo.w, 100)*0.005, fmod(frameInfo.w, 100)*0.005);
 +
float2 vTexCoords = posAndTime.xy*0.05;
 +
               
 +
// Output bump layers texture coordinates   
 +
float fSinTranslation=sin(fTranslation*100)*0.005;
 +
float2 vTranslation0=fTranslation+fSinTranslation;
 +
float2 vTranslation1=fTranslation-fSinTranslation;
 +
float2 vTranslation2=fTranslation;
 +
               
 +
// Scale texture coordinates to get mix of low/high frequency details
 +
outputVertex.Wave0.xy = vTexCoords.xy*0.01+fTranslation*2.0;
 +
outputVertex.Wave1.xy = vTexCoords.xy+fTranslation*2.5;
 +
outputVertex.Wave2.xy = vTexCoords.xy+fTranslation*-2.3;
 +
outputVertex.Wave3.xy = vTexCoords.xy*0.1+fTranslation*1.5;               
 +
                                   
 +
// compute binormal
 +
float3 binormal = normalize(cross(waveNormal, float3(1.0f, 0.0f, 0.0f)));            
 +
float3 tangent = normalize(cross(binormal, waveNormal));
 +
           
 +
// tangent space matrix
 +
float3x3 objToTangentSpace = float3x3(tangent, binormal, waveNormal);
 +
           
 +
float3 viewVectorInObjSpace = mul(viewVector, (float3x3)cameraToGeomMatrix);
 +
           
 +
outputVertex.Eye.xyz = mul(objToTangentSpace, viewVectorInObjSpace);
 +
outputVertex.colorTint = waterTint;
 +
outputVertex.colorTint.a = inputVertex.alpha.xxxx;
 +
// outputVertex.color = waterTint.xxxx;
 +
 +
return(outputVertex);
 +
}
 +
 +
endShaderSource 
 +
end # shaderProgram
 +
 +
shaderProgram -target pixelProgram -method compile -version 2_0             
 +
shaderSource                           
 +
sampler reflect; 
 +
sampler bump;          
 +
struct cInputPixel
 +
{             
 +
float4 sPos        : TEXCOORD0;             
 +
float2 Wave0        : TEXCOORD1;
 +
float2 Wave1        : TEXCOORD2;
 +
float2 Wave2        : TEXCOORD3;
 +
float2 Wave3        : TEXCOORD4;
 +
float3 Eye          : TEXCOORD5;
 +
float4 specular    : COLOR0;
 +
float4 colorTint    : COLOR1;
 +
};
 +
           
 +
float Fresnel(float NdotL, float fresnelBias, float fresnelPow, float facing)
 +
{             
 +
return max(fresnelBias + (1.0f - fresnelBias)*pow(facing, fresnelPow), 0.0);
 +
}
 +
           
 +
float4 PixelMain(cInputPixel pi) : COLOR
 +
{       
 +
float3 vEye = normalize(pi.Eye);
 +
 
 +
// Get bump layers
 +
float3 vBumpTexA = tex2D(bump, pi.Wave0.xy).xyz;
 +
float3 vBumpTexB = tex2D(bump, pi.Wave1.xy).xyz;
 +
float3 vBumpTexC = tex2D(bump, pi.Wave2.xy).xyz;
 +
float3 vBumpTexD = tex2D(bump, pi.Wave3.xy).xyz;
 +
               
 +
// Average bump layers
 +
float3 vBumpTex=normalize(2.0 * (vBumpTexA.xyz + vBumpTexB.xyz + vBumpTexC.xyz + vBumpTexD.xyz)-4.0);
 +
               
 +
// Apply individual bump scale for refraction and reflection               
 +
float3 vReflBump = vBumpTex.xyz ;
 +
float4 vReflection = tex2Dproj(reflect, pi.sPos + float4(vReflBump.xy, 0.0f, 0.0f));//*0.001 + float4(2.0*vBumpTexD-1.0f.xxx, 1);
 +
             
 +
// Compute Fresnel term
 +
float NdotL = max(dot(vEye, vReflBump), 0);
 +
float facing = (1.0 - NdotL);
 +
float fresnel = Fresnel(NdotL, 0.1, 0.5, facing);
 +
         
 +
vReflection.a = fresnel * 0.5;
 +
 +
return saturate(vReflection + pi.colorTint);
 +
}
 +
endShaderSource
 +
end                                                   
 +
     
 +
sampler reflect
 +
texture "OceanReflection"
 +
textureAddressing clamp clamp
 +
end
 +
     
 +
sampler bump
 +
texture "poolShape-body-bump"
 +
textureAddressing tile tile
 +
end 
 +
           
 +
end # end pass
 +
end
 +
enddef
 +
 
 +
define LotSkirtWater()
 +
material     
 +
create DetermineHardwareSupport()
 +
 
 +
if ($useHWShader2Path)
 +
create LotSkirtPSWater()
 +
else
 +
 
 +
shader -layer $nhoodWaterLayer
 +
validateRenderShaderContext -vertexFormat  position      0 required
 +
validateRenderShaderContext -vertexFormat  normal        0 required
 +
validateRenderShaderContext -vertexFormat  texcoord      0 required
 +
viewerRenderTypePred viewerRenderType
 +
           
 +
pass -fixedFunction
 +
   
 +
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
colorScalar $lotSkirtWaterReflColour 0.50
 +
depthTest true -enableDepthWrite false                       
 +
   
 +
#tring to remove warble I think it may be caused by depth bias.
 +
#ffDepthOffset -2
 +
   
 +
stage
 +
ffTextureCoordsSource fromPosition
 +
ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
 +
textureAddressing clamp clamp
 +
texture "ScreenReflection"
 +
       
 +
textureBlend multiply(texture colorScalar) multiply(diffuse colorScalar)  
 +
end              
 +
               
 +
end
 +
end    
 +
endif
 
   end
 
   end
 
enddef
 
enddef
  
define GeneralReflectiveMaterial()
+
define LotSkirtWaterNoReflection()
   create StandardMaterial()
+
   material
 +
      # fallback: no reflection.
 +
      shader -layer ($nhoodWaterLayer)
 +
        viewerRenderTypePred viewerRenderType
 +
       
 +
        create DetermineHardwareSupport()
 +
       
 +
        pass -fixedFunction
 +
  # For now, we are diabling the lighting since we simply want to use the vertex colors.
 +
  create LightingStatesNoStdLightsParam(false true)
 +
  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
 
 +
            colorScalar (.4, .6, .9, .4)     
 +
           
 +
            #tring to remove warble I think it may be caused by depth bias.
 +
            #ffDepthOffset -2                             
 +
           
 +
            fillmode $stdMatFillMode
 +
            stage
 +
              #texture reflectionoutdoorwater-envcube
 +
              if ($cubeMapSupport)
 +
                  texture $skyboxCubeMap
 +
                  textureMIPFilterHint disabled
 +
 
 +
                  ffTextureCoordsSource fromReflectionVector
 +
                  ffTextureMatrix -orientCameraToGlobal
 +
 
 +
                  textureAddressing clamp clamp clamp
 +
                  textureBlend multiply(texture colorScalar) select(colorScalar)
 +
              else
 +
                  textureBlend select(colorScalar) multiply(diffuse colorScalar)
 +
              endif
 +
            end 
 +
        end 
 +
      end
 +
  end             
 
enddef
 
enddef
  
materialDefinition puddle_liquid_rain
+
materialDefinition lotSkirtSea
   setDefinition GeneralReflectiveMaterial
+
   setDefinition LotSkirtWater 
   addParam deprecatedStdMatInvDiffuseCoeffMultiplier 1.2
+
   addParam stdMatLightingEnabled false
  addParam forceHighQualitySkinning 0
+
  addParam forceIgnoreShapeBlend 0
+
  addParam reflectivity 0.1
+
  addParam stdMatAlphaBlendMode blend
+
  addParam stdMatAlphaMultiplier 0.5
+
  addParam stdMatAlphaRefValue 127
+
  addParam stdMatAlphaTestEnabled 0
+
  addParam stdMatBaseTextureAlphaReplicate 0
+
  addParam stdMatCullMode cullClockwise
+
  addParam stdMatDiffCoef 0.39,0.46,0.49
+
  addParam stdMatEmissiveCoef 0,0,0
+
  addParam stdMatEnvCubeBlurFactor 0.000000
+
  addParam stdMatEnvCubeCoef 0.3,0.3,0.3
+
  addParam stdMatEnvCubeLockedToCamera 0
+
  addParam stdMatEnvCubeMode reflection
+
  addParam stdMatEnvCubeTextureName reflectionkitchenhighcontrast-envcube
+
  addParam stdMatFillMode solid
+
 
   addParam stdMatLayer 0
 
   addParam stdMatLayer 0
   addParam stdMatLightingEnabled 1
+
    
   addParam stdMatMinLightRangeHint 4
+
   addParam stdMatDiffCoef (1, 1, 1) 
  addParam stdMatSpecCoef 0.54,0.72,0.76
+
  addParam stdMatSpecPower 22     
+
  addParam stdMatAddLayer -10
+
end
+
  
materialDefinition puddle_liquid_blue
+
   addParam wmReflectionTexture swimming_pool-envcube
  setDefinition GeneralReflectiveMaterial
+
   addParam deprecatedStdMatInvDiffuseCoeffMultiplier 1.2
+
  addParam forceHighQualitySkinning 0
+
  addParam forceIgnoreShapeBlend 0
+
  addParam reflectivity 0.1
+
  addParam stdMatAlphaBlendMode blend
+
  addParam stdMatAlphaMultiplier 0.5
+
  addParam stdMatAlphaRefValue 127
+
  addParam stdMatAlphaTestEnabled 0
+
  addParam stdMatBaseTextureAlphaReplicate 0
+
  addParam stdMatCullMode cullClockwise
+
  addParam stdMatDiffCoef 0.23,0.41,0.49
+
  addParam stdMatEmissiveCoef 0,0,0
+
  addParam stdMatEnvCubeBlurFactor 0.000000
+
  addParam stdMatEnvCubeCoef 0.1,0.1,0.1
+
  addParam stdMatEnvCubeLockedToCamera 0
+
  addParam stdMatEnvCubeMode reflection
+
  addParam stdMatEnvCubeTextureName reflectionkitchenhighcontrast-envcube
+
  addParam stdMatFillMode solid
+
  addParam stdMatLayer 0
+
  addParam stdMatLightingEnabled 1
+
  addParam stdMatMinLightRangeHint 4
+
  addParam stdMatSpecCoef 0.55,0.55,0.55
+
  addParam stdMatSpecPower 6.1 
+
  addParam stdMatAddLayer -10
+
end
+
  
 +
  addParam wmTransparency 0.4
  
#endshader
+
  addParam wmXSpeed        3
 +
  addParam wmXRepeat      5
 +
  addParam wmXWaveHeight  0.001
 +
 
 +
  addParam wmYSpeed        3
 +
  addParam wmYRepeat      6
 +
  addParam wmYWaveHeight  0.001
 +
 
 +
end
 +
 
 +
materialDefinition lotSkirtSeaNoReflection
 +
  setDefinition LotSkirtWaterNoReflection 
 +
end

Revision as of 13:34, 5 March 2008

  1. Shaders for neighborhood
  1. layers
  2. normal shadows are layer 2 (after opaques), tree shadows are moved to -2 to make them
  3. render to the first buffer. Tree shadows (-2) do not show up on fields (7).

seti nhoodWaterLayer 1 seti nhoodCanvasLayer -8 seti nhoodTreeShadowLayer -2

setf neighborhoodMaterialScaleU 8.0 # defaults for neighborhood materials without these defined setf neighborhoodMaterialScaleV 8.0 # defaults for neighborhood materials without these defined

setf nhoodWaterMap1Scale 7.0 setf nhoodWaterMap1Speed 0.5 setf nhoodWaterMap2Scale 5.0 setf nhoodWaterMap2Speed 0.3


setv2 baseTexOffset (0.5, 0.5) setv3 nhoodDiffCoef (0.75, 0.93, 0.75)


setf nhoodPaintTextureScale 13 #Repeat distance of neighborhood textures in tiles.

                                    #NOTE: There is a related parameter called "TextureVariantGridSize" in 
                                    #NeighborhoodTerrain.ini. You would normally (though not necessarily) want it to be
                                    #the same as this number.

setf waterEdgeTextureScale 250.0 #Repeat distance in meters setf terrainEdgeTextureScale 100.0 #Repeat distance in meters


  1. Reflective water

setc nhoodWaterReflColour (0.55, .6, 0.65) setc lotSkirtWaterReflColour (0.65, 0.7, 0.85) setf nhoodWaterReflStrength 0.75 setf nhoodWaterReflOffset 0.0020

  1. Standard water

setf nhoodWaterbumpMapScale 8.0 setf nhoodWaterAlpha 0.35

setb isDay true setb isTerrainConcrete false

  1. water clipping plane

setf waterHeight 312.45

  1. underwater gradient texture

set waterGradientTexture neighborhood-underwater-gradient set waterGradientTextureAdditive neighborhood-underwater-gradient-with-black

  1. depth at which the gradient starts to take effect

setf waterGradientZoneStart 0

  1. how far down the gradient goes from that point.

setf waterGradientZoneSize 40

set skyboxCubeMap neighborhood-sky2-envcube

  1. bump mapping

setv3 nhoodSunDir (-0.5, 1, 0.5) # default -- should be set by code from the lighting.txt value

  1. overall kind-of brightness booster for bump map.

setf bumpMapBoost 1.5

  1. ==============================================================================
  2. derived bump map quantities

define BiasedNormal(n bn)

  setf  nLen (sqrt(sqr($&{n}.x) + sqr($&{n}.y) + sqr($&{n}.z)))
  setv3 &{bn} ((0.5,0.5,0.5) * (($&{n} / $nLen.xxx) + (1,1,1)))

enddef

create BiasedNormal(nhoodSunDir nhoodSunDirBiased) setv3 nhoodSunDirBiased ($nhoodSunDirBiased * $bumpMapBoost.xxx)

set terrainType "unset"

  1. defaults off, can be turned on at startup.

setb simpleTerrain false setb isImposter false

include neighborhoodSWVS.matShad

  1. ==============================================================================

define NeighborhoodCanvas()

  1. this material does nothing but prep the z-buffer, and render black.

material

     if ($simpleTerrain)
        shader
        end
     endif
     shader -layer (($nhoodCanvasLayer) * 8)
        
        validateRenderShaderContext -vertexFormat  position      0 required
        validateRenderShaderContext -vertexFormat  normal        0 required
        
        if (not $isImposter)         
           validateRenderShaderContext -vertexFormat  texcoord      0 required
        endif
        viewerRenderTypePred viewerRenderType
           
        create DetermineHardwareSupport()
        
        if (strcmp("Concrete", "${terrainType}") = 0)
           setb isTerrainConcrete true
        endif
        if (not $isUnderWater or viewerRenderType != $kRenderTypeReflection)
           if ($useSWVertexShaderPath)
              create NeighborhoodTerrainPrepWorkSWVS()
           else
              pass -fixedFunction
                 create LightingStatesNoStdLights()
                 
                 cullmode none # so that reflections don't "creep under" edge of terrain
                 colorScalar (0.0, 0.0, 0.0, 1.0)
                                   
                 if ($isImposter and $isTerrainConcrete)
                    ffDepthOffset -1
                 endif
                 stage
                    if (not $isImposter)
                       ffTextureCoordsSource fromPosition
                    endif
                    textureBlend select(colorScalar) select(outRegister)
                 end 
              end
           endif
           
        endif
        
     end
  end

enddef


  1. ==============================================================================
  2. Used for those triangles in the canvas which are partially under water.

define NeighborhoodCanvasStraddle() material

     if ($simpleTerrain)
        shader
        end
     endif
  1. material for reflection camera
     shader -layer (($nhoodCanvasLayer) * 8)
     

validateRenderShaderContext -vertexFormat position 0 required validateRenderShaderContext -vertexFormat normal 0 required validateRenderShaderContext -vertexFormat texcoord 0 required viewerRenderTypePred $kRenderTypeReflection

#Render the portion that is above water only

create DetermineHardwareSupport()

if ($useSWVertexShaderPath)

create NeighborhoodWaterlineStraddleSWVS()

else

pass -fixedFunction create LightingStatesNoStdLights() alphaBlend srcFactor(one) add dstFactor(zero) cullmode none # so that reflections don't "creep under" edge of terrain colorScalar (0.0, 0.0, 0.0, 1.0)

alphaTest true 128 alphaTestFunction acceptIfGreater

stage # above water -- clip by using depth-based 0/1 texture. texture blackWhite textureAddressing clamp clamp textureFilterHint point point textureMIPFilterHint disabled

ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert ffTextureCoordsSource fromPosition textureBlend select(colorScalar) select(texture) end end endif

end


     #material for standard camera   
     #shader -layer (-128)      

shader -layer (-128)

validateRenderShaderContext -vertexFormat position 0 required validateRenderShaderContext -vertexFormat normal 0 required validateRenderShaderContext -vertexFormat texcoord 0 required viewerRenderTypePred $kRenderTypeNormal

create DetermineHardwareSupport()

if ($useSWVertexShaderPath) create NeighborhoodWaterlineStraddleStandardCameraSWVS() else

#Render the portion that is above water only pass -fixedFunction create LightingStatesNoStdLights() alphaBlend srcFactor(one) add dstFactor(zero) cullmode none # so that reflections don't "creep under" edge of terrain colorScalar (0.0, 0.0, 0.0, 1.0)

stage textureBlend select(colorScalar) select(outRegister) end end endif

end

end enddef

  1. ==============================================================================
  2. Material for terrain geometry that is partially or completely under water.

define NeighborhoodWaterTerrain() material

     if ($simpleTerrain)
        shader
        end
     endif
     

shader -layer (($nhoodCanvasLayer + 2) * 8) validateRenderShaderContext -vertexFormat position 0 required validateRenderShaderContext -vertexFormat normal 0 required validateRenderShaderContext -vertexFormat texcoord 0 required viewerRenderTypePred viewerRenderType


create DetermineHardwareSupport()

if (viewerRenderType != $kRenderTypeReflection)

if ($useSWVertexShaderPath) create NeighborhoodUnderWaterTerrainSWVS()

else

pass -fixedFunction


create LightingStatesNoStdLights()

alphaBlend srcFactor(destColor) add dstFactor(zero) cullmode none # so that reflections don't "creep under" edge of terrain # apply depth-based gradient texture to terrain that is under water. stage texture $waterGradientTexture

if ($cubeMapSupport) textureAddressing tile clamp else textureAddressing clamp clamp endif

set d ($waterHeight - $waterGradientZoneStart) set s (-$waterGradientZoneSize) ffTextureMatrix -cameraToGlobal -order xzyw -scale $s -trans (0, $d) -invert ffTextureCoordsSource fromPosition textureBlend select(texture) select(outRegister) end end

endif

endif

end end enddef

  1. ==============================================================================

define NeighborhoodTerrainPaintShader()

  shader -layer (($nhoodCanvasLayer + 1) * 8)
     validateRenderShaderContext -vertexFormat  position      0 required
     validateRenderShaderContext -vertexFormat  normal        0 required
           
        if (not $isImposter)
           validateRenderShaderContext -vertexFormat  texcoord      0 required
        endif

create DetermineHardwareSupport()

if (strcmp("Concrete", "${terrainType}") = 0)

           setb isTerrainConcrete true
        endif
  		

if ($useSWVertexShaderPath) create NeighborhoodMainTerrainShaderSWVS()

else

pass -fixedFunction

create LightingStatesNoStdLights() alphaBlend srcFactor(srcAlpha) add dstFactor(one) cullmode none # so that reflections don't "creep under" edge of terrain

if ($isImposter and $isTerrainConcrete)

                 ffDepthOffset -1
              endif
  		                     

colorScalar $nhoodSunDirBiased

depthTest true -enableDepthWrite false depthTestFunction acceptIfEqual

seti snowLevel (tsHasSnow)

if ($snowLevel = 1) set weatherSuffix "-LSNOW" elseif ($snowLevel = 2)

                 set weatherSuffix "-HSNOW"
              else
                 set weatherSuffix ""
              endif
              

stage texture $alphaMap textureAddressing clamp clamp

                 if ($isImposter)

ffTextureMatrix -cameraToGlobal -scalev ((0.1 * $alphaMapScaleU), (0.1 * $alphaMapScaleV)) ffTextureCoordsSource fromPosition else ffTextureMatrix -scalev ($alphaMapScaleU, $alphaMapScaleV) ffTextureCoordsSource 0 endif textureBlend select(outRegister) select(texture) end

stage texture "${paintTexture}${weatherSuffix}" textureAddressing tile tile if ($isImposter) ffTextureMatrix -cameraToGlobal -scalev ((10.0 * $nhoodPaintTextureScale), (10.0 * $nhoodPaintTextureScale)) -invert ffTextureCoordsSource fromPosition else ffTextureMatrix -scalev ($nhoodPaintTextureScale, $nhoodPaintTextureScale) -invert ffTextureCoordsSource 0 endif textureBlend select(texture outRegister) select(outRegister) end end

        endif		

end enddef

define NeighborhoodTerrainPaint()

  material
     
     if ($simpleTerrain)
        shader
        end
     endif
     
     create NeighborhoodTerrainPaintShader()
  end

enddef


  1. ==============================================================================

set ratioH 1 # default material parameter value set ratioW 1 # default material parameter value set useReflection 1 # default material parameter value define NeighborhoodWater()

  material
     # never draw water in its reflection.  Already handled by code.				
     if ($simpleTerrain)
        shader -layer $nhoodWaterLayer
           pass -fixedFunction 
              colorScalar (0.3, 0.4,0.8) 1.0
              stage 
                 textureBlend select(colorScalar) select(colorScalar)
              end
           end
        end
     endif


     # First option: reflection mapped water.
     if ($useReflection)
        shader -layer $nhoodWaterLayer
           validateRenderShaderContext -vertexFormat  position      0 required
           validateRenderShaderContext -vertexFormat  normal        0 required
           validateRenderShaderContext -vertexFormat  texcoord      0 required
           viewerRenderTypePred viewerRenderType
           ################################################################################
           # Three pass/2 texture rippled reflection -- does not run on GeF2 only 2 stages (for GeF4+)
           pass -fixedFunction -modifiedEachFrameHint
           
           
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
              colorScalar $nhoodWaterReflColour $nhoodWaterReflStrength
              depthTest true -enableDepthWrite false
              
              stage
                 ffTextureCoordsSource fromPosition
                 ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
                 textureAddressing clamp clamp
                 texture "ScreenReflection"
                 
                 textureBlend multiply(texture colorScalar) select(outRegister) tempRegister
              end 
              stage
                 ffTextureCoordsSource fromPosition
                 ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5 + $nhoodWaterReflOffset, 0.5 + $nhoodWaterReflOffset)
                 textureAddressing clamp clamp
                 
                 texture "ScreenReflection"
                 textureBlend multiply(texture colorScalar) select(outRegister)
              end             
              stage
                 texture "neighborhood-water-1"
                 textureAddressing tile tile
                 # -atrans waveformType cycles/sec offset (startU, startV)  (endU, endV)
                 textureMatrixAnimation -targetType fixedFunction -atrans sawtooth ($nhoodWaterMap1Speed / $nhoodWaterMap1Scale) 0 (0, 0) ($nhoodWaterMap1Scale, 0) -ascale sawtooth 1 0 ($nhoodWaterMap1Scale, $nhoodWaterMap1Scale)
                 ffTextureCoordsSource 0
                 textureBlend lerpTextureAlpha(tempRegister outRegister) select(colorScalar)
              end 
           end
        end
       
        shader -layer $nhoodWaterLayer
           validateRenderShaderContext -vertexFormat  position      0 required
           validateRenderShaderContext -vertexFormat  normal        0 required
           validateRenderShaderContext -vertexFormat  texcoord      0 required
           viewerRenderTypePred viewerRenderType
           ################################################################################
           # Two stage case since the three stage case above fails on most low end hardware because of its third stage (GF2).
           pass -fixedFunction -modifiedEachFrameHint
           
           
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
              colorScalar $nhoodWaterReflColour $nhoodWaterReflStrength
              depthTest true -enableDepthWrite false
              
              stage
                 ffTextureCoordsSource fromPosition
                 ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
                 textureAddressing clamp clamp
                 texture "ScreenReflection"
                 
                 textureBlend multiply(texture colorScalar) select(outRegister)
              end 
              
              stage
                 texture "neighborhood-water-1"
                 textureAddressing tile tile
                 # -atrans waveformType cycles/sec offset (startU, startV)  (endU, endV)
                 #textureMatrixAnimation -targetType fixedFunction -atrans sawtooth ($nhoodWaterMap1Speed / $nhoodWaterMap1Scale) 0 (0, 0) ($nhoodWaterMap1Scale, 0) -ascale sawtooth 1 0 ($nhoodWaterMap1Scale, $nhoodWaterMap1Scale)
                 ffTextureCoordsSource 0
                 textureBlend lerpTextureAlpha(outRegister outRegister) select(colorScalar)
              end
              
           end
        end
        
     endif
     
     ################################################################################
     # fallback: no reflection.
     shader -layer ($nhoodWaterLayer)
        viewerRenderTypePred viewerRenderType
        
        create DetermineHardwareSupport()
        
        pass -fixedFunction

# For now, we are diabling the lighting since we simply want to use the vertex colors. create LightingStatesNoStdLightsParam(false true) alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)

           colorScalar (.4, .6, .9, .6)      
           
           fillmode $stdMatFillMode
           stage
              #texture reflectionoutdoorwater-envcube
              if ($cubeMapSupport)
                 texture $skyboxCubeMap
                 textureMIPFilterHint disabled
                 ffTextureCoordsSource fromReflectionVector
                 ffTextureMatrix -orientCameraToGlobal
                 textureAddressing clamp clamp clamp
                 textureBlend multiply(texture colorScalar) select(colorScalar)
              else
                 textureBlend select(colorScalar) select(colorScalar)
              endif
           end  
        end   

     end


     ################################################################################
     # Final fallback.

#<shader -layer ($nhoodWaterLayer) viewerRenderTypePred viewerRenderType

pass -fixedFunction

fillmode $stdMatFillMode create LightingStatesNoStdLights() alphaBlend srcFactor(one) add dstFactor(srcAlpha) colorScalar (.2, .3, .5, .05) stage textureBlend select(colorScalar) select(colorScalar) end end


end#>

       create NeighborhoodWaterSWVS()
               
     

end

enddef


  1. ==============================================================================
  2. The layer ID for this should be lower than "nhoodWaterLayer" Id because we want the farther side of the water box should be
  3. drawn as well.
  4. the layer ID of any under-water objects (so

define NeighborhoodWaterEdge()

  material
     if ($simpleTerrain)
        shader
        end
     endif
     
     
     shader -layer (($nhoodWaterLayer - 1) * 8)
        validateRenderShaderContext -vertexFormat  position      0 required
        validateRenderShaderContext -vertexFormat  texcoord      0 required
        
        pass -fixedFunction
           create LightingStates()
           alphaBlend srcFactor(one) add dstFactor(zero)
           cullmode cullCounterClockwise
           stage
              texture $waterEdgeTexture
              textureAddressing tile tile
              ffTextureMatrix -scalev (1/$waterEdgeTextureScale, 1/$waterEdgeTextureScale)
              ffTextureCoordsSource 0
              textureBlend select(texture) select(diffuse)
           end 
        end    
          
     end
  end
 

enddef

  1. ==============================================================================

define NeighborhoodTerrainEdge()

  material
  
     if ($simpleTerrain)
        shader
        end
     endif
     
     shader -layer (($nhoodCanvasLayer + 13) * 8)
        validateRenderShaderContext -vertexFormat  position      0 required
        validateRenderShaderContext -vertexFormat  normal        0 required
        validateRenderShaderContext -vertexFormat  texcoord      0 required
        pass -fixedFunction
           create LightingStates()
           alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
           stage
              texture $terrainEdgeTexture
              textureAddressing tile tile
              ffTextureMatrix -scalev (1/$terrainEdgeTextureScale, 1/$terrainEdgeTextureScale)
              ffTextureCoordsSource 0
              textureBlend multiply(texture diffuse) select(texture)
           end 
        end       
       
     end
  end

enddef

  1. ==============================================================================

define NHoodTerrainLighting()

  set terrainRepresentativeTexture "lottexture-test-01_detail"

material shader -layer (($nhoodCanvasLayer + 3) * 8) validateRenderShaderContext -vertexFormat position 0 required validateRenderShaderContext -vertexFormat normal 0 required

if (not $isImposter) validateRenderShaderContext -vertexFormat texcoord 0 required endif


        if (strcmp("Concrete", "${terrainType}") = 0)
           setb isTerrainConcrete true
        endif
     
        if ($simpleTerrain)
        
           if (strcmp("Desert", "${terrainType}") = 0)
              set terrainRepresentativeTexture "lottexture-canvas-desert"
           endif
        
           shader
              pass -fixedFunction                  

ffDepthOffset -1

                 stage
    						texture "nhoodLightMap"     						
    						if ($isImposter)

ffTextureMatrix -cameraToGlobal -scalev (1280, 1280) -invert ffTextureCoordsSource fromPosition else ffTextureMatrix -scalev (128, 128) -invert ffTextureCoordsSource 0 endif

                    textureBlend select(texture) select(texture)
                 end 
                 
                 stage 
   						texture $terrainRepresentativeTexture    						
   						if ($isImposter)

ffTextureMatrix -cameraToGlobal -scalev (160, 160) -invert ffTextureCoordsSource fromPosition else ffTextureMatrix -scalev (16, 16) -invert ffTextureCoordsSource 0 endif

                    #textureBlend multiply(texture outRegister) select(outRegister)
                    textureBlend select(texture outRegister) select(outRegister)
                 end
              end
           end
           
        endif
     

create DetermineHardwareSupport()

if ($useSWVertexShaderPath) create NeighborhoodTerrainLightingSWVS() else pass -fixedFunction

create LightingStatesNoStdLights()

# standard Lightmap * dest alphaBlend srcFactor(destColor) add dstFactor(zero)

# if the outbound 'clip' texture has 0 in it, don't emit those pixels. alphaTest true 127 alphaTestFunction acceptIfGreater


fillmode $stdMatFillMode

if ($isImposter and $isTerrainConcrete) ffDepthOffset -1 endif

depthTestFunction acceptIfEqual # emit the lightmap stage texture "nhoodLightMap" if ($isImposter) ffTextureMatrix -cameraToGlobal -scalev (1280, 1280) -invert ffTextureCoordsSource fromPosition else ffTextureMatrix -scalev (128, 128) -invert ffTextureCoordsSource 0 endif

if (tsHasSnow >= 1) colorScalar (0.3, 0.3, 0.35, 0) else colorScalar (0, 0, 0, 0) endif

textureBlend add(texture colorScalar) select(texture) end

# modulate by the 'above water' texture, which is a 2x1 texture with black and white in it.

stage # above water -- clip by using depth-based 0/1 texture. texture blackWhite textureAddressing clamp clamp textureFilterHint point point textureMIPFilterHint disabled

if ( $isImposter) ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 10, 0) -invert else ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert endif ffTextureCoordsSource fromPosition textureBlend multiply(texture:alphaReplicate outRegister) select(texture) end end endif end end

enddef


  1. ==============================================================================

define NHoodTerrainHighlightMaterial()

  material
     shader -layer (($nhoodCanvasLayer + 9) * 8)
        validateRenderShaderContext -vertexFormat  position      0 required
        validateRenderShaderContext -vertexFormat  normal        0 required
        validateRenderShaderContext -vertexFormat  texcoord      0 required

create DetermineHardwareSupport()

if ($useSWVertexShaderPath) create NeighborhoodTerrainHighlightSWVS() else pass -fixedFunction create LightingStates() alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) fillmode $stdMatFillMode

 				colorScalar (1, 1, 1, $highlightAlpha)

stage texture $highlightTexture textureAddressing tile tile textureBlend select(texture) multiply(texture colorScalar) end end endif

     end
  end

enddef

  1. ==============================================================================

define NHoodTerrainOutlineHighlightMaterial()

  material
     shader -layer (($nhoodCanvasLayer + 10) * 8)
        validateRenderShaderContext -vertexFormat  position      0 required
        validateRenderShaderContext -vertexFormat  normal        0 required
        validateRenderShaderContext -vertexFormat  texcoord      0 required

pass -fixedFunction create LightingStatesNoStdLights() alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) fillmode $stdMatFillMode depthTest true -enableDepthWrite false

stage texture $texture textureAddressing clamp clamp ffTextureCoordsSource 0 textureBlend select(texture) select(texture) end end

     end
  end

enddef

  1. ==============================================================================

setb nhoodIsPartlyUnderwater false define PartiallyUnderWaterMaterial()

  seti vt viewerRenderType
  

## prevents the thumbnails of rocks and such from being 'under water', by punting to standard material.

  # thumbnails are rendered at 0,0,0, but water tends to be above them at 312 ft/yards whatever.
  

if (viewerRenderType = $kRenderTypeThumbnail) create StandardMaterial()

   else
   	create UnderWaterShadingMaterial()

endif

enddef

define UnderWaterShadingMaterial()

  material
     shader -layer (($nhoodCanvasLayer + 4) * 8)
        validateRenderShaderContext -vertexFormat  position 0 required
        validateRenderShaderContext -vertexFormat  normal   0 required
        validateRenderShaderContext -viewerRenderType viewerRenderType
  
        if ($stdMatBaseTextureEnabled)
           validateRenderShaderContext -vertexFormat  texcoord 0 required
        endif
  


        pass -fixedFunction
  
           ffMatCoef -amb $stdMatDiffCoef -ambAlpha $stdMatAlphaMultiplier -diff $stdMatDiffCoef  -diffAlpha $stdMatAlphaMultiplier -emit $stdMatEmissiveCoef -emitAlpha $stdMatAlphaMultiplier -spec $stdMatSpecCoef -specPow $stdMatSpecPower
  
           create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
           fillmode $stdMatFillMode
           cullmode $stdMatCullMode
  
           create LightingStates()                        
                       
           stage
              create StandardShaderTextureState(Base)               
              textureBlend multiply(texture outRegister) multiply(texture outRegister)               
           end
           
           #################################################################
           if ($stdMatIsPartlyUnderwater and tsIsInNeighborhood)
              if (viewerRenderType = $kRenderTypeReflection)
                 alphaTest true 128
                 alphaTestFunction acceptIfGreater
                 stage
                    # above water -- clip by using depth-based 0/1 texture.
                    texture blackWhite
                    textureAddressing clamp clamp
                    textureFilterHint point point
                    textureMIPFilterHint disabled
                       
                    ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
                    ffTextureCoordsSource fromPosition
                    textureBlend multiply(texture outRegister) select(texture)
                 end 
              else
                 stage
                    # would we want to source this from somewhere?
                    texture $waterGradientTexture
                    textureAddressing tile clamp
                    
                    set d ($waterHeight - $waterGradientZoneStart) 
                    set s (-$waterGradientZoneSize)
                    ffTextureMatrix -cameraToGlobal -order xzyw -scale $s -trans (0, $d) -invert
                    ffTextureCoordsSource fromPosition
                    textureBlend multiply(texture outRegister) select(outRegister)
                 end         
              endif
           else
              # if we are in lot mode and we want to fade this shape
              if (numLightsOfType(${kShapeColorLight}) != 0) 
                 alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
                 depthTest true -enableDepthWrite false
                 colorScalar (1, 1, 1, 1) -applyShapeColor 0 
                 stage
                    textureBlend select(outRegister) select(colorScalar)
                 end
              endif
           endif
           #################################################################
        end
        
        seti weatherLightCount (numLightsOfType(${kWeatherLight}))
  	      
     end
     
     # fallback shader, no darken by depth, since "FromPosition" tends to be totally FUBAR  in SWVP.
     shader -layer (($nhoodCanvasLayer + 4) * 8)
     

pass -fixedFunction

           ffMatCoef -amb $stdMatDiffCoef -ambAlpha $stdMatAlphaMultiplier -diff $stdMatDiffCoef  -diffAlpha $stdMatAlphaMultiplier -emit $stdMatEmissiveCoef -emitAlpha $stdMatAlphaMultiplier -spec $stdMatSpecCoef -specPow $stdMatSpecPower
  
           create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
           fillmode $stdMatFillMode
           cullmode $stdMatCullMode
  
           create LightingStates()
           
           stage
              create StandardShaderTextureState(Base)               
              textureBlend multiply(texture outRegister) multiply(texture outRegister)
           end
           
           # if we are in lot mode and we want to fade this shape
           if (not tsIsInNeighborhood and numLightsOfType(${kShapeColorLight}) != 0) 
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
              depthTest true -enableDepthWrite false
              colorScalar (1, 1, 1, 1) -applyShapeColor 0 
              stage
                 textureBlend select(outRegister) select(colorScalar)
              end
           endif
           

end


     end
  end

enddef


  1. ===================================================================================

define ImposterArrowMaterial()

  material
     shader -layer (($nhoodCanvasLayer + 11) * 8)
        
        validateRenderShaderContext -vertexFormat  position      0 required
        validateRenderShaderContext -vertexFormat  normal        0 required
        validateRenderShaderContext -vertexFormat  texcoord      0 required

pass -fixedFunction create LightingStatesNoStdLights() alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) fillmode $stdMatFillMode

           # TODO: change this, cannot turn off depth since that is used for dirty rect

depthTest false -enableDepthWrite false

stage texture $texture textureAddressing tile tile ffTextureCoordsSource 0 textureBlend select(texture) select(texture) end end

     end
  end

enddef

  1. ===================================================================================

define NeighborhoodTreeGUOBMaterial()

  1. $stdMatTextureName
  2. $stdMatAlphaMulitplier
 # TODO: fix these so that they are not hardcoded, must be passed through content
 set  textureName      "genericroundsoftguob-alpha"
 setf alphaMultiplier  0.65
 # try using vs_2_sw on the trees since sw vs is not as susceptible to state changes
 # this only handles tree GUOBs in the nhood.
 material
  
     #the engine will try this shader first..
     shader -layer $nhoodTreeShadowLayer
       # shadows can never be seen in reflections (they're on the ground)
       viewerRenderTypePred $kRenderTypeReflection false
       pass
          alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
          depthTest true -enableDepthWrite false
          
           shaderProgram -target vertexProgram -method assemble
             bindConstants 0 -bindingID geomToClip -constantCount 4
             shaderSource
                vs_1_1
                dcl_position v0
                dcl_texcoord v1
                m4x4 oPos, v0, c0
                mov oT0, v1
                
             endShaderSource
           end
          
           shaderProgram -target pixelProgram -method assemble
              shaderSource
                 ps_1_1
                 def c0,1,1,1,$alphaMultiplier
                 tex t0
                 mul r0,t0, c0
              endShaderSource
              
           end
           
           sampler 0
             texture $textureName
             textureAddressing clamp clamp clamp
           end
       end
     end
     
  # and fall back to this one if it can't render the above.
  shader -layer $nhoodTreeShadowLayer
       # shadows can never be seen in reflections (they're on the ground)
       viewerRenderTypePred $kRenderTypeReflection false
       pass -fixedFunction
          alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
          depthTest true -enableDepthWrite false
          
          colorScalar (1,1,1, $alphaMultiplier)
          
          stage
             texture $textureName
             textureAddressing clamp clamp clamp
             textureBlend select(texture) multiply(texture colorScalar)
          end
       end
  end
   
 end

enddef

  1. =======================================================================================

define NeighborhoodBuildingMaterial()

  material  
     shader -layer 0  
        setb isDay tsIsDay
        setb shouldShow (($showOnDay and $isDay) or ((not $showOnDay) and (not $isDay)))
        if ($shouldShow)
           pass -fixedFunction    
              
              if (numLightsOfType(${kShapeColorLight}) > 0)               
                 alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
                 depthTest true -enableDepthWrite false               
                 colorScalar (1, 1, 1, 1) -applyShapeColor 0 
              else
                 colorScalar (1, 1, 1, 1)
              endif     
              
              
              if ($isDay) #lighting is only applied at day time
                 ffLighting -enable true -localViewer false -normalizeNormals false
                 create NonStandardLighting()            
                 ffMatCoef -amb (0.8,0.8,0.8) -ambAlpha 1.0 -diff (0.8,0.8,0.8) -diffAlpha 1.0	-spec (0,0,0) -specPow 0
              
                 stage
                    ffTextureCoordsSource 0
                    texture $texMaterial
                    textureBlend multiply(texture diffuse) multiply(texture colorScalar)
                 end
              else
                 stage
                    ffTextureCoordsSource 0
                    texture $texMaterial
                    textureBlend select(texture) multiply(texture colorScalar)
                 end
              endif
           end            
        endif
     end
  end   

enddef

  1. ============================================================================================
  1. make tree shadows render to an opaque (but blended layer) so they drop into the static layer
  2. this overrides the texture name and alpha blend level.

materialDefinition neighborhood_roundshadow

  setDefinition NeighborhoodTreeGUOBMaterial

end

  1. rectangular shadows are used by the car shadows, until can pass the existing texture name onto the material,
  2. leave those shadows as transparent layer 7 that will get alpha sorted, etc.
  3. materialDefinition neighborhood_rectangularshadow
  4. setDefinition NeighborhoodTreeGUOBMaterial
  5. end
  1. forest

materialDefinition forest_01_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition forest_02_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end


  1. oak

materialDefinition treeoak01_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition treeoak02_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition treeoak03_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition treeoak04_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition treeoak05_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition treeoak06_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end

  1. scrub oak

materialDefinition neighborhoodtreescruboak_shadows_alpha

  setDefinition NeighborhoodTreeGUOBMaterial

end

  1. birch

materialDefinition treebirch01_shadows

  setDefinition NeighborhoodTreeGUOBMaterial
 

end materialDefinition treebirch02_shadows

  setDefinition NeighborhoodTreeGUOBMaterial
  

end materialDefinition treebirch03_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition treebirch04_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition treebirch05_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end materialDefinition treebirch06_shadows

  setDefinition NeighborhoodTreeGUOBMaterial

end

  1. TODO: need to redefine the tree shaders, at least skip in reflections
  2. this is also causing massive batch count for main view (scrolling)
  3. all trees should be combined into a single part/texture atlas with their shadows
  4. render them after the terrain
  5. materialDefinition treeoak01_diffuse
  6. setDefinition StandardMaterial
  7. end


  1. ===================================================================================

materialDefinition neighborhood-canvas-outOfWater

  setDefinition NeighborhoodCanvas
  addParam   isUnderWater false

end

materialDefinition neighborhood-canvas-underwater

  setDefinition NeighborhoodCanvas
  addParam   isUnderWater true

end

materialDefinition neighborhood-canvas-straddle

  setDefinition NeighborhoodCanvasStraddle

end

materialDefinition neighborhood-underwater-terrain

  setDefinition NeighborhoodWaterTerrain

end

materialDefinition waterEdgeBoxMaterial

  setDefinition NeighborhoodWaterEdge
  addParam waterEdgeTexture "neighborhood-sides-water"

end

materialDefinition terrainEdgeBoxMaterial

  setDefinition NeighborhoodTerrainEdge
  addParam terrainEdgeTexture "neighborhood-sides-dirt"

end

materialDefinition nhoodTerrainLightingMaterial

  setDefinition NHoodTerrainLighting

end

materialDefinition nhoodTerrainLightingMaterialImposter

  setDefinition NHoodTerrainLighting
  addParam isImposter true

end

materialDefinition nhoodReflectionSkybox

  setDefinition SkyboxCompositionPassMaterial
  addParam skyboxCubeTexture $skyboxCubeMap

end

materialDefinition lotSkirtReflectionSkybox

  setDefinition SkyboxCompositionPassMaterial
  addParam skyboxCubeTexture $skyboxCubeMap

end

materialDefinition lotPlacementArrow

  setDefinition ImposterArrowMaterial
  addParam texture lot-placement-arrow

end

  1. Material used in highlighting the terrain to depict a house for which no imposter exists yet.

materialDefinition DefaultResidentialLotImposterMaterial

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lothighlight-residential"
  addParam highlightAlpha 0.5

end

materialDefinition DefaultCommunityLotImposterMaterial

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lothighlight-community"
  addParam highlightAlpha 0.5

end


  1. Material used in creating a terrain thumbnail for a lot for which no imposter exists yet.

materialDefinition DefaultLotThumbnailMaterial

  setDefinition StandardMaterial
  addParam stdMatBaseTextureEnabled "true"
  addParam stdMatBaseTextureName "lotselection-done"
  addParam stdMatLightingEnabled true
  addParam stdMatDiffCoef (1, 1, 1)

end

materialDefinition bridge_sides

  1. setDefinition StandardMaterial
  setDefinition PartiallyUnderWaterMaterial
  addParam stdMatAlphaBlendMode none
  addParam stdMatBaseTextureEnabled true
  addParam stdMatBaseTextureName bridge-sides
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
  addParam stdMatIsPartlyUnderwater true

end

materialDefinition cliff_boulder_material

  1. setDefinition StandardMaterial
  setDefinition PartiallyUnderWaterMaterial
  addParam stdMatAlphaBlendMode none
  addParam stdMatBaseTextureEnabled true
  addParam stdMatBaseTextureName nh-test-cliff
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
  addParam stdMatIsPartlyUnderwater true

end

materialDefinition plesiosaur_skin_material

  1. setDefinition StandardMaterial
  setDefinition PartiallyUnderWaterMaterial
  addParam stdMatAlphaBlendMode none
  addParam stdMatBaseTextureEnabled true
  addParam stdMatBaseTextureName plesiosaur-skin
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
  addParam stdMatIsPartlyUnderwater true
  
  # these are mvoing objects, need to be at or above layer 0
  addParam nhoodCanvasLayer -4
  

end

materialDefinition neighborhood_bouyside_material

  1. setDefinition StandardMaterial
  setDefinition PartiallyUnderWaterMaterial
  addParam stdMatAlphaBlendMode none
  addParam stdMatBaseTextureEnabled true
  addParam stdMatBaseTextureName neighborhood_bouyside
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
  addParam stdMatIsPartlyUnderwater true
  
  # these are mvoing objects, need to be at or above layer 0
  addParam nhoodCanvasLayer -4

end


materialDefinition RelationshipArchGreen

  setDefinition StandardMaterial
  addParam   stdMatSpecPower 20
  addParam   stdMatDiffCoef (0.3, 1, 0.3)
  addParam   stdMatSpecCoef (1, 1, 1)
  addParam   stdMatAlphaMultiplier 0.6
  addParam   stdMatAlphaBlendMode blend

end

materialDefinition housePlacementOKHighlight

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lotselection-good"
  addParam highlightAlpha 0.15

end

materialDefinition housePlacementNotOKHighlight

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lotselection-bad"
  addParam highlightAlpha 0.15

end

materialDefinition roadIndicatorOK

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lothighlight-roadghost-good"
  addParam highlightAlpha 0.75

end

materialDefinition roadIndicatorNotOK

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lothighlight-roadghost-bad"
  addParam highlightAlpha 0.75

end

materialDefinition DefaultLotHighlight

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lotselection-good"
  addParam highlightAlpha 0.25

end

materialDefinition ResidentialLotHighlight

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lothighlight-residential"
  addParam highlightAlpha 0.40

end

materialDefinition CommunityLotHighlight

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lothighlight-community"
  addParam highlightAlpha 0.40

end

materialDefinition DormLotHighlight

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lothighlight-dorm"
  addParam highlightAlpha 0.40

end

materialDefinition NotOKLotHighlight

  setDefinition NHoodTerrainHighlightMaterial
  addParam highlightTexture "lotselection-bad"
  addParam highlightAlpha 0.40

end

materialDefinition neighborhoodbuildingres1_windows_night

  setDefinition NeighborhoodBuildingMaterial
  addParam texMaterial neighborhoodbuildingres1_repeat-surface-night
  addParam showOnDay false

end

materialDefinition neighborhoodbuildingres1_windows_day

  setDefinition NeighborhoodBuildingMaterial
  addParam texMaterial neighborhoodbuildingres1_repeat-surface 
  addParam showOnDay true

end

  1. this is commented out because the UI renders this without use of the material
  2. materialDefinition ZoomConePyramid
  3. setDefinition ZoomConeMaterial
  4. addParam baseColor (1.0, 1.0, 1.0, 0.5)
  5. end

define LotSkirtPSWater()

   shader -layer ($poolWaterLayer+1)
       validateRenderShaderContext -vertexFormat position 0 required

pass -clipAlways -modifiedEachFrameHint #fillmode wireframe alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) seti textureLights (numLightsOfType(environmentCube)) depthTest true -enableDepthWrite false

shaderProgram -target vertexProgram -method compile -version 1_1

bindConstants 0 -bindingID geomToClip -constantCount 4 bindConstants 4 -bindingID geomToCamera -constantCount 3

bindConstants 7 -bindingID frameInfo

bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed) bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed)

# pre-evaluate these setf xscale (-$wmXRepeat * $wmXWaveHeight) setf yscale (-$wmYRepeat * $wmYWaveHeight) bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0) bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float bindConstants 18 -bindingID cameraToGlobal -constantCount 3 bindConstants 21 -bindingID cameraToGeom -constantCount 3

if (tsIsDay) bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1) bindConstants 28 -bindingID immediateData -data (-0.3, 0.1, 0.1, 0.0) else bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1) bindConstants 28 -bindingID immediateData -data (-0.3, -0.2, -0.1, 0.0) endif

shaderSource

float4 frameInfo : register(c7); float4 waveDataX : register(c11); float4 waveDataY : register(c12); float4 waveDataHelper : register(c13); float4x4 clipSpaceMatrix : register(c0); float4x3 cameraSpaceMatrix : register(c4); float4x3 cameraToGlobalMatrix : register(c18); float4x3 cameraToGeomMatrix : register(c21);

float4 nightColor: register(c25); float4 waterTint: register(c28);

float4 lightDirection : register(c14); float4 lightColor : register(c15); float4 lightSpecular : register(c16);

const static float4 refractionWeights={1,1,2,0}; const static float4 layerBlue={1.0, 1.0, 1.0, 1.0};

struct InputVertex { float3 position: POSITION0; float3 normal : NORMAL0; float2 alpha  : TEXCOORD1; };

struct OutputVertex { float4 clipPosition : POSITION; float4 sPos  : TEXCOORD0; float2 Wave0  : TEXCOORD1; float2 Wave1  : TEXCOORD2; float2 Wave2  : TEXCOORD3; float2 Wave3  : TEXCOORD4; float3 Eye  : TEXCOORD5; float4 specular  : COLOR0; float4 colorTint  : COLOR1; };


OutputVertex VertexMain( InputVertex inputVertex) { // Do Y-direction waves // r0 = (x, y, z, t)

OutputVertex outputVertex;

float4 posAndTime; posAndTime.xyz = inputVertex.position; posAndTime.w = frameInfo.w;

float temp = dot(posAndTime, waveDataX); float z = sin(temp) * waveDataX.z + inputVertex.position.z; temp = dot(posAndTime, waveDataY); posAndTime.z = z + sin(temp) * waveDataY.z ;//-0.1f; //The -.01 is a fudge factor to remove some of the edge creep associated with moving the height of the wave. -tom posAndTime.w = 1.0f;

outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix); outputVertex.sPos = float4(0.5f*(outputVertex.clipPosition.ww - outputVertex.clipPosition.xy), outputVertex.clipPosition.ww);

float3 waveNormal = normalize(inputVertex.normal + float3(cos(temp)*waveDataHelper.xy, 0)); float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix)); float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix); float3 viewVector = normalize(-cameraSpacePosition);

float3 halfVector = normalize(viewVector + lightDirection); outputVertex.specular = lightSpecular*pow(dot(cameraSpaceNormal, halfVector), 50)*nightColor*lightColor*0.5;


float2 fTranslation=float2(fmod(frameInfo.w, 100)*0.005, fmod(frameInfo.w, 100)*0.005); float2 vTexCoords = posAndTime.xy*0.05;

// Output bump layers texture coordinates float fSinTranslation=sin(fTranslation*100)*0.005; float2 vTranslation0=fTranslation+fSinTranslation; float2 vTranslation1=fTranslation-fSinTranslation; float2 vTranslation2=fTranslation;

// Scale texture coordinates to get mix of low/high frequency details outputVertex.Wave0.xy = vTexCoords.xy*0.01+fTranslation*2.0; outputVertex.Wave1.xy = vTexCoords.xy+fTranslation*2.5; outputVertex.Wave2.xy = vTexCoords.xy+fTranslation*-2.3; outputVertex.Wave3.xy = vTexCoords.xy*0.1+fTranslation*1.5;

// compute binormal float3 binormal = normalize(cross(waveNormal, float3(1.0f, 0.0f, 0.0f))); float3 tangent = normalize(cross(binormal, waveNormal));

// tangent space matrix float3x3 objToTangentSpace = float3x3(tangent, binormal, waveNormal);

float3 viewVectorInObjSpace = mul(viewVector, (float3x3)cameraToGeomMatrix);

outputVertex.Eye.xyz = mul(objToTangentSpace, viewVectorInObjSpace); outputVertex.colorTint = waterTint; outputVertex.colorTint.a = inputVertex.alpha.xxxx; // outputVertex.color = waterTint.xxxx;

return(outputVertex); }

endShaderSource end # shaderProgram

shaderProgram -target pixelProgram -method compile -version 2_0 shaderSource sampler reflect; sampler bump; struct cInputPixel { float4 sPos  : TEXCOORD0; float2 Wave0  : TEXCOORD1; float2 Wave1  : TEXCOORD2; float2 Wave2  : TEXCOORD3; float2 Wave3  : TEXCOORD4; float3 Eye  : TEXCOORD5; float4 specular  : COLOR0; float4 colorTint  : COLOR1; };

float Fresnel(float NdotL, float fresnelBias, float fresnelPow, float facing) { return max(fresnelBias + (1.0f - fresnelBias)*pow(facing, fresnelPow), 0.0); }

float4 PixelMain(cInputPixel pi) : COLOR { float3 vEye = normalize(pi.Eye);

// Get bump layers float3 vBumpTexA = tex2D(bump, pi.Wave0.xy).xyz; float3 vBumpTexB = tex2D(bump, pi.Wave1.xy).xyz; float3 vBumpTexC = tex2D(bump, pi.Wave2.xy).xyz; float3 vBumpTexD = tex2D(bump, pi.Wave3.xy).xyz;

// Average bump layers float3 vBumpTex=normalize(2.0 * (vBumpTexA.xyz + vBumpTexB.xyz + vBumpTexC.xyz + vBumpTexD.xyz)-4.0);

// Apply individual bump scale for refraction and reflection float3 vReflBump = vBumpTex.xyz ; float4 vReflection = tex2Dproj(reflect, pi.sPos + float4(vReflBump.xy, 0.0f, 0.0f));//*0.001 + float4(2.0*vBumpTexD-1.0f.xxx, 1);

// Compute Fresnel term float NdotL = max(dot(vEye, vReflBump), 0); float facing = (1.0 - NdotL); float fresnel = Fresnel(NdotL, 0.1, 0.5, facing);

vReflection.a = fresnel * 0.5;

return saturate(vReflection + pi.colorTint); } endShaderSource end

sampler reflect texture "OceanReflection" textureAddressing clamp clamp end

sampler bump texture "poolShape-body-bump" textureAddressing tile tile end

end # end pass end enddef

define LotSkirtWater() material create DetermineHardwareSupport()

if ($useHWShader2Path) create LotSkirtPSWater() else

shader -layer $nhoodWaterLayer validateRenderShaderContext -vertexFormat position 0 required validateRenderShaderContext -vertexFormat normal 0 required validateRenderShaderContext -vertexFormat texcoord 0 required viewerRenderTypePred viewerRenderType

pass -fixedFunction

alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) colorScalar $lotSkirtWaterReflColour 0.50 depthTest true -enableDepthWrite false

#tring to remove warble I think it may be caused by depth bias. #ffDepthOffset -2

stage ffTextureCoordsSource fromPosition ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5) textureAddressing clamp clamp texture "ScreenReflection"

textureBlend multiply(texture colorScalar) multiply(diffuse colorScalar) end

end end endif

  end

enddef

define LotSkirtWaterNoReflection()

  material
     # fallback: no reflection.
     shader -layer ($nhoodWaterLayer)
        viewerRenderTypePred viewerRenderType
        
        create DetermineHardwareSupport()
        
        pass -fixedFunction

# For now, we are diabling the lighting since we simply want to use the vertex colors. create LightingStatesNoStdLightsParam(false true) alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)

           colorScalar (.4, .6, .9, .4)      
           
           #tring to remove warble I think it may be caused by depth bias.
           #ffDepthOffset -2                              
           
           fillmode $stdMatFillMode
           stage
              #texture reflectionoutdoorwater-envcube
              if ($cubeMapSupport)
                 texture $skyboxCubeMap
                 textureMIPFilterHint disabled
                 ffTextureCoordsSource fromReflectionVector
                 ffTextureMatrix -orientCameraToGlobal
                 textureAddressing clamp clamp clamp
                 textureBlend multiply(texture colorScalar) select(colorScalar)
              else
                 textureBlend select(colorScalar) multiply(diffuse colorScalar)
              endif
           end  
        end   
     end
  end               

enddef

materialDefinition lotSkirtSea

  setDefinition LotSkirtWater  
  addParam stdMatLightingEnabled false
  addParam stdMatLayer 0
  
  addParam stdMatDiffCoef (1, 1, 1)   
  addParam wmReflectionTexture swimming_pool-envcube
  addParam wmTransparency 0.4
  addParam wmXSpeed        3
  addParam wmXRepeat       5
  addParam wmXWaveHeight   0.001 
  
  addParam wmYSpeed        3
  addParam wmYRepeat       6
  addParam wmYWaveHeight   0.001 
 

end

materialDefinition lotSkirtSeaNoReflection

  setDefinition LotSkirtWaterNoReflection   

end

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox