Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
Line 1: Line 1:
 +
##############################################################
 +
# Pool Water
 
#
 
#
# roof material definitions.
+
 
 +
seti poolWaterLayer 5
 +
 
 +
 
 +
##############################################################
 +
# Simple water material
 
#
 
#
 +
# This material modulates the vertices by two sin waves --
 +
# one in X and one in Y. It then produces reflection and
 +
# refraction direction texture coordinates suitable for a
 +
# cubic environment map.
  
# 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)
+
#beginshader PoolWaterMaterialTwoWave
 +
#description Pool water with X/Y waves
  
            stage
+
#BeginStdAttrBlock
              textureBlend select(colorScalar) select(colorScalar)
+
            end
+
        end
+
  
pass -fixedFunction       
 
            create LightingStatesNoStdLights()
 
            fillmode wireframe
 
    cullmode none
 
            depthTest true -enableDepthWrite false
 
            colorScalar (0, 0, 0)
 
  
            stage
+
setf wmTransparency  0.5
              textureBlend select(colorScalar) select(colorScalar)
+
#attrdescription Water transparency
            end
+
        end
+
  
       end
+
setf wmXSpeed        3    # min:0 max:100
  end
+
#attrdescription Lookup texture for diffuse intensity.
enddef
+
setf wmXRepeat       1    # min:0 max:100
 +
#attrdescription Lookup texture for diffuse intensity.
 +
setf wmXWaveHeight  0.1  # min:0 max:100
 +
#attrdescription Lookup texture for diffuse intensity.
  
define RoofPreviewMaterialBack()
+
setf wmYSpeed       5    # min:0 max:100
  material
+
#attrdescription Lookup texture for diffuse intensity.
      shader -layer 9999
+
setf wmYRepeat      1.8  # min:0 max:100
        vertexFormatPred position      0 true
+
#attrdescription Lookup texture for diffuse intensity.
        vertexFormatPred normal       0 true
+
setf wmYWaveHeight  0.2  # min:0 max:100
        vertexFormatPred blendindices  0 false
+
#attrdescription Lookup texture for diffuse intensity.
        vertexFormatPred targetindices 0 false
+
       
+
        pass -fixedFunction       
+
            colorScalar (0.25, 0.1, 0.1, 1.0)       
+
            create LightingStatesNoStdLights()
+
  
            depthTest true -enableDepthWrite true
+
set wmReflectionTexture reflectionoutdoorwater-envcube
 +
#attrdescription Environment cube map texture for reflection
  
    alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
setb wmRefractionEnabled false
 +
#attrdescription Whether refraction is enabled
  
            stage
+
set wmRefractionTexture reflectionoutdoorwater-envcube
              textureBlend select(colorScalar) select(colorScalar)
+
#attrdescription Environment cube map texture for refraction
            end
+
        end
+
  
      end
 
  end
 
enddef
 
  
define RoofPreviewMaterialStrip()
+
#EndStdAttrBlock
   material
+
 
       shader -layer 9999
+
define PoolWaterSurfaceMaterial()
         vertexFormatPred position     0 true
+
   material    
        vertexFormatPred blendindices 0 false
+
       shader -layer $poolWaterLayer
         vertexFormatPred targetindices 0 false
+
         validateRenderShaderContext -vertexFormat position 0 required
 +
   
 +
         create DetermineHardwareSupport()
 +
   
 +
        if ($useSWVertexShaderPath or $useFixedFunctionPath)
 +
            # The vertex shader to ripple the water surface is deemed too expensive for SWVS.
 +
            # Note that because on some low-end cards shaders are turned off, DetermineHardwareSupport()
 +
            # will set $useFixedFunctionPath to true and $useSWVertexShaderPath to false; however,
 +
            # since the device is in swvp mode, the RegularWavesHLSL shader would validate anyway, which
 +
            # we don't want. Therefore here we do the simplified water surface if using either SWVS or FFP.
 +
            create SimplifiedWaterSurface()
 +
        else
 +
            if ($useHWShader2Path)
 +
              create HighEndWaterSurface()             
 +
            else
 +
              create RegularWavesHLSL()
 +
            endif
 +
        endif
 
          
 
          
        pass -fixedFunction       
+
      end #end shader
            colorScalar (1.0, 1.0, 1.0, 1.0)       
+
     
            create LightingStatesNoStdLights()
+
      # basic fallback.
 
+
      shader -layer $poolWaterLayer
            depthTest true -enableDepthWrite false    
+
        create SimplifiedWaterSurface()        
 
+
      end #end shader
            stage
+
     
              textureBlend select(colorScalar) select(colorScalar)
+
  end #end material
            end  
+
enddef
        end
+
  
 +
define SimplifiedWaterSurface()
 +
  pass -fixedFunction     
 +
      alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
      depthTest true -enableDepthWrite false
 +
      colorScalar (0.2,0.3,1.0) 0.4           
 +
      stage
 +
        textureBlend select(colorScalar) select(colorScalar)
 
       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
+
define RegularWavesHLSL()
 +
 +
  #DRIVERBUG
 +
  # The -clipAlways flag is needed to work around what appears to be a driver bug.
 +
  # On NVIDIA GF2 class HW, the presence of the cube map texture in the pass below
 +
  # leads to a large performance drop whenever the pass is rendered with clipping disabled.
 +
  # Rendering this pass with clipping enabled avoids the performance drop. In addition,
 +
  # substituting a 2D texture for the cube map texture, or rendering this pass in HW
 +
  # using fixed function vertex processing also avoids the performance drop (but would obviously
 +
  # not have the desired visual result).
 +
  # The cause of this is unknown. This was observed on a GF4GO, driver version 42.58.
 +
pass -clipAlways -modifiedEachFrameHint
 +
#fillmode wireframe
 +
alphaBlend srcFactor(one) add dstFactor(one)
 +
      seti textureLights (numLightsOfType(environmentCube))       
 +
 
 +
shaderProgram -target vertexProgram -method compile -version 1_1
  
            stage
+
bindConstants 0 -bindingID geomToClip -constantCount 4
              textureBlend select(colorScalar) select(colorScalar)
+
bindConstants 4 -bindingID geomToCamera -constantCount 3
            end
+
        end
+
  
      end
+
bindConstants 7 -bindingID frameInfo
  end
+
 
enddef
+
bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed)
 +
bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed)
  
define RoofPreviewMaterialTopBoundary()
+
# pre-evaluate these
  material
+
setf xscale (-$wmXRepeat * $wmXWaveHeight)
      shader -layer 9999
+
setf yscale (-$wmYRepeat * $wmYWaveHeight)
        vertexFormatPred position      0 true
+
bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
        vertexFormatPred normal        0 true
+
bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
        vertexFormatPred blendindices  0 false
+
bindConstants 18 -bindingID cameraToGlobal -constantCount 3
        vertexFormatPred targetindices 0 false
+
 
          
 
          
         pass -fixedFunction          
+
         if (tsIsDay)          
             colorScalar (0.4, 0, 0.1, 1.0)         
+
             bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)         
             create LightingStatesNoStdLights()
+
        else
 +
             bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)        
 +
        endif
  
            depthTest true -enableDepthWrite true
+
shaderSource
  
    alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
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);
 +
 +
            float4 nightColor: register(c25);
 +
           
 +
float4 lightDirection : register(c14);
 +
float4 lightColor : register(c15);
 +
const static float4 refractionWeights={1,1,2,0};
 +
 +
const static float4 layerBlue={0.3, 0.7, 1.0, 1};
 +
 +
struct InputVertex
 +
{
 +
float3 position: POSITION0;
 +
float3 normal : NORMAL0;
 +
};
 +
 +
struct OutputVertex
 +
{
 +
float4 clipPosition : POSITION;
 +
float4 diffuseColor: COLOR0;
 +
float4 specularColor: COLOR1;
 +
float3 reflection : TEXCOORD0;
 +
 +
};
 +
           
 +
 +
 +
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);
 +
 +
// z = h * sin(...)
  
            stage
+
float z;
              textureBlend select(colorScalar) select(colorScalar)
+
// scale temp to fit -pi +pi range
            end
+
//temp = temp *  (1 / (2 * 3.14159)) + 0.5;
        end
+
 +
float3 waveNormal;
 +
 +
z = sin(temp) * waveDataX.z + inputVertex.position.z;
 +
 +
waveNormal.x = cos(temp) * waveDataHelper.x + inputVertex.normal.x;
 +
 +
temp = dot(posAndTime, waveDataY);
 +
//temp = temp *  (1 / (2 * 3.14159)) + 0.5;
 +
 +
z +=  sin(temp) * waveDataY.z;
 +
 +
waveNormal.y = cos(temp) * waveDataHelper.y + inputVertex.normal.y;
 +
 +
waveNormal.z = inputVertex.normal.z;
 +
 +
waveNormal = normalize(waveNormal);
 +
 +
posAndTime.w = 1.0;
 +
posAndTime.z = z;
 +
 +
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix);
 +
 +
float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix));
  
pass -fixedFunction       
+
float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix);
            create LightingStatesNoStdLights()
+
            fillmode wireframe
+
float3 viewVector = normalize(-cameraSpacePosition);
            depthTest true -enableDepthWrite false
+
            colorScalar (0, 0, 0)
+
float3 R = reflect(viewVector, cameraSpaceNormal);
 +
 +
outputVertex.reflection = mul( -R, cameraToGlobalMatrix);
 +
 +
 +
float fresnel = dot(viewVector , cameraSpaceNormal);
 +
 +
float rdotl = saturate(dot(R, lightDirection));
 +
 +
float I = pow(rdotl+0.1, 15); // fudge factor to punch up the highlights.
 +
 +
              nightColor = nightColor * 2;                         
 +
                         
 +
outputVertex.diffuseColor = ((1.0 - fresnel) * saturate(nightColor) * 0.5) * layerBlue;
 +
 +
outputVertex.specularColor = I;
 +
return(outputVertex);
 +
 +
}
  
            stage
+
 
              textureBlend select(colorScalar) select(colorScalar)
+
endShaderSource 
            end  
+
end # shaderProgram
        end
+
 +
stage
 +
texture $wmReflectionTexture
 +
textureAddressing clamp clamp clamp
 +
textureBlend multiply(texture diffuse) select(diffuse)
 +
end
 +
     
 +
     
 +
addSpecular true
 +
 +
end # end pass
  
  
      end
 
  end
 
 
enddef
 
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
+
define HighEndWaterSurface()
                  {
+
    
                    float4 hpos : POSITION;
+
pass -clipAlways -modifiedEachFrameHint
                    float4 color   : COLOR0;                                   
+
#fillmode wireframe
                    float4 ambient  : COLOR1;
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
                    float2 txcoord : TEXCOORD0;
+
      seti textureLights (numLightsOfType(environmentCube)
                  float3 lightDir0: TEXCOORD1;
+
      depthTest true -enableDepthWrite false         
                  float3 lightDir1: TEXCOORD2;
+
 
                  float3 lightDir2: TEXCOORD3;
+
shaderProgram -target vertexProgram -method compile -version 1_1
                  float3 lightCol0: TEXCOORD4;
+
                  float3 lightCol1: TEXCOORD5;
+
                  float3 lightCol2: TEXCOORD6;
+
                  float3 normal : TEXCOORD7;
+
                  };
+
                 
+
                  v2f VertexMain(a2v IN)
+
                  {
+
                  v2f OUT;
+
  
                  // vertex position in object space
+
bindConstants 0 -bindingID geomToClip -constantCount 4
                  float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);                                    
+
bindConstants 4 -bindingID geomToCamera -constantCount 3
                 
+
                  // 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;
+
bindConstants 7 -bindingID frameInfo
                  }
+
 
                         
+
bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed)
      endShaderSource
+
bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed)
            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
+
# pre-evaluate these
                    { 
+
setf xscale (-$wmXRepeat * $wmXWaveHeight)
                        // normal map
+
setf yscale (-$wmYRepeat * $wmYWaveHeight)
                        float4 normal = tex2D(normmap, pi.txcoord);                                     
+
bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
                               
+
bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
                        //bump.xyz = 4.0 * (bump.xyz - (0.5).xxx);                           
+
bindConstants 18 -bindingID cameraToGlobal -constantCount 3
//                        bump.z = pi.normal.z;
+
bindConstants 21 -bindingID cameraToGeom -constantCount 3
                        //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
+
        if (tsIsDay)       
  end # end material
+
            bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)       
enddef
+
        else
 +
            bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)       
 +
        endif
  
define RoofSnow()
+
shaderSource
  material
+
 
      shader -layer 2       
+
float4 frameInfo : register(c7);
        validateRenderShaderContext -vertexFormat position 0 required
+
float4 waveDataX : register(c11);
        validateRenderShaderContext -vertexFormat normal 0 required
+
float4 waveDataY : register(c12);
        validateRenderShaderContext -vertexFormat texcoord 0 required
+
float4 waveDataHelper : register(c13);
        validateRenderShaderContext -vertexFormat texcoord 1 required
+
float4x4 clipSpaceMatrix : register(c0);
                         
+
float4x3 cameraSpaceMatrix : register(c4);
        pass
+
float4x3 cameraToGlobalMatrix : register(c18);
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
float4x3 cameraToGeomMatrix : register(c21);
            cullmode $stdMatCullMode
+
             #fillmode wireframe
+
 +
             float4 nightColor: register(c25);
 
              
 
              
            shaderProgram -target vertexProgram -method compile -version 2_0
+
float4 lightDirection : register(c14);
              bindConstants 0 -bindingID  geomToClip    -constantCount 4        
+
float4 lightColor : register(c15);
               bindConstants 4 -bindingID  geomToCamera  -constantCount 3
+
float4 lightSpecular : register(c16);
      bindConstants 7 -bindingID  cameraToGeom  -constantCount 3
+
const static float4 refractionWeights={1,1,2,0};
      bindConstants 15 -bindingID ambientLight -constantCount 1 -constantType float                        
+
      bindConstants 18 -bindingID allStandardLightData -constantCount 4 -constantType float      
+
const static float4 layerBlue={0.3, 0.7, 1.0, 1};
     
+
      shaderSource
+
struct InputVertex
        float4x4 modelviewproj : register(c0);
+
{
        float4x3 modelview : register(c4);
+
float3 position: POSITION0;
      float4x3 modelviewInv : register(c7);            
+
float3 normal : NORMAL0;
                  // light direction
+
};
      float4 lightDir0 : register(c18);      
+
     
+
struct OutputVertex
                  float4 ambient : register(c15);
+
{
           
+
float4 clipPosition : POSITION;
      struct a2v
+
float4 sPos        : TEXCOORD0;
                  {
+
float2 Wave0       : TEXCOORD1;
                    float4 pos : POSITION;                    
+
               float2 Wave1        : TEXCOORD2;
                    float3 normal : NORMAL;
+
              float2 Wave2        : TEXCOORD3;
                    float2 tangent : TEXCOORD0;                    
+
              float2 Wave3        : TEXCOORD4;
                  };
+
              float3 Eye          : TEXCOORD5;
 +
              float4 specular    : COLOR0;   
 +
};
 +
           
 +
 +
 +
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;
 +
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+fTranslation*2.0;
 +
              outputVertex.Wave1.xy = vTexCoords.xy*2.0+fTranslation*4.0;
 +
              outputVertex.Wave2.xy = vTexCoords.xy*7.0+fTranslation*2.0;
 +
              outputVertex.Wave3.xy = vTexCoords.xy*12.0+fTranslation;               
 +
                                   
 +
            // 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);
 +
 +
 +
return(outputVertex);
 +
}
  
                  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
+
endShaderSource 
                  float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);  
+
end # shaderProgram
                 
+
                  float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);
+
shaderProgram -target pixelProgram -method compile -version 2_0             
                                   
+
        shaderSource                           
                  // compute binormal
+
            sampler reflect;
                  float3 binormal = normalize(cross(IN.normal, tangent));
+
            sampler bump;        
                 
+
            struct cInputPixel
                  // tangent space matrix
+
            {             
                  float3x3 tbn = float3x3(tangent, binormal, IN.normal);
+
              float4 sPos        : TEXCOORD0;              
                 
+
              float2 Wave0        : TEXCOORD1;
                  // light direction in object space                  
+
              float2 Wave1        : TEXCOORD2;
                  float3 lt0 = mul(lightDir0, (float3x3)modelviewInv);
+
              float2 Wave2        : TEXCOORD3;
                 
+
              float2 Wave3        : TEXCOORD4;
                  // light 0 direction in tangent space                                    
+
              float3 Eye          : TEXCOORD5;
                  OUT.tanLightDir = normalize(mul(tbn, lt0));
+
              float4 specular    : COLOR0;
                  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"                           
+
            float Fresnel(float NdotL, float fresnelBias, float fresnelPow, float facing)
                  shaderSource                       
+
            {             
                                         
+
               return max(fresnelBias + (1.0f - fresnelBias)*pow(facing, fresnelPow), 0.0);
                    struct v2f
+
            }
                    {
+
           
                        float4 hpos : POSITION;                   
+
            float4 PixelMain(cInputPixel pi) : COLOR
                    float4 color : TEXCOORD0;
+
            {       
                    float3 camNormal : TEXCOORD1;
+
              float3 vEye = normalize(pi.Eye);
                    float3 lightDir : TEXCOORD2;
+
                    float3 R : TEXCOORD3;   
+
                    float3 tanLightDir : TEXCOORD4; 
+
                    float2 bumpCoords : TEXCOORD5;                                         
+
                    };
+
  
                    float4 PixelMain(v2f pi) : COLOR
+
              // Get bump layers
                    {                         
+
              float3 vBumpTexA = tex2D(bump, pi.Wave0.xy).xyz;
                        return pi.color;  
+
              float3 vBumpTexB = tex2D(bump, pi.Wave1.xy).xyz;
                        //return float4(0, 0, 0, 1) + 0.8*max(dot(pi.camNormal, pi.lightDir), 0).xxxx + pi.color;
+
              float3 vBumpTexC = tex2D(bump, pi.Wave2.xy).xyz;
                    }
+
              float3 vBumpTexD = tex2D(bump, pi.Wave3.xy).xyz;
                  endShaderSource
+
               
              end              
+
              // Average bump layers
                                                             
+
              float3 vBumpTex=normalize(2.0 * (vBumpTexA.xyz + vBumpTexB.xyz + vBumpTexC.xyz + vBumpTexD.xyz)-4.0);
                                           
+
               
         end # end pass
+
              // Apply individual bump scale for refraction and reflection             
          
+
              float3 vReflBump = vBumpTex.xyz * float3(0.1, 0.1, 1.0)
       end #end shader
+
             
  end # end material
+
              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.2, 5.0, facing);
 +
                             
 +
              vReflection.a = fresnel;             
 +
              return saturate(vReflection + float4(0.0, 0.25, 0.5, 0.0) + pi.specular);
 +
            }
 +
        endShaderSource
 +
      end                                                    
 +
     
 +
      sampler reflect
 +
         texture "PoolReflection"
 +
        textureAddressing clamp clamp
 +
      end
 +
     
 +
      sampler bump
 +
         texture "poolShape-body-bump"
 +
        textureAddressing tile tile
 +
       end  
 +
           
 +
end # end pass
 +
 
 
enddef
 
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
+
#endshader PoolWaterSurfaceMaterial
        {                                                 
+
            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"                           
+
# NOTE:
       bindConstants 0 -bindingID ambientLight -constantCount 1 -constantType float
+
# refraction in vector terms:
 +
#  v  = incoming unit vector
 +
#  n  = surface normal
 +
#  v' = refracted vector
 +
#  a  = refraction ratio, ni / nr =~ 0.75 for air->water
 +
#
 +
# v' = v - sn
 +
# where s = sqrt(1 - a^2 (1 - (v.n)^2))  - v.n.
 +
 
 +
 
 +
 
 +
##########################################################
 +
# Caustics
 +
#
 +
 
 +
define TiledTextureAnimShaderProgram(tilesX tilesY speed)
 +
   shaderProgram -target vertexProgram -method assemble
 +
 
 +
      bindConstants 0 -bindingID frameInfo            # for time in .w
 +
       bindConstants 1 -data      (&tilesX, &tilesY, &speed, 1)        # tx, ty, speed
 +
      bindConstants 2 -data      ((1/&tilesX), (1/&tilesY), (&tilesY - 1), 1) # 1/tx 1/ty ty-1     
 +
      if (tsIsDay)
 +
        bindConstants 3 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)
 +
      else
 +
        bindConstants 3 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)
 +
      endif
 +
     
 +
      shaderSource
 +
        vs_1_1
 +
        dcl_position v0
 +
        dcl_texcoord v1
 +
 
 +
        mov oPos, v0  # clip space quad, no transforms needed.
 
        
 
        
      shaderSource                       
+
        # tiled texture animation
         float3 ambientLight : register(c0);
+
         mov r0, c0
 +
        mul r1, c1.z, r0.w
 +
        frc r5.y, r1.y
 
          
 
          
         sampler normmap;
+
         mul r1, c1.y, r5.y    # f -> [0, ty)
         struct v2f
+
         frc r5.y, r1
         {
+
         sub r3.y, r1, r5.y    # v' = floor(f)
            float4 hpos : POSITION;                           
+
       
        float4 color : COLOR0;                    
+
        mul r1, c1.x, r5.y    # f -> [0, tx)
        float4 tanHalfAngle : TEXCOORD0;
+
        frc r5.y, r1
        float3 lightColor : TEXCOORD1;               
+
         sub r3.x, r1, r5.y    # u' = floor(f)
        float3 tanLightDir : TEXCOORD2; 
+
        float2 bumpCoords : TEXCOORD3;                                         
+
         };
+
  
         float4 PixelMain(v2f pi) : COLOR
+
         add r8.xy, v1.xy, r3.xy
        {                                                 
+
        mul oT0.xy, r8.xy, c2.xy
            float4 normal = 2.0f * (tex2D(normmap, pi.bumpCoords) - 0.5f);                       
+
       
            float diffuse = saturate(dot(pi.tanLightDir, normal.xyz))*0.57f;                             
+
        mov oD0, c3 # also spit out diffuse color with modcolor information
            return float4(float3(diffuse.xxx*float3(0.85,0.85,1) + ambientLight.xxx)*pi.lightColor.xyz, 1.0);
+
          
         }
+
 
       endShaderSource
 
       endShaderSource
   end              
+
 
 +
   end
 
enddef
 
enddef
  
define RoofSnow2()
+
define CausticsGeneratorMaterial()  
   material
+
   material    
       shader -layer -2       
+
       # This material updates a render target with the current frame
        validateRenderShaderContext -vertexFormat position 0 required
+
      # of the tile animation. This is the only way to handle a repeated
        validateRenderShaderContext -vertexFormat normal 0 required
+
      # animating texture (not to mention using it for projective texturing)
        validateRenderShaderContext -vertexFormat texcoord 0 required
+
      # in the absence of clip maps.
        validateRenderShaderContext -vertexFormat texcoord 1 required
+
     
                         
+
      create DetermineHardwareSupport()
        pass
+
     
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
      if ($causticsEnabled and $useFixedFunctionPath = false and $useSWVertexShaderPath = false)
            cullmode $stdMatCullMode           
+
     
            #fillmode wireframe
+
        shader -layer +9999
           
+
            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
+
            pass             
                  {
+
              renderClipSpaceRect
                    float4 hpos : POSITION;                                         
+
             
                  float4 color : COLOR0;                  
+
              renderTarget causticsTile -fixed (64, 64) -allocateDepthBuffer false -undo
                  float4 tanHalfAngle : TEXCOORD0;
+
                  float3 lightColor : TEXCOORD1;
+
                  float3 tanLightDir : TEXCOORD2;                             
+
                  float2 bumpCoords : TEXCOORD3;                  
+
                  };
+
                 
+
                  v2f VertexMain(a2v IN)
+
                  {
+
                  v2f OUT;
+
  
                  // vertex position in object space
+
              create TiledTextureAnimShaderProgram(8 4 1)
                  float4 pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);  
+
             
                 
+
              alphaBlend srcFactor(one) add dstFactor(zero)
                  float3 tangent = float3(IN.tangent.x, IN.tangent.y, 0);
+
              alphaTest false 0
                                   
+
              alphaTestFunction acceptIfGreater
                  // 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)
+
               depthTest false -enableDepthWrite false
                  create RoofSnowPS1()                         
+
               depthTestFunction accept
               else
+
 
                  create RoofSnowPS2()                         
+
               # 7/24/2004 Fix bug with kRenderTypeNormal default stencil state and nv40. 
               endif                
+
              # It reads random stencil values even this target has no depth stencil target.                
 +
              # This stencil call will break pixo, but pixo does not show caustics.
 +
              stencil false
 +
 
 +
              fillmode $stdMatFillMode                           
 
                
 
                
               sampler normmap
+
               shaderProgram -target pixelProgram -method compile -version 1_1             
                   texture "snow-ground-bump"
+
                  shaderSource                           
                   textureAddressing tile tile
+
                    sampler caustics;
               end                                    
+
                    struct cInputPixel
                                           
+
                    {
         end # end pass
+
                        float4 color : COLOR;
 +
                        float2 tc0 : TEXCOORD0;
 +
                    };
 +
                    float4 PixelMain(cInputPixel pi) : COLOR
 +
                    {       
 +
                        float4 texColor = tex2D(caustics, pi.tc0);                                               
 +
                        return texColor*pi.color;                       
 +
                    }
 +
                  endShaderSource
 +
              end                                                   
 +
             
 +
              sampler 0
 +
                   texture causticsTiled
 +
                   textureAddressing tile tile                
 +
               end
 +
                             
 +
            end 
 +
         end
 +
      else
 +
        shader
 
          
 
          
      end #end shader
+
        end
   end # end material
+
      endif
 +
   end
 
enddef
 
enddef
 +
 +
setf causticsStrength 0.8
 +
setf causticsBaseStrength 0.5
 +
 +
 +
###################################################
 +
# Materials
 +
#
  
  
materialDefinition RoofPreview
+
# Pool surface materials
   setDefinition StandardMaterial
+
materialDefinition "poolWater-0"
   addParam   stdMatSpecPower 0
+
   setDefinition PoolWaterSurfaceMaterial
  addParam  stdMatDiffCoef (0.4, 0.385, 0.38)
+
   addParam stdMatDiffCoef (0, 0, 1)   
  addParam   stdMatBaseTextureName roof-manor
+
   addParam wmRefractionEnabled true
   addParam   stdMatBaseTextureEnabled true
+
  addParam  stdMatCullMode none
+
 
end
 
end
  
 +
materialDefinition "poolWater-1"
 +
  setDefinition PoolWaterSurfaceMaterial 
 +
  addParam stdMatLightingEnabled false
 +
  addParam stdMatLayer 0
 +
 
 +
  addParam stdMatDiffCoef (1, 1, 1) 
  
materialDefinition RoofUnder
+
   addParam wmReflectionTexture swimming_pool-envcube
   setDefinition StandardMaterial
+
 
   addParam   stdMatSpecPower 0
+
   addParam wmTransparency 0.4
   addParam  stdMatDiffCoef (0.8, 0.8, 0.8)
+
 
   addParam   stdMatBaseTextureName roof-manor-under
+
  addParam wmXSpeed        3
   addParam   stdMatBaseTextureEnabled true
+
  addParam wmXRepeat      5
   addParam  stdMatCullMode none
+
   addParam wmXWaveHeight   0.01
 +
 
 +
   addParam wmYSpeed        3
 +
   addParam wmYRepeat      6
 +
   addParam wmYWaveHeight   0.01
 
end
 
end
  
materialDefinition RoofTrim
+
materialDefinition "poolWater-2"
   setDefinition StandardMaterial
+
   setDefinition PoolWaterSurfaceMaterial
   addParam   stdMatSpecPower 0
+
   addParam stdMatLightingEnabled false
   addParam   stdMatDiffCoef (0.8, 0.8, 0.8)
+
  addParam stdMatLayer 0
   addParam   stdMatBaseTextureName roof-manor-trim
+
 
   addParam  stdMatBaseTextureEnabled true
+
   addParam stdMatDiffCoef (0, 0, 1) 
   addParam  stdMatCullMode none
+
 
 +
  addParam wmTransparency 0.5
 +
 
 +
   addParam wmXSpeed        3
 +
  addParam wmXRepeat      12
 +
   addParam wmXWaveHeight   0 #0.02
 +
 
 +
   addParam wmYSpeed        3
 +
  addParam wmYRepeat      12
 +
  addParam wmYWaveHeight   0 # 0.02
 
end
 
end
  
materialDefinition RoofPreviewTopBoundary
+
materialDefinition "poolWater-4"
   setDefinition RoofPreviewMaterialTopBoundary
+
   setDefinition WaterAnimatingTextures
 +
  addParam waterSpeed 0.3
 
end
 
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)
+
# Pool depth layer materials
             pass -fixedFunction
+
 
 +
# this is here soley because the layering on standard material
 +
# is too constrained. We need a layer less than 7, or we'll
 +
# render over transparent areas of Sims (e.g. hair) when
 +
# they're in the pool at a shallow view angle.
 +
setc poolLayerColour (0, 0.5, 1.0, 1.0)
 +
define PoolDepthLayerMaterial()
 +
  material   
 +
      create DetermineHardwareSupport()
 +
      if ($useSWVertexShaderPath or $useFixedFunctionPath)
 +
        shader
 +
        end
 +
      else
 +
        shader -layer $poolWaterLayer
 +
             validateRenderShaderContext -vertexFormat position 0 required
 +
            validateRenderShaderContext -vertexFormat texcoord 0 required
 +
           
 +
            pass
 
               alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 
               alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
              depthTest true -enableDepthWrite false
+
      depthTest true -enableDepthWrite false
               depthTestFunction acceptIfLessOrEqual
+
               #fillmode wireframe
               create LightingStates()
+
               shaderProgram -target vertexProgram -method compile -version 1_1
 +
                  bindConstants 0 -bindingID geomToClip -constantCount 4
 +
                  bindConstants 4 -bindingID immediateData -data ($poolLayerColour)
 +
                 
 +
                  shaderSource
 +
                    float4x4 clipSpaceMatrix      : register(c0);
 +
                    float4  poolLayer            : register(c4);
 +
                   
 +
                    struct cVertexIn
 +
                    {
 +
                        float3 mPosition : POSITION0; 
 +
                        float2 alpha    : TEXCOORD0;                 
 +
                    };
 +
                   
 +
                    struct cVertexOut
 +
                    {
 +
                        float4 mClipPosition : POSITION;                   
 +
                        float4 mColor        : COLOR0;
 +
                    };
 +
                   
 +
                    cVertexOut VertexMain(cVertexIn vertexIn)
 +
                    {               
 +
                        cVertexOut result;                                                                       
 +
                        result.mClipPosition = mul(float4(vertexIn.mPosition, 1), clipSpaceMatrix);                   
 +
                        result.mColor = float4(poolLayer.r, poolLayer.g, poolLayer.b, poolLayer.a * vertexIn.alpha.x);
 +
                        return result;       
 +
                    }
 +
                   
 +
                  endShaderSource
 +
              end                     
 
                
 
                
               colorScalar (0.25, 0.25, 0.35, 1)
+
               shaderProgram -target pixelProgram -method compile -version 1_1
               
+
                   shaderSource                 
              stage                 
+
                    float4 PixelMain(float4 color : COLOR) : COLOR
                  texture "snow-light-roof-pass1"
+
                    {                                           
                   ffTextureCoordsSource fromPosition
+
                        return color;
                  ffTextureMatrix -cameraToGlobal -scalev (6, 6) -invert                               
+
                    }
                  textureAddressing tile tile
+
                   endShaderSource
                  textureFilterHint bilinear bilinear
+
               end                      
                   textureBlend multiplyAdd(texture diffuse colorScalar) select(texture)             
+
             end         
               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
+
       endif
 
   end
 
   end
 
enddef
 
enddef
  
materialDefinition RoofSnowMaterial
+
materialDefinition "poolWaterLayer-0"
   setDefinition RoofSnowShader 
+
   # this layer does nothing but create the caustics tile.
   addParam stdMatCullMode none
+
   setDefinition CausticsGeneratorMaterial 
end
+
end  
  
# texture, lit, normal mappedm, no specular
+
materialDefinition "poolWaterLayer-1"
materialDefinition RoofTop
+
   setDefinition PoolDepthLayerMaterial    
   setDefinition RoofTopMaterial
+
   addParam poolLayerColour (0, 0.5, 1.0, 0.2)
  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
 
end
 
+
materialDefinition "poolWaterLayer-2"
 
+
   setDefinition PoolDepthLayerMaterial 
materialDefinition RoofEdges
+
   addParam poolLayerColour (0, 0.5, 1.0, 0.2)     
   setDefinition StandardMaterial
+
end
   addParam   stdMatSpecPower 0
+
materialDefinition "poolWaterLayer-3"
  addParam  stdMatDiffCoef (0.8, 0.8, 0.8)
+
   setDefinition PoolDepthLayerMaterial
   addParam  stdMatBaseTextureName roof-manor-edges
+
   addParam poolLayerColour (0, 0.5, 1.0, 0.5)    
   addParam  stdMatBaseTextureEnabled true
+
   addParam  stdMatCullMode none
+
 
end
 
end
  
# texture, lit, normal mappedm, no specular
+
materialDefinition mtl_0
materialDefinition RoofTopThumbnail
+
   setDefinition CausticsGeneratorMaterial
   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
 
end
  
# texture, lit, normal mappedm, no specular
+
materialDefinition "lightingwallpoolsimple_reflective"
# modify this material for roof highlights
+
   setDefinition StandardMaterial   
materialDefinition RoofTopHighlight
+
   addParam  stdMatDiffCoef (0.8, 0.8, 0.8)  
   setDefinition StandardMaterial
+
   addParam  stdMatAlphaMultiplier 1.0
  addParam   stdMatSpecPower 0
+
  addParam  stdMatAlphaBlendMode none
   addParam  stdMatDiffCoef (0.4, 0.385, 0.38)
+
  addParam  stdMatSpecCoef 0.091,0.091,0.091
   addParam  stdMatBaseTextureName roof-redtile
+
 
   addParam  stdMatBaseTextureEnabled true
 
   addParam  stdMatBaseTextureEnabled true
   addParam  stdMatNormalMapTextureName roof-redtile-bump
+
   addParam  stdMatBaseTextureName lightingwallpoolsimple-surface
   addParam  stdMatNormalMapTextureEnabled true
+
   addParam  stdMatEnvCubeLockedToCamera 0
   addParam  stdMatBaseTextureAddressingU clamp
+
   addParam  stdMatEnvCubeMode reflection
   addParam  stdMatBaseTextureAddressingV clamp
+
   addParam  stdMatEnvCubeTextureName reflectionkitchenhighcontrast-envcube
   addParam  stdMatBaseTextureAddressingW clamp
+
   addParam  forceIgnoreShapeBlend true
  addParam  stdMatNormalMapTextureAddressingU clamp
+
  addParam  stdMatNormalMapTextureAddressingV clamp
+
  addParam  stdMatNormalMapTextureAddressingW clamp
+
end
+
 
+
##############################################################
+
# 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
 
end

Revision as of 14:40, 5 March 2008

  1. Pool Water

seti poolWaterLayer 5


  1. Simple water material
  2. This material modulates the vertices by two sin waves --
  3. one in X and one in Y. It then produces reflection and
  4. refraction direction texture coordinates suitable for a
  5. cubic environment map.


  1. beginshader PoolWaterMaterialTwoWave
  2. description Pool water with X/Y waves
  1. BeginStdAttrBlock


setf wmTransparency 0.5

  1. attrdescription Water transparency

setf wmXSpeed 3 # min:0 max:100

  1. attrdescription Lookup texture for diffuse intensity.

setf wmXRepeat 1 # min:0 max:100

  1. attrdescription Lookup texture for diffuse intensity.

setf wmXWaveHeight 0.1 # min:0 max:100

  1. attrdescription Lookup texture for diffuse intensity.

setf wmYSpeed 5 # min:0 max:100

  1. attrdescription Lookup texture for diffuse intensity.

setf wmYRepeat 1.8 # min:0 max:100

  1. attrdescription Lookup texture for diffuse intensity.

setf wmYWaveHeight 0.2 # min:0 max:100

  1. attrdescription Lookup texture for diffuse intensity.

set wmReflectionTexture reflectionoutdoorwater-envcube

  1. attrdescription Environment cube map texture for reflection

setb wmRefractionEnabled false

  1. attrdescription Whether refraction is enabled

set wmRefractionTexture reflectionoutdoorwater-envcube

  1. attrdescription Environment cube map texture for refraction


  1. EndStdAttrBlock

define PoolWaterSurfaceMaterial()

  material      
     shader -layer $poolWaterLayer
        validateRenderShaderContext -vertexFormat position 0 required

        create DetermineHardwareSupport()
   
        if ($useSWVertexShaderPath or $useFixedFunctionPath)
           # The vertex shader to ripple the water surface is deemed too expensive for SWVS.
           # Note that because on some low-end cards shaders are turned off, DetermineHardwareSupport()
           # will set $useFixedFunctionPath to true and $useSWVertexShaderPath to false; however, 
           # since the device is in swvp mode, the RegularWavesHLSL shader would validate anyway, which
           # we don't want. Therefore here we do the simplified water surface if using either SWVS or FFP.
           create SimplifiedWaterSurface()
        else
           if ($useHWShader2Path)
              create HighEndWaterSurface()               
           else
              create RegularWavesHLSL()
           endif
        endif
        
     end #end shader
     
     # basic fallback.
     shader -layer $poolWaterLayer
        create SimplifiedWaterSurface()          
     end #end shader
     
  end  #end material

enddef

define SimplifiedWaterSurface()

  pass -fixedFunction      
     alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
     depthTest true -enableDepthWrite false
     colorScalar (0.2,0.3,1.0) 0.4            
     stage
        textureBlend select(colorScalar) select(colorScalar)
     end
  end

enddef


define RegularWavesHLSL()

  #DRIVERBUG
  # The -clipAlways flag is needed to work around what appears to be a driver bug.
  # On NVIDIA GF2 class HW, the presence of the cube map texture in the pass below
  # leads to a large performance drop whenever the pass is rendered with clipping disabled.
  # Rendering this pass with clipping enabled avoids the performance drop. In addition,
  # substituting a 2D texture for the cube map texture, or rendering this pass in HW
  # using fixed function vertex processing also avoids the performance drop (but would obviously
  # not have the desired visual result).
  # The cause of this is unknown. This was observed on a GF4GO, driver version 42.58.

pass -clipAlways -modifiedEachFrameHint #fillmode wireframe alphaBlend srcFactor(one) add dstFactor(one)

     seti textureLights (numLightsOfType(environmentCube))        
  

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

        if (tsIsDay)         
           bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)         
        else
           bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)         
        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);

           float4 nightColor: register(c25);
           

float4 lightDirection : register(c14); float4 lightColor : register(c15); const static float4 refractionWeights={1,1,2,0};

const static float4 layerBlue={0.3, 0.7, 1.0, 1};

struct InputVertex { float3 position: POSITION0; float3 normal : NORMAL0; };

struct OutputVertex { float4 clipPosition : POSITION; float4 diffuseColor: COLOR0; float4 specularColor: COLOR1; float3 reflection : TEXCOORD0;

};


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);

// z = h * sin(...)

float z; // scale temp to fit -pi +pi range //temp = temp * (1 / (2 * 3.14159)) + 0.5;

float3 waveNormal;

z = sin(temp) * waveDataX.z + inputVertex.position.z;

waveNormal.x = cos(temp) * waveDataHelper.x + inputVertex.normal.x;

temp = dot(posAndTime, waveDataY); //temp = temp * (1 / (2 * 3.14159)) + 0.5;

z += sin(temp) * waveDataY.z;

waveNormal.y = cos(temp) * waveDataHelper.y + inputVertex.normal.y;

waveNormal.z = inputVertex.normal.z;

waveNormal = normalize(waveNormal);

posAndTime.w = 1.0; posAndTime.z = z;

outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix);

float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix));

float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix);

float3 viewVector = normalize(-cameraSpacePosition);

float3 R = reflect(viewVector, cameraSpaceNormal);

outputVertex.reflection = mul( -R, cameraToGlobalMatrix);


float fresnel = dot(viewVector , cameraSpaceNormal);

float rdotl = saturate(dot(R, lightDirection));

float I = pow(rdotl+0.1, 15); // fudge factor to punch up the highlights.

              nightColor = nightColor * 2;                           
                          

outputVertex.diffuseColor = ((1.0 - fresnel) * saturate(nightColor) * 0.5) * layerBlue;

outputVertex.specularColor = I; return(outputVertex);

}


endShaderSource end # shaderProgram

stage texture $wmReflectionTexture textureAddressing clamp clamp clamp textureBlend multiply(texture diffuse) select(diffuse) end


addSpecular true

end # end pass


enddef


define HighEndWaterSurface()

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)         
        else
           bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)         
        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 lightDirection : register(c14); float4 lightColor : register(c15); float4 lightSpecular : register(c16); const static float4 refractionWeights={1,1,2,0};

const static float4 layerBlue={0.3, 0.7, 1.0, 1};

struct InputVertex { float3 position: POSITION0; float3 normal : NORMAL0; };

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;     

};


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; 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+fTranslation*2.0;
              outputVertex.Wave1.xy = vTexCoords.xy*2.0+fTranslation*4.0;
              outputVertex.Wave2.xy = vTexCoords.xy*7.0+fTranslation*2.0;
              outputVertex.Wave3.xy = vTexCoords.xy*12.0+fTranslation;                															

// 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);


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;
           };
           
           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 * float3(0.1, 0.1, 1.0);  
              
              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.2, 5.0, facing);
                             
              vReflection.a = fresnel;               
              return saturate(vReflection + float4(0.0, 0.25, 0.5, 0.0) + pi.specular);
           }
        endShaderSource
     end                                                     
     
     sampler reflect
        texture "PoolReflection"
        textureAddressing clamp clamp
     end		
     
     sampler bump
        texture "poolShape-body-bump"
        textureAddressing tile tile
     end   
           

end # end pass

enddef


  1. endshader PoolWaterSurfaceMaterial


  1. NOTE:
  2. refraction in vector terms:
  3. v = incoming unit vector
  4. n = surface normal
  5. v' = refracted vector
  6. a = refraction ratio, ni / nr =~ 0.75 for air->water
  7. v' = v - sn
  8. where s = sqrt(1 - a^2 (1 - (v.n)^2)) - v.n.


  1. Caustics

define TiledTextureAnimShaderProgram(tilesX tilesY speed)

  shaderProgram -target vertexProgram -method assemble
  
     bindConstants 0 -bindingID frameInfo            # for time in .w
     bindConstants 1 -data      (&tilesX, &tilesY, &speed, 1)         # tx, ty, speed
     bindConstants 2 -data      ((1/&tilesX), (1/&tilesY), (&tilesY - 1), 1) # 1/tx 1/ty ty-1      
     if (tsIsDay)
        bindConstants 3 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)
     else
        bindConstants 3 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)
     endif
     
     shaderSource
        vs_1_1
        dcl_position v0
        dcl_texcoord v1
        mov oPos, v0  # clip space quad, no transforms needed.
     
        # tiled texture animation
        mov r0, c0
        mul r1, c1.z, r0.w
        frc r5.y, r1.y
        
        mul r1, c1.y, r5.y    # f -> [0, ty)
        frc r5.y, r1
        sub r3.y, r1, r5.y    # v' = floor(f)
        
        mul r1, c1.x, r5.y    # f -> [0, tx)
        frc r5.y, r1
        sub r3.x, r1, r5.y    # u' = floor(f)
        add r8.xy, v1.xy,  r3.xy
        mul oT0.xy, r8.xy, c2.xy
        
        mov oD0, c3 # also spit out diffuse color with modcolor information
        
     endShaderSource
  
  end		

enddef

define CausticsGeneratorMaterial()

  material      
     # This material updates a render target with the current frame
     # of the tile animation. This is the only way to handle a repeated
     # animating texture (not to mention using it for projective texturing)
     # in the absence of clip maps.
     
     create DetermineHardwareSupport()
     
     if ($causticsEnabled and $useFixedFunctionPath = false and $useSWVertexShaderPath = false)
     
        shader -layer +9999 
           pass              
              renderClipSpaceRect
              
              renderTarget causticsTile -fixed (64, 64) -allocateDepthBuffer false -undo
              create TiledTextureAnimShaderProgram(8 4 1)
              
              alphaBlend srcFactor(one) add dstFactor(zero)
              alphaTest false 0
              alphaTestFunction acceptIfGreater
              depthTest false -enableDepthWrite false
              depthTestFunction accept
              # 7/24/2004 Fix bug with kRenderTypeNormal default stencil state and nv40.  
              # It reads random stencil values even this target has no depth stencil target.               
              # This stencil call will break pixo, but pixo does not show caustics.
              stencil false
              fillmode $stdMatFillMode                             
              
              shaderProgram -target pixelProgram -method compile -version 1_1               
                 shaderSource                            
                    sampler caustics;
                    struct cInputPixel
                    {
                       float4 color : COLOR;
                       float2 tc0 : TEXCOORD0;
                    };
                    float4 PixelMain(cInputPixel pi) : COLOR
                    {         
                       float4 texColor = tex2D(caustics, pi.tc0);                                                
                       return texColor*pi.color;                        
                    }
                 endShaderSource
              end                                                     
              
              sampler 0
                 texture causticsTiled
                 textureAddressing tile tile                  
              end
                             
           end   
        end
     else
        shader
        
        end
     endif
  end

enddef

setf causticsStrength 0.8 setf causticsBaseStrength 0.5


  1. Materials


  1. Pool surface materials

materialDefinition "poolWater-0"

  setDefinition PoolWaterSurfaceMaterial
  addParam stdMatDiffCoef (0, 0, 1)   
  addParam wmRefractionEnabled true

end

materialDefinition "poolWater-1"

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

end

materialDefinition "poolWater-2"

  setDefinition PoolWaterSurfaceMaterial
  addParam stdMatLightingEnabled false
  addParam stdMatLayer 0
  
  addParam stdMatDiffCoef (0, 0, 1)   
  addParam wmTransparency 0.5
  addParam wmXSpeed        3
  addParam wmXRepeat       12
  addParam wmXWaveHeight   0 #0.02 
  
  addParam wmYSpeed        3
  addParam wmYRepeat       12 
  addParam wmYWaveHeight   0 # 0.02 

end

materialDefinition "poolWater-4"

  setDefinition WaterAnimatingTextures
  addParam waterSpeed 0.3

end


  1. Pool depth layer materials
  1. this is here soley because the layering on standard material
  2. is too constrained. We need a layer less than 7, or we'll
  3. render over transparent areas of Sims (e.g. hair) when
  4. they're in the pool at a shallow view angle.

setc poolLayerColour (0, 0.5, 1.0, 1.0) define PoolDepthLayerMaterial()

  material     
     create DetermineHardwareSupport() 
     if ($useSWVertexShaderPath or $useFixedFunctionPath)
        shader
        end
     else
        shader -layer $poolWaterLayer
           validateRenderShaderContext -vertexFormat position 0 required
           validateRenderShaderContext -vertexFormat texcoord 0 required
           
           pass
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)

depthTest true -enableDepthWrite false

              #fillmode wireframe
              shaderProgram -target vertexProgram -method compile -version 1_1
                 bindConstants 0 -bindingID geomToClip -constantCount 4
                 bindConstants 4 -bindingID immediateData -data ($poolLayerColour)
                 
                 shaderSource
                    float4x4 clipSpaceMatrix      : register(c0);
                    float4   poolLayer            : register(c4);
                    
                    struct cVertexIn
                    {
                       float3 mPosition : POSITION0;   
                       float2 alpha     : TEXCOORD0;                  
                    };
                    
                    struct cVertexOut
                    {
                       float4 mClipPosition : POSITION;                     
                       float4 mColor        : COLOR0;
                    };
                    
                    cVertexOut VertexMain(cVertexIn vertexIn)
                    {                 
                       cVertexOut result;                                                                        
                       result.mClipPosition = mul(float4(vertexIn.mPosition, 1), clipSpaceMatrix);                     
                       result.mColor = float4(poolLayer.r, poolLayer.g, poolLayer.b, poolLayer.a * vertexIn.alpha.x); 
                       return result;         
                    }
                    
                 endShaderSource
              end                       
              
              shaderProgram -target pixelProgram -method compile -version 1_1
                 shaderSource                  
                    float4 PixelMain(float4 color : COLOR) : COLOR
                    {                                             
                       return color;
                    }
                 endShaderSource
              end                        
           end         
        end
     endif
  end

enddef

materialDefinition "poolWaterLayer-0"

  # this layer does nothing but create the caustics tile.
  setDefinition CausticsGeneratorMaterial   

end

materialDefinition "poolWaterLayer-1"

  setDefinition PoolDepthLayerMaterial   
  addParam poolLayerColour (0, 0.5, 1.0, 0.2)

end materialDefinition "poolWaterLayer-2"

  setDefinition PoolDepthLayerMaterial  
  addParam poolLayerColour (0, 0.5, 1.0, 0.2)    

end materialDefinition "poolWaterLayer-3"

  setDefinition PoolDepthLayerMaterial
  addParam poolLayerColour (0, 0.5, 1.0, 0.5)   

end

materialDefinition mtl_0

  setDefinition CausticsGeneratorMaterial

end

materialDefinition "lightingwallpoolsimple_reflective"

  setDefinition StandardMaterial   
  addParam   stdMatDiffCoef (0.8, 0.8, 0.8)   
  addParam   stdMatAlphaMultiplier 1.0
  addParam   stdMatAlphaBlendMode none
  addParam   stdMatSpecCoef 0.091,0.091,0.091
  addParam   stdMatBaseTextureEnabled true
  addParam   stdMatBaseTextureName lightingwallpoolsimple-surface
  addParam   stdMatEnvCubeLockedToCamera 0
  addParam   stdMatEnvCubeMode reflection
  addParam   stdMatEnvCubeTextureName reflectionkitchenhighcontrast-envcube
  addParam   forceIgnoreShapeBlend true

end

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox