Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
Line 1: Line 1:
# EP5-SS & EP6-BV & EP7 FT
 
# 0xCD7FE87A
 
# 0x1C0532FA
 
# 0x26B3DB7C
 
# 0xFF3A262A
 
# neighborhood
 
 
 
#
 
#
# Shaders for neighborhood  (Moi's neighbourhoodRouge-EP5-SS & EP6-BV & EP7 FT)
+
# Shaders for indoor & outdoor tiles; i.e., "Floors".
 
#
 
#
# For study or modding, edit --> find or search for "### MODDED"
 
# "Bolded" terms or values are for emphasis; "Italic" terms or values are customised/customized terms or values; "Bolded & Italic" terms or values are emphasised/emphasized customised/customized terms or values; "Underlined" is show out the altered.
 
 
#
 
#
  
# layers
+
seti gridLayer 13
# normal shadows are layer 2 (after opaques), tree shadows are moved to -2 to make them
+
seti floorLayer -4
# render to the first bufferTree shadows (-2) do not show up on fields (7).
+
setf floorMaterialScaleU 1.0 # defaults for Floor materials without these defined
seti nhoodWaterLayer            1
+
setf floorMaterialScaleV 1.0 # defaults for Floor materials without these defined
seti nhoodCanvasLayer          -8
+
setb floorHighlightOn false
seti nhoodTreeShadowLayer      -2
+
setc floorHighlightIntensity (0.25, 0.25, 0.25, 1.0)  # attenuation of the floor highlight texture
 +
setf floorGridAlpha 0.775
 +
seti previewLayer 0 # -28
  
setf  neighborhoodMaterialScaleU 8.0  # defaults for neighborhood materials without these defined
+
# debug options for PS hardware only, only set one of these to true
setf  neighborhoodMaterialScaleV 8.0 # defaults for neighborhood materials without these defined
+
setb debugShowFloorIncidence false  # shows the incidence maps as color
 +
setb debugShowFloorNormalMap false  # shows the raw normal map (if it exists)
 +
setb debugFloorLighting false      # no base texture, only lighting results
 +
setb debugShowLightMapTexcoords false # texcoords as color
  
setf  nhoodWaterMap1Scale    7.0
 
setf  nhoodWaterMap1Speed    0.5
 
setf  nhoodWaterMap2Scale    5.0
 
setf  nhoodWaterMap2Speed    0.3
 
  
 +
setb floorCausticsPass false
 +
seti floorRenderStyle 0
 +
setb hasCutout false
  
setv2 baseTexOffset (0.5, 0.5)
+
include PixelShaderFloors.matShad
setv3 nhoodDiffCoef (0.75, 0.93, 0.75)
+
  
  
setf  nhoodPaintTextureScale  13      #Repeat distance of neighborhood textures in tiles.
+
#beginshader Floor
                                    #NOTE: There is a related parameter called "TextureVariantGridSize" in
+
#description Basic floor tile shader; texture + floor gradient + shadows
                                    #NeighborhoodTerrain.ini. You would normally (though not necessarily) want it to be
+
#extraparam float floorMaterialScaleU 1 0.125 64 ; no. tiles to map across U axis, use any positive number
                                    #the same as this number.
+
#extraparam float floorMaterialScaleV 1 0.125 64 ; no. tiles to map across V axis, use any positive number
setf  waterEdgeTextureScale  250.0  #Repeat distance in meters
+
define Floor()
setf  terrainEdgeTextureScale 100.0  #Repeat distance in meters
+
   material
 
+
      if ($stdMatLightingDebug)
 
+
        create LightingDebugStandardMaterialOverrides()
### MODDED1 # coloration for water fallbacks without mirror reflection # Just alter the corresponding RGB(Alpha) values
+
      endif
# Neighbourhood Water Colouration
+
      create FloorShaders()
setv4 nAbahoodWater (0.75, 0.6, 0.45, 0.667)
+
   end
# neighbourhood water fallback coloration when without ScreenReflection
+
setv4 nAbahoodEau (0.75, 0.6, 0.45, 0.667)
+
# lotskirt water fallback coloration when without ScreenReflection
+
 
+
### 0.15, 0.045, 0.03
+
### 0.3, 0.09, 0.06
+
### 0.8,0.25,0.1
+
 
+
### MODDED2 # coloration for waters with mirror reflection # Just alter the corresponding RGB(Alpha = reflectivity or relfective strength) values
+
# Reflective water
+
setc  nhoodWaterReflColour  (0.75, 0.15, 0.05)
+
# neighbourhood water coloration RGB when by default with ScreenReflection
+
setc  lotSkirtWaterReflColour (0.75, 0.15, 0.05)
+
# in-lot lotskirt water coloration RGB when by default with ScreenReflection
+
setf  nhoodWaterReflStrength  0.75
+
# neighbourhood water reflectivity alpha when by default with ScreenReflection
+
setf  lotSkirtWaterReflStrength 0.75
+
# in-lot lotskirt water reflectivity alpha when by default with ScreenReflection
+
setf  nhoodWaterReflOffset    0.0020
+
 
+
# Standard water
+
setf nhoodWaterbumpMapScale 8.0
+
### MODDED3 # coloration for neighbourhood water transparency
+
setf nhoodWaterAlpha        0.333
+
# neighbourhood water geneal transparency
+
 
+
 
+
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
+
 
+
 
+
##################################################
+
set useReflection 0 # default material parameter value
+
 
+
seti poolWaterLayer 5
+
 
+
setf wmTransparency  0.5
+
#attrdescription Water transparency
+
 
+
setf wmXSpeed        3    # min:0 max:100
+
#attrdescription Lookup texture for diffuse intensity.
+
setf wmXRepeat      1     # min:0 max:100
+
#attrdescription Lookup texture for diffuse intensity.
+
setf wmXWaveHeight  0.1  # min:0 max:100
+
#attrdescription Lookup texture for diffuse intensity.
+
 
+
setf wmYSpeed        5    # min:0 max:100
+
#attrdescription Lookup texture for diffuse intensity.
+
setf wmYRepeat      1.8  # min:0 max:100
+
#attrdescription Lookup texture for diffuse intensity.
+
setf wmYWaveHeight  0.2  # min:0 max:100
+
#attrdescription Lookup texture for diffuse intensity.
+
 
+
set wmReflectionTexture reflectionoutdoorwater-envcube
+
#attrdescription Environment cube map texture for reflection
+
 
+
setb wmRefractionEnabled false
+
#attrdescription Whether refraction is enabled
+
 
+
set wmRefractionTexture swimming_pool-envcube
+
#attrdescription Environment cube map texture for refraction
+
##################################################
+
 
+
 
+
# ==============================================================================
+
# 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
 
enddef
 +
#endshader
  
create BiasedNormal(nhoodSunDir nhoodSunDirBiased)
 
setv3 nhoodSunDirBiased ($nhoodSunDirBiased * $bumpMapBoost.xxx)
 
  
set terrainType "unset"
+
#beginshader FloorPool
 
+
#description Pool tile shader, with caustics.
# defaults off, can be turned on at startup.
+
#extraparam bool floorCausticsPass 1 ; set to true to add water caustics.
setb simpleTerrain false
+
define FloorPool()
setb isImposter false
+
  material
 
+
       if ($stdMatLightingDebug)
include neighborhoodSWVS.matShad
+
         create LightingDebugStandardMaterialOverrides()
 
+
# ==============================================================================
+
 
+
define NeighborhoodCanvas()
+
 
+
# this material does nothing but prep the z-buffer, and render black.
+
 
+
material
+
       if ($simpleTerrain)
+
         shader
+
        end
+
 
       endif
 
       endif
 
+
       create FloorShaders()
       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
 
   end
 
enddef
 
enddef
 +
#endshader
  
  
# ==============================================================================
 
# Used for those triangles in the canvas which are partially under water.
 
#
 
define NeighborhoodCanvasStraddle()
 
material
 
  
      if ($simpleTerrain)
 
        shader
 
        end
 
      endif
 
  
# material for reflection camera
+
#
 +
# Standard floor shaders
 +
#
 +
define FloorShaders()
  
      shader -layer (($nhoodCanvasLayer) * 8)
+
  if (viewerRenderType = $kRenderTypeShadowMap)
     
+
  create ShadowMapVS_PS()
validateRenderShaderContext -vertexFormat  position      0 required
+
else
validateRenderShaderContext -vertexFormat  normal        0 required
+
  setb bumpMapFloors false
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
+
  create DetermineHardwareSupport()
alphaTestFunction acceptIfGreater
+
 
 +
  setb hasTexcoord2 (hasVertexFormat(texcoord,1))
 +
 
 +
      # check for the page, the global bumpmap glag, and for the normal map in the material
 +
  if (varExists(page) and $bumpMapping and $stdMatNormalMapTextureEnabled and $hasTexcoord2)
 +
  setb bumpMapFloors true
 +
  endif
  
stage
+
      if ($useHWShader1Path or $useHWShader2Path)
# above water -- clip by using depth-based 0/1 texture.
+
 
texture blackWhite
+
  create PixelShaderFloors($bumpMapFloors)
textureAddressing clamp clamp
+
 
textureFilterHint point point
+
  else
textureMIPFilterHint disabled
+
                 
+
ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
+
ffTextureCoordsSource fromPosition
+
textureBlend select(colorScalar) select(texture)
+
end
+
end
+
endif
+
+
end
+
 
        
 
        
     
+
  # fixed function paths NEVER get bump mapping due to fill rate and memory concerns.
     
+
 
      #material for standard camera 
+
  create FixedFunctionFloorShader()   
      #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
+
  # ultimate fallback pass? no light map, one stage.  
textureBlend select(colorScalar) select(outRegister)
+
  shader -layer $floorLayer
end
+
  validateRenderShaderContext -vertexFormat position 0 required
end
+
  validateRenderShaderContext -vertexFormat normal 0 required
endif
+
  validateRenderShaderContext -vertexFormat texcoord 0 required
+
  validateRenderShaderContext -viewerRenderType viewerRenderType
end
+
     
+
end
+
enddef
+
 
+
# ==============================================================================
+
# 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
+
 
+
# ==============================================================================
+
 
+
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
 
  pass -fixedFunction
 
+
  create LightingStates()
  create LightingStatesNoStdLights()
+
  create AttenuatedMatCoef(1)
  alphaBlend srcFactor(srcAlpha) add dstFactor(one)
+
  fillmode $stdMatFillMode
  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)
+
  if ($hasCutout)                        
      set weatherSuffix "-LSNOW"
+
                   depthTestFunction acceptIfEqual
  elseif ($snowLevel = 2)
+
                   set weatherSuffix "-HSNOW"
+
 
               else
 
               else
                   set weatherSuffix ""
+
                   depthTestFunction acceptIfLessOrEqual
 
               endif
 
               endif
             
+
 
 
  stage
 
  stage
  texture $alphaMap
+
  texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
  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
 
  textureAddressing tile tile
  if ($isImposter)
+
  ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
  ffTextureMatrix -cameraToGlobal -scalev ((10.0 * $nhoodPaintTextureScale), (10.0 * $nhoodPaintTextureScale)) -invert
+
  textureTransformType vector2
  ffTextureCoordsSource fromPosition
+
  ffTextureCoordsSource 0
  else
+
  textureBlend multiplyScale2(texture diffuse) select(outRegister)
      ffTextureMatrix -scalev ($nhoodPaintTextureScale, $nhoodPaintTextureScale) -invert
+
      ffTextureCoordsSource 0
+
  endif
+
  textureBlend select(texture outRegister) select(outRegister)
+
 
  end  
 
  end  
  end      
+
  end
        endif
+
 
+
  create HighlightPass()
end
+
 
 +
  end
 +
  endif
 +
endif
 +
 
enddef
 
enddef
  
define NeighborhoodTerrainPaint()
+
#
   material
+
# Standard floor shader,
 +
#
 +
define FixedFunctionFloorShader()
 +
    
 +
  setb lightMapAvailable false
 +
  if (varExists(page))
 +
      setb lightMapAvailable true
 +
  endif
 +
 
 +
  setb caustics false
 +
  if ($floorCausticsPass and $causticsEnabled)
 +
      setb caustics true
 +
  endif 
 +
 
 +
  shader -layer $floorLayer
 +
      validateRenderShaderContext -vertexFormat position 0 required
 +
      validateRenderShaderContext -vertexFormat texcoord 0 required
 +
      validateRenderShaderContext -viewerRenderType viewerRenderType
 
        
 
        
       if ($simpleTerrain)
+
       set stdMatSpecCoef (0, 0, 0)
        shader
+
       set stdMatSpecPower 0
        end
+
       endif
+
     
+
      create NeighborhoodTerrainPaintShader()
+
  end
+
enddef
+
+
  
# ==============================================================================
+
if ($caustics)
 +
pass -fixedFunction -modifiedEachFrameHint     
 +
else
 +
pass -fixedFunction
 +
endif
  
set ratioH 1  # default material parameter value
+
      ffDepthOffset 0
set ratioW 1  # default material parameter value
+
        
set useReflection 1 # default material parameter value
+
       if ($hasCutout)                        
define NeighborhoodWater()
+
         depthTestFunction acceptIfEqual
  material
+
      else
       # never draw water in its reflection.  Already handled by code.
+
         depthTestFunction acceptIfLessOrEqual
 
+
       if ($simpleTerrain)
+
         shader -layer $nhoodWaterLayer
+
            pass -fixedFunction
+
### MODDED1a # Neighbourhood water: no-reflection simple point
+
      colorScalar $nAbahoodWater
+
###              colorScalar (0.3, 0.4,0.8) 1.0
+
              stage
+
                  textureBlend select(colorScalar) select(colorScalar)
+
              end
+
            end
+
         end
+
 
       endif
 
       endif
 +
     
 +
      # empirically, Floors seem to only take 3 inputs
 +
      # the base texture
 +
      # the light map
 +
      # the material color, which seems to act as a 'tune' value.
 +
     
 +
      # Lightmaps are scaled by 0.5, so this must multiply by 2 to get to the correct brightness.
 +
      # No alpha blending is required, nor is alpha scaling required.
 +
 
 +
        # # don't pre-scale -- that's in the texture.
 +
        fillmode $stdMatFillMode
 +
           
 +
        if ($lightMapAvailable)
  
 +
            colorScalar ($stdMatDiffCoef) 1
  
      # First option: reflection mapped water.
+
stage
      if ($useReflection)
+
create SelectFloorLightMap()
 
+
             
        shader -layer $nhoodWaterLayer
+
# add the lightmap lighting to any direct lights.
             validateRenderShaderContext -vertexFormat  position      0 required
+
# the light map has been prescaled by 0.5
             validateRenderShaderContext -vertexFormat  normal        0 required
+
textureBlend multiply(texture colorScalar) select(texture)
             validateRenderShaderContext -vertexFormat  texcoord      0 required
+
end
             viewerRenderTypePred viewerRenderType
+
              
 +
             stage
 +
              texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
 +
           
 +
              textureAddressing tile tile
 +
              ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
 +
              ffTextureCoordsSource 0
 +
 +
              textureBlend multiplyScale2(texture outRegister) select(colorScalar)
 +
             end
 +
              
 +
        else
 +
       
 +
        # no lightmap case:
  
            ################################################################################
 
            # Three pass/2 texture rippled reflection -- does not run on GeF2 only 2 stages (for GeF4+)
 
            pass -fixedFunction -modifiedEachFrameHint
 
 
              
 
              
 +
            colorScalar ($stdMatDiffCoef) 1
 
              
 
              
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
            stage
               colorScalar $nhoodWaterReflColour $nhoodWaterReflStrength
+
               texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
               depthTest true -enableDepthWrite false
+
           
 +
               textureAddressing tile tile
 +
              ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
 +
              ffTextureCoordsSource 0
 
                
 
                
              stage
+
              textureBlend multiply(colorScalar texture) select(colorScalar)
                  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
        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
+
        endif
               depthTest true -enableDepthWrite false
+
       
 +
 +
 +
end
 +
 
 +
      if ( $lightMapAvailable) # thumbnails don't have lightmaps, causing this to fail without them, so assume no work to be done without lightmaps.
 +
     
 +
        if ($lmIntegratedShadows )
 +
            # Still experimental
 +
            pass -fixedFunction
 +
               create LightingStatesNoStdLights()
 +
               fillmode $stdMatFillMode
 
                
 
                
 +
              alphaBlend srcFactor(destColor) add dstFactor(zero)
 +
             
 +
              alphaTest true 100
 +
              alphaTestFunction acceptIfGreater
 +
 
 +
              colorScalar (0.61, 0.61, 0.61)  # needs to be set by tsUserEtc
 +
 
 +
              ffDepthOffset 1
 +
 
 
               stage
 
               stage
                   ffTextureCoordsSource fromPosition
+
                   create SelectFloorLightMap()
                  ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
+
                   textureBlend select(colorScalar) select(texture)
                  textureAddressing clamp clamp
+
                  texture "ScreenReflection"
+
                 
+
                   textureBlend multiply(texture colorScalar) select(outRegister)
+
 
               end  
 
               end  
                
+
            end
 +
        elseif ((not ($useHWShader2Path or $useHWShader1Path)))
 +
            # Mark the depth buffer where the shadow is so object shadows
 +
            # do not overlap.
 +
            pass -fixedFunction
 +
               create LightingStatesNoStdLights()
 +
              alphaBlend srcFactor(zero) add dstFactor(one)
 +
              fillmode $stdMatFillMode
 +
 
 +
              ffDepthOffset 1
 +
              depthTest true -enableDepthWrite true
 +
              alphaTest true 100
 +
              alphaTestFunction acceptIfLess
 +
 
 
               stage
 
               stage
                   texture "neighborhood-water-1"
+
                   create SelectFloorLightMap()
                  textureAddressing tile tile
+
                   textureBlend select(texture) select(texture)
                  # -atrans waveformType cycles/sec offset (startU, startV)  (endU, endV)
+
               end  
                  #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
         end
+
         endif
       
+
 
       endif
 
       endif
 
        
 
        
      ################################################################################
+
create HighlightPass()
      # 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)
+
 
+
### MODDED1b # Neighbourhood water: no-reflection fallback point
+
      colorScalar $nAbahoodWater
+
###            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
+
+
+
      ################################################################################
+
+
#        create NeighborhoodWaterSWVS()
+
        create NeighborhoodWaterSWVSmoiAg()          
+
 
end
 
end
 +
 
 
 
 +
 
 
enddef
 
enddef
  
  
################
+
#beginshader FloorReflective
define NeighborhoodWaterSWVSmoiAg()
+
#description Basic floor tile shader with reflection; texture + floor gradient + shadows
shader -layer (($waterLayer) * 18 + 17)
+
#extraparam float floorMaterialScaleU 1 0.125 64 ; no. tiles to map for U axis, use any positive number
+
#extraparam float floorMaterialScaleV 1 0.125 64 ; no. tiles to map for V axis, use any positive number
validateRenderShaderContext -viewerRenderType viewerRenderType
+
#extraparam float reflectStrength 1 0 1 ; strength of reflection, in range 0 to 1
+
 
pass
+
set ratioH 1  # default material parameter value
+
set ratioW 1  # default material parameter value
fillmode $stdMatFillMode
+
set useReflectionFloors 0 # default material parameter value
+
define FloorReflective()
alphaBlend srcFactor(one) add dstFactor(srcAlpha)
+
material
+
shader
shaderProgram -target vertexProgram -method assemble
+
#reflective floors are currently dead. might ressurect them in an expansion pack
create BindsForSoftwareVSTransforms(false false)
+
shaderSource
+
 
 
vs_1_1
 
 
def c50, 0, 0.5,1,2
 
def c11, 0,0,1,0
 
### MODDED4  # Neighbourhood water final fallback: Just alter the highlit RGB values (in bold and italic style)
 
def c12, 0.098, 0.336, 0.469, 0.1
 
dcl_position v0
 
dcl_normal v1
 
m4x3 r0.xyz, v0, c8  ; to camera space
 
m3x3 r3.xyz, v1, c8
 
 
mov r0.w, c50.z
 
m4x4 oPos, r0, c0    ; camera to clip
 
 
dp3 r1.w, r0, r0
 
rsq r1, r1.w
 
mul r1, r1.w, r0 ; r1= view vector.
 
 
dp3 r2, r3, -r1 ; view dot normal
 
max r2, r2, c50.x
 
 
add r3, c50.z, -r2
 
 
mul oD0.xyz, r3, c12
 
mov oD0.w, r2
 
 
endShaderSource
 
end
 
 
 
stage
 
textureBlend select(diffuse) select(diffuse)
 
end
 
 
end
 
end
 
 
 
end
 
end
 
enddef
 
enddef
####################
 
  
  
  
 +
#
 +
# gridMaterial -- composites the alpha grid texture over the normal floor texture
 +
#                NOTE: In order to guarantee this is drawn on top of the normal
 +
#                floor tile textures, the layer has to be higher than that for
 +
#                the normal floor textures.
  
 
+
define TileGridMaterial()
# ==============================================================================
+
# 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()
+
 
+
  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
+
 
+
# ==============================================================================
+
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
+
 
+
#==============================================================================
+
define NHoodTerrainLighting()
+
 
+
  set terrainRepresentativeTexture "lottexture-test-01_detail"
+
  
 
material
 
material
shader -layer (($nhoodCanvasLayer + 3) * 8)
+
      if (viewerRenderType = $kRenderTypeNormal)
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)
+
         shader -layer $gridLayer
       
+
           
             if (strcmp("Desert", "${terrainType}") = 0)
+
              # this is using modifiedEachFrameHint, because when the pool tool
              set terrainRepresentativeTexture "lottexture-canvas-desert"
+
              #  is used it does not invalidate the entire terrain or invalidate the frame.
            endif
+
              pass -fixedFunction # -modifiedEachFrameHint
       
+
                  validateRenderShaderContext -viewerRenderType $kRenderTypeNormal  # normal render
            shader
+
              
              pass -fixedFunction                 
+
                  create LightingStatesNoStdLights()
  ffDepthOffset -1                
+
                  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 
+
                 
 +
                  # Add an alpha test to avoid processing fully transparent pixels
 +
                  alphaTest true 0
 +
                  alphaTestFunction acceptIfGreater                 
 +
                   
 +
                  # Since the terrain has identical geometry, and is assumed to be rendered
 +
                  # before the grid, there is no need to write to the z-buffer again.  If
 +
                  # the geometry of the grid diverges from the geometry of the terrain, we
 +
                  # *may* want to reenable depth writes here.
 +
                 
 +
                  depthTest true -enableDepthWrite false
 +
                  ffDepthOffset 2
 +
                  fillmode $stdMatFillMode
 +
                  colorScalar (0,0,0) $floorGridAlpha
 
                   stage
 
                   stage
    texture "nhoodLightMap"   
+
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
    if ($isImposter)
+
                    ffTextureCoordsSource 0
      ffTextureMatrix -cameraToGlobal -scalev (1280, 1280) -invert
+
                     textureBlend multiply(texture colorScalar) multiply(texture colorScalar)
      ffTextureCoordsSource fromPosition
+
  else
+
      ffTextureMatrix -scalev (128, 128) -invert
+
      ffTextureCoordsSource 0
+
  endif
+
                       
+
                     textureBlend select(texture) select(texture)
+
 
                   end  
 
                   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
            end
 
 
              
 
              
         endif
+
         end #shader
     
+
      else
 
+
        shader
create DetermineHardwareSupport()
+
       
+
        end
if ($useSWVertexShaderPath)
+
      endif
create NeighborhoodTerrainLightingSWVS()
+
end #mat
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
  
 +
#
 +
# inverseGridMaterial -- composites the inverse of the alpha grid texture over the normal floor texture
 +
#                NOTE: In order to guarantee this is drawn on top of the normal
 +
#                floor tile textures, the layer has to be higher than that for
 +
#                the normal floor textures.
  
# ==============================================================================
+
define InverseTileGridMaterial()
  
define NHoodTerrainHighlightMaterial()
+
#trace "$currentMaterialName inverse tile grid material"
  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
+
 
+
# ==============================================================================
+
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
+
 
+
# ==============================================================================
+
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
 
   material
      shader -layer (($nhoodCanvasLayer + 4) * 8)
+
shader -layer $gridLayer
        validateRenderShaderContext -vertexFormat  position 0 required
+
         if (viewerRenderType = $kRenderTypeNormal)
        validateRenderShaderContext -vertexFormat  normal  0 required
+
     
        validateRenderShaderContext -viewerRenderType viewerRenderType
+
             create DetermineHardwareSupport()
 
+
         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 ($useHWShader1Path or $useHWShader2Path)
             if ($stdMatIsPartlyUnderwater and tsIsInNeighborhood)
+
               create PixelShaderInverseTileGridRendering()
               if (viewerRenderType = $kRenderTypeReflection)
+
            else
                   alphaTest true 128
+
              # this pass draws the completely opaque region of the grid line
 +
              # hiding the incorrect sorting behavior of the second pass at high
 +
              # resolution mipmap levels
 +
              pass -fixedFunction
 +
                  create LightingStatesNoStdLights()
 +
                   alphaTest true 192
 
                   alphaTestFunction acceptIfGreater
 
                   alphaTestFunction acceptIfGreater
 +
                  fillmode $stdMatFillMode
 +
 
 
                   stage
 
                   stage
                     # above water -- clip by using depth-based 0/1 texture.
+
                     texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
                    texture blackWhite
+
                     ffTextureCoordsSource 0
                    textureAddressing clamp clamp
+
                     textureBlend select(texture:invert) select(texture)
                    textureFilterHint point point
+
                    textureMIPFilterHint disabled
+
                       
+
                    ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
+
                     ffTextureCoordsSource fromPosition
+
                     textureBlend multiply(texture outRegister) select(texture)
+
 
                   end  
 
                   end  
               else
+
               end
                  stage
+
 
                    # would we want to source this from somewhere?
+
              # this pass draws the transition region along the edges of the grid lines
                    texture $waterGradientTexture
+
              # this provides a blurry grid at lower mipmap levels (where the solid grid
                    textureAddressing tile clamp
+
              # line disappears entirely)
                   
+
              pass -fixedFunction
                    set d ($waterHeight - $waterGradientZoneStart)
+
                   create LightingStatesNoStdLights()
                    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)
 
                   alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
                   depthTest true -enableDepthWrite false
+
                  alphaTest true 192
                   colorScalar (1, 1, 1, 1) -applyShapeColor 0
+
                    alphaTestFunction acceptIfLess
 +
                   depthTest true -enableDepthWrite false  
 +
                   fillmode $stdMatFillMode
 +
 
 
                   stage
 
                   stage
                     textureBlend select(outRegister) select(colorScalar)
+
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
                   end
+
                    ffTextureCoordsSource 0
               endif
+
                     textureBlend select(texture:invert) select(texture)
 +
                   end  
 +
               end
 
             endif
 
             endif
            #################################################################
 
 
         end
 
         end
 +
      else
 +
        shader
 
          
 
          
         seti weatherLightCount (numLightsOfType(${kWeatherLight}))
+
         end
       
+
      endif
       end
+
end
 +
enddef
 +
 
 +
 
 +
define TileLocalGridMaterial()
 +
  material
 +
       # 7/26/04 This material should only be reinstated if the cursor moves a part that causes
 +
      # visible damage to be updated with respect to where it is moved.  Marking all the
 +
      # terrain tiles with this modifiedEachFrameHint is too slow.  For now this material
 +
      # is disabled.
 
        
 
        
       # fallback shader, no darken by depth, since "FromPosition" tends to be totally FUBAR  in SWVP.
+
       if (viewerRenderType = $kRenderTypeNormal)
      shader -layer (($nhoodCanvasLayer + 4) * 8)
+
 
        
 
        
pass -fixedFunction
+
        attributes
 
+
            attribute alphaScale float1
             ffMatCoef -amb $stdMatDiffCoef -ambAlpha $stdMatAlphaMultiplier -diff $stdMatDiffCoef  -diffAlpha $stdMatAlphaMultiplier -emit $stdMatEmissiveCoef -emitAlpha $stdMatAlphaMultiplier -spec $stdMatSpecCoef -specPow $stdMatSpecPower
+
             attribute alphaTrans float2
 
+
        end
            create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
+
       
            fillmode $stdMatFillMode
+
        shader -layer $gridLayer
             cullmode $stdMatCullMode
+
             vertexFormatPred blendindices  0 false
 
+
             vertexFormatPred targetindices 0 false
             create LightingStates()
+
 
              
 
              
             stage
+
             # Local grid is revelated across the multiple tiles and it does not track damage.
              create StandardShaderTextureState(Base)             
+
             # Using modifiedEachFrameHint so that grid lines are not left behind.
              textureBlend multiply(texture outRegister) multiply(texture outRegister)
+
             pass -fixedFunction # -modifiedEachFrameHint
            end
+
              create LightingStatesNoStdLights()
              
+
             # 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)
 
               alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
               depthTest true -enableDepthWrite false
+
              # Add an alpha test to avoid processing fully transparent pixels
               colorScalar (1, 1, 1, 1) -applyShapeColor 0  
+
              alphaTest true 0
 +
              alphaTestFunction acceptIfGreater
 +
              # Since the terrain has identical geometry, and is assumed to be rendered
 +
              # before the grid, there is no need to write to the z-buffer again.  If
 +
              # the geometry of the grid diverges from the geometry of the terrain, we
 +
              # *may* want to reenable depth writes here.
 +
               depthTest true -enableDepthWrite false  
 +
              fillmode $stdMatFillMode
 +
             
 +
              ffDepthOffset 2  # above the shadow/overlay layer.
 +
 
 +
               colorScalar (0,0,0) $floorGridAlpha
 +
             
 
               stage
 
               stage
                   textureBlend select(outRegister) select(colorScalar)
+
                  texture "localgrid-alphafadeout" ${stdMatBaseTextureParam}
 +
                  ffTextureCoordsSource 0
 +
                  textureAddressing clamp clamp
 +
                  textureTransformType vector2
 +
                  ffTextureMatrix -scale @alphaScale -trans @alphaTrans
 +
                   textureBlend select(outRegister) multiply(texture colorScalar)
 
               end
 
               end
            endif
+
             
           
+
              stage
end
+
                  texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
                  ffTextureCoordsSource 0           
     
+
                  textureBlend multiply(texture colorScalar) multiply(texture outRegister)
      end
+
              end
 
+
            end
  end
+
        end
+
      else
enddef
+
        shader
 
+
 
+
 
+
# ===================================================================================
+
define ImposterArrowMaterial()
+
  material
+
      shader -layer (($nhoodCanvasLayer + 11) * 8)
+
 
          
 
          
         validateRenderShaderContext -vertexFormat  position      0 required
+
         end
        validateRenderShaderContext -vertexFormat  normal        0 required
+
       endif
        validateRenderShaderContext -vertexFormat  texcoord      0 required
+
   end
 
+
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
 
enddef
  
# ===================================================================================
 
 
define NeighborhoodTreeGUOBMaterial()
 
 
# $stdMatTextureName
 
# $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
 
  
 +
define SelectFloorLightMap()
 +
  texture "floorLightMap_${page}"
 +
  ffTextureCoordsSource 1
 
enddef
 
enddef
  
#=======================================================================================
+
define SelectFloorIncidenceMap()
define NeighborhoodBuildingMaterial()
+
   texture "floorIncidenceMap_${page}"
   material 
+
  ffTextureCoordsSource 1
      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
 
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 neighborhood_roundshadow
+
# PS highlighting done in the shader instead of normal maps.
  setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
  
# rectangular shadows are used by the car shadows, until can pass the existing texture name onto the material,
+
define HighlightPass()
# leave those shadows as transparent layer 7 that will get alpha sorted, etc.
+
  if ($floorHighlightOn)
#materialDefinition neighborhood_rectangularshadow
+
      # pass for the additive part of the highlight texture
#   setDefinition NeighborhoodTreeGUOBMaterial
+
      pass -fixedFunction
#end
+
        create LightingStates()
 +
        alphaBlend srcFactor(one) add dstFactor(one)  # just add the highlight to whatever was there
 +
       
 +
        # Add an alpha test to avoid processing fully transparent pixels
 +
        alphaTest true 0
 +
      alphaTestFunction acceptIfGreater
  
# forest
+
        fillmode $stdMatFillMode
materialDefinition forest_01_shadows
+
  setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
materialDefinition forest_02_shadows
+
  setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
  
 +
        colorScalar ($floorHighlightIntensity)  # adjust highlight texture brightness
  
# oak
+
        stage
materialDefinition treeoak01_shadows
+
            texture "floor_selection_colors"
  setDefinition NeighborhoodTreeGUOBMaterial
+
            ffTextureCoordsSource 0  # use the floor pattern texture coordinates
end
+
            textureBlend multiplyAdd(texture colorScalar outRegister) select(texture)
materialDefinition treeoak02_shadows
+
        end
  setDefinition NeighborhoodTreeGUOBMaterial
+
      end
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
+
  
# scrub oak
+
      # pass for the subtractive part of the highlight texture
materialDefinition neighborhoodtreescruboak_shadows_alpha
+
      pass -fixedFunction
  setDefinition NeighborhoodTreeGUOBMaterial
+
        create LightingStates()
end
+
        alphaBlend srcFactor(one) sub dstFactor(one)  # just add the highlight to whatever was there
 +
       
 +
        # Add an alpha test to avoid processing fully transparent pixels
 +
        alphaTest true 0
 +
      alphaTestFunction acceptIfEqual
  
# birch
+
        fillmode $stdMatFillMode
materialDefinition treebirch01_shadows
+
  setDefinition NeighborhoodTreeGUOBMaterial
+
 
+
end
+
materialDefinition treebirch02_shadows
+
  setDefinition NeighborhoodTreeGUOBMaterial
+
 
+
end
+
materialDefinition treebirch03_shadows
+
  setDefinition NeighborhoodTreeGUOBMaterial
+
  
end
+
        colorScalar ($floorHighlightIntensity)  # adjust highlight texture brightness
materialDefinition treebirch04_shadows
+
  setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
materialDefinition treebirch05_shadows
+
  setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
materialDefinition treebirch06_shadows
+
  setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
  
# TODO: need to redefine the tree shaders, at least skip in reflections
+
        stage
#  this is also causing massive batch count for main view (scrolling)
+
            texture "floor_selection_colors"
# all trees should be combined into a single part/texture atlas with their shadows
+
            ffTextureCoordsSource 0  # use the floor pattern texture coordinates
# render them after the terrain
+
            textureBlend multiplyAdd(texture colorScalar outRegister) select(texture)
#materialDefinition treeoak01_diffuse
+
        end
#  setDefinition StandardMaterial
+
      end
#end
+
  endif
 +
enddef
  
 
+
# Empty tile
# ===================================================================================
+
materialDefinition tileshaderempty
 
+
   setDefinition Null
materialDefinition neighborhood-canvas-outOfWater
+
   setDefinition NeighborhoodCanvas
+
  addParam  isUnderWater false
+
 
end
 
end
  
materialDefinition neighborhood-canvas-underwater
+
materialDefinition tileShaderMayLevel_0
   setDefinition NeighborhoodCanvas
+
   setDefinition SolidColorMaterial
   addParam  isUnderWater true
+
   addParam scLayer $previewLayer
 +
  addParam color (0,1,0)    
 
end
 
end
  
materialDefinition neighborhood-canvas-straddle
+
materialDefinition tileShaderMayNotLevel_0
   setDefinition NeighborhoodCanvasStraddle
+
   setDefinition SolidColorMaterial 
 +
  addParam scLayer $previewLayer
 +
  addParam color (1,0,0) 
 
end
 
end
  
materialDefinition neighborhood-underwater-terrain
+
materialDefinition tileShaderMayLevel_0_
   setDefinition NeighborhoodWaterTerrain
+
   setDefinition SolidColorMaterial
 +
  addParam scLayer $previewLayer
 +
  addParam depthOffset 2
 +
  addParam color (0,1,0) 
 
end
 
end
  
materialDefinition waterEdgeBoxMaterial
+
materialDefinition tileShaderMayNotLevel_0_
   setDefinition NeighborhoodWaterEdge
+
   setDefinition SolidColorMaterial
   addParam waterEdgeTexture "neighborhood-sides-water"
+
   addParam scLayer $previewLayer
 +
  addParam depthOffset 2
 +
  addParam color (1,0,0) 
 
end
 
end
  
materialDefinition terrainEdgeBoxMaterial
 
  setDefinition NeighborhoodTerrainEdge
 
  addParam terrainEdgeTexture "neighborhood-sides-dirt"
 
end
 
  
materialDefinition nhoodTerrainLightingMaterial
+
# Terrain grid
   setDefinition NHoodTerrainLighting
+
materialDefinition floorGridBlack
 +
   setDefinition TileGridMaterial
 +
  addParam stdMatBaseTextureName floor-grid
 
end
 
end
  
materialDefinition nhoodTerrainLightingMaterialImposter
+
# Local Terrain grid
   setDefinition NHoodTerrainLighting
+
materialDefinition floorLocalGridBlack
   addParam isImposter true
+
   setDefinition TileGridMaterial # TileLocalGridMaterial
 +
   addParam stdMatBaseTextureName floor-grid
 
end
 
end
  
materialDefinition nhoodReflectionSkybox
+
# Upper floor grid
   setDefinition SkyboxCompositionPassMaterial
+
materialDefinition floorGridWhite
   addParam skyboxCubeTexture $skyboxCubeMap
+
   setDefinition InverseTileGridMaterial
 +
   addParam stdMatBaseTextureName floor-grid
 
end
 
end
  
materialDefinition lotSkirtReflectionSkybox
+
# Active-level Terrain grid
   setDefinition SkyboxCompositionPassMaterial
+
materialDefinition floorGridBlackActiveLevel
   addParam skyboxCubeTexture $skyboxCubeMap
+
   setDefinition TileGridMaterial # TileLocalGridMaterial
 +
   addParam stdMatBaseTextureName floor-grid-active
 
end
 
end
  
materialDefinition lotPlacementArrow
+
# Active-level Local Terrain grid
   setDefinition ImposterArrowMaterial
+
materialDefinition floorLocalGridBlackActiveLevel
   addParam texture lot-placement-arrow
+
   setDefinition TileGridMaterial # TileLocalGridMaterial
 +
   addParam stdMatBaseTextureName floor-grid-active
 
end
 
end
  
# Material used in highlighting the terrain to depict a house for which no imposter exists yet.
+
# Active-level Upper Floor grid
materialDefinition DefaultResidentialLotImposterMaterial
+
materialDefinition floorGridWhiteActiveLevel
   setDefinition NHoodTerrainHighlightMaterial
+
   setDefinition InverseTileGridMaterial
   addParam highlightTexture "lothighlight-residential"
+
   addParam stdMatBaseTextureName floor-grid-active
  addParam highlightAlpha 0.5
+
 
end
 
end
  
materialDefinition DefaultCommunityLotImposterMaterial
 
  setDefinition NHoodTerrainHighlightMaterial
 
  addParam highlightTexture "lothighlight-community"
 
  addParam highlightAlpha 0.5
 
end
 
  
 
+
materialDefinition floor_oak_seethrough
# Material used in creating a terrain thumbnail for a lot for which no imposter exists yet.
+
   setDefinition FloorReflective
materialDefinition DefaultLotThumbnailMaterial
+
   addParam stdMatLayer 2
   setDefinition StandardMaterial
+
   addParam stdMatBaseTextureName floor-oak
   addParam stdMatBaseTextureEnabled "true"
+
   addParam reflectStrength .3
   addParam stdMatBaseTextureName "lotselection-done"
+
   addParam stdMatLightingEnabled true
+
  addParam stdMatDiffCoef (1, 1, 1)
+
 
end
 
end
  
materialDefinition bridge_sides
+
materialDefinition floor_mountainFogTile
#  setDefinition StandardMaterial
+
   setDefinition FloorReflective
   setDefinition PartiallyUnderWaterMaterial
+
   addParam stdMatLayer 2
   addParam stdMatAlphaBlendMode none
+
   addParam stdMatBaseTextureName floor-mountainFogTile
  addParam stdMatBaseTextureEnabled true
+
   addParam reflectStrength .1
   addParam stdMatBaseTextureName bridge-sides
+
   addParam stdMatDiffCoef (0.8, 0.8, 0.8)
+
  addParam stdMatIsPartlyUnderwater true
+
 
end
 
end
  
materialDefinition cliff_boulder_material
+
materialDefinition floor_brickPatio
#  setDefinition StandardMaterial
+
   setDefinition Floor
   setDefinition PartiallyUnderWaterMaterial
+
   addParam stdMatBaseTextureName floor-brickPatio
  addParam stdMatAlphaBlendMode none
+
   addParam stdMatDiffCoef (0.63, 0.63, 0.56)
  addParam stdMatBaseTextureEnabled true
+
   addParam stdMatBaseTextureName nh-test-cliff
+
   addParam stdMatDiffCoef (0.8, 0.8, 0.8)
+
  addParam stdMatIsPartlyUnderwater true
+
 
end
 
end
  
materialDefinition plesiosaur_skin_material
+
materialDefinition FloorThickness
#  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
 
   setDefinition StandardMaterial
   addParam  stdMatSpecPower 20
+
   addParam  stdMatSpecPower 0
   addParam  stdMatDiffCoef (0.3, 1, 0.3)
+
   addParam  stdMatDiffCoef (0.5, 0.5, 0.5)
  addParam  stdMatSpecCoef (1, 1, 1)
+
   addParam   stdMatBaseTextureName floor-edge
  addParam  stdMatAlphaMultiplier 0.6
+
   addParam  stdMatBaseTextureEnabled true
  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 ($nhoodWaterLayer+1)
+
###    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};
+
### MODDED5  # in-lot lotskirt water: Just alter the highlit RGB values (in bold style)
+
const static float4 layerBlue={1.8, 0.25, 0.1, 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 # end shader
+
enddef # shader() LotSkirtPSWater()
+
 
+
#######################################
+
 
+
define LotSkirtPSWaterHLSL()
+
### conmbo of PS2 1st PS1 shader progrmme and old HLSL stage
+
 
+
      shader -layer ($nhoodWaterLayer+1)
+
###    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};
+
### MODDED6  # in-lot lotskirt water: Just alter the highlit RGB values (in bold style)
+
const static float4 layerBlue={1.8, 0.25, 0.1, 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
+
+
stage
+
texture $wmReflectionTexture
+
textureAddressing clamp clamp clamp
+
textureBlend multiply(texture diffuse) select(diffuse)
+
end
+
     
+
     
+
addSpecular true
+
+
end # end pass
+
end # end shader
+
enddef # shader() LotSkirtPSWaterHLSL()
+
 
+
#######################################
+
 
+
define LotSkirtWaterR1()
+
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)
+
### MODDED2a  # in-lot lotskirt water fallback reflection: Just a check point
+
colorScalar $lotSkirtWaterReflColour $lotSkirtWaterReflStrength
+
### 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    # stage         
+
               
+
end # pass
+
end    # shader
+
enddef # shader() LotSkirtWaterR1()
+
 
+
#######################################
+
 
+
define LotSkirtWaterR2()
+
      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)
+
 
+
### MODDED1c  # in-lot lotskirt water fallback reflection: Just a check point
+
      colorScalar $nAbahoodEau
+
###            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  # stage
+
 
+
        end  # pass()
+
      end # shader()
+
enddef # shader() LotSkirtWaterR2()
+
 
+
#######################################
+
 
+
 
+
define LotSkirtWater()
+
 
+
material     
+
create DetermineHardwareSupport()
+
 
+
if ($useHWShader2Path)
+
create LotSkirtPSWater()
+
else
+
create LotSkirtWaterR1()
+
      endif # PS2
+
 
+
### basic Fallback
+
        if ($useSWVertexShaderPath or $useFixedFunctionPath)
+
create LotSkirtWaterR2()
+
else
+
create LotSkirtPSWaterHLSL()
+
endif # SWV or FF
+
 
+
  end # end material
+
 
+
enddef # material() LotSkirtWater()
+
 
+
 
+
#######################################
+
 
+
define LotSkirtWaterNoReflection()
+
 
+
set useReflection 0 # default material parameter value
+
 
+
  material
+
      # fallback: no reflection.
+
        create DetermineHardwareSupport()
+
 
+
        if ($useSWVertexShaderPath or $useFixedFunctionPath)
+
create LotSkirtWaterR2()
+
else
+
create LotSkirtPSWaterHLSL()
+
endif # SWV or FF
+
 
+
### basic Fallback
+
create LotSkirtWaterR2()
+
 
+
  end    # material         
+
enddef # material() LotSkirtWaterNoReflection()
+
 
+
 
+
#######################################
+
 
+
 
+
materialDefinition lotSkirtSea
+
  setDefinition LotSkirtWater 
+
   addParam stdMatLightingEnabled false
+
  addParam stdMatLayer 0
+
  addParam stdMatDiffCoef (1.8, 0.25, 0.1)    
+
 
+
  addParam wmRefractionEnabled true
+
 
+
 
+
  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 
+
 
+
  addParam stdMatLightingEnabled false
+
  addParam stdMatLayer 0
+
  addParam stdMatDiffCoef (1.8, 0.25, 0.1) 
+
 
+
  addParam wmRefractionEnabled true
+
 
+
 
+
  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
 
end

Revision as of 23:15, 14 September 2008

  1. Shaders for indoor & outdoor tiles; i.e., "Floors".

seti gridLayer 13 seti floorLayer -4 setf floorMaterialScaleU 1.0 # defaults for Floor materials without these defined setf floorMaterialScaleV 1.0 # defaults for Floor materials without these defined setb floorHighlightOn false setc floorHighlightIntensity (0.25, 0.25, 0.25, 1.0) # attenuation of the floor highlight texture setf floorGridAlpha 0.775 seti previewLayer 0 # -28

  1. debug options for PS hardware only, only set one of these to true

setb debugShowFloorIncidence false # shows the incidence maps as color setb debugShowFloorNormalMap false # shows the raw normal map (if it exists) setb debugFloorLighting false # no base texture, only lighting results setb debugShowLightMapTexcoords false # texcoords as color


setb floorCausticsPass false seti floorRenderStyle 0 setb hasCutout false

include PixelShaderFloors.matShad


  1. beginshader Floor
  2. description Basic floor tile shader; texture + floor gradient + shadows
  3. extraparam float floorMaterialScaleU 1 0.125 64 ; no. tiles to map across U axis, use any positive number
  4. extraparam float floorMaterialScaleV 1 0.125 64 ; no. tiles to map across V axis, use any positive number

define Floor()

  material
     if ($stdMatLightingDebug)
        create LightingDebugStandardMaterialOverrides()
     endif
     create FloorShaders()
  end

enddef

  1. endshader


  1. beginshader FloorPool
  2. description Pool tile shader, with caustics.
  3. extraparam bool floorCausticsPass 1 ; set to true to add water caustics.

define FloorPool()

  material
     if ($stdMatLightingDebug)
        create LightingDebugStandardMaterialOverrides()
     endif
     create FloorShaders()
  end

enddef

  1. endshader



  1. Standard floor shaders

define FloorShaders()

  if (viewerRenderType = $kRenderTypeShadowMap)

create ShadowMapVS_PS() else setb bumpMapFloors false

create DetermineHardwareSupport()

setb hasTexcoord2 (hasVertexFormat(texcoord,1))

     # check for the page, the global bumpmap glag, and for the normal map in the material

if (varExists(page) and $bumpMapping and $stdMatNormalMapTextureEnabled and $hasTexcoord2) setb bumpMapFloors true endif

     if ($useHWShader1Path or $useHWShader2Path)
  	

create PixelShaderFloors($bumpMapFloors)

else

# fixed function paths NEVER get bump mapping due to fill rate and memory concerns.

create FixedFunctionFloorShader()

# ultimate fallback pass? no light map, one stage. shader -layer $floorLayer validateRenderShaderContext -vertexFormat position 0 required validateRenderShaderContext -vertexFormat normal 0 required validateRenderShaderContext -vertexFormat texcoord 0 required validateRenderShaderContext -viewerRenderType viewerRenderType

pass -fixedFunction create LightingStates() create AttenuatedMatCoef(1) fillmode $stdMatFillMode

if ($hasCutout)

                 depthTestFunction acceptIfEqual
              else
                 depthTestFunction acceptIfLessOrEqual
              endif

stage texture $stdMatBaseTextureName ${stdMatBaseTextureParam} textureAddressing tile tile ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV) textureTransformType vector2 ffTextureCoordsSource 0 textureBlend multiplyScale2(texture diffuse) select(outRegister) end end

create HighlightPass()

end endif endif

enddef

  1. Standard floor shader,

define FixedFunctionFloorShader()

  setb lightMapAvailable false
  if (varExists(page))
     setb lightMapAvailable true
  endif
  
  setb caustics false
  if ($floorCausticsPass and $causticsEnabled)
     setb caustics true
  endif   
  
  shader -layer $floorLayer
     validateRenderShaderContext -vertexFormat position 0 required
     validateRenderShaderContext -vertexFormat texcoord 0 required
     validateRenderShaderContext -viewerRenderType viewerRenderType
     
     set stdMatSpecCoef (0, 0, 0)
     set stdMatSpecPower 0

if ($caustics) pass -fixedFunction -modifiedEachFrameHint else pass -fixedFunction endif

     ffDepthOffset 0
     
     if ($hasCutout)                         
        depthTestFunction acceptIfEqual
     else
        depthTestFunction acceptIfLessOrEqual
     endif
     
     # empirically, Floors seem to only take 3 inputs
     # the base texture
     # the light map
     # the material color, which seems to act as a 'tune' value.
     
     # Lightmaps are scaled by 0.5, so this must multiply by 2 to get to the correct brightness.
     # No alpha blending is required, nor is alpha scaling required.
  
        # # don't pre-scale -- that's in the texture.
        fillmode $stdMatFillMode
            
        if ($lightMapAvailable)
           colorScalar ($stdMatDiffCoef) 1

stage create SelectFloorLightMap()

# add the lightmap lighting to any direct lights. # the light map has been prescaled by 0.5 textureBlend multiply(texture colorScalar) select(texture) end

           stage
              texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
              textureAddressing tile tile
              ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
              ffTextureCoordsSource 0
              textureBlend multiplyScale2(texture outRegister) select(colorScalar)
           end 
           
        else
        
        # no lightmap case:


           colorScalar ($stdMatDiffCoef) 1
           
           stage
              texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
              textureAddressing tile tile
              ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
              ffTextureCoordsSource 0
              
             textureBlend multiply(colorScalar texture) select(colorScalar)
           end
         
           
        endif


end

     if ( $lightMapAvailable)  # thumbnails don't have lightmaps, causing this to fail without them, so assume no work to be done without lightmaps.
     
        if ($lmIntegratedShadows )
           # Still experimental
           pass -fixedFunction
              create LightingStatesNoStdLights()
              fillmode $stdMatFillMode
              
              alphaBlend srcFactor(destColor) add dstFactor(zero)
              
              alphaTest true 100
              alphaTestFunction acceptIfGreater
  
              colorScalar (0.61, 0.61, 0.61)  # needs to be set by tsUserEtc
  
              ffDepthOffset 1
  
              stage
                 create SelectFloorLightMap()
                 textureBlend select(colorScalar) select(texture)
              end 
           end
        elseif ((not ($useHWShader2Path or $useHWShader1Path)))
           # Mark the depth buffer where the shadow is so object shadows
           # do not overlap.
           pass -fixedFunction
              create LightingStatesNoStdLights()
              alphaBlend srcFactor(zero) add dstFactor(one)
              fillmode $stdMatFillMode
  
              ffDepthOffset 1
              depthTest true -enableDepthWrite true
              alphaTest true 100
              alphaTestFunction acceptIfLess
  
              stage
                 create SelectFloorLightMap()
                 textureBlend select(texture) select(texture)
              end 
           end
        endif
     endif
     

create HighlightPass() end


enddef


  1. beginshader FloorReflective
  2. description Basic floor tile shader with reflection; texture + floor gradient + shadows
  3. extraparam float floorMaterialScaleU 1 0.125 64 ; no. tiles to map for U axis, use any positive number
  4. extraparam float floorMaterialScaleV 1 0.125 64 ; no. tiles to map for V axis, use any positive number
  5. extraparam float reflectStrength 1 0 1 ; strength of reflection, in range 0 to 1

set ratioH 1 # default material parameter value set ratioW 1 # default material parameter value set useReflectionFloors 0 # default material parameter value define FloorReflective() material shader #reflective floors are currently dead. might ressurect them in an expansion pack

end end enddef


  1. gridMaterial -- composites the alpha grid texture over the normal floor texture
  2. NOTE: In order to guarantee this is drawn on top of the normal
  3. floor tile textures, the layer has to be higher than that for
  4. the normal floor textures.

define TileGridMaterial()

material

     if (viewerRenderType = $kRenderTypeNormal)
     
        shader -layer $gridLayer
           
              # this is using modifiedEachFrameHint, because when the pool tool
              #   is used it does not invalidate the entire terrain or invalidate the frame.
              pass -fixedFunction # -modifiedEachFrameHint
                 validateRenderShaderContext -viewerRenderType $kRenderTypeNormal  # normal render
           
                 create LightingStatesNoStdLights()
                 alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
                 
                 # Add an alpha test to avoid processing fully transparent pixels
                 alphaTest true 0
                 alphaTestFunction acceptIfGreater                  
                    
                 # Since the terrain has identical geometry, and is assumed to be rendered
                 # before the grid, there is no need to write to the z-buffer again.  If
                 # the geometry of the grid diverges from the geometry of the terrain, we
                 # *may* want to reenable depth writes here.
                 
                 depthTest true -enableDepthWrite false 
                 ffDepthOffset 2
                 fillmode $stdMatFillMode
                 colorScalar (0,0,0) $floorGridAlpha
                 stage
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
                    ffTextureCoordsSource 0
                    textureBlend multiply(texture colorScalar) multiply(texture colorScalar)
                 end 
              end
           
        end #shader
     else
        shader
        
        end
     endif

end #mat enddef

  1. inverseGridMaterial -- composites the inverse of the alpha grid texture over the normal floor texture
  2. NOTE: In order to guarantee this is drawn on top of the normal
  3. floor tile textures, the layer has to be higher than that for
  4. the normal floor textures.

define InverseTileGridMaterial()

#trace "$currentMaterialName inverse tile grid material"

  material

shader -layer $gridLayer

        if (viewerRenderType = $kRenderTypeNormal)
     
           create DetermineHardwareSupport()
           
           if ($useHWShader1Path or $useHWShader2Path)
              create PixelShaderInverseTileGridRendering()
           else
              # this pass draws the completely opaque region of the grid line
              # hiding the incorrect sorting behavior of the second pass at high
              # resolution mipmap levels
              pass -fixedFunction
                 create LightingStatesNoStdLights()
                 alphaTest true 192
                 alphaTestFunction acceptIfGreater
                 fillmode $stdMatFillMode
  
                 stage
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
                    ffTextureCoordsSource 0
                    textureBlend select(texture:invert) select(texture)
                 end 
              end 
  
              # this pass draws the transition region along the edges of the grid lines
              # this provides a blurry grid at lower mipmap levels (where the solid grid
              # line disappears entirely)
              pass -fixedFunction
                 create LightingStatesNoStdLights()
                 alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
                 alphaTest true 192
                    alphaTestFunction acceptIfLess
                 depthTest true -enableDepthWrite false 
                 fillmode $stdMatFillMode
  
                 stage
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
                    ffTextureCoordsSource 0
                    textureBlend select(texture:invert) select(texture)
                 end 
              end 
           endif
        end
     else
        shader
        
        end
     endif

end enddef


define TileLocalGridMaterial()

  material
     # 7/26/04 This material should only be reinstated if the cursor moves a part that causes 
     # visible damage to be updated with respect to where it is moved.  Marking all the 
     # terrain tiles with this modifiedEachFrameHint is too slow.  For now this material
     # is disabled. 
     
     if (viewerRenderType = $kRenderTypeNormal)
     
        attributes
           attribute alphaScale float1
           attribute alphaTrans float2
        end
        
        shader -layer $gridLayer
           vertexFormatPred blendindices  0 false
           vertexFormatPred targetindices 0 false
           
           # Local grid is revelated across the multiple tiles and it does not track damage.
           # Using modifiedEachFrameHint so that grid lines are not left behind.
           pass -fixedFunction # -modifiedEachFrameHint
              create LightingStatesNoStdLights()
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
              # Add an alpha test to avoid processing fully transparent pixels
              alphaTest true 0
              alphaTestFunction acceptIfGreater
              # Since the terrain has identical geometry, and is assumed to be rendered
              # before the grid, there is no need to write to the z-buffer again.  If
              # the geometry of the grid diverges from the geometry of the terrain, we
              # *may* want to reenable depth writes here.
              depthTest true -enableDepthWrite false 
              fillmode $stdMatFillMode
              
              ffDepthOffset 2   # above the shadow/overlay layer.
  
              colorScalar (0,0,0) $floorGridAlpha
              
              stage
                 texture "localgrid-alphafadeout" ${stdMatBaseTextureParam}
                 ffTextureCoordsSource 0
                 textureAddressing clamp clamp
                 textureTransformType vector2
                 ffTextureMatrix -scale @alphaScale -trans @alphaTrans
                 textureBlend select(outRegister) multiply(texture colorScalar)
              end
              
              stage
                 texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
                 ffTextureCoordsSource 0            
                 textureBlend multiply(texture colorScalar) multiply(texture outRegister)
              end
           end
        end
     else
        shader
        
        end
     endif
  end			

enddef


define SelectFloorLightMap()

  texture "floorLightMap_${page}"
  ffTextureCoordsSource 1

enddef

define SelectFloorIncidenceMap()

  texture "floorIncidenceMap_${page}"
  ffTextureCoordsSource 1

enddef


  1. PS highlighting done in the shader instead of normal maps.

define HighlightPass()

  if ($floorHighlightOn)
     # pass for the additive part of the highlight texture
     pass -fixedFunction
        create LightingStates()
        alphaBlend srcFactor(one) add dstFactor(one)  # just add the highlight to whatever was there
        
        # Add an alpha test to avoid processing fully transparent pixels
        alphaTest true 0
     	 alphaTestFunction acceptIfGreater
        fillmode $stdMatFillMode
        colorScalar ($floorHighlightIntensity)  # adjust highlight texture brightness
        stage
           texture "floor_selection_colors"
           ffTextureCoordsSource 0  # use the floor pattern texture coordinates
           textureBlend multiplyAdd(texture colorScalar outRegister) select(texture)
        end
     end
     # pass for the subtractive part of the highlight texture
     pass -fixedFunction
        create LightingStates()
        alphaBlend srcFactor(one) sub dstFactor(one)  # just add the highlight to whatever was there
        
        # Add an alpha test to avoid processing fully transparent pixels
        alphaTest true 0
     	 alphaTestFunction acceptIfEqual
        fillmode $stdMatFillMode
        colorScalar ($floorHighlightIntensity)  # adjust highlight texture brightness
        stage
           texture "floor_selection_colors"
           ffTextureCoordsSource 0  # use the floor pattern texture coordinates
           textureBlend multiplyAdd(texture colorScalar outRegister) select(texture)
        end
     end
  endif

enddef

  1. Empty tile

materialDefinition tileshaderempty

  setDefinition Null

end

materialDefinition tileShaderMayLevel_0

  setDefinition SolidColorMaterial
  addParam scLayer $previewLayer
  addParam color (0,1,0)   

end

materialDefinition tileShaderMayNotLevel_0

  setDefinition SolidColorMaterial   
  addParam scLayer $previewLayer
  addParam color (1,0,0)   

end

materialDefinition tileShaderMayLevel_0_

  setDefinition SolidColorMaterial
  addParam scLayer $previewLayer
  addParam depthOffset 2
  addParam color (0,1,0)   

end

materialDefinition tileShaderMayNotLevel_0_

  setDefinition SolidColorMaterial
  addParam scLayer $previewLayer
  addParam depthOffset 2
  addParam color (1,0,0)   

end


  1. Terrain grid

materialDefinition floorGridBlack

  setDefinition TileGridMaterial
  addParam stdMatBaseTextureName floor-grid

end

  1. Local Terrain grid

materialDefinition floorLocalGridBlack

  setDefinition TileGridMaterial # TileLocalGridMaterial
  addParam stdMatBaseTextureName floor-grid

end

  1. Upper floor grid

materialDefinition floorGridWhite

  setDefinition InverseTileGridMaterial
  addParam stdMatBaseTextureName floor-grid

end

  1. Active-level Terrain grid

materialDefinition floorGridBlackActiveLevel

  setDefinition TileGridMaterial # TileLocalGridMaterial
  addParam stdMatBaseTextureName floor-grid-active

end

  1. Active-level Local Terrain grid

materialDefinition floorLocalGridBlackActiveLevel

  setDefinition TileGridMaterial # TileLocalGridMaterial
  addParam stdMatBaseTextureName floor-grid-active

end

  1. Active-level Upper Floor grid

materialDefinition floorGridWhiteActiveLevel

  setDefinition InverseTileGridMaterial
  addParam stdMatBaseTextureName floor-grid-active

end


materialDefinition floor_oak_seethrough

  setDefinition FloorReflective
  addParam stdMatLayer 2
  addParam stdMatBaseTextureName floor-oak
  addParam reflectStrength .3

end

materialDefinition floor_mountainFogTile

  setDefinition FloorReflective
  addParam stdMatLayer 2
  addParam stdMatBaseTextureName floor-mountainFogTile
  addParam reflectStrength .1

end

materialDefinition floor_brickPatio

  setDefinition Floor
  addParam stdMatBaseTextureName floor-brickPatio
  addParam stdMatDiffCoef (0.63, 0.63, 0.56)

end

materialDefinition FloorThickness

  setDefinition StandardMaterial
  addParam   stdMatSpecPower 0
  addParam   stdMatDiffCoef (0.5, 0.5, 0.5)
  addParam   stdMatBaseTextureName floor-edge
  addParam   stdMatBaseTextureEnabled true

end

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox