Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
Line 1: Line 1:
#
 
# Shaders for the Sims themselves
 
#
 
# Most Sims shaders (currently) come from the Alias export.
 
# However, here are a few special ones.
 
#
 
  
  
  
# A gray default shader for when we can't find one
+
# ==============================================================================
  
materialDefinition defaultSimsShader
+
setf swvsWaterlineShift -0.50
  setDefinition Phong
+
  addParam stdMatDiffCoef (.5, .5, .6)
+
end
+
  
  
# contains the shader pre-create commands for all Sim materials
+
define NeighborhoodTerrainPrepWorkSWVS()
define SimsShaderPreCreate()
+
  preCreate -viewerRenderType $kRenderTypeNormal -viewerRenderType ($mirrorReflectionsEnabled ? $kRenderTypeMirror : $kRenderTypeNormal) -deformations
+
#<
+
  preCreate -lights directional 2
+
  preCreate -lights directional 2 point 1
+
  preCreate -lights directional 2 point 2
+
  preCreate -lights directional 2 point 3
+
  preCreate -lights directional 2 point 4
+
  preCreate -lights directional 2 point 5
+
  preCreate -lights directional 2 point 6
+
  preCreate -lights directional 2 point 1 spot 1
+
  preCreate -lights directional 2 spot  1
+
  preCreate -lights directional 5 environmentCube 1
+
#>
+
enddef
+
  
 +
# this material does nothing but prep the z-buffer, and render black.
  
# special layer for the censor shader. This ensures that the censor shader can
+
pass
# be skipped during the censor render itself. The number is referred to from
+
# C++ code.
+
seti kCensorShaderLayer -1
+
 
+
# material to copy from the censor texture to the view target
+
define CensorCompositingMaterial()
+
  material
+
      shader -layer ($kCensorShaderLayer)
+
        pass
+
            renderTarget viewerRenderTarget
+
         
+
            # vertex program           
+
            shaderProgram -target vertexProgram -method assemble
+
              shaderSource
+
                  vs_1_1
+
                  dcl_position v0
+
                  dcl_texcoord v1
+
                 
+
                  mov oPos, v0
+
                  mov oT0.xy, v1
+
                 
+
              endShaderSource
+
            end
+
       
+
            # pixel program
+
            stage
+
              texture "CensorTexture"
+
       
+
              textureFilterHint point point
+
              textureAddressing clamp clamp clamp
+
       
+
              textureBlend select(texture) select(texture)
+
            end
+
        end
+
      end
+
  end
+
enddef
+
 
+
materialDefinition CensorMaterial
+
  setDefinition CensorCompositingMaterial 
+
end
+
  
 +
shaderProgram -target vertexProgram -method link
  
define PlumbBobAnimatedColor()
+
create BindsForSoftwareVSTransforms(false false)
material
+
shaderFragment TransformPositionRigidNoLighting2_x
attributes
+
shaderFragment NoLighting2_x
attribute myColor float3 (0, 1, 0)
+
attribute myAlpha float1 0.843
+
 
end
 
end
 
+
 +
colorScalar (0.0, 0.0, 0.0, 1.0)
 +
     
 +
stage
 +
textureBlend select(colorScalar) select(colorScalar)
 +
end
 +
end
 
 
+
enddef
shader -layer (18 * 17 + 17)
+
+
validateRenderShaderContext -vertexFormat position 0 required
+
validateRenderShaderContext -vertexFormat normal 0 required
+
  
create DetermineHardwareSupport()
 
create SetupCommonHWShaderVariablesAndPredicates()
 
 
  
if ($useFixedFunctionPath)
+
# ==============================================================================
pass -fixedFunction
+
# Used for those triangles in the canvas which are partially under water.
create LightingStates()
+
#
create AttenuatedMatCoef(0.25)
+
define NeighborhoodWaterlineStraddleSWVS()
fillmode $stdMatFillMode
+
  
depthTest true -enableDepthWrite false
+
    vertexFormatPred position      0 true
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
    vertexFormatPred normal        0 true
 +
    vertexFormatPred texcoord      0 true
 +
    viewerRenderTypePred $kRenderTypeReflection
  
stage
+
pass
colorScalar @myColor @myAlpha
+
shaderProgram -target vertexProgram -method link
textureBlend multiplyScale4(diffuse colorScalar) multiply(diffuse colorScalar)
+
create BindsForSoftwareVSTransforms(false false)
end
+
bindConstants 11 -bindingID immediateData -data (0,0, 1.0/$waterHeight , -0.25) -constantType float
+
create TransformFragments(false false true false 0 0 false 2_x)
end # pass
+
shaderFragment TerrainWaterMaskTexGenUVZero2_x
else
+
end
 +
 +
alphaBlend srcFactor(one) add dstFactor(srcAlpha)
 +
cullmode none # so that reflections don't "creep under" edge of terrain
 +
#colorScalar (0.0, 1.0, 0.1, 0.0)
  
# empircally, there are NO lights associated with the plumb bob, so I won't bother to compute them.
+
#alphaTest true 128
pass
+
#alphaTestFunction acceptIfGreater
+
shaderProgram -target vertexProgram -method link
+
create BindsForHardwareVS1Transforms(false false)
+
shaderFragment TransformPositionRigidNoLighting1_1
+
shaderFragment NoLighting1_1
+
end
+
+
depthTest true -enableDepthWrite false
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
  
stage
+
depthTest true -enableDepthWrite true
colorScalar @myColor @myAlpha
+
depthTestFunction accept
textureBlend multiplyScale4(diffuse colorScalar) select(colorScalar)
+
end  #stage
+
 
 
end # pass
+
stage
endif
+
# above water -- clip by using depth-based 0/1 texture.
       
+
texture blackWhite
       
+
textureAddressing clamp clamp
       
+
textureFilterHint point point
end # shader
+
textureMIPFilterHint disabled
end #material
+
         
 
+
textureBlend select(texture) select(texture)
 +
end  
 +
 
 +
end
 +
 +
 
enddef
 
enddef
 
 
  
  
# New material for use of new plumb bob
 
materialDefinition plumbBob_core
 
  setDefinition PlumbBobAnimatedColor
 
  addParam      stdMatDiffCoef (1,1,1,1)
 
end
 
  
 +
# used to render black on the straddle piece, so other passes can plop stuff on top.
 +
define NeighborhoodWaterlineStraddleStandardCameraSWVS()
  
  
 +
pass
 +
shaderProgram -target vertexProgram -method link
 +
create BindsForSoftwareVSTransforms(false false)
 +
shaderFragment TransformPositionRigidNoLighting2_x
 +
shaderFragment NoLighting2_x
 +
end
 +
 +
#alphaBlend srcFactor(one) add dstFactor(zero)
 +
 +
cullmode none # so that reflections don't "creep under" edge of terrain
 +
colorScalar (0.0, 0.0, 0.0, 1.0)
  
 +
stage
 +
textureBlend select(colorScalar) select(colorScalar)
 +
end
  
 +
end
  
 +
 +
enddef
  
#########################################################
 
# Sims Shaders
 
#
 
# These include a version of the standard material
 
# (SimStandardMaterial) that is used for things
 
# such as hair and faces, and SimSkin, which is
 
# used for a body with composited textures.
 
  
 +
# ==============================================================================
 +
# Material for terrain geometry that is partially or completely under water.
 +
define NeighborhoodUnderWaterTerrainSWVS()
 +
 
 +
 
 +
pass
 +
 +
shaderProgram -target vertexProgram -method assemble
 +
create BindsForSoftwareVSTransforms(false false)
 +
 +
setf normalizerScale (1.0/($waterHeight))
  
# Any mesh subsets that use composited textures must be use the following material
+
setv4 texgenData ($normalizerScale, 1, $waterHeight, -0.5)
# The aliasshader command tells the mel parser that SimSkin has the same parameters as StandardMaterial
+
 +
bindConstants 11 -bindingID immediateData -data $texgenData
 +
 +
shaderSource
 +
vs_1_1
 +
 +
def c12,0, 0.5 ,1,2
 +
dcl_position v0
 +
 +
m4x4 oPos, v0, c4    ; geom to clip
 +
 +
mad r0.xyz, v0.zzz, -c11.xxx, c11.yy    ; normalize this from 0 to 1.
 +
 +
mov oT0.xy, r0
 +
 +
add oT1.xy, r0, -c11.ww    ; shift by 0.5, so that the 'clip texture', ends up at the water level.
  
# if compositing is to be used, these are the names of the composited textures
+
mov oD0, c12.y
set  compositeBaseTextureName  ""
+
endShaderSource
set  compositeBaseTextureParam  ""
+
set  compositeSpecTextureName  ""
+
end
set  compositeSpecTextureParam  ""
+
set  compositeBumpTextureName  ""
+
alphaBlend srcFactor(zero) add dstFactor(srcColor)
set  compositeBumpTextureParam  ""
+
 +
cullmode none # so that reflections don't "creep under" edge of terrain
 +
 +
alphaTest true 128
 +
alphaTestFunction acceptIfGreater
  
# allow at most 8 base (diffuse) textures to be composited
+
# apply depth-based gradient texture to terrain that is under water.
set  baseTexture0 ""
+
set  baseTexture1 ""
+
set  baseTexture2 ""
+
set  baseTexture3 ""
+
set  baseTexture4 ""
+
set  baseTexture5 ""
+
set  baseTexture6 ""
+
set  baseTexture7 ""
+
  
# allow at most 8 specular mask textures to be composited
+
set  specTexture0 ""
+
stage
set  specTexture1 ""
+
texture $waterGradientTexture
set  specTexture2 ""
+
textureAddressing clamp clamp
set  specTexture3 ""
+
textureBlend multiply(diffuse texture) select(outRegister)
set  specTexture4 ""
+
end
set  specTexture5 ""
+
set  specTexture6 ""
+
set  specTexture7 ""
+
  
# allow at most 8 normal map textures to be composited
 
set  bumpTexture0 ""
 
set  bumpTexture1 ""
 
set  bumpTexture2 ""
 
set  bumpTexture3 ""
 
set  bumpTexture4 ""
 
set  bumpTexture5 ""
 
set  bumpTexture6 ""
 
set  bumpTexture7 ""
 
  
# the number of textures to composite
+
stage
set  numTexturesToComposite  0
+
texture blackWhite
 +
textureAddressing clamp clamp
 +
textureFilterHint point point
 +
textureMIPFilterHint disabled
 +
textureBlend select(outRegister) select(texture)
 +
end
 +
 +
#<
 +
stage
 +
textureBlend select(diffuse) select(diffuse)
 +
end
 +
#>
  
#beginshader SimSkin
+
end
#description The basic material for defining a material that will be composited with Skin.
+
#extraparam int  stdMatLayer 0 -32 32 ; attrdescription Layer for drawing, use even for opaque and odd for translucent
+
enddef
#extraparam enum stdMatAlphaBlendMode  none  (none)  ; Never blended
+
#endshader SimSkin
+
  
# generic overall hint (ie, in game)
+
# ==============================================================================
setb useCPUCompositedTextures true
+
# renders the terrain colors. The geometry is a patchwork 'quilt' of sorts, with overlapping edges
 +
# this overlapping is handled by alpha blending
  
include DX9SimMaterials.matShad
 
include DX8SimMaterials.matShad
 
include DX7SimMaterials.matShad
 
include SWVSSimMaterials.matShad
 
  
# face materials set this to 'true' so that the eyes can move.
+
define NeighborhoodMainTerrainShaderSWVS()
setb eyeGizmoEnable false
+
  
# game will set this if in CAS, so all sim materials can composite on the fly.
 
setb simSkinFlag false
 
setb contentViewer false
 
  
 +
pass
 +
  if (not $isImposter)
 +
  shaderProgram -target vertexProgram -method link
 +
  create BindsForSoftwareVSTransforms(false false)
 +
 
 +
  setv4 texgenData (1.0/$nhoodPaintTextureScale, 1.0/$nhoodPaintTextureScale, $alphaMapScaleU, $alphaMapScaleV )
 +
 
 +
  bindConstants 11 -bindingID immediateData -data  $texgenData -constantType float
 +
  # no morphs, skins or normals
 +
  shaderFragment TransformPositionRigidNoLighting2_x
 +
  shaderFragment TerrainPaintTexGen2_x
 +
  end
 +
else
 +
  shaderProgram -target vertexProgram -method assemble
 +
  create BindsForSoftwareVSTransforms(false false)
  
# This is a fudge factor, what this does is cover up a boo-boo I made.
+
  setv4 texgenData (1.0/$nhoodPaintTextureScale, 1.0/$nhoodPaintTextureScale, $alphaMapScaleU, $alphaMapScaleV )
# the lighting.txt file was 'tuned' using a DX7 sim material with a 0.4 multiplier, instead of 0.5 (x2 on the blender side to get back to 1.0)
+
  bindConstants 11 -bindingID immediateData -data $texgenData
# what this lead to was a desired look on dx7 cards, but dx8 and dx7 were washed out, being 20% brighter.
+
 
# so this fudge factor scales sims in dx8 and dx9 'down' by this amount to bring them into line with the "broken" dx7.
+
  shaderSource
# for now, this is a temp fix for E3 2004, but this might live on forever.  
+
  vs_1_1
# in a perfect world, this factor will be removed and the game lighting 're tuned' to use the unscaled lighting.
+
 
# this will probably need to happen anyway, with new materials and lighting models planned in the expansion packs.
+
  def c12,0, 0.5 ,1,2
 +
  def c13, 0.0076923, 0.25, 0, 0
 +
  dcl_position v0  
 +
  m4x4 oPos, v0, c4
 +
                             
 +
              mov oT0.xy, c13.yy
 +
              mul oT1.xy, c11.xy, v0.xy
 +
            endShaderSource
 +
  end
 +
endif
 +
 +
alphaBlend srcFactor(srcAlpha) add dstFactor(one)
 +
cullmode none # so that reflections don't "creep under" edge of terrain
 +
                   
 +
#colorScalar $nhoodSunDirBiased
 +
       
 +
depthTest true -enableDepthWrite false
 +
depthTestFunction acceptIfEqual
 +
 +
colorScalar 1.0,1.0,1.0,1.0
 +
 +
stage
 +
texture $alphaMap
 +
textureAddressing clamp clamp
 +
textureBlend select(colorScalar) select(texture)
 +
end
 +
 +
stage
 +
texture $paintTexture
 +
textureAddressing tile tile
 +
textureBlend multiply(texture outRegister) select(outRegister)
 +
end
 +
end
 +
 +
enddef
  
setf simMaterialLightingScale 0.8
 
  
  
define SimSkin()
 
  
material
+
# ==============================================================================
  
setb simSkinFlag true
+
define NeighborhoodWaterSWVS()
 
+
shader -layer (($waterLayer) * 18 + 17)
#trace "$currentMaterialName simskin"
+
 
+
setb hasSecondUV (hasVertexFormat(texcoord, 1))
+
#trace "SIMSKIN $currentMaterialName  UV2: $hasSecondUV Eye: $eyeGizmoEnable"
+
 
 
 +
validateRenderShaderContext -viewerRenderType viewerRenderType
 
 
# if it has eyes, then it's a face too.
+
pass
# .x = U shift (up/down) of eye, y = V shift (left/right) of eye, z = left eye stretch, w = right eye stretch
+
# might be switched to a 'look at' vector, so the VS can compute the offsets directly.
+
 
+
  # body may stil get these attributes, but the VS attached to the material only looks at these if a 2nd UV exists and
+
  # eyeGizmoEnable is true.
+
 
+
attributes
+
      attribute eyeDirection float2 (0, 0)
+
attribute l_eyeStretch float1 (0)
+
attribute r_eyeStretch float1 (0)
+
end
+
 
+
create SimsShaderPreCreate()   
+
create DetermineHardwareSupport()
+
 
+
# always composite on the CPU for anything other than dx9.
+
#if ($useSWVertexShaderPath or $useFixedFunctionPath or $useHWShader1Path)
+
# #trace "Using CPU composited textures"
+
# setb useCPUCompositedTextures true
+
#endif
+
+
+
#if ($useCPUCompositedTextures)
+
 
+
# pass through base texture name
+
 
 
if ($numTexturesToComposite)
+
fillmode $stdMatFillMode
if (strcmp("${compositeBaseTextureName}", "") != 0)
+
set stdMatBaseTextureName $compositeBaseTextureName
+
set stdMatBaseTextureEnabled true
+
else
+
set stdMatBaseTextureEnabled false
+
endif
+
endif
+
     
+
 
 
# do nothing is stdMatBaseTextureName is non-null, then just leave it alone...
+
alphaBlend srcFactor(one) add dstFactor(srcAlpha)
# this is contentViewer case.
+
 
+
shaderProgram -target vertexProgram -method assemble
+
create BindsForSoftwareVSTransforms(false false)
+
shaderSource
if ($useHWShader2Path and $bumpMapping)
+
if (strcmp("${compositeBumpTextureName}", "") != 0)
+
set stdMatNormalMapTextureName $compositeBumpTextureName
+
setb stdMatNormalMapTextureEnabled true
+
else
+
# if this is null, then make sure stuff is turned off
+
if (strcmp("${stdMatNormalMapTextureName}", "") = 0)
+
setb stdMatNormalMapTextureEnabled false
+
endif
+
 
 
#otherwise, leave everything alone, it's a non-compositing simSkin
+
vs_1_1
+
endif
+
def c50, 0, 0.5,1,2
endif
+
def c11, 0,0,1,0
+
def c12, 0.2,0.5,0.7, 0.1
setb bViewerIsThumbnail (viewerRenderType = $kViewerRenderTypeFamilyThumbnail)  
+
dcl_position v0
 +
dcl_normal v1
 +
m4x3 r0.xyz, v0, c8  ; to camera space
 +
m3x3 r3.xyz, v1, c8
 
 
# we only want to render thumbnails in fixed function and we want to do two passes to correct alpha for the thumbnail
+
mov r0.w, c50.z
if ($useHWShader2Path and not $bViewerIsThumbnail)
+
m4x4 oPos, r0, c0    ; camera to clip
create CreateSimStandardMaterialDX9()
+
endif
+
dp3 r1.w, r0, r0
+
rsq r1, r1.w
# if ($useHWShader1Path)
+
mul r1, r1.w, r0 ; r1= view vector.
# create CreateSimStandardMaterialDX8()
+
# endif
+
dp3 r2, r3, -r1 ; view dot normal
+
max r2, r2, c50.x
if ($useSWVertexShaderPath)
+
create CreateSimStandardMaterialSWVS()
+
endif
+
+
if ($useFixedFunctionPath or $useHWShader1Path or ($bViewerIsThumbnail and not $useSWVertexShaderPath))
+
create CreateSimStandardMaterialFixedFunction()
+
endif     
+
#<
+
else
+
 
+
+
# backup case for Content viewer, which can have no compositing.
+
 
+
if (strcmp("${baseTexture0}","") = 0)
+
    # if base is null, then hopefull the stdMatBase/NormalMap names are OK, so send it to SimStandard, which has no layering.
+
    setb contentViewer true
+
create SimStandardMaterial()
+
else
+
+
if ($useHWShader2Path)
+
#trace "HW2 GPU COMPOSITE: $currentMaterialName"
+
create DX9SimSkinCompositingMaterial()
+
endif
+
+
+
if ($useHWShader1Path)
+
#trace "HW1: $currentMaterialName"
+
create CreateSimSkinPerPixelCompositingMaterialPS1()
+
endif
+
 
 
 +
add r3, c50.z, -r2
 +
 +
mul oD0.xyz, r3, c12
 +
mov oD0.w, r2
 +
 +
endShaderSource
 +
end
 
 
if ($useFixedFunctionPath)
 
create CreateSimPerPixelCompositingMaterialFixedFunction()
 
endif
 
 
 
endif
+
stage
 +
textureBlend select(diffuse) select(diffuse)
 +
end
 +
end
 
 
 
 
endif
+
end
#>
+
enddef
+
  
end
 
  
 +
# ==============================================================================
 +
# The layer ID for this should be lower than "waterLayer" Id because we want the farther side of the water box should be
 +
# drawn as well.
 +
# the layer ID of any under-water objects (so
 +
define NeighborhoodWaterEdgeSWS()
 +
 
 +
pass
 +
 
 +
alphaBlend srcFactor(one) add dstFactor(zero)
 +
cullmode none # we want to render the father side of the water edge also
 +
           
 +
stage
 +
texture $waterEdgeTexture
 +
textureAddressing tile tile
 +
#ffTextureMatrix -scalev (1/$waterEdgeTextureScale, 1/$waterEdgeTextureScale)
 +
#ffTextureCoordsSource 0
 +
textureBlend select(texture) select(diffuse)
 +
end
 +
end
 +
 
enddef
 
enddef
  
 +
# ==============================================================================
 +
# a terrain edge is a 'slice' or 'cover plate' for the terrain when viewed edge-on, since the terrain is not infinite in all directions.
  
 +
define NeighborhoodTerrainEdgeSWVS()
  
#set up default params
+
pass
setb simHairFlag false
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 
+
       
define SimHair()
+
stage
  setb simHairFlag true
+
texture $terrainEdgeTexture
+
textureAddressing tile tile
if (strcmp("${baseTexture0}","") = 0 or $numTexturesToComposite = 0)
+
create SimStandardMaterial()
+
#ffTextureMatrix -scalev (1/$terrainEdgeTextureScale, 1/$terrainEdgeTextureScale)
else
+
#ffTextureCoordsSource 0
create SimSkin()
+
endif
+
textureBlend multiply(texture diffuse) select(texture)
 +
           
 +
        end
 +
end
 
 
 
enddef
 
enddef
  
  
 +
#==============================================================================
 +
# the last pass that applies the terrain lightmap across the neighborhood, but not underwater
  
# Any Sim materials (clothes/skin) that do not use composited textures use
 
# the following material.
 
  
#beginshader SimStandardMaterial
+
define NeighborhoodTerrainLightingSWVS()
#description Similar to standard material, but used on Sims themselves (fewer options).
+
#extraparam enum stdMatAlphaBlendMode  none  (none blend additive)  ; The transparency mode.
+
#extraparam bool stdMatAlphaTestEnabled 0        ; Can drop pixels, like a 'mask'
+
#extraparam int stdMatAlphaRefValue 127 0 255    ; which alpha value to keep a pixel, 255 is 'white'.
+
#extraparam int  stdMatLayer 0 -32 32 ; attrdescription Layer for drawing, use even for opaque and odd for translucent
+
#extraparam enum stdMatEnvCubeMode  none  (none reflection)  ; add a reflection layer to this material, will not propogate to SimSkin.
+
#endshader SimStandardMaterial
+
  
 +
pass
 +
shaderProgram -target vertexProgram -method assemble
 +
create BindsForSoftwareVSTransforms(false false)
  
 +
setf textureScale (1.0/($waterHeight))
 +
setv4 texgenData ($textureScale, 1, $waterHeight, -0.5)
 +
bindConstants 11 -bindingID immediateData -data $texgenData
 +
 +
shaderSource
 +
vs_1_1
 +
 +
def c12,0, 0.5 ,1,2
 +
def c13, 0.0078125, 0.00078125, 0, 0
 +
dcl_position v0
 +
        endShaderSource
 +
       
 +
        if (not $isImposter)                 
 +
shaderSource  "dcl_texcoord v1"
 +
        endif
  
define SimStandardMaterial()
+
        shaderSource
 +
m4x4 oPos, v0, c4
 +
 +
mad r0.xyz, v0.zzz, -c11.xxx, c11.yy    ; normalize this from 0 to 1.
 +
 +
add oT0.xy, r0, -c11.ww    ; shift by 0.5, so that the 'clip texture', ends up at the water level.
 +
 +
  endShaderSource
  
 
+
        if ($isImposter)          
create DetermineHardwareSupport()
+
            shaderSource               
 
+
              mul oT1.xy, v0.xy, c13.yy
  setb bViewerIsThumbnail (viewerRenderType = $kViewerRenderTypeFamilyThumbnail)
+
            endShaderSource
+
        else
if ($useHWShader2Path and not $bViewerIsThumbnail)
+
            shaderSource "mul oT1.xy, v1, c13.xx"
create CreateSimStandardMaterialDX9()
+
        endif
endif
+
 +
end
 +
 +
# setup for SRC * DEST, standard lightmap.
 
 
 +
alphaBlend srcFactor(destColor) add dstFactor(zero)
 +
 +
alphaTest true 128
 +
alphaTestFunction acceptIfGreater
  
  if ($useSWVertexShaderPath)
+
fillmode $stdMatFillMode
create CreateSimStandardMaterialSWVS()
+
endif
+
 
 
if ($useFixedFunctionPath or $useHWShader1Path or ($bViewerIsThumbnail and not $useSWVertexShaderPath))
+
# not really important to do this?
create CreateSimStandardMaterialFixedFunction()
+
endif
+
 
 
 +
depthTest true -enableDepthWrite false
 +
      depthTestFunction acceptIfEqual
 +
 +
colorScalar (1,1,1,1)
  
enddef
+
stage
 +
# if below water -- get black from this texture.
 +
texture blackWhite
 +
textureAddressing clamp clamp
 +
textureFilterHint point point
 +
textureMIPFilterHint disabled
 +
textureBlend select(texture:alphaReplicate) select(texture:invert)
 +
                 
 +
end
 +
           
 +
stage
 +
texture "nhoodLightMap"
 +
textureBlend multiply(texture outRegister:alphaReplicate) select(outRegister)
 +
end 
  
 +
end
  
  
 
 
 
 
define SimMaterialSetup()
 
 
 
validateRenderShaderContext -vertexFormat position 0 required
 
validateRenderShaderContext -vertexFormat normal 0 required
 
validateRenderShaderContext -vertexFormat texcoord 0 required
 
 
  # no sim material can have specular, since they might diverse and cause seams.
 
  setf stdMatSpecPower 0
 
 
 
seti lightingMode $kNoLighting   
 
 
create SetupCommonHWShaderVariablesAndPredicates()
 
 
if (numLightsOfType(${kShapeColorLight}) > 0 )
 
seti stdMatShapeColorIndex 0
 
set stdMatAlphaBlendMode blend
 
endif
 
 
#trace "Light counts: DISTANT: $distantLightCount, POINT: $pointLightCount, SPOT $spotLightCount"
 
 
create BumpTextureCount()
 
 
if ($stdMatNormalMapTextureEnabled = false)
 
seti bumpTextureCount 0
 
endif
 
 
 
 
#trace "Bump texture count: $bumpTextureCount"
 
#trace "ShapeColor Index for this Sim Material is: $stdMatShapeColorIndex"
 
 
 
  create TestForEyeMotion()
 
 
 
 
enddef
 
enddef
  
  
 +
# ==============================================================================
 +
# for rendering Lots, and when the lot creation tool is being used, this material renders the glowing-gridded rectangles
  
 +
define NeighborhoodTerrainHighlightSWVS()
  
define BumpTextureCount()
+
pass
 
+
seti bumpTextureCount 0
+
 
+
 
+
if ($bumpMapping)
+
 
 
if (strcmp("${bumpTexture0}","")!=0)
+
shaderProgram -target vertexProgram -method link
seti bumpTextureCount ($bumpTextureCount +1)
+
create BindsForSoftwareVSTransforms(false false)
endif
+
#setv4 texgenData (1, 1, 0.0, 0.0)
 +
 +
#bindConstants 11 -bindingID immediateData -data $texgenData
 +
 +
shaderFragment TransformPositionRigidNoLighting2_x
 +
shaderFragment NoTextureMagic2_x
 +
 +
end
 
 
if (strcmp("${bumpTexture1}","")!=0)
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
seti bumpTextureCount ($bumpTextureCount +1)
+
fillmode $stdMatFillMode
endif
+
colorScalar (1, 1, 1, $highlightAlpha)
  
if (strcmp("${bumpTexture2}","")!=0)
+
stage
seti bumpTextureCount ($bumpTextureCount +1)
+
texture $highlightTexture
endif
+
textureAddressing tile tile
+
if (strcmp("${bumpTexture3}","")!=0)
+
seti bumpTextureCount ($bumpTextureCount +1)
+
endif
+
  
if (strcmp("${bumpTexture4}","")!=0)
+
textureBlend select(texture) multiply(texture colorScalar)
seti bumpTextureCount ($bumpTextureCount +1)
+
end
endif
+
end   
 
+
if (strcmp("${bumpTexture5}","")!=0)
+
seti bumpTextureCount ($bumpTextureCount +1)
+
endif
+
 
+
if (strcmp("${bumpTexture6}","")!=0)
+
seti bumpTextureCount ($bumpTextureCount +1)
+
endif
+
 
+
if (strcmp("${bumpTexture7}","")!=0)
+
seti bumpTextureCount ($bumpTextureCount +1)
+
endif
+
+
endif
+
 
+
setb  hasTangents (hasVertexFormat(tangent,0))
+
 
 
 
 
enddef
 
 
 
#==============================================================================
 
# Macro for setting alpha blending and alpha test state for sim hair materials.
 
define SimHairAlphaState(alphaBlendMode) 
 
  #trace "SimHairAlphaState: $currentMaterialName, Alpha Blending Mode: &{alphaBlendMode}"
 
  if (strcmp("&{alphaBlendMode}", "blend") = 0)
 
  alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 
  depthTest true -enableDepthWrite true
 
  alphaTest true 60
 
    alphaTestFunction acceptIfGreater
 
  elseif (strcmp("&{alphaBlendMode}", "additive") = 0)
 
    alphaBlend srcFactor(srcAlpha) add dstFactor(one)
 
  depthTest true -enableDepthWrite false
 
  alphaTest $stdMatAlphaTestEnabled $stdMatAlphaRefValue
 
    alphaTestFunction acceptIfGreaterOrEqual
 
  elseif ($stdMatAlphaTestEnabled)
 
  alphaTest true $stdMatAlphaRefValue
 
    alphaTestFunction acceptIfGreaterOrEqual
 
  endif
 
 
enddef
 
enddef

Revision as of 07:40, 19 March 2008


  1. ==============================================================================

setf swvsWaterlineShift -0.50


define NeighborhoodTerrainPrepWorkSWVS()

  1. this material does nothing but prep the z-buffer, and render black.

pass

shaderProgram -target vertexProgram -method link

create BindsForSoftwareVSTransforms(false false) shaderFragment TransformPositionRigidNoLighting2_x shaderFragment NoLighting2_x end

colorScalar (0.0, 0.0, 0.0, 1.0)

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

enddef


  1. ==============================================================================
  2. Used for those triangles in the canvas which are partially under water.

define NeighborhoodWaterlineStraddleSWVS()

   vertexFormatPred position      0 true
   vertexFormatPred normal        0 true
   vertexFormatPred texcoord      0 true
   viewerRenderTypePred $kRenderTypeReflection

pass shaderProgram -target vertexProgram -method link create BindsForSoftwareVSTransforms(false false) bindConstants 11 -bindingID immediateData -data (0,0, 1.0/$waterHeight , -0.25) -constantType float create TransformFragments(false false true false 0 0 false 2_x) shaderFragment TerrainWaterMaskTexGenUVZero2_x end

alphaBlend srcFactor(one) add dstFactor(srcAlpha) cullmode none # so that reflections don't "creep under" edge of terrain #colorScalar (0.0, 1.0, 0.1, 0.0)

#alphaTest true 128 #alphaTestFunction acceptIfGreater

depthTest true -enableDepthWrite true depthTestFunction accept

stage # above water -- clip by using depth-based 0/1 texture. texture blackWhite textureAddressing clamp clamp textureFilterHint point point textureMIPFilterHint disabled

textureBlend select(texture) select(texture) end

end


enddef


  1. used to render black on the straddle piece, so other passes can plop stuff on top.

define NeighborhoodWaterlineStraddleStandardCameraSWVS()


pass shaderProgram -target vertexProgram -method link create BindsForSoftwareVSTransforms(false false) shaderFragment TransformPositionRigidNoLighting2_x shaderFragment NoLighting2_x end

#alphaBlend srcFactor(one) add dstFactor(zero)

cullmode none # so that reflections don't "creep under" edge of terrain colorScalar (0.0, 0.0, 0.0, 1.0)

stage textureBlend select(colorScalar) select(colorScalar) end

end


enddef


  1. ==============================================================================
  2. Material for terrain geometry that is partially or completely under water.

define NeighborhoodUnderWaterTerrainSWVS()


pass

shaderProgram -target vertexProgram -method assemble create BindsForSoftwareVSTransforms(false false)

setf normalizerScale (1.0/($waterHeight))

setv4 texgenData ($normalizerScale, 1, $waterHeight, -0.5)

bindConstants 11 -bindingID immediateData -data $texgenData

shaderSource vs_1_1

def c12,0, 0.5 ,1,2 dcl_position v0

m4x4 oPos, v0, c4  ; geom to clip

mad r0.xyz, v0.zzz, -c11.xxx, c11.yy  ; normalize this from 0 to 1.

mov oT0.xy, r0

add oT1.xy, r0, -c11.ww  ; shift by 0.5, so that the 'clip texture', ends up at the water level.

mov oD0, c12.y endShaderSource

end

alphaBlend srcFactor(zero) add dstFactor(srcColor)

cullmode none # so that reflections don't "creep under" edge of terrain

alphaTest true 128 alphaTestFunction acceptIfGreater

# apply depth-based gradient texture to terrain that is under water.


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


stage texture blackWhite textureAddressing clamp clamp textureFilterHint point point textureMIPFilterHint disabled textureBlend select(outRegister) select(texture) end

#< stage textureBlend select(diffuse) select(diffuse) end

  1. >

end

enddef

  1. ==============================================================================
  2. renders the terrain colors. The geometry is a patchwork 'quilt' of sorts, with overlapping edges
  3. this overlapping is handled by alpha blending


define NeighborhoodMainTerrainShaderSWVS()


pass if (not $isImposter) shaderProgram -target vertexProgram -method link create BindsForSoftwareVSTransforms(false false)

setv4 texgenData (1.0/$nhoodPaintTextureScale, 1.0/$nhoodPaintTextureScale, $alphaMapScaleU, $alphaMapScaleV )

bindConstants 11 -bindingID immediateData -data $texgenData -constantType float # no morphs, skins or normals shaderFragment TransformPositionRigidNoLighting2_x shaderFragment TerrainPaintTexGen2_x end else shaderProgram -target vertexProgram -method assemble create BindsForSoftwareVSTransforms(false false)

setv4 texgenData (1.0/$nhoodPaintTextureScale, 1.0/$nhoodPaintTextureScale, $alphaMapScaleU, $alphaMapScaleV ) bindConstants 11 -bindingID immediateData -data $texgenData

shaderSource vs_1_1

def c12,0, 0.5 ,1,2 def c13, 0.0076923, 0.25, 0, 0 dcl_position v0 m4x4 oPos, v0, c4

              mov oT0.xy, c13.yy
              mul oT1.xy, c11.xy, v0.xy
           endShaderSource

end endif

alphaBlend srcFactor(srcAlpha) add dstFactor(one) cullmode none # so that reflections don't "creep under" edge of terrain

#colorScalar $nhoodSunDirBiased

depthTest true -enableDepthWrite false depthTestFunction acceptIfEqual

colorScalar 1.0,1.0,1.0,1.0

stage texture $alphaMap textureAddressing clamp clamp textureBlend select(colorScalar) select(texture) end

stage texture $paintTexture textureAddressing tile tile textureBlend multiply(texture outRegister) select(outRegister) end end

enddef



  1. ==============================================================================

define NeighborhoodWaterSWVS() shader -layer (($waterLayer) * 18 + 17)

validateRenderShaderContext -viewerRenderType viewerRenderType

pass

fillmode $stdMatFillMode

alphaBlend srcFactor(one) add dstFactor(srcAlpha)

shaderProgram -target vertexProgram -method assemble create BindsForSoftwareVSTransforms(false false) shaderSource

vs_1_1

def c50, 0, 0.5,1,2 def c11, 0,0,1,0 def c12, 0.2,0.5,0.7, 0.1 dcl_position v0 dcl_normal v1 m4x3 r0.xyz, v0, c8  ; to camera space m3x3 r3.xyz, v1, c8

mov r0.w, c50.z m4x4 oPos, r0, c0  ; camera to clip

dp3 r1.w, r0, r0 rsq r1, r1.w mul r1, r1.w, r0 ; r1= view vector.

dp3 r2, r3, -r1 ; view dot normal max r2, r2, c50.x

add r3, c50.z, -r2

mul oD0.xyz, r3, c12 mov oD0.w, r2

endShaderSource end


stage textureBlend select(diffuse) select(diffuse) end end


end enddef


  1. ==============================================================================
  2. The layer ID for this should be lower than "waterLayer" Id because we want the farther side of the water box should be
  3. drawn as well.
  4. the layer ID of any under-water objects (so

define NeighborhoodWaterEdgeSWS()

pass

alphaBlend srcFactor(one) add dstFactor(zero) cullmode none # we want to render the father side of the water edge also

stage texture $waterEdgeTexture textureAddressing tile tile #ffTextureMatrix -scalev (1/$waterEdgeTextureScale, 1/$waterEdgeTextureScale) #ffTextureCoordsSource 0 textureBlend select(texture) select(diffuse) end end

enddef

  1. ==============================================================================
  2. a terrain edge is a 'slice' or 'cover plate' for the terrain when viewed edge-on, since the terrain is not infinite in all directions.

define NeighborhoodTerrainEdgeSWVS()

pass alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)

stage texture $terrainEdgeTexture textureAddressing tile tile

#ffTextureMatrix -scalev (1/$terrainEdgeTextureScale, 1/$terrainEdgeTextureScale) #ffTextureCoordsSource 0

textureBlend multiply(texture diffuse) select(texture)

        end

end

enddef


  1. ==============================================================================
  2. the last pass that applies the terrain lightmap across the neighborhood, but not underwater


define NeighborhoodTerrainLightingSWVS()

pass shaderProgram -target vertexProgram -method assemble create BindsForSoftwareVSTransforms(false false)

setf textureScale (1.0/($waterHeight)) setv4 texgenData ($textureScale, 1, $waterHeight, -0.5) bindConstants 11 -bindingID immediateData -data $texgenData

shaderSource vs_1_1

def c12,0, 0.5 ,1,2 def c13, 0.0078125, 0.00078125, 0, 0 dcl_position v0

        endShaderSource
        				
        if (not $isImposter)                  				

shaderSource "dcl_texcoord v1"

        endif				
        shaderSource				

m4x4 oPos, v0, c4

mad r0.xyz, v0.zzz, -c11.xxx, c11.yy  ; normalize this from 0 to 1.

add oT0.xy, r0, -c11.ww  ; shift by 0.5, so that the 'clip texture', ends up at the water level.

endShaderSource

        if ($isImposter)            
           shaderSource                
              mul oT1.xy, v0.xy, c13.yy
           endShaderSource
        else
           shaderSource "mul oT1.xy, v1, c13.xx"
        endif

end

# setup for SRC * DEST, standard lightmap.

alphaBlend srcFactor(destColor) add dstFactor(zero)

alphaTest true 128 alphaTestFunction acceptIfGreater

fillmode $stdMatFillMode

# not really important to do this?

depthTest true -enableDepthWrite false

     depthTestFunction acceptIfEqual

colorScalar (1,1,1,1)

stage # if below water -- get black from this texture. texture blackWhite textureAddressing clamp clamp textureFilterHint point point textureMIPFilterHint disabled textureBlend select(texture:alphaReplicate) select(texture:invert)

end

stage texture "nhoodLightMap" textureBlend multiply(texture outRegister:alphaReplicate) select(outRegister) end

end


enddef


  1. ==============================================================================
  2. for rendering Lots, and when the lot creation tool is being used, this material renders the glowing-gridded rectangles

define NeighborhoodTerrainHighlightSWVS()

pass

shaderProgram -target vertexProgram -method link create BindsForSoftwareVSTransforms(false false) #setv4 texgenData (1, 1, 0.0, 0.0)

#bindConstants 11 -bindingID immediateData -data $texgenData

shaderFragment TransformPositionRigidNoLighting2_x shaderFragment NoTextureMagic2_x

end

alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) fillmode $stdMatFillMode colorScalar (1, 1, 1, $highlightAlpha)

stage texture $highlightTexture textureAddressing tile tile

textureBlend select(texture) multiply(texture colorScalar) end end

enddef

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox