Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
Line 1: Line 1:
#
+
pass -clipAlways -modifiedEachFrameHint
# Shaders for indoor & outdoor tiles; i.e., "Floors".
+
#fillmode wireframe
#
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
#
+
       seti textureLights (numLightsOfType(environmentCube))
 
+
       depthTest true -enableDepthWrite false         
seti gridLayer 13
+
seti floorLayer -4
+
setf floorMaterialScaleU 1.0  # defaults for Floor materials without these defined
+
setf floorMaterialScaleV 1.0  # defaults for Floor materials without these defined
+
setb floorHighlightOn false
+
setc floorHighlightIntensity (0.25, 0.25, 0.25, 1.0)  # attenuation of the floor highlight texture
+
setf floorGridAlpha 0.775
+
seti previewLayer 0 # -28
+
 
+
# debug options for PS hardware only, only set one of these to true
+
setb debugShowFloorIncidence false  # shows the incidence maps as color
+
setb debugShowFloorNormalMap false  # shows the raw normal map (if it exists)
+
setb debugFloorLighting false      # no base texture, only lighting results
+
setb debugShowLightMapTexcoords false  # texcoords as color
+
 
+
 
+
setb floorCausticsPass false
+
seti floorRenderStyle 0
+
setb hasCutout false
+
 
+
include PixelShaderFloors.matShad
+
 
+
 
+
#beginshader Floor
+
#description Basic floor tile shader; texture + floor gradient + shadows
+
#extraparam float floorMaterialScaleU 1 0.125 64 ; no. tiles to map across U axis, use any positive number
+
#extraparam float floorMaterialScaleV 1 0.125 64 ; no. tiles to map across V axis, use any positive number
+
define Floor()
+
  material
+
      if ($stdMatLightingDebug)
+
        create LightingDebugStandardMaterialOverrides()
+
      endif
+
      create FloorShaders()
+
  end
+
enddef
+
#endshader
+
 
+
 
+
#beginshader FloorPool
+
#description Pool tile shader, with caustics.
+
#extraparam bool floorCausticsPass 1 ; set to true to add water caustics.
+
define FloorPool()
+
  material
+
       if ($stdMatLightingDebug)
+
        create LightingDebugStandardMaterialOverrides()
+
      endif
+
      create FloorShaders()
+
  end
+
enddef
+
#endshader
+
 
+
 
+
 
+
 
+
#
+
# Standard floor shaders
+
#
+
define FloorShaders()
+
 
+
  if (viewerRenderType = $kRenderTypeShadowMap)
+
  create ShadowMapVS_PS()
+
else
+
  setb bumpMapFloors false
+
 
+
  create DetermineHardwareSupport()
+
 
+
  setb hasTexcoord2 (hasVertexFormat(texcoord,1))
+
 
+
       # check for the page, the global bumpmap glag, and for the normal map in the material
+
  if (varExists(page) and $bumpMapping and $stdMatNormalMapTextureEnabled and $hasTexcoord2)
+
  setb bumpMapFloors true
+
  endif
+
 
+
      if ($useHWShader1Path or $useHWShader2Path)
+
 
+
  create PixelShaderFloors($bumpMapFloors)
+
 
+
  else
+
     
+
  # fixed function paths NEVER get bump mapping due to fill rate and memory concerns.
+
 
+
  create FixedFunctionFloorShader() 
+
 
+
  # ultimate fallback pass? no light map, one stage.
+
  shader -layer $floorLayer
+
  validateRenderShaderContext -vertexFormat position 0 required
+
  validateRenderShaderContext -vertexFormat normal 0 required
+
  validateRenderShaderContext -vertexFormat texcoord 0 required
+
  validateRenderShaderContext -viewerRenderType viewerRenderType
+
 
+
  pass -fixedFunction
+
  create LightingStates()
+
  create AttenuatedMatCoef(1)
+
  fillmode $stdMatFillMode
+
 
+
  if ($hasCutout)                       
+
                  depthTestFunction acceptIfEqual
+
              else
+
                  depthTestFunction acceptIfLessOrEqual
+
              endif
+
 
+
  stage
+
  texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
  textureAddressing tile tile
+
  ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
+
  textureTransformType vector2
+
  ffTextureCoordsSource 0
+
  textureBlend multiplyScale2(texture diffuse) select(outRegister)
+
  end
+
  end
+
 
+
  create HighlightPass()
+
 
+
  end
+
  endif
+
endif
+
+
enddef
+
 
+
#
+
# Standard floor shader,
+
#
+
define FixedFunctionFloorShader()
+
 
    
 
    
  setb lightMapAvailable false
+
shaderProgram -target vertexProgram -method compile -version 1_1
  if (varExists(page))
+
      setb lightMapAvailable true
+
  endif
+
 
+
  setb caustics false
+
  if ($floorCausticsPass and $causticsEnabled)
+
      setb caustics true
+
  endif 
+
 
+
  shader -layer $floorLayer
+
      validateRenderShaderContext -vertexFormat position 0 required
+
      validateRenderShaderContext -vertexFormat texcoord 0 required
+
      validateRenderShaderContext -viewerRenderType viewerRenderType
+
     
+
      set stdMatSpecCoef (0, 0, 0)
+
      set stdMatSpecPower 0
+
  
if ($caustics)
+
bindConstants 0 -bindingID geomToClip -constantCount 4
pass -fixedFunction -modifiedEachFrameHint     
+
bindConstants 4 -bindingID geomToCamera -constantCount 3
else
+
pass -fixedFunction
+
endif
+
  
      ffDepthOffset 0
+
bindConstants 7 -bindingID frameInfo
     
+
      if ($hasCutout)                       
+
        depthTestFunction acceptIfEqual
+
      else
+
        depthTestFunction acceptIfLessOrEqual
+
      endif
+
     
+
      # empirically, Floors seem to only take 3 inputs
+
      # the base texture
+
      # the light map
+
      # the material color, which seems to act as a 'tune' value.
+
     
+
      # Lightmaps are scaled by 0.5, so this must multiply by 2 to get to the correct brightness.
+
      # No alpha blending is required, nor is alpha scaling required.
+
 
+
        # # don't pre-scale -- that's in the texture.
+
        fillmode $stdMatFillMode
+
           
+
        if ($lightMapAvailable)
+
  
            colorScalar ($stdMatDiffCoef) 1
+
bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed)
 +
bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed)
  
stage
+
# pre-evaluate these
create SelectFloorLightMap()
+
setf xscale (-$wmXRepeat * $wmXWaveHeight)
             
+
setf yscale (-$wmYRepeat * $wmYWaveHeight)
# add the lightmap lighting to any direct lights.
+
bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
# the light map has been prescaled by 0.5
+
bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
textureBlend multiply(texture colorScalar) select(texture)
+
bindConstants 18 -bindingID cameraToGlobal -constantCount 3
end
+
bindConstants 21 -bindingID cameraToGeom -constantCount 3
           
+
       
            stage
+
        if (tsIsDay)        
              texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
             bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)       
           
+
              textureAddressing tile tile
+
              ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
+
              ffTextureCoordsSource 0
+
+
              textureBlend multiplyScale2(texture outRegister) select(colorScalar)
+
             end
+
           
+
 
         else
 
         else
       
+
             bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)        
        # no lightmap case:
+
 
+
              
+
            colorScalar ($stdMatDiffCoef) 1
+
           
+
            stage
+
              texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
           
+
              textureAddressing tile tile
+
              ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
+
              ffTextureCoordsSource 0
+
             
+
              textureBlend multiply(colorScalar texture) select(colorScalar)
+
            end
+
         
+
           
+
 
+
 
         endif
 
         endif
       
 
 
 
end
 
  
      if ( $lightMapAvailable)  # thumbnails don't have lightmaps, causing this to fail without them, so assume no work to be done without lightmaps.
+
shaderSource
     
+
        if ($lmIntegratedShadows )
+
            # Still experimental
+
            pass -fixedFunction
+
              create LightingStatesNoStdLights()
+
              fillmode $stdMatFillMode
+
             
+
              alphaBlend srcFactor(destColor) add dstFactor(zero)
+
             
+
              alphaTest true 100
+
              alphaTestFunction acceptIfGreater
+
 
+
              colorScalar (0.61, 0.61, 0.61)  # needs to be set by tsUserEtc
+
 
+
              ffDepthOffset 1
+
 
+
              stage
+
                  create SelectFloorLightMap()
+
                  textureBlend select(colorScalar) select(texture)
+
              end
+
            end
+
        elseif ((not ($useHWShader2Path or $useHWShader1Path)))
+
            # Mark the depth buffer where the shadow is so object shadows
+
            # do not overlap.
+
            pass -fixedFunction
+
              create LightingStatesNoStdLights()
+
              alphaBlend srcFactor(zero) add dstFactor(one)
+
              fillmode $stdMatFillMode
+
 
+
              ffDepthOffset 1
+
              depthTest true -enableDepthWrite true
+
              alphaTest true 100
+
              alphaTestFunction acceptIfLess
+
 
+
              stage
+
                  create SelectFloorLightMap()
+
                  textureBlend select(texture) select(texture)
+
              end
+
            end
+
        endif
+
      endif
+
     
+
create HighlightPass()
+
end
+
 
+
+
 
+
enddef
+
  
 
+
float4 frameInfo : register(c7);
#beginshader FloorReflective
+
float4 waveDataX : register(c11);
#description Basic floor tile shader with reflection; texture + floor gradient + shadows
+
float4 waveDataY : register(c12);
#extraparam float floorMaterialScaleU 1 0.125 64 ; no. tiles to map for U axis, use any positive number
+
float4 waveDataHelper : register(c13);
#extraparam float floorMaterialScaleV 1 0.125 64 ; no. tiles to map for V axis, use any positive number
+
float4x4 clipSpaceMatrix : register(c0);
#extraparam float reflectStrength 1 0 1 ; strength of reflection, in range 0 to 1
+
float4x3 cameraSpaceMatrix : register(c4);
 
+
float4x3 cameraToGlobalMatrix : register(c18);
set ratioH 1  # default material parameter value
+
float4x3 cameraToGeomMatrix : register(c21);
set ratioW 1  # default material parameter value
+
set useReflectionFloors 0 # default material parameter value
+
define FloorReflective()
+
material
+
shader
+
#reflective floors are currently dead. might ressurect them in an expansion pack
+
 
 
end
+
            float4 nightColor: register(c25);
end
+
enddef
+
 
+
 
+
 
+
#
+
# gridMaterial -- composites the alpha grid texture over the normal floor texture
+
#                NOTE: In order to guarantee this is drawn on top of the normal
+
#                floor tile textures, the layer has to be higher than that for
+
#                the normal floor textures.
+
 
+
define TileGridMaterial()
+
 
+
material
+
      if (viewerRenderType = $kRenderTypeNormal)
+
     
+
        shader -layer $gridLayer
+
 
              
 
              
              # this is using modifiedEachFrameHint, because when the pool tool
+
float4 lightDirection : register(c14);
              #  is used it does not invalidate the entire terrain or invalidate the frame.
+
float4 lightColor : register(c15);
              pass -fixedFunction # -modifiedEachFrameHint
+
float4 lightSpecular : register(c16);
                  validateRenderShaderContext -viewerRenderType $kRenderTypeNormal  # normal render
+
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;   
 +
};
 
              
 
              
                  create LightingStatesNoStdLights()
+
                  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
                 
+
OutputVertex VertexMain( InputVertex inputVertex)
                  # Add an alpha test to avoid processing fully transparent pixels
+
{
                  alphaTest true 0
+
// Do Y-direction waves
                  alphaTestFunction acceptIfGreater                 
+
// r0 = (x, y, z, t)
                   
+
                  # Since the terrain has identical geometry, and is assumed to be rendered
+
OutputVertex outputVertex;
                  # before the grid, there is no need to write to the z-buffer againIf
+
                  # the geometry of the grid diverges from the geometry of the terrain, we
+
float4 posAndTime;
                  # *may* want to reenable depth writes here.
+
posAndTime.xyz = inputVertex.position;
                 
+
posAndTime.w = frameInfo.w;
                  depthTest true -enableDepthWrite false
+
                  ffDepthOffset 2
+
float temp = dot(posAndTime, waveDataX);
                  fillmode $stdMatFillMode
+
float z = sin(temp) * waveDataX.z + inputVertex.position.z;
                  colorScalar (0,0,0) $floorGridAlpha
+
temp = dot(posAndTime, waveDataY);
                  stage
+
posAndTime.z = z + sin(temp) * waveDataY.z;
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
posAndTime.w = 1.0f;
                    ffTextureCoordsSource 0
+
                    textureBlend multiply(texture colorScalar) multiply(texture colorScalar)
+
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix);
                  end
+
outputVertex.sPos = float4(0.5f*(outputVertex.clipPosition.ww - outputVertex.clipPosition.xy), outputVertex.clipPosition.ww);
              end
+
           
+
float3 waveNormal = normalize(inputVertex.normal + float3(cos(temp)*waveDataHelper.xy, 0));
        end #shader
+
        float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix));
      else
+
float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix);
        shader
+
float3 viewVector = normalize(-cameraSpacePosition);
       
+
        end
+
float3 halfVector = normalize(viewVector + lightDirection);
      endif
+
outputVertex.specular = lightSpecular*pow(dot(cameraSpaceNormal, halfVector), 50)*nightColor*lightColor*0.5;
end #mat
+
enddef
+
 +
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);
 +
}
  
#
 
# inverseGridMaterial -- composites the inverse of the alpha grid texture over the normal floor texture
 
#                NOTE: In order to guarantee this is drawn on top of the normal
 
#                floor tile textures, the layer has to be higher than that for
 
#                the normal floor textures.
 
  
define InverseTileGridMaterial()
+
endShaderSource 
 
+
end # shaderProgram
#trace "$currentMaterialName  inverse tile grid material"
+
+
shaderProgram -target pixelProgram -method compile -version 2_0             
  material
+
         shaderSource                           
shader -layer $gridLayer
+
            sampler reflect; 
         if (viewerRenderType = $kRenderTypeNormal)
+
            sampler bump;         
     
+
            struct cInputPixel
             create DetermineHardwareSupport()
+
            {             
 +
              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);
 +
            }
 
              
 
              
             if ($useHWShader1Path or $useHWShader2Path)
+
             float4 PixelMain(cInputPixel pi) : COLOR
              create PixelShaderInverseTileGridRendering()
+
             {        
             else
+
               float3 vEye = normalize(pi.Eye);
              # this pass draws the completely opaque region of the grid line
+
              # hiding the incorrect sorting behavior of the second pass at high
+
              # resolution mipmap levels
+
              pass -fixedFunction
+
                  create LightingStatesNoStdLights()
+
                  alphaTest true 192
+
                  alphaTestFunction acceptIfGreater
+
                  fillmode $stdMatFillMode
+
 
+
                  stage
+
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
                    ffTextureCoordsSource 0
+
                    textureBlend select(texture:invert) select(texture)
+
                  end
+
               end
+
 
+
              # this pass draws the transition region along the edges of the grid lines
+
              # this provides a blurry grid at lower mipmap levels (where the solid grid
+
              # line disappears entirely)
+
              pass -fixedFunction
+
                  create LightingStatesNoStdLights()
+
                  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
                  alphaTest true 192
+
                    alphaTestFunction acceptIfLess
+
                  depthTest true -enableDepthWrite false
+
                  fillmode $stdMatFillMode
+
 
+
                  stage
+
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
                    ffTextureCoordsSource 0
+
                    textureBlend select(texture:invert) select(texture)
+
                  end
+
              end
+
            endif
+
        end
+
      else
+
        shader
+
       
+
        end
+
      endif
+
end
+
enddef
+
  
 
+
              // Get bump layers
define TileLocalGridMaterial()
+
              float3 vBumpTexA = tex2D(bump, pi.Wave0.xy).xyz;
  material
+
              float3 vBumpTexB = tex2D(bump, pi.Wave1.xy).xyz;
      # 7/26/04 This material should only be reinstated if the cursor moves a part that causes
+
              float3 vBumpTexC = tex2D(bump, pi.Wave2.xy).xyz;
      # visible damage to be updated with respect to where it is moved. Marking all the
+
              float3 vBumpTexD = tex2D(bump, pi.Wave3.xy).xyz;
      # terrain tiles with this modifiedEachFrameHint is too slowFor now this material
+
               
      # is disabled.  
+
              // 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                                                   
 
        
 
        
       if (viewerRenderType = $kRenderTypeNormal)
+
       sampler reflect
 +
        texture "PoolReflection"
 +
        textureAddressing clamp clamp
 +
      end
 
        
 
        
        attributes
+
      sampler bump
            attribute alphaScale float1
+
         texture "poolShape-body-bump"
            attribute alphaTrans float2
+
         textureAddressing tile tile
         end
+
      end 
          
+
        shader -layer $gridLayer
+
            vertexFormatPred blendindices  0 false
+
            vertexFormatPred targetindices 0 false
+
 
              
 
              
            # Local grid is revelated across the multiple tiles and it does not track damage.
+
end # end pass
            # Using modifiedEachFrameHint so that grid lines are not left behind.
+
            pass -fixedFunction # -modifiedEachFrameHint
+
              create LightingStatesNoStdLights()
+
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
              # Add an alpha test to avoid processing fully transparent pixels
+
              alphaTest true 0
+
              alphaTestFunction acceptIfGreater
+
              # Since the terrain has identical geometry, and is assumed to be rendered
+
              # before the grid, there is no need to write to the z-buffer again.  If
+
              # the geometry of the grid diverges from the geometry of the terrain, we
+
              # *may* want to reenable depth writes here.
+
              depthTest true -enableDepthWrite false
+
              fillmode $stdMatFillMode
+
             
+
              ffDepthOffset 2  # above the shadow/overlay layer.
+
 
    
 
    
              colorScalar (0,0,0) $floorGridAlpha
 
             
 
              stage
 
                  texture "localgrid-alphafadeout" ${stdMatBaseTextureParam}
 
                  ffTextureCoordsSource 0
 
                  textureAddressing clamp clamp
 
                  textureTransformType vector2
 
                  ffTextureMatrix -scale @alphaScale -trans @alphaTrans
 
                  textureBlend select(outRegister) multiply(texture colorScalar)
 
              end
 
             
 
              stage
 
                  texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
 
                  ffTextureCoordsSource 0           
 
                  textureBlend multiply(texture colorScalar) multiply(texture outRegister)
 
              end
 
            end
 
        end
 
      else
 
        shader
 
       
 
        end
 
      endif
 
  end
 
 
enddef
 
enddef
 
 
define SelectFloorLightMap()
 
  texture "floorLightMap_${page}"
 
  ffTextureCoordsSource 1
 
enddef
 
 
define SelectFloorIncidenceMap()
 
  texture "floorIncidenceMap_${page}"
 
  ffTextureCoordsSource 1
 
enddef
 
 
 
# PS highlighting done in the shader instead of normal maps.
 
 
define HighlightPass()
 
  if ($floorHighlightOn)
 
      # pass for the additive part of the highlight texture
 
      pass -fixedFunction
 
        create LightingStates()
 
        alphaBlend srcFactor(one) add dstFactor(one)  # just add the highlight to whatever was there
 
       
 
        # Add an alpha test to avoid processing fully transparent pixels
 
        alphaTest true 0
 
      alphaTestFunction acceptIfGreater
 
 
        fillmode $stdMatFillMode
 
 
        colorScalar ($floorHighlightIntensity)  # adjust highlight texture brightness
 
 
        stage
 
            texture "floor_selection_colors"
 
            ffTextureCoordsSource 0  # use the floor pattern texture coordinates
 
            textureBlend multiplyAdd(texture colorScalar outRegister) select(texture)
 
        end
 
      end
 
 
      # pass for the subtractive part of the highlight texture
 
      pass -fixedFunction
 
        create LightingStates()
 
        alphaBlend srcFactor(one) sub dstFactor(one)  # just add the highlight to whatever was there
 
       
 
        # Add an alpha test to avoid processing fully transparent pixels
 
        alphaTest true 0
 
      alphaTestFunction acceptIfEqual
 
 
        fillmode $stdMatFillMode
 
 
        colorScalar ($floorHighlightIntensity)  # adjust highlight texture brightness
 
 
        stage
 
            texture "floor_selection_colors"
 
            ffTextureCoordsSource 0  # use the floor pattern texture coordinates
 
            textureBlend multiplyAdd(texture colorScalar outRegister) select(texture)
 
        end
 
      end
 
  endif
 
enddef
 
 
# Empty tile
 
materialDefinition tileshaderempty
 
  setDefinition Null
 
end
 
 
materialDefinition tileShaderMayLevel_0
 
  setDefinition SolidColorMaterial
 
  addParam scLayer $previewLayer
 
  addParam color (0,1,0) 
 
end
 
 
materialDefinition tileShaderMayNotLevel_0
 
  setDefinition SolidColorMaterial 
 
  addParam scLayer $previewLayer
 
  addParam color (1,0,0) 
 
end
 
 
materialDefinition tileShaderMayLevel_0_
 
  setDefinition SolidColorMaterial
 
  addParam scLayer $previewLayer
 
  addParam depthOffset 2
 
  addParam color (0,1,0) 
 
end
 
 
materialDefinition tileShaderMayNotLevel_0_
 
  setDefinition SolidColorMaterial
 
  addParam scLayer $previewLayer
 
  addParam depthOffset 2
 
  addParam color (1,0,0) 
 
end
 
 
 
# Terrain grid
 
materialDefinition floorGridBlack
 
  setDefinition TileGridMaterial
 
  addParam stdMatBaseTextureName floor-grid
 
end
 
 
# Local Terrain grid
 
materialDefinition floorLocalGridBlack
 
  setDefinition TileGridMaterial # TileLocalGridMaterial
 
  addParam stdMatBaseTextureName floor-grid
 
end
 
 
# Upper floor grid
 
materialDefinition floorGridWhite
 
  setDefinition InverseTileGridMaterial
 
  addParam stdMatBaseTextureName floor-grid
 
end
 
 
# Active-level Terrain grid
 
materialDefinition floorGridBlackActiveLevel
 
  setDefinition TileGridMaterial # TileLocalGridMaterial
 
  addParam stdMatBaseTextureName floor-grid-active
 
end
 
 
# Active-level Local Terrain grid
 
materialDefinition floorLocalGridBlackActiveLevel
 
  setDefinition TileGridMaterial # TileLocalGridMaterial
 
  addParam stdMatBaseTextureName floor-grid-active
 
end
 
 
# Active-level Upper Floor grid
 
materialDefinition floorGridWhiteActiveLevel
 
  setDefinition InverseTileGridMaterial
 
  addParam stdMatBaseTextureName floor-grid-active
 
end
 
 
 
materialDefinition floor_oak_seethrough
 
  setDefinition FloorReflective
 
  addParam stdMatLayer 2
 
  addParam stdMatBaseTextureName floor-oak
 
  addParam reflectStrength .3
 
end
 
 
materialDefinition floor_mountainFogTile
 
  setDefinition FloorReflective
 
  addParam stdMatLayer 2
 
  addParam stdMatBaseTextureName floor-mountainFogTile
 
  addParam reflectStrength .1
 
end
 
 
materialDefinition floor_brickPatio
 
  setDefinition Floor
 
  addParam stdMatBaseTextureName floor-brickPatio
 
  addParam stdMatDiffCoef (0.63, 0.63, 0.56)
 
end
 
 
materialDefinition FloorThickness
 
  setDefinition StandardMaterial
 
  addParam  stdMatSpecPower 0
 
  addParam  stdMatDiffCoef (0.5, 0.5, 0.5)
 
  addParam  stdMatBaseTextureName floor-edge
 
  addParam  stdMatBaseTextureEnabled true
 
end
 

Revision as of 00:38, 16 June 2009

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

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox