Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
 
(10 intermediate revisions by one user not shown)
Line 1: Line 1:
#
+
define TransparentMirrorReflection()
# Shaders for indoor & outdoor tiles; i.e., "Floors".
+
#
+
#
+
 
+
seti gridLayer 13
+
seti floorLayer -4
+
setf floorMaterialScaleU 1.0  # defaults for Floor materials without these defined
+
setf floorMaterialScaleV 1.0  # defaults for Floor materials without these defined
+
setb floorHighlightOn false
+
setc floorHighlightIntensity (0.25, 0.25, 0.25, 1.0)  # attenuation of the floor highlight texture
+
setf floorGridAlpha 0.775
+
seti previewLayer 0 # -28
+
 
+
# 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
 
   material
       if ($stdMatLightingDebug)
+
       if (viewerRenderType = $kRenderTypeShadow)
         create LightingDebugStandardMaterialOverrides()
+
         create StandardShaderShadow()
 +
      else
 +
        if (viewerRenderType = $kRenderTypeThumbnail)
 +
            create TransparentBlankMirrorMaterial($kRenderTypeThumbnail)
 +
        else           
 +
            if (not $mirrorReflectionsEnabled)
 +
              set currentType (viewerRenderType)
 +
              create TransparentBlankMirrorMaterial($currentType)
 +
            else
 +
              create TransparentMirrorReflectionMaterial()
 +
            endif           
 +
        endif       
 
       endif
 
       endif
      create FloorShaders()
 
 
   end
 
   end
 
enddef
 
enddef
#endshader
 
  
 
+
define TransparentBlankMirrorMaterial(renderType)
#beginshader FloorPool
+
       shader
#description Pool tile shader, with caustics.
+
         validateRenderShaderContext -viewerRenderType &renderType
#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
+
  if (varExists(page))
+
      setb lightMapAvailable true
+
  endif
+
 
+
  setb caustics false
+
  if ($floorCausticsPass and $causticsEnabled)
+
      setb caustics true
+
  endif 
+
 
+
  shader -layer $floorLayer
+
      validateRenderShaderContext -vertexFormat position 0 required
+
      validateRenderShaderContext -vertexFormat texcoord 0 required
+
      validateRenderShaderContext -viewerRenderType viewerRenderType
+
     
+
      set stdMatSpecCoef (0, 0, 0)
+
      set stdMatSpecPower 0
+
 
+
if ($caustics)
+
pass -fixedFunction -modifiedEachFrameHint     
+
else
+
pass -fixedFunction
+
endif
+
 
+
      ffDepthOffset 0
+
     
+
      if ($hasCutout)                       
+
        depthTestFunction acceptIfEqual
+
      else
+
        depthTestFunction acceptIfLessOrEqual
+
      endif
+
     
+
      # empirically, Floors seem to only take 3 inputs
+
      # the base texture
+
      # the light map
+
      # the material color, which seems to act as a 'tune' value.
+
     
+
      # Lightmaps are scaled by 0.5, so this must multiply by 2 to get to the correct brightness.
+
      # No alpha blending is required, nor is alpha scaling required.
+
 
+
        # # don't pre-scale -- that's in the texture.
+
        fillmode $stdMatFillMode
+
           
+
        if ($lightMapAvailable)
+
 
+
            colorScalar ($stdMatDiffCoef) 1
+
 
+
stage
+
create SelectFloorLightMap()
+
             
+
# add the lightmap lighting to any direct lights.
+
# the light map has been prescaled by 0.5
+
textureBlend multiply(texture colorScalar) select(texture)
+
end
+
           
+
            stage
+
              texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
           
+
              textureAddressing tile tile
+
              ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
+
              ffTextureCoordsSource 0
+
+
              textureBlend multiplyScale2(texture outRegister) select(colorScalar)
+
            end
+
           
+
        else
+
 
          
 
          
         # no lightmap case:
+
         pass           
 
+
             shaderProgram -target vertexProgram -method assemble
              
+
              bindConstants 0 -bindingID geomToClip -constantCount 4
             colorScalar ($stdMatDiffCoef) 1
+
              shaderSource
 +
                  vs_1_1
 +
                  dcl_position v0
 +
                  m4x4 oPos, v0, c0
 +
              endShaderSource
 +
             end
 
              
 
              
 +
            colorScalar (0,0,0) 0.5
 
             stage
 
             stage
               texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
               textureBlend select(colorScalar) select(colorScalar)
           
+
             end          
              textureAddressing tile tile
+
        end
              ffTextureMatrix -scalev (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
+
      end     
              ffTextureCoordsSource 0
+
enddef
             
+
              textureBlend multiply(colorScalar texture) select(colorScalar)
+
             end
+
         
+
           
+
  
        endif
+
define TransparentMirrorReflectionMaterial()
       
+
+
+
end
+
 
+
      if ( $lightMapAvailable) # thumbnails don't have lightmaps, causing this to fail without them, so assume no work to be done without lightmaps.
+
 
        
 
        
        if ($lmIntegratedShadows )
+
      shader -layer -9998  # this material must render first
            # Still experimental
+
        validateRenderShaderContext -viewerRenderType $kRenderTypeMirror # reflection render
            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
+
  
 +
        pass -renderEachFrame
 +
            renderTarget $reflectionRenderTarget -setViewport viewportFromParentRenderContext
  
#beginshader FloorReflective
+
            depthTest true -enableDepthWrite true
#description Basic floor tile shader with reflection; texture + floor gradient + shadows
+
#extraparam float floorMaterialScaleU 1 0.125 64 ; no. tiles to map for U axis, use any positive number
+
#extraparam float floorMaterialScaleV 1 0.125 64 ; no. tiles to map for V axis, use any positive number
+
#extraparam float reflectStrength 1 0 1 ; strength of reflection, in range 0 to 1
+
  
set ratioH 1  # default material parameter value
+
            applyStencilStateForOverlappingReflections
set ratioW 1  # default material parameter value
+
set useReflectionFloors 0 # default material parameter value
+
define FloorReflective()
+
material
+
shader
+
#reflective floors are currently dead. might ressurect them in an expansion pack
+
+
end
+
end
+
enddef
+
  
 +
            alphaBlend srcFactor(zero) add dstFactor(one)
  
 +
            cullmode none
  
#
+
            shaderProgram -target vertexProgram -method assemble           
# gridMaterial -- composites the alpha grid texture over the normal floor texture
+
               bindConstants 0 -bindingID geomToClipFromParentView -constantCount 4
#                NOTE: In order to guarantee this is drawn on top of the normal
+
              shaderSource
#                floor tile textures, the layer has to be higher than that for
+
                   vs_1_1
#                the normal floor textures.
+
                   dcl_position v0
 
+
                   def c5, 1,0,0,1
define TileGridMaterial()
+
                   m4x4 r0,  v0c0
 
+
                   mov oPos.x, -r0
material
+
                   mov oPos.yzw, r0                 
      if (viewerRenderType = $kRenderTypeNormal)
+
               endShaderSource
     
+
             end
        shader -layer $gridLayer
+
           
+
               # this is using modifiedEachFrameHint, because when the pool tool
+
              #  is used it does not invalidate the entire terrain or invalidate the frame.
+
              pass -fixedFunction # -modifiedEachFrameHint
+
                  validateRenderShaderContext -viewerRenderType $kRenderTypeNormal  # normal render
+
           
+
                   create LightingStatesNoStdLights()
+
                   alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
                    
+
                  # Add an alpha test to avoid processing fully transparent pixels
+
                  alphaTest true 0
+
                  alphaTestFunction acceptIfGreater                 
+
                   
+
                  # Since the terrain has identical geometry, and is assumed to be rendered
+
                   # before the grid, there is no need to write to the z-buffer again. If
+
                   # the geometry of the grid diverges from the geometry of the terrain, we
+
                   # *may* want to reenable depth writes here.
+
                 
+
                  depthTest true -enableDepthWrite false
+
                  ffDepthOffset 2
+
                  fillmode $stdMatFillMode
+
                  colorScalar (0,0,0) $floorGridAlpha
+
                  stage
+
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
                    ffTextureCoordsSource 0
+
                    textureBlend multiply(texture colorScalar) multiply(texture colorScalar)
+
                  end
+
               end
+
              
+
        end #shader
+
      else
+
        shader
+
       
+
 
         end
 
         end
       endif
+
       end
end #mat
+
enddef
+
  
#
+
      shader -layer 6
# inverseGridMaterial -- composites the inverse of the alpha grid texture over the normal floor texture
+
        validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
#                NOTE: In order to guarantee this is drawn on top of the normal
+
        pass -modifiedEachFrameHint
#                floor tile textures, the layer has to be higher than that for
+
            shaderProgram -target vertexProgram -method assemble           
#                the normal floor textures.
+
              bindConstants 0 -bindingID geomToClip -constantCount 4
 +
              bindConstants 4 -bindingID clipToViewTarget -constantCount 4
 +
              shaderSource
 +
                  vs_1_1
 +
                  dcl_position v0
 +
                  def c8,   -0.5, -0.5, 1, 1
 +
                  def c9,    0.5,  0.5, 0, 0
 +
                  def c10,    0.25, 0.25, 0, 0
 +
                  m4x4 r0,  v0,  c0
 +
                  mov oPos, r0
 +
                  mul r2, c9, r0.w
 +
                  mad r4, r0, c8, r2
 +
                  rcp r3.x, c4.x                                 
 +
                  rcp r3.y, c5.y
 +
                  mov r3.zw, c9.zw
 +
                  mul r3, r3, c10
 +
                  mad r6, r0, r3, r4
 +
                  mov oT0, r6.xyww
 +
              endShaderSource             
 +
            end
  
define InverseTileGridMaterial()
+
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
            depthTest true -enableDepthWrite false
 +
            colorScalar (0,0,0) 0.25
  
#trace "$currentMaterialName  inverse tile grid material"
+
             stage
+
               textureTransformType vector3 homogeneous
  material
+
               textureAddressing clamp clamp
shader -layer $gridLayer
+
               texture $reflectionRenderTarget
        if (viewerRenderType = $kRenderTypeNormal)
+
               textureBlend select(texture) select(colorScalar)
     
+
            end
             create DetermineHardwareSupport()
+
                     
           
+
            if ($useHWShader1Path or $useHWShader2Path)
+
               create PixelShaderInverseTileGridRendering()
+
            else
+
               # this pass draws the completely opaque region of the grid line
+
               # hiding the incorrect sorting behavior of the second pass at high
+
              # resolution mipmap levels
+
              pass -fixedFunction
+
                  create LightingStatesNoStdLights()
+
                  alphaTest true 192
+
                  alphaTestFunction acceptIfGreater
+
                  fillmode $stdMatFillMode
+
 
+
                  stage
+
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
                    ffTextureCoordsSource 0
+
                    textureBlend select(texture:invert) select(texture)
+
                  end
+
               end
+
 
+
              # this pass draws the transition region along the edges of the grid lines
+
              # this provides a blurry grid at lower mipmap levels (where the solid grid
+
              # line disappears entirely)
+
              pass -fixedFunction
+
                  create LightingStatesNoStdLights()
+
                  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
                  alphaTest true 192
+
                    alphaTestFunction acceptIfLess
+
                  depthTest true -enableDepthWrite false
+
                  fillmode $stdMatFillMode
+
 
+
                  stage
+
                    texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
+
                    ffTextureCoordsSource 0
+
                    textureBlend select(texture:invert) select(texture)
+
                  end  
+
              end
+
            endif
+
 
         end
 
         end
       else
+
       end
        shader
+
       
+
        end
+
      endif
+
end
+
enddef
+
 
+
 
+
define TileLocalGridMaterial()
+
  material
+
      # 7/26/04 This material should only be reinstated if the cursor moves a part that causes
+
      # visible damage to be updated with respect to where it is moved.  Marking all the
+
      # terrain tiles with this modifiedEachFrameHint is too slow.  For now this material
+
      # is disabled.
+
 
        
 
        
       if (viewerRenderType = $kRenderTypeNormal)
+
       shader -layer 6     
     
+
        validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
        attributes
+
         pass -modifiedEachFrameHint
            attribute alphaScale float1
+
             shaderProgram -target vertexProgram -method assemble           
            attribute alphaTrans float2
+
               bindConstants 0 -bindingID geomToClip -constantCount 4
        end
+
               bindConstants 4 -bindingID clipToViewTarget -constantCount 4
       
+
               shaderSource
         shader -layer $gridLayer
+
                  vs_1_1
            vertexFormatPred blendindices  0 false
+
                  dcl_position v0
            vertexFormatPred targetindices 0 false
+
                  def c8,   -0.5, -0.5, 1, 1
           
+
                  def c9,    0.5,  0.5, 0, 0
            # Local grid is revelated across the multiple tiles and it does not track damage.
+
                  def c10,   0.25, 0.25, 0, 0
            # Using modifiedEachFrameHint so that grid lines are not left behind.
+
                  m4x4 r0,  v0,  c0
             pass -fixedFunction # -modifiedEachFrameHint
+
                  mov oPos, r0
               create LightingStatesNoStdLights()
+
                   mul r2, c9, r0.w
               alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
                   mad r4, r0, c8, r2
               # Add an alpha test to avoid processing fully transparent pixels
+
                   rcp r3.x, c4.x                                 
              alphaTest true 0
+
                   rcp r3.y, c5.y
              alphaTestFunction acceptIfGreater
+
                   mov r3.zw, c9.zw
              # Since the terrain has identical geometry, and is assumed to be rendered
+
                   mul r3, r3, c10
              # before the grid, there is no need to write to the z-buffer again. If
+
                   mad r1, r0, r3, r4
              # the geometry of the grid diverges from the geometry of the terrain, we
+
                   rcp r1.w, r1.w
              # *may* want to reenable depth writes here.
+
                   mul oT0.xy, r1.w, r1.xy
              depthTest true -enableDepthWrite false
+
               endShaderSource             
              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
        end
 
      else
 
        shader
 
       
 
        end
 
      endif
 
  end
 
enddef
 
  
 +
            alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
            depthTest true -enableDepthWrite false
 +
            colorScalar (0,0,0) 0.25
  
define SelectFloorLightMap()
+
            stage
  texture "floorLightMap_${page}"
+
              textureAddressing clamp clamp
  ffTextureCoordsSource 1
+
              texture $reflectionRenderTarget
enddef
+
              textureBlend select(texture) select(colorScalar)
 
+
             end
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
 
       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
 
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
+
materialDefinition transparent_mirror_reflection
   setDefinition StandardMaterial
+
   setDefinition TransparentMirrorReflection
  addParam  stdMatSpecPower 0
+
  addParam  stdMatDiffCoef (0.5, 0.5, 0.5)
+
  addParam  stdMatBaseTextureName floor-edge
+
  addParam  stdMatBaseTextureEnabled true
+
 
end
 
end

Latest revision as of 00:44, 9 July 2009

define TransparentMirrorReflection()

  material
     if (viewerRenderType = $kRenderTypeShadow)
        create StandardShaderShadow()
     else
        if (viewerRenderType = $kRenderTypeThumbnail)
           create TransparentBlankMirrorMaterial($kRenderTypeThumbnail)
        else            
           if (not $mirrorReflectionsEnabled)
              set currentType (viewerRenderType)
              create TransparentBlankMirrorMaterial($currentType)
           else
              create TransparentMirrorReflectionMaterial()
           endif            
        endif         
     endif
  end

enddef

define TransparentBlankMirrorMaterial(renderType)

     shader
        validateRenderShaderContext -viewerRenderType  &renderType
        
        pass             
           shaderProgram -target vertexProgram -method assemble
              bindConstants 0 -bindingID geomToClip -constantCount 4
              shaderSource
                 vs_1_1
                 dcl_position v0
                 m4x4 oPos, v0, c0
              endShaderSource
           end
           
           colorScalar (0,0,0) 0.5
           stage
              textureBlend select(colorScalar) select(colorScalar)
           end            
        end
     end      

enddef

define TransparentMirrorReflectionMaterial()

     shader -layer -9998   # this material must render first
        validateRenderShaderContext -viewerRenderType $kRenderTypeMirror  # reflection render
        pass -renderEachFrame
           renderTarget $reflectionRenderTarget -setViewport viewportFromParentRenderContext
           depthTest true -enableDepthWrite true
           applyStencilStateForOverlappingReflections
           alphaBlend srcFactor(zero) add dstFactor(one)
           cullmode none
           shaderProgram -target vertexProgram -method assemble            
              bindConstants 0 -bindingID geomToClipFromParentView -constantCount 4
              shaderSource
                 vs_1_1
                 dcl_position v0
                 def c5, 1,0,0,1
                 m4x4 r0,   v0,  c0
                 mov oPos.x,  -r0
                 mov oPos.yzw, r0                  
              endShaderSource
           end
        end
     end
     shader -layer 6
        validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
        pass -modifiedEachFrameHint
           shaderProgram -target vertexProgram -method assemble            
              bindConstants 0 -bindingID geomToClip -constantCount 4
              bindConstants 4 -bindingID clipToViewTarget -constantCount 4
              shaderSource
                 vs_1_1
                 dcl_position v0
                 def c8,    -0.5, -0.5, 1, 1
                 def c9,     0.5,  0.5, 0, 0 
                 def c10,    0.25, 0.25, 0, 0
                 m4x4 r0,   v0,  c0
                 mov oPos, r0
                 mul r2, c9, r0.w
                 mad r4, r0, c8, r2
                 rcp r3.x, c4.x                                   
                 rcp r3.y, c5.y
                 mov r3.zw, c9.zw
                 mul r3, r3, c10
                 mad r6, r0, r3, r4
                 mov oT0, r6.xyww
              endShaderSource               
           end
           alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
           depthTest true -enableDepthWrite false
           colorScalar (0,0,0) 0.25
           stage
              textureTransformType vector3 homogeneous
              textureAddressing clamp clamp
              texture $reflectionRenderTarget
              textureBlend select(texture) select(colorScalar)
           end
                      
        end
     end
     
     shader -layer 6      
        validateRenderShaderContext -viewerRenderType $kRenderTypeNormal
        pass -modifiedEachFrameHint
           shaderProgram -target vertexProgram -method assemble            
              bindConstants 0 -bindingID geomToClip -constantCount 4
              bindConstants 4 -bindingID clipToViewTarget -constantCount 4
              shaderSource
                 vs_1_1
                 dcl_position v0
                 def c8,    -0.5, -0.5, 1, 1
                 def c9,     0.5,  0.5, 0, 0
                 def c10,    0.25, 0.25, 0, 0
                 m4x4 r0,   v0,  c0
                 mov oPos, r0
                 mul r2, c9, r0.w
                 mad r4, r0, c8, r2
                 rcp r3.x, c4.x                                   
                 rcp r3.y, c5.y
                 mov r3.zw, c9.zw
                 mul r3, r3, c10
                 mad r1, r0, r3, r4
                 rcp r1.w, r1.w
                 mul oT0.xy, r1.w, r1.xy
              endShaderSource               
           end
           alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
           depthTest true -enableDepthWrite false
           colorScalar (0,0,0) 0.25
           stage
              textureAddressing clamp clamp
              texture $reflectionRenderTarget
              textureBlend select(texture) select(colorScalar)
           end
           
        end
     end

enddef

  1. ---------------------------------------------------------------------------------------------------------------#

materialDefinition transparent_mirror_reflection

  setDefinition TransparentMirrorReflection

end

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox