Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
Line 1: Line 1:
 
#
 
#
# Shaders for neighborhood
+
# roof material definitions.
#
+
 
#
 
#
  
# layers
+
# material for roof preview when they're displayed
# normal shadows are layer 2 (after opaques), tree shadows are moved to -2 to make them
+
define RoofPreviewMaterial()
# render to the first buffer.  Tree shadows (-2) do not show up on fields (7).
+
  material
seti nhoodWaterLayer            1
+
      shader -layer 9999
seti nhoodCanvasLayer          -8
+
        vertexFormatPred position      0 true
seti nhoodTreeShadowLayer      -2
+
        vertexFormatPred normal        0 true
 +
        vertexFormatPred blendindices 0 false
 +
        vertexFormatPred targetindices 0 false
 +
       
 +
        pass -fixedFunction       
 +
            colorScalar (0.5, 0.4, 0.4, 1.0)       
 +
            create LightingStatesNoStdLights()
 +
            depthTest true -enableDepthWrite true
  
setf  neighborhoodMaterialScaleU 8.0  # defaults for neighborhood materials without these defined
+
    alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
setf  neighborhoodMaterialScaleV 8.0  # defaults for neighborhood materials without these defined
+
  
setf  nhoodWaterMap1Scale    7.0
+
            stage
setf  nhoodWaterMap1Speed    0.5
+
              textureBlend select(colorScalar) select(colorScalar)
setf  nhoodWaterMap2Scale    5.0
+
            end
setf  nhoodWaterMap2Speed    0.3
+
        end
  
 +
pass -fixedFunction       
 +
            create LightingStatesNoStdLights()
 +
            fillmode wireframe
 +
    cullmode none
 +
            depthTest true -enableDepthWrite false
 +
            colorScalar (0, 0, 0)
  
setv2 baseTexOffset (0.5, 0.5)
+
            stage
setv3 nhoodDiffCoef (0.75, 0.93, 0.75)
+
              textureBlend select(colorScalar) select(colorScalar)
 +
            end
 +
        end
  
 +
      end
 +
  end
 +
enddef
  
setf  nhoodPaintTextureScale  13      #Repeat distance of neighborhood textures in tiles.
+
define RoofPreviewMaterialBack()
                                    #NOTE: There is a related parameter called "TextureVariantGridSize" in
+
  material
                                    #NeighborhoodTerrain.ini. You would normally (though not necessarily) want it to be
+
      shader -layer 9999
                                    #the same as this number.
+
        vertexFormatPred position      0 true
setf  waterEdgeTextureScale  250.0 #Repeat distance in meters
+
        vertexFormatPred normal        0 true
setf terrainEdgeTextureScale 100.0 #Repeat distance in meters
+
        vertexFormatPred blendindices 0 false
 +
        vertexFormatPred targetindices 0 false
 +
       
 +
        pass -fixedFunction       
 +
            colorScalar (0.25, 0.1, 0.1, 1.0)       
 +
            create LightingStatesNoStdLights()
  
 +
            depthTest true -enableDepthWrite true
  
# Reflective water
+
    alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
setc  nhoodWaterReflColour  (0.55, .6, 0.65)
+
setc  lotSkirtWaterReflColour (0.65, 0.7, 0.85)
+
setf  nhoodWaterReflStrength  0.75
+
setf  nhoodWaterReflOffset    0.0020
+
  
# Standard water
+
            stage
setf nhoodWaterbumpMapScale 8.0
+
              textureBlend select(colorScalar) select(colorScalar)
setf nhoodWaterAlpha        0.35
+
            end
 +
        end
  
setb isDay true
+
      end
setb isTerrainConcrete false
+
   end
 
+
# water clipping plane
+
setf waterHeight 312.45
+
 
+
# underwater gradient texture
+
set  waterGradientTexture neighborhood-underwater-gradient
+
set  waterGradientTextureAdditive neighborhood-underwater-gradient-with-black
+
# depth at which the gradient starts to take effect
+
setf waterGradientZoneStart 0
+
# how far down the gradient goes from that point.
+
setf waterGradientZoneSize 40
+
 
+
set skyboxCubeMap neighborhood-sky2-envcube
+
 
+
# bump mapping
+
setv3 nhoodSunDir (-0.5, 1, 0.5)  # default -- should be set by code from the lighting.txt value
+
# overall kind-of brightness booster for bump map.
+
setf  bumpMapBoost 1.5
+
 
+
# ==============================================================================
+
# derived bump map quantities
+
define BiasedNormal(n bn)
+
  setf  nLen (sqrt(sqr($&{n}.x) + sqr($&{n}.y) + sqr($&{n}.z)))
+
   setv3 &{bn} ((0.5,0.5,0.5) * (($&{n} / $nLen.xxx) + (1,1,1)))
+
 
enddef
 
enddef
  
create BiasedNormal(nhoodSunDir nhoodSunDirBiased)
+
define RoofPreviewMaterialStrip()
setv3 nhoodSunDirBiased ($nhoodSunDirBiased * $bumpMapBoost.xxx)
+
  material
 +
      shader -layer 9999
 +
        vertexFormatPred position      0 true
 +
        vertexFormatPred blendindices  0 false
 +
        vertexFormatPred targetindices 0 false
 +
       
 +
        pass -fixedFunction       
 +
            colorScalar (1.0, 1.0, 1.0, 1.0)       
 +
            create LightingStatesNoStdLights()
  
set terrainType "unset"
+
            depthTest true -enableDepthWrite false    
  
# defaults off, can be turned on at startup.
+
            stage
setb simpleTerrain false
+
              textureBlend select(colorScalar) select(colorScalar)
setb isImposter false
+
            end
 
+
include neighborhoodSWVS.matShad
+
 
+
# ==============================================================================
+
 
+
define NeighborhoodCanvas()
+
 
+
# this material does nothing but prep the z-buffer, and render black.
+
 
+
material
+
      if ($simpleTerrain)
+
        shader
+
 
         end
 
         end
      endif
 
  
      shader -layer (($nhoodCanvasLayer) * 8)
 
       
 
        validateRenderShaderContext -vertexFormat  position      0 required
 
        validateRenderShaderContext -vertexFormat  normal        0 required
 
       
 
        if (not $isImposter)       
 
            validateRenderShaderContext -vertexFormat  texcoord      0 required
 
        endif
 
        viewerRenderTypePred viewerRenderType
 
           
 
        create DetermineHardwareSupport()
 
       
 
        if (strcmp("Concrete", "${terrainType}") = 0)
 
            setb isTerrainConcrete true
 
        endif
 
 
        if (not $isUnderWater or viewerRenderType != $kRenderTypeReflection)
 
            if ($useSWVertexShaderPath)
 
              create NeighborhoodTerrainPrepWorkSWVS()
 
            else
 
              pass -fixedFunction
 
                  create LightingStatesNoStdLights()
 
                 
 
                  cullmode none # so that reflections don't "creep under" edge of terrain
 
                  colorScalar (0.0, 0.0, 0.0, 1.0)
 
                                   
 
                  if ($isImposter and $isTerrainConcrete)
 
                    ffDepthOffset -1
 
                  endif
 
 
                  stage
 
                    if (not $isImposter)
 
                        ffTextureCoordsSource fromPosition
 
                    endif
 
                    textureBlend select(colorScalar) select(outRegister)
 
                  end
 
              end
 
            endif
 
           
 
        endif
 
       
 
 
       end
 
       end
 
   end
 
   end
 
enddef
 
enddef
  
 +
define RoofPreviewMaterialUpperStrip()
 +
  material
 +
      shader -layer 9999
 +
        vertexFormatPred position      0 true
 +
        vertexFormatPred blendindices  0 false
 +
        vertexFormatPred targetindices 0 false
 +
       
 +
        pass -fixedFunction       
 +
            colorScalar (1.0, 0.0, 0.0, 1.0)       
 +
            create LightingStatesNoStdLights()
  
# ==============================================================================
+
            depthTest true -enableDepthWrite false
# Used for those triangles in the canvas which are partially under water.
+
#
+
define NeighborhoodCanvasStraddle()
+
material
+
  
      if ($simpleTerrain)
+
            stage
        shader
+
              textureBlend select(colorScalar) select(colorScalar)
 +
            end
 
         end
 
         end
      endif
 
  
# material for reflection camera
+
      end
 +
  end
 +
enddef
  
       shader -layer (($nhoodCanvasLayer) * 8)
+
define RoofPreviewMaterialTopBoundary()
     
+
  material
validateRenderShaderContext -vertexFormat  position      0 required
+
       shader -layer 9999
validateRenderShaderContext -vertexFormat  normal        0 required
+
        vertexFormatPred position      0 true
validateRenderShaderContext -vertexFormat texcoord      0 required
+
        vertexFormatPred normal        0 true
viewerRenderTypePred $kRenderTypeReflection
+
        vertexFormatPred blendindices 0 false
       
+
        vertexFormatPred targetindices 0 false
#Render the portion that is above water only
+
       
       
+
        pass -fixedFunction        
create DetermineHardwareSupport()
+
            colorScalar (0.4, 0, 0.1, 1.0)       
       
+
            create LightingStatesNoStdLights()
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
+
            depthTest true -enableDepthWrite true
alphaTestFunction acceptIfGreater
+
  
stage
+
    alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
# above water -- clip by using depth-based 0/1 texture.
+
texture blackWhite
+
textureAddressing clamp clamp
+
textureFilterHint point point
+
textureMIPFilterHint disabled
+
                 
+
ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
+
ffTextureCoordsSource fromPosition
+
textureBlend select(colorScalar) select(texture)
+
end
+
end
+
endif
+
+
end
+
     
+
     
+
     
+
      #material for standard camera 
+
      #shader -layer (-128)     
+
shader -layer (-128)
+
+
validateRenderShaderContext -vertexFormat  position      0 required
+
validateRenderShaderContext -vertexFormat  normal        0 required
+
validateRenderShaderContext -vertexFormat  texcoord      0 required
+
viewerRenderTypePred $kRenderTypeNormal
+
       
+
create DetermineHardwareSupport()
+
       
+
if ($useSWVertexShaderPath)
+
create NeighborhoodWaterlineStraddleStandardCameraSWVS()
+
else
+
       
+
#Render the portion that is above water only
+
pass -fixedFunction
+
create LightingStatesNoStdLights()
+
alphaBlend srcFactor(one) add dstFactor(zero)
+
cullmode none # so that reflections don't "creep under" edge of terrain
+
colorScalar (0.0, 0.0, 0.0, 1.0)
+
  
stage
+
            stage
textureBlend select(colorScalar) select(outRegister)
+
              textureBlend select(colorScalar) select(colorScalar)
end  
+
            end  
end
+
endif
+
+
end
+
     
+
end
+
enddef
+
 
+
# ==============================================================================
+
# Material for terrain geometry that is partially or completely under water.
+
define NeighborhoodWaterTerrain()
+
material
+
 
+
      if ($simpleTerrain)
+
        shader
+
 
         end
 
         end
      endif
 
     
 
shader -layer (($nhoodCanvasLayer + 2) * 8)
 
validateRenderShaderContext -vertexFormat  position      0 required
 
validateRenderShaderContext -vertexFormat  normal        0 required
 
validateRenderShaderContext -vertexFormat  texcoord      0 required
 
viewerRenderTypePred viewerRenderType
 
  
+
pass -fixedFunction      
create DetermineHardwareSupport()
+
            create LightingStatesNoStdLights()
+
            fillmode wireframe
if (viewerRenderType != $kRenderTypeReflection)       
+
            depthTest true -enableDepthWrite false
+
            colorScalar (0, 0, 0)
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
+
  
# ==============================================================================
+
            stage
 +
              textureBlend select(colorScalar) select(colorScalar)
 +
            end
 +
        end
  
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()
+
       end
 
+
  if (strcmp("Concrete", "${terrainType}") = 0)
+
            setb isTerrainConcrete true
+
        endif
+
 
+
  if ($useSWVertexShaderPath)
+
  create NeighborhoodMainTerrainShaderSWVS()
+
 
+
  else
+
 
+
  pass -fixedFunction
+
 
+
  create LightingStatesNoStdLights()
+
  alphaBlend srcFactor(srcAlpha) add dstFactor(one)
+
  cullmode none # so that reflections don't "creep under" edge of terrain
+
 
+
  if ($isImposter and $isTerrainConcrete)
+
                  ffDepthOffset -1
+
              endif
+
                     
+
  colorScalar $nhoodSunDirBiased
+
         
+
  depthTest true -enableDepthWrite false
+
  depthTestFunction acceptIfEqual
+
 
+
  seti snowLevel (tsHasSnow)
+
 
+
  if ($snowLevel = 1)
+
      set weatherSuffix "-LSNOW"
+
  elseif ($snowLevel = 2)
+
                  set weatherSuffix "-HSNOW"
+
              else
+
                  set weatherSuffix ""
+
              endif
+
             
+
  stage
+
  texture $alphaMap
+
  textureAddressing clamp clamp
+
 
+
                  if ($isImposter)
+
  ffTextureMatrix -cameraToGlobal -scalev ((0.1 * $alphaMapScaleU), (0.1 * $alphaMapScaleV))
+
  ffTextureCoordsSource fromPosition
+
  else
+
      ffTextureMatrix -scalev ($alphaMapScaleU, $alphaMapScaleV)
+
      ffTextureCoordsSource 0
+
  endif
+
  textureBlend select(outRegister) select(texture)
+
  end
+
 
+
  stage  
+
  texture "${paintTexture}${weatherSuffix}"
+
  textureAddressing tile tile
+
  if ($isImposter)
+
  ffTextureMatrix -cameraToGlobal -scalev ((10.0 * $nhoodPaintTextureScale), (10.0 * $nhoodPaintTextureScale)) -invert
+
  ffTextureCoordsSource fromPosition
+
  else
+
      ffTextureMatrix -scalev ($nhoodPaintTextureScale, $nhoodPaintTextureScale) -invert
+
      ffTextureCoordsSource 0
+
  endif
+
  textureBlend select(texture outRegister) select(outRegister)
+
  end
+
  end        
+
        endif
+
+
end
+
enddef
+
 
+
define NeighborhoodTerrainPaint()
+
  material
+
     
+
      if ($simpleTerrain)
+
        shader
+
        end
+
      endif
+
     
+
      create NeighborhoodTerrainPaintShader()
+
 
   end
 
   end
 
enddef
 
enddef
 
  
# ==============================================================================
+
define RoofBumps()
 
+
set ratioH 1  # default material parameter value
+
set ratioW 1  # default material parameter value
+
set useReflection 1 # default material parameter value
+
define NeighborhoodWater()
+
 
   material
 
   material
       # never draw water in its reflection. Already handled by code.
+
       shader -layer 0
 +
        validateRenderShaderContext -vertexFormat position 0 required
 +
        validateRenderShaderContext -vertexFormat normal 0 required
 +
        validateRenderShaderContext -vertexFormat texcoord 0 required
 +
                         
 +
        pass
 +
            shaderProgram -target vertexProgram -method compile -version 2_0
 +
              bindConstants 0 -bindingID geomToClip    -constantCount 4
 +
      bindConstants 4 -bindingID  geomToCamera  -constantCount 3
 +
      bindConstants 7 -bindingID  cameraToGeom  -constantCount 3      
 +
      bindConstants 10 -bindingID allStandardLightData -constantCount 4 -constantType float
 +
      bindConstants 14 -bindingID immediateData -data $stdMatDiffCoef
 +
      bindConstants 15 -bindingID ambientLight -constantCount 1 -constantType float      
 +
      bindConstants 18 -bindingID allStandardLightData2 -constantCount 32
 +
     
 +
      shaderSource
 +
        float4x4 modelviewproj : register(c0);
 +
      float4x3 modelview : register(c4);
 +
      float4x3 modelviewInv : register(c7);            
 +
     
 +
      // light direction
 +
      float4 lightDir0 : register(c18);      
 +
      float4 lightDir1 : register(c19);
 +
      float4 lightDir2 : register(c20);
 +
     
 +
      // light colors
 +
      float4 lightCol0 : register(c26);
 +
      float4 lightCol1 : register(c27);
 +
      float4 lightCol2 : register(c28);
 +
           
 +
      float4 color : register(c14);      
 +
      float4 ambient : register(c15);
 +
     
 +
      struct a2v
 +
                  {
 +
                    float4 pos : POSITION;                   
 +
                    float3 normal : NORMAL;
 +
                    float2 txcoord : TEXCOORD0;
 +
                    float2 tangent : TEXCOORD1;                   
 +
                  };
  
      if ($simpleTerrain)
+
                  struct v2f
        shader -layer $nhoodWaterLayer
+
                  {
            pass -fixedFunction
+
                    float4 hpos : POSITION;
              colorScalar (0.3, 0.4,0.8) 1.0
+
                    float4 color    : COLOR0;                                   
              stage
+
                    float4 ambient  : COLOR1;
                   textureBlend select(colorScalar) select(colorScalar)
+
                    float2 txcoord : TEXCOORD0;
              end
+
                  float3 lightDir0: TEXCOORD1;
            end
+
                  float3 lightDir1: TEXCOORD2;
        end
+
                  float3 lightDir2: TEXCOORD3;
      endif
+
                  float3 lightCol0: TEXCOORD4;
 +
                  float3 lightCol1: TEXCOORD5;
 +
                  float3 lightCol2: TEXCOORD6;
 +
                  float3 normal : TEXCOORD7;
 +
                  };
 +
                 
 +
                   v2f VertexMain(a2v IN)
 +
                  {
 +
                  v2f OUT;
  
 +
                  // vertex position in object space
 +
                  float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);                                    
 +
                 
 +
                  // vertex position in clip space
 +
                  OUT.hpos = mul(pos, modelviewproj);                            
 +
                 
 +
                  float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);
 +
                                   
 +
                  // compute binormal
 +
                  float3 binormal = normalize(cross(IN.normal, tangent));
 +
                 
 +
                  // tangent space matrix
 +
                  float3x3 tbn = float3x3(tangent, binormal, IN.normal);
 +
                 
 +
                  // light direction in object space                  
 +
                  float3 lt0 = mul(lightDir0, (float3x3)modelviewInv);
 +
                  float3 lt1 = mul(lightDir1, (float3x3)modelviewInv);
 +
                  float3 lt2 = mul(lightDir2, (float3x3)modelviewInv);
 +
                 
 +
                  // light 0 direction in tangent space                                    
 +
                  OUT.lightDir0 = normalize(mul(tbn, lt0));                                  
 +
                  OUT.lightDir1 = normalize(mul(tbn, lt1));
 +
                  OUT.lightDir2 = normalize(mul(tbn, lt2));
 +
                 
 +
                  OUT.lightCol0 = lightCol0;
 +
                  OUT.lightCol1 = lightCol1;
 +
                  OUT.lightCol2 = lightCol2;
 +
                 
 +
                  // copy texture coordinates                  
 +
                  OUT.txcoord=IN.txcoord.xy;
 +
                  OUT.color = color;
 +
                  OUT.color.a = 1;
 +
                 
 +
                  OUT.ambient = ambient;
 +
                  OUT.normal = IN.normal;
  
      # First option: reflection mapped water.
+
                  return OUT;
      if ($useReflection)
+
                  }
 
+
                         
        shader -layer $nhoodWaterLayer
+
      endShaderSource
            validateRenderShaderContext -vertexFormat  position      0 required
+
             end # end shader program
            validateRenderShaderContext -vertexFormat  normal        0 required
+
            validateRenderShaderContext -vertexFormat  texcoord      0 required
+
            viewerRenderTypePred viewerRenderType
+
 
+
             ################################################################################
+
            # Three pass/2 texture rippled reflection -- does not run on GeF2 only 2 stages (for GeF4+)
+
            pass -fixedFunction -modifiedEachFrameHint
+
 
              
 
              
           
+
               shaderProgram -target pixelProgram -method compile -version 1_4  #-disassemble "c:\sims2ep3\hlslPS.txt"           
               alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
              colorScalar $nhoodWaterReflColour $nhoodWaterReflStrength
+
              depthTest true -enableDepthWrite false
+
 
                
 
                
              stage
+
                   shaderSource   
                   ffTextureCoordsSource fromPosition
+
                    sampler texmap;
                  ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
+
                    sampler normmap;
                  textureAddressing clamp clamp
+
                    sampler roofnoise;
                  texture "ScreenReflection"
+
                   
                 
+
                    struct v2f
                  textureBlend multiply(texture colorScalar) select(outRegister) tempRegister
+
                    {
              end
+
                        float4 hpos : POSITION;  
              stage
+
                        float4 color    : COLOR0;                                                 
                  ffTextureCoordsSource fromPosition
+
                        float4 ambient  : COLOR1;
                  ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5 + $nhoodWaterReflOffset, 0.5 + $nhoodWaterReflOffset)
+
                        float2 txcoord : TEXCOORD0;                                               
                  textureAddressing clamp clamp
+
                        float3 lightDir0: TEXCOORD1;
                 
+
                    float3 lightDir1: TEXCOORD2;
                  texture "ScreenReflection"
+
                    float3 lightDir2: TEXCOORD3;
                  textureBlend multiply(texture colorScalar) select(outRegister)
+
                    float3 lightCol0: TEXCOORD4;
              end           
+
                    float3 lightCol1: TEXCOORD5;
              stage
+
                    //float3 lightCol2: TEXCOORD6;
                  texture "neighborhood-water-1"
+
                    //float3 normal : TEXCOORD7;
                  textureAddressing tile tile
+
                    };
                  # -atrans waveformType cycles/sec offset (startU, startV)  (endU, endV)
+
                  textureMatrixAnimation -targetType fixedFunction -atrans sawtooth ($nhoodWaterMap1Speed / $nhoodWaterMap1Scale) 0 (0, 0) ($nhoodWaterMap1Scale, 0) -ascale sawtooth 1 0 ($nhoodWaterMap1Scale, $nhoodWaterMap1Scale)
+
                  ffTextureCoordsSource 0
+
                  textureBlend lerpTextureAlpha(tempRegister outRegister) select(colorScalar)
+
              end
+
            end
+
        end
+
       
+
        shader -layer $nhoodWaterLayer
+
            validateRenderShaderContext -vertexFormat  position      0 required
+
            validateRenderShaderContext -vertexFormat  normal       0 required
+
            validateRenderShaderContext -vertexFormat  texcoord      0 required
+
            viewerRenderTypePred viewerRenderType
+
  
            ################################################################################
+
                    float4 PixelMain(v2f pi) : COLOR
            # Two stage case since the three stage case above fails on most low end hardware because of its third stage (GF2).
+
                    { 
            pass -fixedFunction -modifiedEachFrameHint
+
                        // normal map
           
+
                        float4 normal = tex2D(normmap, pi.txcoord);                                     
           
+
                               
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
                        //bump.xyz = 4.0 * (bump.xyz - (0.5).xxx);                           
              colorScalar $nhoodWaterReflColour $nhoodWaterReflStrength
+
//                        bump.z = pi.normal.z;
               depthTest true -enableDepthWrite false
+
                        //float3 normal = normalize(bump);                                               
 +
                       
 +
                        // color map
 +
                        float4 color = tex2D(texmap, pi.txcoord);             
 +
                                                                                               
 +
                        float diff0 = saturate(dot(pi.lightDir0, normal.xyz));                       
 +
                        //float diff1 = saturate(dot(pi.lightDir1, normal.xyz));
 +
                        //float diff2 = saturate(dot(pi.lightDir2, normal.xyz));
 +
                                             
 +
                        float4 finalColor;
 +
                        finalColor.rgb = diff0;//(diff0*pi.lightCol0 + diff1*pi.lightCol1 + diff2 + pi.ambient)*pi.color.rgb*color.rgb;
 +
                       
 +
                        finalColor.a = 1.0;                       
 +
                        return finalColor;                                                                                                                   
 +
                    }
 +
                  endShaderSource
 +
               end                                                   
 +
                             
 
                
 
                
               stage
+
               sampler normmap
                   ffTextureCoordsSource fromPosition
+
                   texture "roof-manor-test-bump"#$stdMatNormalMapTextureName               
                  ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
+
                   textureAddressing clamp clamp clamp
                   textureAddressing clamp clamp
+
                  texture "ScreenReflection"
+
                 
+
                  textureBlend multiply(texture colorScalar) select(outRegister)
+
              end
+
             
+
              stage
+
                  texture "neighborhood-water-1"
+
                  textureAddressing tile tile
+
                  # -atrans waveformType cycles/sec offset (startU, startV)  (endU, endV)
+
                  #textureMatrixAnimation -targetType fixedFunction -atrans sawtooth ($nhoodWaterMap1Speed / $nhoodWaterMap1Scale) 0 (0, 0) ($nhoodWaterMap1Scale, 0) -ascale sawtooth 1 0 ($nhoodWaterMap1Scale, $nhoodWaterMap1Scale)
+
                  ffTextureCoordsSource 0
+
                  textureBlend lerpTextureAlpha(outRegister outRegister) select(colorScalar)
+
 
               end
 
               end
 
                
 
                
            end
+
               sampler 1#texmap
        end
+
                   texture $stdMatBaseTextureName               
       
+
      endif
+
     
+
      ################################################################################
+
      # fallback: no reflection.
+
      shader -layer ($nhoodWaterLayer)
+
        viewerRenderTypePred viewerRenderType
+
       
+
        create DetermineHardwareSupport()
+
       
+
        pass -fixedFunction
+
  # For now, we are diabling the lighting since we simply want to use the vertex colors.
+
  create LightingStatesNoStdLightsParam(false true)
+
  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
 
+
            colorScalar (.4, .6, .9, .6)     
+
           
+
            fillmode $stdMatFillMode
+
            stage
+
               #texture reflectionoutdoorwater-envcube
+
              if ($cubeMapSupport)
+
                   texture $skyboxCubeMap
+
                  textureMIPFilterHint disabled
+
 
+
                  ffTextureCoordsSource fromReflectionVector
+
                  ffTextureMatrix -orientCameraToGlobal
+
 
+
 
                   textureAddressing clamp clamp clamp
 
                   textureAddressing clamp clamp clamp
                  textureBlend multiply(texture colorScalar) select(colorScalar)
+
               end
               else
+
         end # end pass
                  textureBlend select(colorScalar) select(colorScalar)
+
              endif
+
            end
+
         end  
+
+
      end
+
+
+
      ################################################################################
+
      # Final fallback.
+
#<shader -layer ($nhoodWaterLayer)
+
viewerRenderTypePred viewerRenderType
+
+
pass -fixedFunction
+
+
fillmode $stdMatFillMode
+
create LightingStatesNoStdLights()
+
alphaBlend srcFactor(one) add dstFactor(srcAlpha)
+
colorScalar (.2, .3, .5, .05)     
+
stage
+
textureBlend select(colorScalar) select(colorScalar)
+
end
+
end
+
+
+
end#>
+
+
        create NeighborhoodWaterSWVS()
+
               
+
     
+
end
+
+
enddef
+
 
+
 
+
# ==============================================================================
+
# 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
+
      end #end shader
            create LightingStates()
+
  end # end material
            alphaBlend srcFactor(one) add dstFactor(zero)
+
enddef
            cullmode cullCounterClockwise
+
  
            stage
+
define RoofSnow()
              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
 
   material
 
+
       shader -layer 2       
      if ($simpleTerrain)
+
         validateRenderShaderContext -vertexFormat position 0 required
        shader
+
         validateRenderShaderContext -vertexFormat normal 0 required
        end
+
         validateRenderShaderContext -vertexFormat texcoord 0 required
      endif
+
        validateRenderShaderContext -vertexFormat texcoord 1 required
     
+
                         
       shader -layer (($nhoodCanvasLayer + 13) * 8)
+
         pass  
         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)
 
             alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
             stage
+
             cullmode $stdMatCullMode
              texture $terrainEdgeTexture
+
            #fillmode wireframe
               textureAddressing tile tile
+
           
               ffTextureMatrix -scalev (1/$terrainEdgeTextureScale, 1/$terrainEdgeTextureScale)
+
            shaderProgram -target vertexProgram -method compile -version 2_0
              ffTextureCoordsSource 0
+
               bindConstants 0 -bindingID  geomToClip    -constantCount 4       
              textureBlend multiply(texture diffuse) select(texture)
+
               bindConstants 4 -bindingID  geomToCamera  -constantCount 3
            end
+
      bindConstants 7 -bindingID  cameraToGeom  -constantCount 3
        end     
+
      bindConstants 15 -bindingID ambientLight -constantCount 1 -constantType float                        
       
+
      bindConstants 18 -bindingID allStandardLightData -constantCount 4 -constantType float      
      end
+
     
  end
+
      shaderSource
enddef
+
        float4x4 modelviewproj : register(c0);
 +
        float4x3 modelview : register(c4);
 +
      float4x3 modelviewInv : register(c7);            
 +
                  // light direction
 +
      float4 lightDir0 : register(c18);      
 +
     
 +
                  float4 ambient : register(c15);
 +
           
 +
      struct a2v
 +
                  {
 +
                    float4 pos : POSITION;                   
 +
                    float3 normal : NORMAL;
 +
                    float2 tangent : TEXCOORD0;                   
 +
                  };
  
#==============================================================================
+
                  struct v2f
define NHoodTerrainLighting()
+
                  {
 +
                    float4 hpos : POSITION;                   
 +
                  float4 color : TEXCOORD0;
 +
                  float3 camNormal : TEXCOORD1;
 +
                  float3 lightDir : TEXCOORD2;
 +
                  float3 R : TEXCOORD3;   
 +
                  float3 tanLightDir : TEXCOORD4;                             
 +
                  float2 bumpCoords : TEXCOORD5;
 +
                  };
 +
                 
 +
                  v2f VertexMain(a2v IN)
 +
                  {
 +
                  v2f OUT;
  
  set terrainRepresentativeTexture "lottexture-test-01_detail"
+
                  // vertex position in object space
 +
                  float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);  
 +
                 
 +
                  float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);
 +
                                   
 +
                  // compute binormal
 +
                  float3 binormal = normalize(cross(IN.normal, tangent));
 +
                 
 +
                  // tangent space matrix
 +
                  float3x3 tbn = float3x3(tangent, binormal, IN.normal);
 +
                 
 +
                  // light direction in object space                  
 +
                  float3 lt0 = mul(lightDir0, (float3x3)modelviewInv);
 +
                 
 +
                  // light 0 direction in tangent space                                    
 +
                  OUT.tanLightDir = normalize(mul(tbn, lt0));
 +
                  OUT.bumpCoords = float2(IN.pos.x, IN.pos.y);
 +
                 
 +
                 
 +
                 
 +
                  // vertex position in clip space
 +
                  OUT.hpos = mul(pos, modelviewproj);                            
 +
                                                     
 +
                  // copy texture coordinates                                                      
 +
                  OUT.camNormal = mul(IN.normal, (float3x3)modelview);
 +
                 
 +
                  float3 cameraSpacePosition = mul( pos, modelview);
 +
                  float3 viewVector = normalize(cameraSpacePosition);
 +
      OUT.R = reflect(viewVector, OUT.camNormal);      
 +
                 
 +
                  OUT.color.xyz = tangent*0.5f.xxx + 0.5f.xxx;//ambient.xyz;
 +
                  OUT.color.w = 1.0;
 +
                  OUT.lightDir.xyz = lightDir0.xyz;                   
 +
                  return OUT;
 +
                  }
 +
                         
 +
      endShaderSource
 +
            end # end shader program
 +
           
 +
              shaderProgram -target pixelProgram -method compile -version 2_0 # -disassemble "c:\sims2ep3\hlslPS.txt"                          
 +
                  shaderSource                       
 +
                                         
 +
                    struct v2f
 +
                    {
 +
                        float4 hpos : POSITION;                   
 +
                    float4 color : TEXCOORD0;
 +
                    float3 camNormal : TEXCOORD1;
 +
                    float3 lightDir : TEXCOORD2;
 +
                    float3 R : TEXCOORD3;   
 +
                    float3 tanLightDir : TEXCOORD4; 
 +
                    float2 bumpCoords : TEXCOORD5;                                         
 +
                    };
  
material
+
                    float4 PixelMain(v2f pi) : COLOR
shader -layer (($nhoodCanvasLayer + 3) * 8)
+
                    {                         
validateRenderShaderContext -vertexFormat  position      0 required
+
                        return pi.color; 
validateRenderShaderContext -vertexFormat  normal        0 required
+
                        //return float4(0, 0, 0, 1) + 0.8*max(dot(pi.camNormal, pi.lightDir), 0).xxxx + pi.color;
+
                    }
if (not $isImposter)
+
                  endShaderSource
  validateRenderShaderContext -vertexFormat  texcoord      0 required
+
              end             
endif
+
                                                             
+
                                           
 +
        end # end pass
 +
       
 +
      end #end shader
 +
  end # end material
 +
enddef
  
        if (strcmp("Concrete", "${terrainType}") = 0)
+
define RoofSnowPS2()
            setb isTerrainConcrete true
+
  shaderProgram -target pixelProgram -method compile -version 2_0 # -disassemble "c:\sims2ep5\hlslPS.txt"                          
        endif
+
      bindConstants 0 -bindingID ambientLight -constantCount 1 -constantType float
 
        
 
        
         if ($simpleTerrain)
+
      shaderSource                       
 +
         float3 ambientLight : register(c0);
 
          
 
          
            if (strcmp("Desert", "${terrainType}") = 0)
+
        sampler normmap;
              set terrainRepresentativeTexture "lottexture-canvas-desert"
+
        struct v2f
            endif
+
         {
          
+
             float4 hpos : POSITION;                           
             shader
+
        float4 color : COLOR0;                    
               pass -fixedFunction                 
+
        float4 tanHalfAngle : TEXCOORD0;
  ffDepthOffset -1                
+
        float3 lightColor : TEXCOORD1;                
 +
        float3 tanLightDir : TEXCOORD2; 
 +
        float2 bumpCoords : TEXCOORD3;                                         
 +
        };
  
                  stage
+
        float4 PixelMain(v2f pi) : COLOR
    texture "nhoodLightMap"   
+
        {                                                 
    if ($isImposter)
+
            float4 normal0 = 2.0f * (tex2D(normmap, pi.bumpCoords) - 0.5f);                       
      ffTextureMatrix -cameraToGlobal -scalev (1280, 1280) -invert
+
            float4 normal1 = 2.0f * (tex2D(normmap, pi.bumpCoords*0.4) - 0.5f);
      ffTextureCoordsSource fromPosition
+
            float4 normal = 0.5f*(normal0+normal1);
  else
+
      ffTextureMatrix -scalev (128, 128) -invert
+
      ffTextureCoordsSource 0
+
  endif
+
                       
+
                    textureBlend select(texture) select(texture)
+
                  end
+
                 
+
                  stage
+
    texture $terrainRepresentativeTexture   
+
    if ($isImposter)
+
      ffTextureMatrix -cameraToGlobal -scalev (160, 160) -invert
+
      ffTextureCoordsSource fromPosition
+
  else
+
      ffTextureMatrix -scalev (16, 16) -invert
+
      ffTextureCoordsSource 0
+
  endif
+
   
+
                    #textureBlend multiply(texture outRegister) select(outRegister)
+
                    textureBlend select(texture outRegister) select(outRegister)
+
                  end
+
              end
+
            end
+
 
              
 
              
         endif
+
            float diffuse = saturate(dot(pi.tanLightDir, normal.xyz))*0.6f;                             
        
+
            return float4(float3(diffuse.xxx*float3(0.9,0.9,1) + ambientLight.xxx*0.8)*pi.lightColor.xyz, 1.0);
 +
         }
 +
       endShaderSource
 +
  end             
  
create DetermineHardwareSupport()
 
 
if ($useSWVertexShaderPath)
 
create NeighborhoodTerrainLightingSWVS()
 
else
 
pass -fixedFunction
 
 
create LightingStatesNoStdLights()
 
 
# standard Lightmap * dest
 
alphaBlend srcFactor(destColor) add dstFactor(zero)
 
 
# if the outbound 'clip' texture has 0 in it, don't emit those pixels.
 
alphaTest true 127
 
alphaTestFunction acceptIfGreater
 
 
 
fillmode $stdMatFillMode
 
 
if ($isImposter and $isTerrainConcrete)
 
  ffDepthOffset -1        
 
      endif
 
           
 
depthTestFunction acceptIfEqual
 
            # emit the lightmap
 
stage
 
texture "nhoodLightMap"
 
if ($isImposter)
 
  ffTextureMatrix -cameraToGlobal -scalev (1280, 1280) -invert
 
  ffTextureCoordsSource fromPosition
 
else
 
  ffTextureMatrix -scalev (128, 128) -invert
 
  ffTextureCoordsSource 0
 
endif
 
 
if (tsHasSnow >= 1)
 
  colorScalar (0.3, 0.3, 0.35, 0)
 
  else
 
      colorScalar (0, 0, 0, 0)
 
  endif
 
 
textureBlend add(texture colorScalar) select(texture)
 
end 
 
 
# modulate by the 'above water' texture, which is a 2x1 texture with black and white in it.
 
 
stage
 
# above water -- clip by using depth-based 0/1 texture.
 
texture blackWhite
 
textureAddressing clamp clamp
 
textureFilterHint point point
 
textureMIPFilterHint disabled
 
                 
 
if ( $isImposter)
 
  ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 10, 0) -invert
 
              else
 
  ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
 
endif
 
ffTextureCoordsSource fromPosition
 
textureBlend multiply(texture:alphaReplicate outRegister) select(texture)
 
end
 
end
 
endif  
 
end
 
end
 
 
 
enddef
 
enddef
  
 +
define RoofSnowPS1()
 +
  shaderProgram -target pixelProgram -method compile -version 1_1 # -disassemble "c:\sims2ep5\hlslPS.txt"                           
 +
      bindConstants 0 -bindingID ambientLight -constantCount 1 -constantType float
 +
     
 +
      shaderSource                       
 +
        float3 ambientLight : register(c0);
 +
       
 +
        sampler normmap;
 +
        struct v2f
 +
        {
 +
            float4 hpos : POSITION;                           
 +
        float4 color : COLOR0;                    
 +
        float4 tanHalfAngle : TEXCOORD0;
 +
        float3 lightColor : TEXCOORD1;               
 +
        float3 tanLightDir : TEXCOORD2; 
 +
        float2 bumpCoords : TEXCOORD3;                                         
 +
        };
  
# ==============================================================================
+
        float4 PixelMain(v2f pi) : COLOR
 
+
        {                                                 
define NHoodTerrainHighlightMaterial()
+
            float4 normal = 2.0f * (tex2D(normmap, pi.bumpCoords) - 0.5f);                       
  material
+
            float diffuse = saturate(dot(pi.tanLightDir, normal.xyz))*0.57f;                             
      shader -layer (($nhoodCanvasLayer + 9) * 8)
+
            return float4(float3(diffuse.xxx*float3(0.85,0.85,1) + ambientLight.xxx)*pi.lightColor.xyz, 1.0);
        validateRenderShaderContext -vertexFormat  position      0 required
+
        }
        validateRenderShaderContext -vertexFormat  normal        0 required
+
       endShaderSource
        validateRenderShaderContext -vertexFormat  texcoord      0 required
+
   end              
 
+
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
 
enddef
  
# ==============================================================================
+
define RoofSnow2()
define NHoodTerrainOutlineHighlightMaterial()
+
 
   material
 
   material
       shader -layer (($nhoodCanvasLayer + 10) * 8)
+
       shader -layer -2       
         validateRenderShaderContext -vertexFormat position     0 required
+
         validateRenderShaderContext -vertexFormat position 0 required
         validateRenderShaderContext -vertexFormat normal       0 required
+
         validateRenderShaderContext -vertexFormat normal 0 required
         validateRenderShaderContext -vertexFormat texcoord     0 required
+
         validateRenderShaderContext -vertexFormat texcoord 0 required
 
+
         validateRenderShaderContext -vertexFormat texcoord 1 required
pass -fixedFunction
+
                         
  create LightingStatesNoStdLights()
+
         pass  
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
             alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
fillmode $stdMatFillMode
+
             cullmode $stdMatCullMode          
depthTest true -enableDepthWrite false
+
             #fillmode wireframe
           
+
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
+
      shader -layer (($nhoodCanvasLayer + 4) * 8)
+
         validateRenderShaderContext -vertexFormat position 0 required
+
        validateRenderShaderContext -vertexFormat  normal  0 required
+
        validateRenderShaderContext -viewerRenderType viewerRenderType
+
 
+
        if ($stdMatBaseTextureEnabled)
+
            validateRenderShaderContext -vertexFormat  texcoord 0 required
+
        endif
+
 
+
 
+
 
+
         pass -fixedFunction
+
 
+
             ffMatCoef -amb $stdMatDiffCoef -ambAlpha $stdMatAlphaMultiplier -diff $stdMatDiffCoef  -diffAlpha $stdMatAlphaMultiplier -emit $stdMatEmissiveCoef -emitAlpha $stdMatAlphaMultiplier -spec $stdMatSpecCoef -specPow $stdMatSpecPower
+
 
+
            create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
+
            fillmode $stdMatFillMode
+
             cullmode $stdMatCullMode
+
 
+
             create LightingStates()                       
+
                       
+
            stage
+
              create StandardShaderTextureState(Base)             
+
              textureBlend multiply(texture outRegister) multiply(texture outRegister)             
+
            end
+
 
              
 
              
             #################################################################
+
             shaderProgram -target vertexProgram -method compile -version 1_1
            if ($stdMatIsPartlyUnderwater and tsIsInNeighborhood)
+
              bindConstants 0 -bindingID  geomToClip    -constantCount 4       
               if (viewerRenderType = $kRenderTypeReflection)
+
               bindConstants 4 -bindingID  geomToCamera  -constantCount 3
                  alphaTest true 128
+
      bindConstants 7 -bindingID  cameraToGeom  -constantCount 3
                  alphaTestFunction acceptIfGreater
+
      bindConstants 15 -bindingID ambientLight -constantCount 1 -constantType float                        
                  stage
+
      bindConstants 18 -bindingID allStandardLightData -constantCount 4 -constantType float      
                    # above water -- clip by using depth-based 0/1 texture.
+
     
                    texture blackWhite
+
      if (tsIsDay)        
                    textureAddressing clamp clamp
+
                  bindConstants 10 -bindingID immediateData -data (1, 1, 1, 1)        
                    textureFilterHint point point
+
                    textureMIPFilterHint disabled
+
                       
+
                    ffTextureMatrix -cameraToGlobal -order zzzw -trans ($waterHeight - 0.5, 0) -invert
+
                    ffTextureCoordsSource fromPosition
+
                    textureBlend multiply(texture outRegister) select(texture)
+
                  end
+
 
               else
 
               else
                   stage
+
                   bindConstants 10 -bindingID immediateData -data (0.47, 0.47, 1.2, 1)         
                    # would we want to source this from somewhere?
+
                    texture $waterGradientTexture
+
                    textureAddressing tile clamp
+
                   
+
                    set d ($waterHeight - $waterGradientZoneStart)
+
                    set s (-$waterGradientZoneSize)
+
                    ffTextureMatrix -cameraToGlobal -order xzyw -scale $s -trans (0, $d) -invert
+
                    ffTextureCoordsSource fromPosition
+
                    textureBlend multiply(texture outRegister) select(outRegister)
+
                  end          
+
 
               endif
 
               endif
            else
+
     
              # if we are in lot mode and we want to fade this shape
+
      shaderSource
              if (numLightsOfType(${kShapeColorLight}) != 0)  
+
        float4x4 modelviewproj : register(c0);
                  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
        float4x3 modelview : register(c4);
                  depthTest true -enableDepthWrite false
+
      float4x3 modelviewInv : register(c7);            
                  colorScalar (1, 1, 1, 1) -applyShapeColor 0
+
                   // light direction
                   stage
+
      float4 lightDir0 : register(c18);
                    textureBlend select(outRegister) select(colorScalar)
+
      float4 lightColor0 : register(c10);
                  end
+
     
              endif
+
           
            endif
+
                  float4 ambient : register(c15);
            #################################################################
+
           
        end
+
      struct a2v
       
+
                  {
        seti weatherLightCount (numLightsOfType(${kWeatherLight}))
+
                    float4 pos : POSITION;                   
       
+
                    float3 normal : NORMAL;
      end
+
                    float2 tangent : TEXCOORD0;
     
+
                    float2 bumpcoord : TEXCOORD1;                   
      # fallback shader, no darken by depth, since "FromPosition" tends to be totally FUBAR  in SWVP.
+
                   };
      shader -layer (($nhoodCanvasLayer + 4) * 8)
+
     
+
pass -fixedFunction
+
 
+
            ffMatCoef -amb $stdMatDiffCoef -ambAlpha $stdMatAlphaMultiplier -diff $stdMatDiffCoef  -diffAlpha $stdMatAlphaMultiplier -emit $stdMatEmissiveCoef -emitAlpha $stdMatAlphaMultiplier -spec $stdMatSpecCoef -specPow $stdMatSpecPower
+
 
+
            create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
+
            fillmode $stdMatFillMode
+
            cullmode $stdMatCullMode
+
 
+
            create LightingStates()
+
           
+
            stage
+
              create StandardShaderTextureState(Base)             
+
              textureBlend multiply(texture outRegister) multiply(texture outRegister)
+
            end
+
           
+
            # if we are in lot mode and we want to fade this shape
+
            if (not tsIsInNeighborhood and numLightsOfType(${kShapeColorLight}) != 0)
+
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
              depthTest true -enableDepthWrite false
+
              colorScalar (1, 1, 1, 1) -applyShapeColor 0
+
              stage
+
                   textureBlend select(outRegister) select(colorScalar)
+
              end
+
            endif
+
           
+
end
+
+
     
+
      end
+
  
  end
+
                  struct v2f
+
                  {
enddef
+
                    float4 hpos : POSITION;                                         
 +
                  float4 color : COLOR0;                  
 +
                  float4 tanHalfAngle : TEXCOORD0;
 +
                  float3 lightColor : TEXCOORD1;
 +
                  float3 tanLightDir : TEXCOORD2;                             
 +
                  float2 bumpCoords : TEXCOORD3;                  
 +
                  };
 +
                 
 +
                  v2f VertexMain(a2v IN)
 +
                  {
 +
                  v2f OUT;
  
 +
                  // vertex position in object space
 +
                  float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);  
 +
                 
 +
                  float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);
 +
                                   
 +
                  // compute binormal
 +
                  float3 binormal = normalize(cross(IN.normal, tangent));
 +
                 
 +
                  // tangent space matrix
 +
                  float3x3 tbn = float3x3(tangent, binormal, IN.normal);
 +
                 
 +
                  // light direction in object space                  
 +
                  float3 lt0 = mul(lightDir0, (float3x3)modelviewInv);
 +
                 
 +
                  // light 0 direction in tangent space                                    
 +
                  OUT.tanLightDir = normalize(mul(tbn, lt0));
 +
                  OUT.bumpCoords = float2(IN.bumpcoord.x, IN.bumpcoord.y);
 +
                 
 +
                  // compute tangent space view vector
 +
                  // object space view point
 +
                  float3 viewPoint = mul(float4(0, 0, 0, 1), modelviewInv).xyz;
 +
                  float3 viewVecObj = normalize(viewPoint - IN.pos.xyz);
 +
                 
 +
                  // object space light
 +
                  float3 lightDirObj = normalize(mul(lightDir0, (float3x3)modelviewInv));
 +
                 
 +
                  // half angle vector in object space
 +
                  float3 halfWayVector = normalize(lightDirObj + viewVecObj);                  
 +
                 
 +
                  // transform half angle vector to tangent space
 +
                  OUT.tanHalfAngle.xyz = normalize(mul(tbn, halfWayVector));
 +
                 
 +
                  // specular shadowing term
 +
                  OUT.tanHalfAngle.w = max(dot(halfWayVector, IN.normal), 0);                  
 +
                 
 +
                  // vertex position in clip space
 +
                  OUT.hpos = mul(pos, modelviewproj);                            
 +
                                                                       
 +
                  OUT.color.xyz = ambient.xyz;
 +
                  OUT.color.w = 1.0;
 +
                  OUT.lightColor = lightColor0.xyz;
 +
                  return OUT;
 +
                  }
 +
                         
 +
      endShaderSource
 +
            end # end shader program
  
 
+
              if ($useHWShader1Path)
# ===================================================================================
+
                  create RoofSnowPS1()                          
define ImposterArrowMaterial()
+
              else
  material
+
                  create RoofSnowPS2()                          
      shader -layer (($nhoodCanvasLayer + 11) * 8)
+
              endif             
 +
             
 +
              sampler normmap
 +
                  texture "snow-ground-bump"
 +
                  textureAddressing tile tile
 +
              end                                     
 +
                                           
 +
        end # end pass
 
          
 
          
        validateRenderShaderContext -vertexFormat  position      0 required
+
      end #end shader
        validateRenderShaderContext -vertexFormat  normal        0 required
+
  end # end material
        validateRenderShaderContext -vertexFormat  texcoord      0 required
+
 
+
pass -fixedFunction
+
  create LightingStatesNoStdLights()
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
fillmode $stdMatFillMode
+
            # TODO: change this, cannot turn off depth since that is used for dirty rect
+
depthTest false -enableDepthWrite false
+
           
+
stage
+
texture $texture
+
textureAddressing tile tile
+
ffTextureCoordsSource 0
+
textureBlend select(texture) select(texture)
+
end  
+
end    
+
      end
+
  end
+
 
enddef
 
enddef
  
# ===================================================================================
 
  
define NeighborhoodTreeGUOBMaterial()
+
materialDefinition RoofPreview
 +
  setDefinition StandardMaterial
 +
  addParam  stdMatSpecPower 0
 +
  addParam  stdMatDiffCoef (0.4, 0.385, 0.38)
 +
  addParam  stdMatBaseTextureName roof-manor
 +
  addParam  stdMatBaseTextureEnabled true
 +
  addParam  stdMatCullMode none
 +
end
  
# $stdMatTextureName
 
# $stdMatAlphaMulitplier
 
  
   # TODO: fix these so that they are not hardcoded, must be passed through content
+
materialDefinition RoofUnder
   set  textureName      "genericroundsoftguob-alpha"
+
  setDefinition StandardMaterial
   setf alphaMultiplier  0.65
+
  addParam   stdMatSpecPower 0
 +
  addParam  stdMatDiffCoef (0.8, 0.8, 0.8)
 +
  addParam   stdMatBaseTextureName roof-manor-under
 +
  addParam   stdMatBaseTextureEnabled true
 +
  addParam  stdMatCullMode none
 +
end
  
   # try using vs_2_sw on the trees since sw vs is not as susceptible to state changes
+
materialDefinition RoofTrim
 +
  setDefinition StandardMaterial
 +
  addParam   stdMatSpecPower 0
 +
  addParam  stdMatDiffCoef (0.8, 0.8, 0.8)
 +
  addParam  stdMatBaseTextureName roof-manor-trim
 +
  addParam  stdMatBaseTextureEnabled true
 +
  addParam  stdMatCullMode none
 +
end
  
  # this only handles tree GUOBs in the nhood.
+
materialDefinition RoofPreviewTopBoundary
  material
+
   setDefinition RoofPreviewMaterialTopBoundary
    
+
end
      #the engine will try this shader first..
+
      shader -layer $nhoodTreeShadowLayer
+
        # shadows can never be seen in reflections (they're on the ground)
+
        viewerRenderTypePred $kRenderTypeReflection false
+
     
+
        pass
+
          alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
          depthTest true -enableDepthWrite false
+
         
+
            shaderProgram -target vertexProgram -method assemble
+
              bindConstants 0 -bindingID geomToClip -constantCount 4
+
              shaderSource
+
                vs_1_1
+
                dcl_position v0
+
                dcl_texcoord v1
+
                m4x4 oPos, v0, c0
+
                mov oT0, v1
+
               
+
              endShaderSource
+
            end
+
         
+
            shaderProgram -target pixelProgram -method assemble
+
              shaderSource
+
                  ps_1_1
+
                  def c0,1,1,1,$alphaMultiplier
+
                  tex t0
+
                  mul r0,t0, c0
+
              endShaderSource
+
             
+
            end
+
           
+
            sampler 0
+
              texture $textureName
+
              textureAddressing clamp clamp clamp
+
            end
+
        end
+
      end
+
     
+
  # and fall back to this one if it can't render the above.
+
  shader -layer $nhoodTreeShadowLayer
+
        # shadows can never be seen in reflections (they're on the ground)
+
        viewerRenderTypePred $kRenderTypeReflection false
+
     
+
        pass -fixedFunction
+
          alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
          depthTest true -enableDepthWrite false
+
         
+
          colorScalar (1,1,1, $alphaMultiplier)
+
         
+
          stage
+
              texture $textureName
+
              textureAddressing clamp clamp clamp
+
              textureBlend select(texture) multiply(texture colorScalar)
+
          end
+
        end
+
  end
+
   
+
  end
+
 
+
enddef
+
  
#=======================================================================================
+
define RoofTopMaterial()
define NeighborhoodBuildingMaterial()
+
   material
   material
+
       shader -layer 0
       shader -layer 0
+
         seti snowLevel tsHasSnow
         setb isDay tsIsDay
+
        seti rainLevel tsHasRain
         setb shouldShow (($showOnDay and $isDay) or ((not $showOnDay) and (not $isDay)))
+
          
         if ($shouldShow)
+
         if ($rainLevel >= 1)
             pass -fixedFunction  
+
             pass -fixedFunction -modifiedEachFrameHint
 +
        else
 +
            pass -fixedFunction
 +
        endif
 +
              setb doSkinning false
 +
              setb doMorphing false
 +
              setb cutoutPass false
 +
              create CommonStandardMaterialSetup()
 
                
 
                
               if (numLightsOfType(${kShapeColorLight}) > 0)             
+
               stage
                  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
      create StandardShaderTextureState(Base)
                  depthTest true -enableDepthWrite false             
+
  textureBlend multiplyScale2(texture outRegister) multiply(texture outRegister)
                  colorScalar (1, 1, 1, 1) -applyShapeColor 0
+
      end
              else
+
                  colorScalar (1, 1, 1, 1)
+
              endif   
+
 
                
 
                
 +
        if ($rainLevel >= 1)
 +
            # first pass at roof rain stage
 +
              stage
 +
                  ffTextureCoordsSource 0
 +
                  texture "causticstiled"
 +
                  textureMatrixAnimation -targetType fixedFunction -atrans sawtooth .1 0 (0,1) (0,0)
 +
                  colorScalar (1.0, 0.98, 1.0, .9)
 +
                  textureAddressing tile tile
 +
                  textureBlend lerpColorScalarAlpha(outRegister texture) lerpColorScalarAlpha(colorScalar)
 +
              end
 +
        endif
 
                
 
                
              if ($isDay) #lighting is only applied at day time
+
            end
                  ffLighting -enable true -localViewer false -normalizeNormals false
+
 
                  create NonStandardLighting()          
+
        if ($snowLevel = 1 and viewerRenderType != $kRenderTypeImposter)
                  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
+
            pass -fixedFunction
 +
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
              depthTest true -enableDepthWrite false
 +
              depthTestFunction acceptIfLessOrEqual
 +
              create LightingStates()
 
                
 
                
                  stage
+
              colorScalar (0.25, 0.25, 0.35, 1)
                    ffTextureCoordsSource 0
+
               
                    texture $texMaterial
+
              stage                
                    textureBlend multiply(texture diffuse) multiply(texture colorScalar)
+
                  texture "snow-light-roof-pass1"
                   end
+
                  ffTextureCoordsSource fromPosition
              else
+
                  ffTextureMatrix -cameraToGlobal -scalev (6, 6) -invert                               
                   stage
+
                   textureAddressing tile tile
                    ffTextureCoordsSource 0
+
                  textureFilterHint bilinear bilinear
                    texture $texMaterial
+
                   textureBlend multiplyAdd(texture diffuse colorScalar) select(texture)              
                    textureBlend select(texture) multiply(texture colorScalar)
+
              end
                  end
+
              endif
+
 
             end             
 
             end             
 
         endif
 
         endif
 +
       
 
       end
 
       end
   end  
+
   end
 
enddef
 
enddef
#============================================================================================
 
  
# make tree shadows render to an opaque (but blended layer) so they drop into the static layer
+
define RoofSnowShader()
# this overrides the texture name and alpha blend level.
+
  create DetermineHardwareSupport()
 +
  if (viewerRenderType != $kRenderTypeImposter)
 +
      if ($useHWShader1Path or $useHWShader2Path)
 +
  create RoofSnow2()
 +
  else 
 +
        create RoofSnowFF()
 +
      endif     
 +
  else
 +
      create Null()
 +
  endif
 +
enddef
  
materialDefinition neighborhood_roundshadow
+
define RoofSnowFF()
   setDefinition NeighborhoodTreeGUOBMaterial
+
   material
end
+
      shader -layer 0     
 +
        pass -fixedFunction       
 +
            create LightingStates()
 +
            create AttenuatedMatCoef(1)                                         
 +
                                         
 +
            depthTest true -enableDepthWrite true
 +
            colorScalar (1.0, 0.98, 1.0, 1)
 +
                       
 +
            stage             
 +
  textureBlend multiply(colorScalar diffuse) select(texture)
 +
            end #end stage                       
 +
        end
 +
      end
 +
  end
 +
enddef
  
# rectangular shadows are used by the car shadows, until can pass the existing texture name onto the material,
+
materialDefinition RoofSnowMaterial
# leave those shadows as transparent layer 7 that will get alpha sorted, etc.
+
   setDefinition RoofSnowShader 
#materialDefinition neighborhood_rectangularshadow
+
   addParam stdMatCullMode none
#  setDefinition NeighborhoodTreeGUOBMaterial
+
#end
+
 
+
# forest
+
materialDefinition forest_01_shadows
+
   setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
materialDefinition forest_02_shadows
+
   setDefinition NeighborhoodTreeGUOBMaterial
+
 
end
 
end
  
 
+
# texture, lit, normal mappedm, no specular
# oak
+
materialDefinition RoofTop
materialDefinition treeoak01_shadows
+
   setDefinition RoofTopMaterial
   setDefinition NeighborhoodTreeGUOBMaterial
+
  addParam  stdMatSpecPower 0
end
+
  addParam  stdMatDiffCoef (0.4, 0.385, 0.38)
materialDefinition treeoak02_shadows
+
   addParam  stdMatBaseTextureName roof-manor
   setDefinition NeighborhoodTreeGUOBMaterial
+
  addParam  stdMatBaseTextureEnabled true
end
+
   addParam  stdMatBaseTextureAddressingU clamp
materialDefinition treeoak03_shadows
+
   addParam  stdMatBaseTextureAddressingV clamp
   setDefinition NeighborhoodTreeGUOBMaterial
+
   addParam  stdMatBaseTextureAddressingW clamp
end
+
   addParam  stdMatCullMode none
materialDefinition treeoak04_shadows
+
   setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
materialDefinition treeoak05_shadows
+
   setDefinition NeighborhoodTreeGUOBMaterial
+
end
+
materialDefinition treeoak06_shadows
+
   setDefinition NeighborhoodTreeGUOBMaterial
+
 
end
 
end
  
# scrub oak
 
materialDefinition neighborhoodtreescruboak_shadows_alpha
 
  setDefinition NeighborhoodTreeGUOBMaterial
 
end
 
  
# birch
+
materialDefinition RoofEdges
materialDefinition treebirch01_shadows
+
   setDefinition StandardMaterial
   setDefinition NeighborhoodTreeGUOBMaterial
+
  addParam  stdMatSpecPower 0
    
+
  addParam  stdMatDiffCoef (0.8, 0.8, 0.8)
 +
  addParam  stdMatBaseTextureName roof-manor-edges
 +
  addParam  stdMatBaseTextureEnabled true
 +
  addParam   stdMatCullMode none
 
end
 
end
materialDefinition treebirch02_shadows
 
  setDefinition NeighborhoodTreeGUOBMaterial
 
 
 
end
 
materialDefinition treebirch03_shadows
 
  setDefinition NeighborhoodTreeGUOBMaterial
 
 
end
 
materialDefinition treebirch04_shadows
 
  setDefinition NeighborhoodTreeGUOBMaterial
 
end
 
materialDefinition treebirch05_shadows
 
  setDefinition NeighborhoodTreeGUOBMaterial
 
end
 
materialDefinition treebirch06_shadows
 
  setDefinition NeighborhoodTreeGUOBMaterial
 
end
 
 
# TODO: need to redefine the tree shaders, at least skip in reflections
 
#  this is also causing massive batch count for main view (scrolling)
 
# all trees should be combined into a single part/texture atlas with their shadows
 
# render them after the terrain
 
#materialDefinition treeoak01_diffuse
 
#  setDefinition StandardMaterial
 
#end
 
 
 
# ===================================================================================
 
 
materialDefinition neighborhood-canvas-outOfWater
 
  setDefinition NeighborhoodCanvas
 
  addParam  isUnderWater false
 
end
 
 
materialDefinition neighborhood-canvas-underwater
 
  setDefinition NeighborhoodCanvas
 
  addParam  isUnderWater true
 
end
 
 
materialDefinition neighborhood-canvas-straddle
 
  setDefinition NeighborhoodCanvasStraddle
 
end
 
 
materialDefinition neighborhood-underwater-terrain
 
  setDefinition NeighborhoodWaterTerrain
 
end
 
 
materialDefinition waterEdgeBoxMaterial
 
  setDefinition NeighborhoodWaterEdge
 
  addParam waterEdgeTexture "neighborhood-sides-water"
 
end
 
 
materialDefinition terrainEdgeBoxMaterial
 
  setDefinition NeighborhoodTerrainEdge
 
  addParam terrainEdgeTexture "neighborhood-sides-dirt"
 
end
 
 
materialDefinition nhoodTerrainLightingMaterial
 
  setDefinition NHoodTerrainLighting
 
end
 
 
materialDefinition nhoodTerrainLightingMaterialImposter
 
  setDefinition NHoodTerrainLighting
 
  addParam isImposter true
 
end
 
 
materialDefinition nhoodReflectionSkybox
 
  setDefinition SkyboxCompositionPassMaterial
 
  addParam skyboxCubeTexture $skyboxCubeMap
 
end
 
 
materialDefinition lotSkirtReflectionSkybox
 
  setDefinition SkyboxCompositionPassMaterial
 
  addParam skyboxCubeTexture $skyboxCubeMap
 
end
 
 
materialDefinition lotPlacementArrow
 
  setDefinition ImposterArrowMaterial
 
  addParam texture lot-placement-arrow
 
end
 
 
# Material used in highlighting the terrain to depict a house for which no imposter exists yet.
 
materialDefinition DefaultResidentialLotImposterMaterial
 
  setDefinition NHoodTerrainHighlightMaterial
 
  addParam highlightTexture "lothighlight-residential"
 
  addParam highlightAlpha 0.5
 
end
 
 
materialDefinition DefaultCommunityLotImposterMaterial
 
  setDefinition NHoodTerrainHighlightMaterial
 
  addParam highlightTexture "lothighlight-community"
 
  addParam highlightAlpha 0.5
 
end
 
 
  
# Material used in creating a terrain thumbnail for a lot for which no imposter exists yet.
+
# texture, lit, normal mappedm, no specular
materialDefinition DefaultLotThumbnailMaterial
+
materialDefinition RoofTopThumbnail
 
   setDefinition StandardMaterial
 
   setDefinition StandardMaterial
   addParam stdMatBaseTextureEnabled "true"
+
   addParam   stdMatSpecPower 0
   addParam stdMatBaseTextureName "lotselection-done"
+
   addParam   stdMatDiffCoef (0.8, 0.75, 0.75)
   addParam stdMatLightingEnabled true
+
  addParam  stdMatBaseTextureName roof-manor
   addParam stdMatDiffCoef (1, 1, 1)
+
   addParam   stdMatBaseTextureEnabled true
 +
   addParam   stdMatNormalMapTextureName roof-manor-bump
 +
  addParam  stdMatNormalMapTextureEnabled true
 
end
 
end
  
materialDefinition bridge_sides
+
# texture, lit, normal mappedm, no specular
#   setDefinition StandardMaterial
+
# modify this material for roof highlights
  setDefinition PartiallyUnderWaterMaterial
+
materialDefinition RoofTopHighlight
  addParam stdMatAlphaBlendMode none
+
  addParam stdMatBaseTextureEnabled true
+
  addParam stdMatBaseTextureName bridge-sides
+
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
+
  addParam stdMatIsPartlyUnderwater true
+
end
+
 
+
materialDefinition cliff_boulder_material
+
#  setDefinition StandardMaterial
+
  setDefinition PartiallyUnderWaterMaterial
+
  addParam stdMatAlphaBlendMode none
+
  addParam stdMatBaseTextureEnabled true
+
  addParam stdMatBaseTextureName nh-test-cliff
+
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
+
  addParam stdMatIsPartlyUnderwater true
+
end
+
 
+
materialDefinition plesiosaur_skin_material
+
#   setDefinition StandardMaterial
+
  setDefinition PartiallyUnderWaterMaterial
+
  addParam stdMatAlphaBlendMode none
+
  addParam stdMatBaseTextureEnabled true
+
  addParam stdMatBaseTextureName plesiosaur-skin
+
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
+
  addParam stdMatIsPartlyUnderwater true
+
 
+
  # these are mvoing objects, need to be at or above layer 0
+
  addParam nhoodCanvasLayer -4
+
 
+
end
+
 
+
materialDefinition neighborhood_bouyside_material
+
#  setDefinition StandardMaterial
+
  setDefinition PartiallyUnderWaterMaterial
+
  addParam stdMatAlphaBlendMode none
+
  addParam stdMatBaseTextureEnabled true
+
  addParam stdMatBaseTextureName neighborhood_bouyside
+
  addParam stdMatDiffCoef (0.8, 0.8, 0.8)
+
  addParam stdMatIsPartlyUnderwater true
+
 
+
  # these are mvoing objects, need to be at or above layer 0
+
  addParam nhoodCanvasLayer -4
+
end
+
 
+
 
+
materialDefinition RelationshipArchGreen
+
 
   setDefinition StandardMaterial
 
   setDefinition StandardMaterial
   addParam  stdMatSpecPower 20
+
   addParam  stdMatSpecPower 0
   addParam  stdMatDiffCoef (0.3, 1, 0.3)
+
   addParam  stdMatDiffCoef (0.4, 0.385, 0.38)
   addParam  stdMatSpecCoef (1, 1, 1)
+
   addParam  stdMatBaseTextureName roof-redtile
   addParam  stdMatAlphaMultiplier 0.6
+
   addParam  stdMatBaseTextureEnabled true
   addParam  stdMatAlphaBlendMode blend
+
  addParam  stdMatNormalMapTextureName roof-redtile-bump
 +
  addParam  stdMatNormalMapTextureEnabled true
 +
  addParam  stdMatBaseTextureAddressingU clamp
 +
  addParam  stdMatBaseTextureAddressingV clamp
 +
  addParam  stdMatBaseTextureAddressingW clamp
 +
  addParam  stdMatNormalMapTextureAddressingU clamp
 +
  addParam  stdMatNormalMapTextureAddressingV clamp
 +
   addParam  stdMatNormalMapTextureAddressingW clamp
 
end
 
end
  
materialDefinition housePlacementOKHighlight
+
##############################################################
  setDefinition NHoodTerrainHighlightMaterial
+
# Roofs custom
  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
+
define RoofMaterialFF()
   setDefinition NHoodTerrainHighlightMaterial
+
   material
  addParam highlightTexture "lothighlight-roadghost-bad"
+
      shader -layer $roofLayer
  addParam highlightAlpha 0.75
+
end
+
  
materialDefinition DefaultLotHighlight
+
             pass -fixedFunction
  setDefinition NHoodTerrainHighlightMaterial
+
  addParam highlightTexture "lotselection-good"
+
  addParam highlightAlpha 0.25
+
end
+
 
+
materialDefinition ResidentialLotHighlight
+
  setDefinition NHoodTerrainHighlightMaterial
+
  addParam highlightTexture "lothighlight-residential"
+
  addParam highlightAlpha 0.40
+
end
+
 
+
materialDefinition CommunityLotHighlight
+
  setDefinition NHoodTerrainHighlightMaterial
+
  addParam highlightTexture "lothighlight-community"
+
  addParam highlightAlpha 0.40
+
end
+
 
+
materialDefinition DormLotHighlight
+
  setDefinition NHoodTerrainHighlightMaterial
+
  addParam highlightTexture "lothighlight-dorm"
+
  addParam highlightAlpha 0.40
+
end
+
 
+
materialDefinition NotOKLotHighlight
+
  setDefinition NHoodTerrainHighlightMaterial
+
  addParam highlightTexture "lotselection-bad"
+
  addParam highlightAlpha 0.40
+
end
+
 
+
materialDefinition neighborhoodbuildingres1_windows_night
+
  setDefinition NeighborhoodBuildingMaterial
+
  addParam texMaterial neighborhoodbuildingres1_repeat-surface-night
+
  addParam showOnDay false
+
end
+
 
+
materialDefinition neighborhoodbuildingres1_windows_day
+
  setDefinition NeighborhoodBuildingMaterial
+
  addParam texMaterial neighborhoodbuildingres1_repeat-surface
+
  addParam showOnDay true
+
end
+
 
+
# this is commented out because the UI renders this without use of the material
+
#materialDefinition ZoomConePyramid
+
#  setDefinition ZoomConeMaterial
+
#  addParam baseColor (1.0, 1.0, 1.0, 0.5)
+
#end
+
 
+
define LotSkirtPSWater()
+
    shader -layer ($poolWaterLayer+1)
+
        validateRenderShaderContext -vertexFormat position 0 required
+
pass -clipAlways -modifiedEachFrameHint
+
#fillmode wireframe
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
seti textureLights (numLightsOfType(environmentCube)) 
+
depthTest true -enableDepthWrite false         
+
 
+
shaderProgram -target vertexProgram -method compile -version 1_1
+
 
+
bindConstants 0 -bindingID geomToClip -constantCount 4
+
bindConstants 4 -bindingID geomToCamera -constantCount 3
+
 
+
bindConstants 7 -bindingID frameInfo
+
 
+
bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed)
+
bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed)
+
 
+
# pre-evaluate these
+
setf xscale (-$wmXRepeat * $wmXWaveHeight)
+
setf yscale (-$wmYRepeat * $wmYWaveHeight)
+
bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
+
bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
+
bindConstants 18 -bindingID cameraToGlobal -constantCount 3
+
bindConstants 21 -bindingID cameraToGeom -constantCount 3
+
+
if (tsIsDay)     
+
bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)
+
bindConstants 28 -bindingID immediateData -data (-0.3, 0.1, 0.1, 0.0)       
+
else
+
bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)
+
bindConstants 28 -bindingID immediateData -data (-0.3, -0.2, -0.1, 0.0)     
+
endif
+
 
+
shaderSource
+
 
+
float4 frameInfo : register(c7);
+
float4 waveDataX : register(c11);
+
float4 waveDataY : register(c12);
+
float4 waveDataHelper : register(c13);
+
float4x4 clipSpaceMatrix : register(c0);
+
float4x3 cameraSpaceMatrix : register(c4);
+
float4x3 cameraToGlobalMatrix : register(c18);
+
float4x3 cameraToGeomMatrix : register(c21);
+
+
float4 nightColor: register(c25);
+
float4 waterTint: register(c28);
+
           
+
float4 lightDirection : register(c14);
+
float4 lightColor : register(c15);
+
float4 lightSpecular : register(c16);
+
+
const static float4 refractionWeights={1,1,2,0};
+
const static float4 layerBlue={1.0, 1.0, 1.0, 1.0};
+
+
struct InputVertex
+
{
+
float3 position: POSITION0;
+
float3 normal : NORMAL0;
+
float2 alpha  : TEXCOORD1;
+
};
+
+
struct OutputVertex
+
{
+
float4 clipPosition : POSITION;
+
float4 sPos        : TEXCOORD0;
+
float2 Wave0        : TEXCOORD1;
+
float2 Wave1        : TEXCOORD2;
+
float2 Wave2        : TEXCOORD3;
+
float2 Wave3        : TEXCOORD4;
+
float3 Eye          : TEXCOORD5;
+
float4 specular    : COLOR0; 
+
float4 colorTint    : COLOR1;
+
};
+
           
+
+
+
OutputVertex VertexMain( InputVertex inputVertex)
+
{
+
// Do Y-direction waves
+
// r0 = (x, y, z, t)
+
+
OutputVertex outputVertex;
+
+
float4 posAndTime;
+
posAndTime.xyz = inputVertex.position;
+
posAndTime.w = frameInfo.w;
+
+
float temp = dot(posAndTime, waveDataX);
+
float z = sin(temp) * waveDataX.z + inputVertex.position.z;
+
temp = dot(posAndTime, waveDataY);
+
posAndTime.z =  z + sin(temp) * waveDataY.z ;//-0.1f; //The -.01 is a fudge factor to remove some of the edge creep associated with moving the height of the wave. -tom
+
posAndTime.w = 1.0f;
+
+
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix);
+
outputVertex.sPos = float4(0.5f*(outputVertex.clipPosition.ww - outputVertex.clipPosition.xy), outputVertex.clipPosition.ww);
+
+
float3 waveNormal = normalize(inputVertex.normal + float3(cos(temp)*waveDataHelper.xy, 0));
+
float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix));
+
float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix);
+
float3 viewVector = normalize(-cameraSpacePosition);
+
+
float3 halfVector = normalize(viewVector + lightDirection);
+
outputVertex.specular = lightSpecular*pow(dot(cameraSpaceNormal, halfVector), 50)*nightColor*lightColor*0.5;
+
+
+
float2 fTranslation=float2(fmod(frameInfo.w, 100)*0.005, fmod(frameInfo.w, 100)*0.005);
+
float2 vTexCoords = posAndTime.xy*0.05;
+
               
+
// Output bump layers texture coordinates   
+
float fSinTranslation=sin(fTranslation*100)*0.005;
+
float2 vTranslation0=fTranslation+fSinTranslation;
+
float2 vTranslation1=fTranslation-fSinTranslation;
+
float2 vTranslation2=fTranslation;
+
               
+
// Scale texture coordinates to get mix of low/high frequency details
+
outputVertex.Wave0.xy = vTexCoords.xy*0.01+fTranslation*2.0;
+
outputVertex.Wave1.xy = vTexCoords.xy+fTranslation*2.5;
+
outputVertex.Wave2.xy = vTexCoords.xy+fTranslation*-2.3;
+
outputVertex.Wave3.xy = vTexCoords.xy*0.1+fTranslation*1.5;               
+
                                   
+
// compute binormal
+
float3 binormal = normalize(cross(waveNormal, float3(1.0f, 0.0f, 0.0f)));              
+
float3 tangent = normalize(cross(binormal, waveNormal));
+
           
+
// tangent space matrix
+
float3x3 objToTangentSpace = float3x3(tangent, binormal, waveNormal);
+
           
+
float3 viewVectorInObjSpace = mul(viewVector, (float3x3)cameraToGeomMatrix);
+
           
+
outputVertex.Eye.xyz = mul(objToTangentSpace, viewVectorInObjSpace);
+
outputVertex.colorTint = waterTint;
+
outputVertex.colorTint.a = inputVertex.alpha.xxxx;
+
// outputVertex.color = waterTint.xxxx;
+
+
return(outputVertex);
+
}
+
+
endShaderSource 
+
end # shaderProgram
+
+
shaderProgram -target pixelProgram -method compile -version 2_0             
+
shaderSource                           
+
sampler reflect; 
+
sampler bump;         
+
struct cInputPixel
+
{             
+
float4 sPos        : TEXCOORD0;             
+
float2 Wave0        : TEXCOORD1;
+
float2 Wave1        : TEXCOORD2;
+
float2 Wave2        : TEXCOORD3;
+
float2 Wave3        : TEXCOORD4;
+
float3 Eye          : TEXCOORD5;
+
float4 specular    : COLOR0;
+
float4 colorTint    : COLOR1;
+
};
+
           
+
float Fresnel(float NdotL, float fresnelBias, float fresnelPow, float facing)
+
{             
+
return max(fresnelBias + (1.0f - fresnelBias)*pow(facing, fresnelPow), 0.0);
+
}
+
           
+
float4 PixelMain(cInputPixel pi) : COLOR
+
{       
+
float3 vEye = normalize(pi.Eye);
+
 
+
// Get bump layers
+
float3 vBumpTexA = tex2D(bump, pi.Wave0.xy).xyz;
+
float3 vBumpTexB = tex2D(bump, pi.Wave1.xy).xyz;
+
float3 vBumpTexC = tex2D(bump, pi.Wave2.xy).xyz;
+
float3 vBumpTexD = tex2D(bump, pi.Wave3.xy).xyz;
+
               
+
// Average bump layers
+
float3 vBumpTex=normalize(2.0 * (vBumpTexA.xyz + vBumpTexB.xyz + vBumpTexC.xyz + vBumpTexD.xyz)-4.0);
+
               
+
// Apply individual bump scale for refraction and reflection               
+
float3 vReflBump = vBumpTex.xyz ;
+
float4 vReflection = tex2Dproj(reflect, pi.sPos + float4(vReflBump.xy, 0.0f, 0.0f));//*0.001 + float4(2.0*vBumpTexD-1.0f.xxx, 1);
+
             
+
// Compute Fresnel term
+
float NdotL = max(dot(vEye, vReflBump), 0);
+
float facing = (1.0 - NdotL);
+
float fresnel = Fresnel(NdotL, 0.1, 0.5, facing);
+
         
+
vReflection.a = fresnel * 0.5;
+
+
return saturate(vReflection + pi.colorTint);
+
}
+
endShaderSource
+
end                                                   
+
     
+
sampler reflect
+
texture "OceanReflection"
+
textureAddressing clamp clamp
+
end
+
     
+
sampler bump
+
texture "poolShape-body-bump"
+
textureAddressing tile tile
+
end 
+
           
+
end # end pass
+
end
+
enddef
+
 
+
define LotSkirtWater()
+
material     
+
create DetermineHardwareSupport()
+
 
+
if ($useHWShader2Path)
+
create LotSkirtPSWater()
+
else
+
 
+
shader -layer $nhoodWaterLayer
+
validateRenderShaderContext -vertexFormat  position      0 required
+
validateRenderShaderContext -vertexFormat  normal        0 required
+
validateRenderShaderContext -vertexFormat  texcoord      0 required
+
viewerRenderTypePred viewerRenderType
+
           
+
pass -fixedFunction
+
   
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
colorScalar $lotSkirtWaterReflColour 0.50
+
depthTest true -enableDepthWrite false                       
+
   
+
#tring to remove warble I think it may be caused by depth bias.
+
#ffDepthOffset -2
+
   
+
stage
+
ffTextureCoordsSource fromPosition
+
ffTextureMatrix -cameraToClip -scalev ((-0.5 * $ratioW), (-0.5 * $ratioH)) -trans (0.5, 0.5)
+
textureAddressing clamp clamp
+
texture "ScreenReflection"
+
       
+
textureBlend multiply(texture colorScalar) multiply(diffuse colorScalar)
+
end               
+
               
+
end
+
end   
+
endif
+
  end
+
enddef
+
 
+
define LotSkirtWaterNoReflection()
+
  material
+
      # fallback: no reflection.
+
      shader -layer ($nhoodWaterLayer)
+
        viewerRenderTypePred viewerRenderType
+
 
          
 
          
        create DetermineHardwareSupport()
+
            create LightingStates()  
       
+
            create AttenuatedMatCoef(1)                                          
        pass -fixedFunction
+
                             
  # For now, we are diabling the lighting since we simply want to use the vertex colors.
+
             ffDepthOffset 2           
  create LightingStatesNoStdLightsParam(false true)
+
  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
 
+
             colorScalar (.4, .6, .9, .4)     
+
 
              
 
              
             #tring to remove warble I think it may be caused by depth bias.
+
             depthTest true -enableDepthWrite false
            #ffDepthOffset -2                             
+
                       
           
+
            fillmode $stdMatFillMode
+
 
             stage
 
             stage
               #texture reflectionoutdoorwater-envcube
+
               texture $stdMatBaseTextureName
               if ($cubeMapSupport)
+
               textureAddressing clamp clamp
                  texture $skyboxCubeMap
+
              ffTextureCoordsSource 0
                  textureMIPFilterHint disabled
+
textureBlend multiply(texture diffuse) select(texture)
 +
            end #end stage             
  
                  ffTextureCoordsSource fromReflectionVector
+
                       
                  ffTextureMatrix -orientCameraToGlobal
+
         end #pass     
 
+
       end #end shader 
                  textureAddressing clamp clamp clamp
+
   end #end material
                  textureBlend multiply(texture colorScalar) select(colorScalar)
+
              else
+
                  textureBlend select(colorScalar) multiply(diffuse colorScalar)
+
              endif
+
            end 
+
         end  
+
       end
+
   end              
+
 
enddef
 
enddef
  
materialDefinition lotSkirtSea
+
materialDefinition RoofMaterialStrips
  setDefinition LotSkirtWater 
+
   addParam stdMatBaseTextureName roof-manor 
   addParam stdMatLightingEnabled false
+
   addParam stdMatDiffCoef (0.4, 0.385, 0.38)
  addParam stdMatLayer 0
+
   addParam stdMatSpecPower 0
 
+
   addParam stdMatEmissiveCoef 0,0,0
   addParam stdMatDiffCoef (1, 1, 1)  
+
   addParam stdMatSpecCoef 0,0,0    
 
+
   addParam roofLayer 2
   addParam wmReflectionTexture swimming_pool-envcube
+
   setDefinition RoofMaterialFF
 
+
   addParam wmTransparency 0.4
+
 
+
   addParam wmXSpeed        3
+
  addParam wmXRepeat      5
+
  addParam wmXWaveHeight   0.001
+
 
+
   addParam wmYSpeed        3
+
  addParam wmYRepeat      6
+
  addParam wmYWaveHeight  0.001
+
 
+
end
+
 
+
materialDefinition lotSkirtSeaNoReflection
+
   setDefinition LotSkirtWaterNoReflection 
+
 
end
 
end

Revision as of 14:36, 5 March 2008

  1. roof material definitions.
  1. material for roof preview when they're displayed

define RoofPreviewMaterial()

  material
     shader -layer 9999
        vertexFormatPred position      0 true
        vertexFormatPred normal        0 true
        vertexFormatPred blendindices  0 false
        vertexFormatPred targetindices 0 false
        
        pass -fixedFunction         
           colorScalar (0.5, 0.4, 0.4, 1.0)         
           create LightingStatesNoStdLights()
           depthTest true -enableDepthWrite true

alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)

           stage
              textureBlend select(colorScalar) select(colorScalar)
           end 
        end

pass -fixedFunction

           create LightingStatesNoStdLights()
           fillmode wireframe

cullmode none

           depthTest true -enableDepthWrite false
           colorScalar (0, 0, 0)
           stage
              textureBlend select(colorScalar) select(colorScalar)
           end 
        end
     end
  end

enddef

define RoofPreviewMaterialBack()

  material
     shader -layer 9999
        vertexFormatPred position      0 true
        vertexFormatPred normal        0 true
        vertexFormatPred blendindices  0 false
        vertexFormatPred targetindices 0 false
        
        pass -fixedFunction         
           colorScalar (0.25, 0.1, 0.1, 1.0)         
           create LightingStatesNoStdLights()
           depthTest true -enableDepthWrite true

alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)

           stage
              textureBlend select(colorScalar) select(colorScalar)
           end 
        end
     end
  end

enddef

define RoofPreviewMaterialStrip()

  material
     shader -layer 9999
        vertexFormatPred position      0 true
        vertexFormatPred blendindices  0 false
        vertexFormatPred targetindices 0 false
        
        pass -fixedFunction         
           colorScalar (1.0, 1.0, 1.0, 1.0)         
           create LightingStatesNoStdLights()
           depthTest true -enableDepthWrite false	    
           stage
              textureBlend select(colorScalar) select(colorScalar)
           end 
        end
     end
  end

enddef

define RoofPreviewMaterialUpperStrip()

  material
     shader -layer 9999
        vertexFormatPred position      0 true
        vertexFormatPred blendindices  0 false
        vertexFormatPred targetindices 0 false
        
        pass -fixedFunction         
           colorScalar (1.0, 0.0, 0.0, 1.0)         
           create LightingStatesNoStdLights()
           depthTest true -enableDepthWrite false
           stage
              textureBlend select(colorScalar) select(colorScalar)
           end 
        end
     end
  end

enddef

define RoofPreviewMaterialTopBoundary()

  material
     shader -layer 9999
        vertexFormatPred position      0 true
        vertexFormatPred normal        0 true
        vertexFormatPred blendindices  0 false
        vertexFormatPred targetindices 0 false
        
        pass -fixedFunction         
           colorScalar (0.4, 0, 0.1, 1.0)         
           create LightingStatesNoStdLights()
           depthTest true -enableDepthWrite true

alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)

           stage
              textureBlend select(colorScalar) select(colorScalar)
           end 
        end

pass -fixedFunction

           create LightingStatesNoStdLights()
           fillmode wireframe
           depthTest true -enableDepthWrite false
           colorScalar (0, 0, 0)
           stage
              textureBlend select(colorScalar) select(colorScalar)
           end 
        end


     end
  end

enddef

define RoofBumps()

  material
     shader -layer 0
        validateRenderShaderContext -vertexFormat position 0 required
        validateRenderShaderContext -vertexFormat normal 0 required
        validateRenderShaderContext -vertexFormat texcoord 0 required
                         
        pass 
           shaderProgram -target vertexProgram -method compile -version 2_0
              bindConstants 0 -bindingID  geomToClip     -constantCount 4

bindConstants 4 -bindingID geomToCamera -constantCount 3 bindConstants 7 -bindingID cameraToGeom -constantCount 3 bindConstants 10 -bindingID allStandardLightData -constantCount 4 -constantType float bindConstants 14 -bindingID immediateData -data $stdMatDiffCoef bindConstants 15 -bindingID ambientLight -constantCount 1 -constantType float bindConstants 18 -bindingID allStandardLightData2 -constantCount 32

shaderSource float4x4 modelviewproj : register(c0); float4x3 modelview : register(c4); float4x3 modelviewInv : register(c7);

// light direction float4 lightDir0 : register(c18); float4 lightDir1 : register(c19); float4 lightDir2 : register(c20);

// light colors float4 lightCol0 : register(c26); float4 lightCol1 : register(c27); float4 lightCol2 : register(c28);

float4 color : register(c14); float4 ambient : register(c15);

struct a2v

                 {
                    float4 pos		: POSITION;                     
                    float3 normal	: NORMAL;
                    float2 txcoord	: TEXCOORD0;
                    float2 tangent	: TEXCOORD1;                     
                 };
                 struct v2f
                 {
                    float4 hpos		 : POSITION;	
                    float4 color    : COLOR0;                                    
                    float4 ambient  : COLOR1;
                    float2 txcoord	 : TEXCOORD0;

float3 lightDir0: TEXCOORD1; float3 lightDir1: TEXCOORD2; float3 lightDir2: TEXCOORD3; float3 lightCol0: TEXCOORD4; float3 lightCol1: TEXCOORD5; float3 lightCol2: TEXCOORD6; float3 normal : TEXCOORD7;

                 };
                 
                 v2f VertexMain(a2v IN)
                 {

v2f OUT;

// vertex position in object space float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);

// vertex position in clip space OUT.hpos = mul(pos, modelviewproj);

float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);

// compute binormal float3 binormal = normalize(cross(IN.normal, tangent));

// tangent space matrix float3x3 tbn = float3x3(tangent, binormal, IN.normal);

// light direction in object space float3 lt0 = mul(lightDir0, (float3x3)modelviewInv); float3 lt1 = mul(lightDir1, (float3x3)modelviewInv); float3 lt2 = mul(lightDir2, (float3x3)modelviewInv);

// light 0 direction in tangent space OUT.lightDir0 = normalize(mul(tbn, lt0)); OUT.lightDir1 = normalize(mul(tbn, lt1)); OUT.lightDir2 = normalize(mul(tbn, lt2));

OUT.lightCol0 = lightCol0; OUT.lightCol1 = lightCol1; OUT.lightCol2 = lightCol2;

// copy texture coordinates OUT.txcoord=IN.txcoord.xy; OUT.color = color; OUT.color.a = 1;

OUT.ambient = ambient; OUT.normal = IN.normal;

return OUT;

                 }
                 			         

endShaderSource

           end # end shader program
           
              shaderProgram -target pixelProgram -method compile -version 1_4  #-disassemble "c:\sims2ep3\hlslPS.txt"             
              
                 shaderSource    
                    sampler texmap;
                    sampler normmap;
                    sampler roofnoise;
                    
                    struct v2f
                    {
                       float4 hpos		 : POSITION;	   
                       float4 color    : COLOR0;                                                   
                       float4 ambient  : COLOR1;
                       float2 txcoord	 : TEXCOORD0;                                                
                       float3 lightDir0: TEXCOORD1;

float3 lightDir1: TEXCOORD2; float3 lightDir2: TEXCOORD3; float3 lightCol0: TEXCOORD4; float3 lightCol1: TEXCOORD5; //float3 lightCol2: TEXCOORD6; //float3 normal : TEXCOORD7;

                    };
                    float4 PixelMain(v2f pi) : COLOR
                    {  
                       // normal map
                       float4 normal = tex2D(normmap, pi.txcoord);                                       
                                
                       //bump.xyz = 4.0 * (bump.xyz - (0.5).xxx);                            

// bump.z = pi.normal.z;

                       //float3 normal = normalize(bump);                                                
                       
                       // color map
                       float4 color = tex2D(texmap, pi.txcoord);               
                                                                                               
                       float diff0 = saturate(dot(pi.lightDir0, normal.xyz));                        
                       //float diff1 = saturate(dot(pi.lightDir1, normal.xyz));
                       //float diff2 = saturate(dot(pi.lightDir2, normal.xyz));
                                              
                       float4 finalColor;
                       finalColor.rgb = diff0;//(diff0*pi.lightCol0 + diff1*pi.lightCol1 + diff2 + pi.ambient)*pi.color.rgb*color.rgb;
                       
                       finalColor.a = 1.0;                        
                       return finalColor;                                                                                                                    
                    }
                 endShaderSource
              end                                                     
                             
              
              sampler normmap
                 texture "roof-manor-test-bump"#$stdMatNormalMapTextureName                
                 textureAddressing clamp clamp clamp
              end
              
              sampler 1#texmap
                 texture $stdMatBaseTextureName                
                 textureAddressing clamp clamp clamp
              end
        end # end pass
        
     end #end shader
  end # end material

enddef

define RoofSnow()

  material
     shader -layer 2         
        validateRenderShaderContext -vertexFormat position 0 required
        validateRenderShaderContext -vertexFormat normal 0 required
        validateRenderShaderContext -vertexFormat texcoord 0 required
        validateRenderShaderContext -vertexFormat texcoord 1 required
                         
        pass 
           alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
           cullmode $stdMatCullMode
           #fillmode wireframe
           
           shaderProgram -target vertexProgram -method compile -version 2_0
              bindConstants 0 -bindingID  geomToClip     -constantCount 4        
              bindConstants 4 -bindingID  geomToCamera   -constantCount 3

bindConstants 7 -bindingID cameraToGeom -constantCount 3 bindConstants 15 -bindingID ambientLight -constantCount 1 -constantType float bindConstants 18 -bindingID allStandardLightData -constantCount 4 -constantType float

shaderSource float4x4 modelviewproj : register(c0); float4x3 modelview : register(c4); float4x3 modelviewInv : register(c7);

                 // light direction

float4 lightDir0 : register(c18);

                 float4 ambient : register(c15);

struct a2v

                 {
                    float4 pos		: POSITION;                     
                    float3 normal	: NORMAL;
                    float2 tangent	: TEXCOORD0;                     
                 };
                 struct v2f
                 {
                    float4 hpos		 : POSITION;                     

float4 color : TEXCOORD0; float3 camNormal : TEXCOORD1; float3 lightDir : TEXCOORD2; float3 R : TEXCOORD3; float3 tanLightDir : TEXCOORD4; float2 bumpCoords : TEXCOORD5;

                 };
                 
                 v2f VertexMain(a2v IN)
                 {

v2f OUT;

// vertex position in object space float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);

float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);

// compute binormal float3 binormal = normalize(cross(IN.normal, tangent));

// tangent space matrix float3x3 tbn = float3x3(tangent, binormal, IN.normal);

// light direction in object space float3 lt0 = mul(lightDir0, (float3x3)modelviewInv);

// light 0 direction in tangent space OUT.tanLightDir = normalize(mul(tbn, lt0)); OUT.bumpCoords = float2(IN.pos.x, IN.pos.y);


// vertex position in clip space OUT.hpos = mul(pos, modelviewproj);

// copy texture coordinates OUT.camNormal = mul(IN.normal, (float3x3)modelview);

float3 cameraSpacePosition = mul( pos, modelview); float3 viewVector = normalize(cameraSpacePosition); OUT.R = reflect(viewVector, OUT.camNormal);

OUT.color.xyz = tangent*0.5f.xxx + 0.5f.xxx;//ambient.xyz; OUT.color.w = 1.0; OUT.lightDir.xyz = lightDir0.xyz; return OUT;

                 }
                 			         

endShaderSource

           end # end shader program
           
              shaderProgram -target pixelProgram -method compile -version 2_0 # -disassemble "c:\sims2ep3\hlslPS.txt"                            
                 shaderSource                         
                                         
                    struct v2f
                    {
                       float4 hpos	: POSITION;                     

float4 color : TEXCOORD0; float3 camNormal : TEXCOORD1; float3 lightDir : TEXCOORD2; float3 R : TEXCOORD3; float3 tanLightDir : TEXCOORD4;

  	                  float2 bumpCoords : TEXCOORD5;                                          
                    };
                    float4 PixelMain(v2f pi) : COLOR
                    {                          
                       return pi.color;   
                       //return float4(0, 0, 0, 1) + 0.8*max(dot(pi.camNormal, pi.lightDir), 0).xxxx + pi.color;
                    }
                 endShaderSource
              end               
                                                             
                                            
        end # end pass
        
     end #end shader
  end # end material

enddef

define RoofSnowPS2()

  shaderProgram -target pixelProgram -method compile -version 2_0 # -disassemble "c:\sims2ep5\hlslPS.txt"                            
     bindConstants 0 -bindingID	ambientLight -constantCount	1 -constantType	float
     
     shaderSource                         
        float3 ambientLight : register(c0);
        
        sampler normmap;
        struct v2f
        {
           float4 hpos	: POSITION;                             

float4 color : COLOR0; float4 tanHalfAngle : TEXCOORD0; float3 lightColor : TEXCOORD1; float3 tanLightDir : TEXCOORD2;

  	      float2 bumpCoords : TEXCOORD3;                                          
        };
        float4 PixelMain(v2f pi) : COLOR
        {                                                  
           float4 normal0 = 2.0f * (tex2D(normmap, pi.bumpCoords) - 0.5f);                        
           float4 normal1 = 2.0f * (tex2D(normmap, pi.bumpCoords*0.4) - 0.5f);
           float4 normal = 0.5f*(normal0+normal1);
           
           float diffuse = saturate(dot(pi.tanLightDir, normal.xyz))*0.6f;                              
           return float4(float3(diffuse.xxx*float3(0.9,0.9,1) + ambientLight.xxx*0.8)*pi.lightColor.xyz, 1.0);
        }
     endShaderSource
  end               

enddef

define RoofSnowPS1()

  shaderProgram -target pixelProgram -method compile -version 1_1 # -disassemble "c:\sims2ep5\hlslPS.txt"                            
     bindConstants 0 -bindingID	ambientLight -constantCount	1 -constantType	float
     
     shaderSource                         
        float3 ambientLight : register(c0);
        
        sampler normmap;
        struct v2f
        {
           float4 hpos	: POSITION;                             

float4 color : COLOR0; float4 tanHalfAngle : TEXCOORD0; float3 lightColor : TEXCOORD1; float3 tanLightDir : TEXCOORD2;

  	      float2 bumpCoords : TEXCOORD3;                                          
        };
        float4 PixelMain(v2f pi) : COLOR
        {                                                  
           float4 normal = 2.0f * (tex2D(normmap, pi.bumpCoords) - 0.5f);                        
           float diffuse = saturate(dot(pi.tanLightDir, normal.xyz))*0.57f;                              
           return float4(float3(diffuse.xxx*float3(0.85,0.85,1) + ambientLight.xxx)*pi.lightColor.xyz, 1.0);
        }
     endShaderSource
  end               

enddef

define RoofSnow2()

  material
     shader -layer -2         
        validateRenderShaderContext -vertexFormat position 0 required
        validateRenderShaderContext -vertexFormat normal 0 required
        validateRenderShaderContext -vertexFormat texcoord 0 required
        validateRenderShaderContext -vertexFormat texcoord 1 required
                         
        pass 
           alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
           cullmode $stdMatCullMode            
           #fillmode wireframe
           
           shaderProgram -target vertexProgram -method compile -version 1_1
              bindConstants 0 -bindingID  geomToClip     -constantCount 4        
              bindConstants 4 -bindingID  geomToCamera   -constantCount 3

bindConstants 7 -bindingID cameraToGeom -constantCount 3 bindConstants 15 -bindingID ambientLight -constantCount 1 -constantType float bindConstants 18 -bindingID allStandardLightData -constantCount 4 -constantType float

if (tsIsDay)

                 bindConstants 10 -bindingID immediateData -data (1, 1, 1, 1)         
              else
                 bindConstants 10 -bindingID immediateData -data (0.47, 0.47, 1.2, 1)         
              endif

shaderSource float4x4 modelviewproj : register(c0); float4x3 modelview : register(c4); float4x3 modelviewInv : register(c7);

                 // light direction

float4 lightDir0 : register(c18); float4 lightColor0 : register(c10);


                 float4 ambient : register(c15);

struct a2v

                 {
                    float4 pos		: POSITION;                     
                    float3 normal	: NORMAL;
                    float2 tangent	: TEXCOORD0; 
                    float2 bumpcoord : TEXCOORD1;                    
                 };
                 struct v2f
                 {
                    float4 hpos		 : POSITION;                                          

float4 color : COLOR0; float4 tanHalfAngle : TEXCOORD0; float3 lightColor : TEXCOORD1; float3 tanLightDir : TEXCOORD2; float2 bumpCoords : TEXCOORD3;

                 };
                 
                 v2f VertexMain(a2v IN)
                 {

v2f OUT;

// vertex position in object space float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);

float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);

// compute binormal float3 binormal = normalize(cross(IN.normal, tangent));

// tangent space matrix float3x3 tbn = float3x3(tangent, binormal, IN.normal);

// light direction in object space float3 lt0 = mul(lightDir0, (float3x3)modelviewInv);

// light 0 direction in tangent space OUT.tanLightDir = normalize(mul(tbn, lt0)); OUT.bumpCoords = float2(IN.bumpcoord.x, IN.bumpcoord.y);

// compute tangent space view vector // object space view point float3 viewPoint = mul(float4(0, 0, 0, 1), modelviewInv).xyz; float3 viewVecObj = normalize(viewPoint - IN.pos.xyz);

// object space light float3 lightDirObj = normalize(mul(lightDir0, (float3x3)modelviewInv));

// half angle vector in object space float3 halfWayVector = normalize(lightDirObj + viewVecObj);

// transform half angle vector to tangent space OUT.tanHalfAngle.xyz = normalize(mul(tbn, halfWayVector));

// specular shadowing term OUT.tanHalfAngle.w = max(dot(halfWayVector, IN.normal), 0);

// vertex position in clip space OUT.hpos = mul(pos, modelviewproj);

OUT.color.xyz = ambient.xyz; OUT.color.w = 1.0; OUT.lightColor = lightColor0.xyz; return OUT;

                 }
                 			         

endShaderSource

           end # end shader program
              if ($useHWShader1Path)
                 create RoofSnowPS1()                           
              else
                 create RoofSnowPS2()                           
              endif               
              
              sampler normmap
                 texture "snow-ground-bump"
                 textureAddressing tile tile
              end                                      
                                            
        end # end pass
        
     end #end shader
  end # end material

enddef


materialDefinition RoofPreview

  setDefinition StandardMaterial
  addParam   stdMatSpecPower 0
  addParam   stdMatDiffCoef (0.4, 0.385, 0.38)
  addParam   stdMatBaseTextureName roof-manor
  addParam   stdMatBaseTextureEnabled true
  addParam   stdMatCullMode none

end


materialDefinition RoofUnder

  setDefinition StandardMaterial
  addParam   stdMatSpecPower 0
  addParam   stdMatDiffCoef (0.8, 0.8, 0.8)
  addParam   stdMatBaseTextureName roof-manor-under
  addParam   stdMatBaseTextureEnabled true
  addParam   stdMatCullMode none

end

materialDefinition RoofTrim

  setDefinition StandardMaterial
  addParam   stdMatSpecPower 0
  addParam   stdMatDiffCoef (0.8, 0.8, 0.8)
  addParam   stdMatBaseTextureName roof-manor-trim
  addParam   stdMatBaseTextureEnabled true
  addParam   stdMatCullMode none

end

materialDefinition RoofPreviewTopBoundary

  setDefinition RoofPreviewMaterialTopBoundary

end

define RoofTopMaterial()

  material
     shader -layer 0
        seti snowLevel tsHasSnow
        seti rainLevel tsHasRain
        
        if ($rainLevel >= 1)
           pass -fixedFunction -modifiedEachFrameHint
        else
           pass -fixedFunction
        endif
              setb doSkinning false
              setb doMorphing false
              setb cutoutPass false
              create CommonStandardMaterialSetup()
              
              stage

create StandardShaderTextureState(Base) textureBlend multiplyScale2(texture outRegister) multiply(texture outRegister) end

        if ($rainLevel >= 1)
           # first pass at roof rain stage
              stage
                 ffTextureCoordsSource 0
                 texture "causticstiled"
                 textureMatrixAnimation -targetType fixedFunction -atrans sawtooth .1 0 (0,1) (0,0)
                 colorScalar (1.0, 0.98, 1.0, .9)
                 textureAddressing tile tile
                 textureBlend lerpColorScalarAlpha(outRegister texture) lerpColorScalarAlpha(colorScalar)
              end
        endif
              
           end
        if ($snowLevel = 1 and viewerRenderType != $kRenderTypeImposter)
           pass -fixedFunction
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
              depthTest true -enableDepthWrite false
              depthTestFunction acceptIfLessOrEqual
              create LightingStates()
              
              colorScalar (0.25, 0.25, 0.35, 1)
               
              stage                  
                 texture "snow-light-roof-pass1"
                 ffTextureCoordsSource fromPosition
                 ffTextureMatrix -cameraToGlobal -scalev (6, 6) -invert                                 
                 textureAddressing tile tile
                 textureFilterHint bilinear bilinear
                 textureBlend multiplyAdd(texture diffuse colorScalar) select(texture)               
              end
           end            
        endif
        
     end
  end

enddef

define RoofSnowShader()

  create DetermineHardwareSupport()
  if (viewerRenderType != $kRenderTypeImposter)
     if ($useHWShader1Path or $useHWShader2Path)

create RoofSnow2() else

        create RoofSnowFF()
     endif      
  else
     create Null()
  endif

enddef

define RoofSnowFF()

  material
     shader -layer 0      
        pass -fixedFunction         
           create LightingStates() 
           create AttenuatedMatCoef(1)                                           
                                         
           depthTest true -enableDepthWrite true
           colorScalar (1.0, 0.98, 1.0, 1)
                       
           stage               		

textureBlend multiply(colorScalar diffuse) select(texture)

           end #end stage                        
        end
     end
  end

enddef

materialDefinition RoofSnowMaterial

  setDefinition RoofSnowShader   
  addParam stdMatCullMode none

end

  1. texture, lit, normal mappedm, no specular

materialDefinition RoofTop

  setDefinition RoofTopMaterial 
  addParam   stdMatSpecPower 0
  addParam   stdMatDiffCoef (0.4, 0.385, 0.38)
  addParam   stdMatBaseTextureName roof-manor
  addParam   stdMatBaseTextureEnabled true
  addParam   stdMatBaseTextureAddressingU clamp
  addParam   stdMatBaseTextureAddressingV clamp
  addParam   stdMatBaseTextureAddressingW clamp
  addParam   stdMatCullMode none

end


materialDefinition RoofEdges

  setDefinition StandardMaterial
  addParam   stdMatSpecPower 0
  addParam   stdMatDiffCoef (0.8, 0.8, 0.8)
  addParam   stdMatBaseTextureName roof-manor-edges
  addParam   stdMatBaseTextureEnabled true
  addParam   stdMatCullMode none

end

  1. texture, lit, normal mappedm, no specular

materialDefinition RoofTopThumbnail

  setDefinition StandardMaterial
  addParam   stdMatSpecPower 0
  addParam   stdMatDiffCoef (0.8, 0.75, 0.75)
  addParam   stdMatBaseTextureName roof-manor
  addParam   stdMatBaseTextureEnabled true
  addParam   stdMatNormalMapTextureName roof-manor-bump
  addParam   stdMatNormalMapTextureEnabled true

end

  1. texture, lit, normal mappedm, no specular
  2. modify this material for roof highlights

materialDefinition RoofTopHighlight

  setDefinition StandardMaterial
  addParam   stdMatSpecPower 0
  addParam   stdMatDiffCoef (0.4, 0.385, 0.38)
  addParam   stdMatBaseTextureName roof-redtile
  addParam   stdMatBaseTextureEnabled true
  addParam   stdMatNormalMapTextureName roof-redtile-bump
  addParam   stdMatNormalMapTextureEnabled true
  addParam   stdMatBaseTextureAddressingU clamp
  addParam   stdMatBaseTextureAddressingV clamp
  addParam   stdMatBaseTextureAddressingW clamp
  addParam   stdMatNormalMapTextureAddressingU clamp
  addParam   stdMatNormalMapTextureAddressingV clamp
  addParam   stdMatNormalMapTextureAddressingW clamp

end

  1. Roofs custom


define RoofMaterialFF()

  material
     shader -layer $roofLayer
           pass -fixedFunction
        
           create LightingStates() 
           create AttenuatedMatCoef(1)                                           
                             
           ffDepthOffset 2            
           
           depthTest true -enableDepthWrite false
                       
           stage
              texture $stdMatBaseTextureName
              textureAddressing clamp clamp
              ffTextureCoordsSource 0					

textureBlend multiply(texture diffuse) select(texture)

           end #end stage               


        end #pass      
     end #end shader   
  end #end material 

enddef

materialDefinition RoofMaterialStrips

  addParam stdMatBaseTextureName roof-manor   
  addParam stdMatDiffCoef (0.4, 0.385, 0.38)
  addParam stdMatSpecPower 0
  addParam stdMatEmissiveCoef 0,0,0
  addParam stdMatSpecCoef 0,0,0   
  addParam roofLayer 2
  setDefinition RoofMaterialFF

end

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox