Difference between revisions of "TEST-STRCMP4CODES"

From SimsWiki
Jump to: navigation, search
Line 1: Line 1:
##############################################################
+
#
# Pool Water
+
# Shaders for the Sims themselves
 +
#
 +
# Most Sims shaders (currently) come from the Alias export.
 +
# However, here are a few special ones.
 
#
 
#
  
seti poolWaterLayer 5
 
  
  
##############################################################
+
# A gray default shader for when we can't find one
# Simple water material
+
#
+
# This material modulates the vertices by two sin waves --
+
# one in X and one in Y. It then produces reflection and
+
# refraction direction texture coordinates suitable for a
+
# cubic environment map.
+
  
 +
materialDefinition defaultSimsShader
 +
  setDefinition Phong
 +
  addParam stdMatDiffCoef (.5, .5, .6)
 +
end
  
#beginshader PoolWaterMaterialTwoWave
 
#description Pool water with X/Y waves
 
  
#BeginStdAttrBlock
+
# contains the shader pre-create commands for all Sim materials
 +
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
  
  
setf wmTransparency  0.5
+
# special layer for the censor shader. This ensures that the censor shader can
#attrdescription Water transparency
+
# be skipped during the censor render itself. The number is referred to from
 +
# C++ code.
 +
seti kCensorShaderLayer -1
  
setf wmXSpeed        3    # min:0 max:100
+
# material to copy from the censor texture to the view target
#attrdescription Lookup texture for diffuse intensity.
+
define CensorCompositingMaterial()
setf wmXRepeat       1    # min:0 max:100
+
  material
#attrdescription Lookup texture for diffuse intensity.
+
       shader -layer ($kCensorShaderLayer)
setf wmXWaveHeight  0.1  # min:0 max:100
+
        pass
#attrdescription Lookup texture for diffuse intensity.
+
            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
  
setf wmYSpeed        5    # min:0 max:100
+
materialDefinition CensorMaterial
#attrdescription Lookup texture for diffuse intensity.
+
  setDefinition CensorCompositingMaterial    
setf wmYRepeat      1.8  # min:0 max:100
+
end
#attrdescription Lookup texture for diffuse intensity.
+
setf wmYWaveHeight  0.2   # min:0 max:100
+
#attrdescription Lookup texture for diffuse intensity.
+
  
set wmReflectionTexture reflectionoutdoorwater-envcube
 
#attrdescription Environment cube map texture for reflection
 
  
setb wmRefractionEnabled false
+
define PlumbBobAnimatedColor()
#attrdescription Whether refraction is enabled
+
material
 +
attributes
 +
attribute myColor float3 (0, 1, 0)
 +
attribute myAlpha float1 0.843
 +
end
  
set wmRefractionTexture reflectionoutdoorwater-envcube
+
#attrdescription Environment cube map texture for refraction
+
 +
shader -layer (18 * 17 + 17)
 +
 +
validateRenderShaderContext -vertexFormat position 0 required
 +
validateRenderShaderContext -vertexFormat normal 0 required
  
 +
create DetermineHardwareSupport()
 +
create SetupCommonHWShaderVariablesAndPredicates()
 +
  
#EndStdAttrBlock
+
if ($useFixedFunctionPath)
 +
pass -fixedFunction
 +
create LightingStates()
 +
create AttenuatedMatCoef(0.25)
 +
fillmode $stdMatFillMode
  
define PoolWaterSurfaceMaterial()
+
depthTest true -enableDepthWrite false
  material     
+
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
      shader -layer $poolWaterLayer
+
 
        validateRenderShaderContext -vertexFormat position 0 required
+
stage
+
colorScalar @myColor @myAlpha
        create DetermineHardwareSupport()
+
textureBlend multiplyScale4(diffuse colorScalar) multiply(diffuse colorScalar)
   
+
end  
        if ($useSWVertexShaderPath or $useFixedFunctionPath)
+
            # The vertex shader to ripple the water surface is deemed too expensive for SWVS.
+
end # pass
            # Note that because on some low-end cards shaders are turned off, DetermineHardwareSupport()
+
else
            # will set $useFixedFunctionPath to true and $useSWVertexShaderPath to false; however,
+
 
            # since the device is in swvp mode, the RegularWavesHLSL shader would validate anyway, which
+
# empircally, there are NO lights associated with the plumb bob, so I won't bother to compute them.
            # we don't want. Therefore here we do the simplified water surface if using either SWVS or FFP.
+
pass
            create SimplifiedWaterSurface()
+
        else
+
shaderProgram -target vertexProgram -method link
            if ($useHWShader2Path)
+
create BindsForHardwareVS1Transforms(false false)
              create HighEndWaterSurface()              
+
shaderFragment TransformPositionRigidNoLighting1_1
            else
+
shaderFragment NoLighting1_1
              create RegularWavesHLSL()
+
end
            endif
+
        endif
+
depthTest true -enableDepthWrite false
 +
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 +
 
 +
stage
 +
colorScalar @myColor @myAlpha
 +
textureBlend multiplyScale4(diffuse colorScalar) select(colorScalar)
 +
end  #stage
 +
 +
end # pass
 +
endif
 +
       
 
          
 
          
      end #end shader
+
          
     
+
end # shader
      # basic fallback.
+
end #material
      shader -layer $poolWaterLayer
+
 
        create SimplifiedWaterSurface()          
+
      end #end shader
+
     
+
  end #end material
+
 
enddef
 
enddef
 +
 
  
define SimplifiedWaterSurface()
 
  pass -fixedFunction     
 
      alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
 
      depthTest true -enableDepthWrite false
 
      colorScalar (0.2,0.3,1.0) 0.4           
 
      stage
 
        textureBlend select(colorScalar) select(colorScalar)
 
      end
 
  end
 
enddef
 
  
 +
# New material for use of new plumb bob
 +
materialDefinition plumbBob_core
 +
  setDefinition PlumbBobAnimatedColor
 +
  addParam      stdMatDiffCoef (1,1,1,1)
 +
end
  
define RegularWavesHLSL()
 
 
  #DRIVERBUG
 
  # The -clipAlways flag is needed to work around what appears to be a driver bug.
 
  # On NVIDIA GF2 class HW, the presence of the cube map texture in the pass below
 
  # leads to a large performance drop whenever the pass is rendered with clipping disabled.
 
  # Rendering this pass with clipping enabled avoids the performance drop. In addition,
 
  # substituting a 2D texture for the cube map texture, or rendering this pass in HW
 
  # using fixed function vertex processing also avoids the performance drop (but would obviously
 
  # not have the desired visual result).
 
  # The cause of this is unknown. This was observed on a GF4GO, driver version 42.58.
 
pass -clipAlways -modifiedEachFrameHint
 
#fillmode wireframe
 
alphaBlend srcFactor(one) add dstFactor(one)
 
      seti textureLights (numLightsOfType(environmentCube))       
 
 
 
shaderProgram -target vertexProgram -method compile -version 1_1
 
  
bindConstants 0 -bindingID geomToClip -constantCount 4
 
bindConstants 4 -bindingID geomToCamera -constantCount 3
 
  
bindConstants 7 -bindingID frameInfo
 
  
bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed)
 
bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed)
 
  
# pre-evaluate these
 
setf xscale (-$wmXRepeat * $wmXWaveHeight)
 
setf yscale (-$wmYRepeat * $wmYWaveHeight)
 
bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
 
bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
 
bindConstants 18 -bindingID cameraToGlobal -constantCount 3
 
       
 
        if (tsIsDay)       
 
            bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)       
 
        else
 
            bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)       
 
        endif
 
  
shaderSource
 
  
float4 frameInfo : register(c7);
+
#########################################################
float4 waveDataX : register(c11);
+
# Sims Shaders
float4 waveDataY : register(c12);
+
#
float4 waveDataHelper : register(c13);
+
# These include a version of the standard material
float4x4 clipSpaceMatrix : register(c0);
+
# (SimStandardMaterial) that is used for things
float4x3 cameraSpaceMatrix : register(c4);
+
# such as hair and faces, and SimSkin, which is
float4x3 cameraToGlobalMatrix : register(c18);
+
# used for a body with composited textures.
+
            float4 nightColor: register(c25);
+
           
+
float4 lightDirection : register(c14);
+
float4 lightColor : register(c15);
+
const static float4 refractionWeights={1,1,2,0};
+
+
const static float4 layerBlue={0.3, 0.7, 1.0, 1};
+
+
struct InputVertex
+
{
+
float3 position: POSITION0;
+
float3 normal : NORMAL0;
+
};
+
+
struct OutputVertex
+
{
+
float4 clipPosition : POSITION;
+
float4 diffuseColor: COLOR0;
+
float4 specularColor: COLOR1;
+
float3 reflection : TEXCOORD0;
+
+
};
+
           
+
+
+
OutputVertex VertexMain( InputVertex inputVertex)
+
{
+
// Do Y-direction waves
+
// r0 = (x, y, z, t)
+
+
OutputVertex outputVertex;
+
+
float4 posAndTime;
+
posAndTime.xyz = inputVertex.position;
+
posAndTime.w = frameInfo.w;
+
+
float temp = dot(posAndTime, waveDataX);
+
+
// z = h * sin(...)
+
  
float z;
 
// scale temp to fit -pi +pi range
 
//temp = temp *  (1 / (2 * 3.14159)) + 0.5;
 
 
float3 waveNormal;
 
 
z = sin(temp) * waveDataX.z + inputVertex.position.z;
 
 
waveNormal.x = cos(temp) * waveDataHelper.x + inputVertex.normal.x;
 
 
temp = dot(posAndTime, waveDataY);
 
//temp = temp *  (1 / (2 * 3.14159)) + 0.5;
 
 
z +=  sin(temp) * waveDataY.z;
 
 
waveNormal.y = cos(temp) * waveDataHelper.y + inputVertex.normal.y;
 
 
waveNormal.z = inputVertex.normal.z;
 
 
waveNormal = normalize(waveNormal);
 
 
posAndTime.w = 1.0;
 
posAndTime.z = z;
 
 
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix);
 
 
float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix));
 
  
float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix);
+
# Any mesh subsets that use composited textures must be use the following material
+
# The aliasshader command tells the mel parser that SimSkin has the same parameters as StandardMaterial
float3 viewVector = normalize(-cameraSpacePosition);
+
+
float3 R = reflect(viewVector, cameraSpaceNormal);
+
+
outputVertex.reflection = mul( -R, cameraToGlobalMatrix);
+
+
+
float fresnel = dot(viewVector , cameraSpaceNormal);
+
+
float rdotl = saturate(dot(R, lightDirection));
+
+
float I = pow(rdotl+0.1, 15); // fudge factor to punch up the highlights.
+
+
              nightColor = nightColor * 2;                         
+
                         
+
outputVertex.diffuseColor = ((1.0 - fresnel) * saturate(nightColor) * 0.5) * layerBlue;
+
+
outputVertex.specularColor = I;
+
return(outputVertex);
+
+
}
+
  
 +
# if compositing is to be used, these are the names of the composited textures
 +
set  compositeBaseTextureName  ""
 +
set  compositeBaseTextureParam  ""
 +
set  compositeSpecTextureName  ""
 +
set  compositeSpecTextureParam  ""
 +
set  compositeBumpTextureName  ""
 +
set  compositeBumpTextureParam  ""
  
endShaderSource 
+
# allow at most 8 base (diffuse) textures to be composited
end # shaderProgram
+
set  baseTexture0 ""
+
set  baseTexture1 ""
stage
+
set  baseTexture2 ""
texture $wmReflectionTexture
+
set  baseTexture3 ""
textureAddressing clamp clamp clamp
+
set  baseTexture4 ""
textureBlend multiply(texture diffuse) select(diffuse)
+
set  baseTexture5 ""
end
+
set  baseTexture6 ""
     
+
set  baseTexture7 ""
     
+
addSpecular true
+
+
end # end pass
+
  
 +
# allow at most 8 specular mask textures to be composited
 +
set  specTexture0 ""
 +
set  specTexture1 ""
 +
set  specTexture2 ""
 +
set  specTexture3 ""
 +
set  specTexture4 ""
 +
set  specTexture5 ""
 +
set  specTexture6 ""
 +
set  specTexture7 ""
  
enddef
+
# 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
 +
set  numTexturesToComposite  0
  
define HighEndWaterSurface()
+
#beginshader SimSkin
 
+
#description The basic material for defining a material that will be composited with Skin.
pass -clipAlways -modifiedEachFrameHint
+
#extraparam int  stdMatLayer 0 -32 32 ; attrdescription Layer for drawing, use even for opaque and odd for translucent
#fillmode wireframe
+
#extraparam enum stdMatAlphaBlendMode  none  (none)   ; Never blended
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
#endshader SimSkin
      seti textureLights (numLightsOfType(environmentCube)) 
+
      depthTest true -enableDepthWrite false         
+
 
+
shaderProgram -target vertexProgram -method compile -version 1_1
+
  
bindConstants 0 -bindingID geomToClip -constantCount 4
+
# generic overall hint (ie, in game)
bindConstants 4 -bindingID geomToCamera -constantCount 3
+
setb useCPUCompositedTextures true
  
bindConstants 7 -bindingID frameInfo
+
include DX9SimMaterials.matShad
 +
include DX8SimMaterials.matShad
 +
include DX7SimMaterials.matShad
 +
include SWVSSimMaterials.matShad
  
bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed)
+
# face materials set this to 'true' so that the eyes can move.
bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed)
+
setb eyeGizmoEnable false
  
# pre-evaluate these
+
# game will set this if in CAS, so all sim materials can composite on the fly.
setf xscale (-$wmXRepeat * $wmXWaveHeight)
+
setb simSkinFlag false
setf yscale (-$wmYRepeat * $wmYWaveHeight)
+
setb contentViewer false
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);
+
# This is a fudge factor, what this does is cover up a boo-boo I made.
float4 waveDataX : register(c11);
+
# 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)
float4 waveDataY : register(c12);
+
# what this lead to was a desired look on dx7 cards, but dx8 and dx7 were washed out, being 20% brighter.
float4 waveDataHelper : register(c13);
+
# so this fudge factor scales sims in dx8 and dx9 'down' by this amount to bring them into line with the "broken" dx7.
float4x4 clipSpaceMatrix : register(c0);
+
# for now, this is a temp fix for E3 2004, but this might live on forever.
float4x3 cameraSpaceMatrix : register(c4);
+
# in a perfect world, this factor will be removed and the game lighting 're tuned' to use the unscaled lighting.
float4x3 cameraToGlobalMatrix : register(c18);
+
# this will probably need to happen anyway, with new materials and lighting models planned in the expansion packs.
float4x3 cameraToGeomMatrix : register(c21);
+
 
 +
setf simMaterialLightingScale 0.8
 +
 
 +
 
 +
define SimSkin()
 +
 
 +
material
 +
 
 +
setb simSkinFlag true
 +
 
 +
#trace "$currentMaterialName simskin"
 +
 
 +
setb hasSecondUV (hasVertexFormat(texcoord, 1))
 +
#trace "SIMSKIN $currentMaterialName  UV2: $hasSecondUV Eye: $eyeGizmoEnable"
 +
 +
 +
# if it has eyes, then it's a face too.
 +
# .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)
 +
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...
 +
# this is contentViewer case.
 +
 
 +
 +
 +
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
 
 
            float4 nightColor: register(c25);
+
endif
           
+
endif
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;   
+
};
+
           
+
 
 
 +
setb bViewerIsThumbnail (viewerRenderType = $kViewerRenderTypeFamilyThumbnail)  
 +
 +
# we only want to render thumbnails in fixed function and we want to do two passes to correct alpha for the thumbnail
 +
if ($useHWShader2Path and not $bViewerIsThumbnail)
 +
create CreateSimStandardMaterialDX9()
 +
endif
 
 
OutputVertex VertexMain( InputVertex inputVertex)
+
# if ($useHWShader1Path)
{
+
# create CreateSimStandardMaterialDX8()
// Do Y-direction waves
+
# endif
// r0 = (x, y, z, t)
+
+
if ($useSWVertexShaderPath)
OutputVertex outputVertex;
+
create CreateSimStandardMaterialSWVS()
+
endif
float4 posAndTime;
+
posAndTime.xyz = inputVertex.position;
+
if ($useFixedFunctionPath or $useHWShader1Path or ($bViewerIsThumbnail and not $useSWVertexShaderPath))
posAndTime.w = frameInfo.w;
+
create CreateSimStandardMaterialFixedFunction()
+
endif     
float temp = dot(posAndTime, waveDataX);
+
#<
float z = sin(temp) * waveDataX.z + inputVertex.position.z;
+
else
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);
+
}
+
  
 +
 +
# backup case for Content viewer, which can have no compositing.
  
endShaderSource 
+
if (strcmp("${baseTexture0}","") = 0)
end # shaderProgram
+
    # 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
 
 
shaderProgram -target pixelProgram -method compile -version 2_0             
+
if ($useHWShader2Path)
        shaderSource                           
+
#trace "HW2 GPU COMPOSITE: $currentMaterialName"
            sampler reflect; 
+
create DX9SimSkinCompositingMaterial()
            sampler bump;         
+
endif
            struct cInputPixel
+
            {             
+
              float4 sPos        : TEXCOORD0;             
+
if ($useHWShader1Path)
              float2 Wave0        : TEXCOORD1;
+
#trace "HW1: $currentMaterialName"
              float2 Wave1        : TEXCOORD2;
+
create CreateSimSkinPerPixelCompositingMaterialPS1()
              float2 Wave2        : TEXCOORD3;
+
endif
              float2 Wave3        : TEXCOORD4;
+
              float3 Eye          : TEXCOORD5;
+
              float4 specular    : COLOR0;
+
if ($useFixedFunctionPath)
            };
+
create CreateSimPerPixelCompositingMaterialFixedFunction()
           
+
endif
            float Fresnel(float NdotL, float fresnelBias, float fresnelPow, float facing)
+
            {             
+
endif
              return max(fresnelBias + (1.0f - fresnelBias)*pow(facing, fresnelPow), 0.0);
+
            }
+
           
+
endif
            float4 PixelMain(cInputPixel pi) : COLOR
+
#>
            {       
+
              float3 vEye = normalize(pi.Eye);
+
 
 +
end
  
              // 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
 
enddef
  
  
#endshader PoolWaterSurfaceMaterial
 
  
 +
#set up default params
 +
setb simHairFlag false
  
 +
define SimHair()
 +
  setb simHairFlag true
 +
 +
if (strcmp("${baseTexture0}","") = 0 or $numTexturesToComposite = 0)
 +
create SimStandardMaterial()
 +
else
 +
create SimSkin()
 +
endif
 +
 +
enddef
  
# NOTE:
 
# refraction in vector terms:
 
#  v  = incoming unit vector
 
#  n  = surface normal
 
#  v' = refracted vector
 
#  a  = refraction ratio, ni / nr =~ 0.75 for air->water
 
#
 
# v' = v - sn
 
# where s = sqrt(1 - a^2 (1 - (v.n)^2))  - v.n.
 
  
  
 +
# Any Sim materials (clothes/skin) that do not use composited textures use
 +
# the following material.
  
##########################################################
+
#beginshader SimStandardMaterial
# Caustics
+
#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
 +
 
 +
 
 +
 
 +
define SimStandardMaterial()
  
define TiledTextureAnimShaderProgram(tilesX tilesY speed)
 
  shaderProgram -target vertexProgram -method assemble
 
 
    
 
    
      bindConstants 0 -bindingID frameInfo            # for time in .w
+
create DetermineHardwareSupport()
      bindConstants 1 -data      (&tilesX, &tilesY, &speed, 1)         # tx, ty, speed
+
      bindConstants 2 -data      ((1/&tilesX), (1/&tilesY), (&tilesY - 1), 1) # 1/tx 1/ty ty-1     
+
      if (tsIsDay)
+
        bindConstants 3 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)
+
      else
+
        bindConstants 3 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)
+
      endif
+
     
+
      shaderSource
+
        vs_1_1
+
        dcl_position v0
+
        dcl_texcoord v1
+
  
        mov oPos, v0  # clip space quad, no transforms needed.
+
  setb bViewerIsThumbnail (viewerRenderType = $kViewerRenderTypeFamilyThumbnail)
     
+
        # tiled texture animation
+
if ($useHWShader2Path and not $bViewerIsThumbnail)
        mov r0, c0
+
create CreateSimStandardMaterialDX9()
        mul r1, c1.z, r0.w
+
endif
        frc r5.y, r1.y
+
       
+
 
        mul r1, c1.y, r5.y   # f -> [0, ty)
+
   if ($useSWVertexShaderPath)
        frc r5.y, r1
+
create CreateSimStandardMaterialSWVS()
        sub r3.y, r1, r5.y    # v' = floor(f)
+
endif
       
+
        mul r1, c1.x, r5.y    # f -> [0, tx)
+
if ($useFixedFunctionPath or $useHWShader1Path or ($bViewerIsThumbnail and not $useSWVertexShaderPath))
        frc r5.y, r1
+
create CreateSimStandardMaterialFixedFunction()
        sub r3.x, r1, r5.y    # u' = floor(f)
+
endif
 +
  
        add r8.xy, v1.xy,  r3.xy
 
        mul oT0.xy, r8.xy, c2.xy
 
       
 
        mov oD0, c3 # also spit out diffuse color with modcolor information
 
       
 
      endShaderSource
 
 
 
  end
 
 
enddef
 
enddef
  
define CausticsGeneratorMaterial() 
 
  material     
 
      # This material updates a render target with the current frame
 
      # of the tile animation. This is the only way to handle a repeated
 
      # animating texture (not to mention using it for projective texturing)
 
      # in the absence of clip maps.
 
     
 
      create DetermineHardwareSupport()
 
     
 
      if ($causticsEnabled and $useFixedFunctionPath = false and $useSWVertexShaderPath = false)
 
     
 
        shader -layer +9999
 
  
            pass             
 
              renderClipSpaceRect
 
             
 
              renderTarget causticsTile -fixed (64, 64) -allocateDepthBuffer false -undo
 
  
              create TiledTextureAnimShaderProgram(8 4 1)
 
             
 
              alphaBlend srcFactor(one) add dstFactor(zero)
 
              alphaTest false 0
 
              alphaTestFunction acceptIfGreater
 
  
              depthTest false -enableDepthWrite false
 
              depthTestFunction accept
 
  
              # 7/24/2004 Fix bug with kRenderTypeNormal default stencil state and nv40. 
 
              # It reads random stencil values even this target has no depth stencil target.             
 
              # This stencil call will break pixo, but pixo does not show caustics.
 
              stencil false
 
  
              fillmode $stdMatFillMode                           
 
             
 
              shaderProgram -target pixelProgram -method compile -version 1_1             
 
                  shaderSource                           
 
                    sampler caustics;
 
                    struct cInputPixel
 
                    {
 
                        float4 color : COLOR;
 
                        float2 tc0 : TEXCOORD0;
 
                    };
 
                    float4 PixelMain(cInputPixel pi) : COLOR
 
                    {       
 
                        float4 texColor = tex2D(caustics, pi.tc0);                                               
 
                        return texColor*pi.color;                       
 
                    }
 
                  endShaderSource
 
              end                                                   
 
             
 
              sampler 0
 
                  texture causticsTiled
 
                  textureAddressing tile tile                 
 
              end
 
                             
 
            end 
 
        end
 
      else
 
        shader
 
       
 
        end
 
      endif
 
  end
 
enddef
 
 
setf causticsStrength 0.8
 
setf causticsBaseStrength 0.5
 
  
 +
define SimMaterialSetup()
  
###################################################
 
# Materials
 
#
 
  
 +
validateRenderShaderContext -vertexFormat position 0 required
 +
validateRenderShaderContext -vertexFormat normal 0 required
 +
validateRenderShaderContext -vertexFormat texcoord 0 required
  
# Pool surface materials
+
  # no sim material can have specular, since they might diverse and cause seams.
materialDefinition "poolWater-0"
+
   setf stdMatSpecPower 0
  setDefinition PoolWaterSurfaceMaterial
+
  addParam stdMatDiffCoef (0, 0, 1) 
+
  addParam wmRefractionEnabled true
+
end
+
 
+
materialDefinition "poolWater-1"
+
  setDefinition PoolWaterSurfaceMaterial 
+
  addParam stdMatLightingEnabled false
+
   addParam stdMatLayer 0
+
 
    
 
    
  addParam stdMatDiffCoef (1, 1, 1) 
+
seti lightingMode $kNoLighting   
  
  addParam wmReflectionTexture swimming_pool-envcube
+
create SetupCommonHWShaderVariablesAndPredicates()
  
  addParam wmTransparency 0.4
+
if (numLightsOfType(${kShapeColorLight}) > 0 )
 +
seti stdMatShapeColorIndex 0
 +
set stdMatAlphaBlendMode blend
 +
endif
 +
 +
#trace "Light counts: DISTANT: $distantLightCount, POINT: $pointLightCount, SPOT $spotLightCount"
  
  addParam wmXSpeed        3
+
create BumpTextureCount()
  addParam wmXRepeat      5
+
  addParam wmXWaveHeight  0.01
+
 
+
  addParam wmYSpeed        3
+
  addParam wmYRepeat      6
+
  addParam wmYWaveHeight  0.01
+
end
+
  
materialDefinition "poolWater-2"
+
if ($stdMatNormalMapTextureEnabled = false)
  setDefinition PoolWaterSurfaceMaterial
+
seti bumpTextureCount 0
  addParam stdMatLightingEnabled false
+
endif
  addParam stdMatLayer 0
+
 
    
 
    
   addParam stdMatDiffCoef (0, 0, 1)  
+
#trace "Bump texture count: $bumpTextureCount"
 +
#trace "ShapeColor Index for this Sim Material is: $stdMatShapeColorIndex"
 +
    
 +
  create TestForEyeMotion()
  
  addParam wmTransparency 0.5
+
 +
enddef
  
  addParam wmXSpeed        3
 
  addParam wmXRepeat      12
 
  addParam wmXWaveHeight  0 #0.02
 
 
 
  addParam wmYSpeed        3
 
  addParam wmYRepeat      12
 
  addParam wmYWaveHeight  0 # 0.02
 
end
 
  
materialDefinition "poolWater-4"
 
  setDefinition WaterAnimatingTextures
 
  addParam waterSpeed 0.3
 
end
 
  
  
# Pool depth layer materials
+
define BumpTextureCount()
  
# this is here soley because the layering on standard material
+
seti bumpTextureCount 0
# is too constrained. We need a layer less than 7, or we'll
+
# render over transparent areas of Sims (e.g. hair) when
+
# they're in the pool at a shallow view angle.
+
setc poolLayerColour (0, 0.5, 1.0, 1.0)
+
define PoolDepthLayerMaterial()
+
  material   
+
      create DetermineHardwareSupport()
+
      if ($useSWVertexShaderPath or $useFixedFunctionPath)
+
        shader
+
        end
+
      else
+
        shader -layer $poolWaterLayer
+
            validateRenderShaderContext -vertexFormat position 0 required
+
            validateRenderShaderContext -vertexFormat texcoord 0 required
+
           
+
            pass
+
              alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
+
      depthTest true -enableDepthWrite false
+
              #fillmode wireframe
+
              shaderProgram -target vertexProgram -method compile -version 1_1
+
                  bindConstants 0 -bindingID geomToClip -constantCount 4
+
                  bindConstants 4 -bindingID immediateData -data ($poolLayerColour)
+
                 
+
                  shaderSource
+
                    float4x4 clipSpaceMatrix      : register(c0);
+
                    float4  poolLayer            : register(c4);
+
                   
+
                    struct cVertexIn
+
                    {
+
                        float3 mPosition : POSITION0; 
+
                        float2 alpha    : TEXCOORD0;                 
+
                    };
+
                   
+
                    struct cVertexOut
+
                    {
+
                        float4 mClipPosition : POSITION;                   
+
                        float4 mColor        : COLOR0;
+
                    };
+
                   
+
                    cVertexOut VertexMain(cVertexIn vertexIn)
+
                    {               
+
                        cVertexOut result;                                                                       
+
                        result.mClipPosition = mul(float4(vertexIn.mPosition, 1), clipSpaceMatrix);                   
+
                        result.mColor = float4(poolLayer.r, poolLayer.g, poolLayer.b, poolLayer.a * vertexIn.alpha.x);
+
                        return result;       
+
                    }
+
                   
+
                  endShaderSource
+
              end                     
+
             
+
              shaderProgram -target pixelProgram -method compile -version 1_1
+
                  shaderSource                 
+
                    float4 PixelMain(float4 color : COLOR) : COLOR
+
                    {                                           
+
                        return color;
+
                    }
+
                  endShaderSource
+
              end                       
+
            end       
+
        end
+
      endif
+
  end
+
enddef
+
  
materialDefinition "poolWaterLayer-0"
 
  # this layer does nothing but create the caustics tile.
 
  setDefinition CausticsGeneratorMaterial 
 
end
 
  
materialDefinition "poolWaterLayer-1"
+
if ($bumpMapping)
  setDefinition PoolDepthLayerMaterial 
+
  addParam poolLayerColour (0, 0.5, 1.0, 0.2)
+
if (strcmp("${bumpTexture0}","")!=0)
end
+
seti bumpTextureCount ($bumpTextureCount +1)
materialDefinition "poolWaterLayer-2"  
+
endif
  setDefinition PoolDepthLayerMaterial 
+
  addParam poolLayerColour (0, 0.5, 1.0, 0.2)  
+
if (strcmp("${bumpTexture1}","")!=0)
end
+
seti bumpTextureCount ($bumpTextureCount +1)
materialDefinition "poolWaterLayer-3"
+
endif
  setDefinition PoolDepthLayerMaterial
+
  addParam poolLayerColour (0, 0.5, 1.0, 0.5)  
+
end
+
  
materialDefinition mtl_0
+
if (strcmp("${bumpTexture2}","")!=0)
  setDefinition CausticsGeneratorMaterial
+
seti bumpTextureCount ($bumpTextureCount +1)
end
+
endif
 +
 +
if (strcmp("${bumpTexture3}","")!=0)
 +
seti bumpTextureCount ($bumpTextureCount +1)
 +
endif
  
materialDefinition "lightingwallpoolsimple_reflective"
+
if (strcmp("${bumpTexture4}","")!=0)
  setDefinition StandardMaterial 
+
seti bumpTextureCount ($bumpTextureCount +1)
  addParam  stdMatDiffCoef (0.8, 0.8, 0.8)  
+
endif
  addParam  stdMatAlphaMultiplier 1.0
+
 
  addParam  stdMatAlphaBlendMode none
+
if (strcmp("${bumpTexture5}","")!=0)
  addParam  stdMatSpecCoef 0.091,0.091,0.091
+
seti bumpTextureCount ($bumpTextureCount +1)
  addParam   stdMatBaseTextureEnabled true
+
endif
   addParam  stdMatBaseTextureName lightingwallpoolsimple-surface
+
 
   addParam  stdMatEnvCubeLockedToCamera 0
+
if (strcmp("${bumpTexture6}","")!=0)
  addParam  stdMatEnvCubeMode reflection
+
seti bumpTextureCount ($bumpTextureCount +1)
   addParam  stdMatEnvCubeTextureName reflectionkitchenhighcontrast-envcube
+
endif
   addParam  forceIgnoreShapeBlend true
+
 
end
+
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

Revision as of 14:45, 5 March 2008

  1. Shaders for the Sims themselves
  2. Most Sims shaders (currently) come from the Alias export.
  3. However, here are a few special ones.


  1. A gray default shader for when we can't find one

materialDefinition defaultSimsShader

  setDefinition Phong
  addParam stdMatDiffCoef (.5, .5, .6)

end


  1. contains the shader pre-create commands for all Sim materials

define SimsShaderPreCreate()

  preCreate -viewerRenderType $kRenderTypeNormal -viewerRenderType ($mirrorReflectionsEnabled ? $kRenderTypeMirror : $kRenderTypeNormal) -deformations
  1. <
  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
  1. >

enddef


  1. special layer for the censor shader. This ensures that the censor shader can
  2. be skipped during the censor render itself. The number is referred to from
  3. C++ code.

seti kCensorShaderLayer -1

  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


define PlumbBobAnimatedColor() material attributes attribute myColor float3 (0, 1, 0) attribute myAlpha float1 0.843 end


shader -layer (18 * 17 + 17)

validateRenderShaderContext -vertexFormat position 0 required validateRenderShaderContext -vertexFormat normal 0 required

create DetermineHardwareSupport() create SetupCommonHWShaderVariablesAndPredicates()


if ($useFixedFunctionPath) pass -fixedFunction create LightingStates() create AttenuatedMatCoef(0.25) fillmode $stdMatFillMode

depthTest true -enableDepthWrite false alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)

stage colorScalar @myColor @myAlpha textureBlend multiplyScale4(diffuse colorScalar) multiply(diffuse colorScalar) end

end # pass else

# empircally, there are NO lights associated with the plumb bob, so I won't bother to compute them. pass

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 colorScalar @myColor @myAlpha textureBlend multiplyScale4(diffuse colorScalar) select(colorScalar) end #stage

end # pass endif


end # shader end #material

enddef


  1. New material for use of new plumb bob

materialDefinition plumbBob_core

  setDefinition PlumbBobAnimatedColor
  addParam      stdMatDiffCoef (1,1,1,1)

end




  1. Sims Shaders
  2. These include a version of the standard material
  3. (SimStandardMaterial) that is used for things
  4. such as hair and faces, and SimSkin, which is
  5. used for a body with composited textures.


  1. Any mesh subsets that use composited textures must be use the following material
  2. The aliasshader command tells the mel parser that SimSkin has the same parameters as StandardMaterial
  1. if compositing is to be used, these are the names of the composited textures

set compositeBaseTextureName "" set compositeBaseTextureParam "" set compositeSpecTextureName "" set compositeSpecTextureParam "" set compositeBumpTextureName "" set compositeBumpTextureParam ""

  1. allow at most 8 base (diffuse) textures to be composited

set baseTexture0 "" set baseTexture1 "" set baseTexture2 "" set baseTexture3 "" set baseTexture4 "" set baseTexture5 "" set baseTexture6 "" set baseTexture7 ""

  1. allow at most 8 specular mask textures to be composited

set specTexture0 "" set specTexture1 "" set specTexture2 "" set specTexture3 "" set specTexture4 "" set specTexture5 "" set specTexture6 "" set specTexture7 ""

  1. 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 ""

  1. the number of textures to composite

set numTexturesToComposite 0

  1. beginshader SimSkin
  2. description The basic material for defining a material that will be composited with Skin.
  3. extraparam int stdMatLayer 0 -32 32 ; attrdescription Layer for drawing, use even for opaque and odd for translucent
  4. extraparam enum stdMatAlphaBlendMode none (none)  ; Never blended
  5. endshader SimSkin
  1. generic overall hint (ie, in game)

setb useCPUCompositedTextures true

include DX9SimMaterials.matShad include DX8SimMaterials.matShad include DX7SimMaterials.matShad include SWVSSimMaterials.matShad

  1. face materials set this to 'true' so that the eyes can move.

setb eyeGizmoEnable false

  1. game will set this if in CAS, so all sim materials can composite on the fly.

setb simSkinFlag false setb contentViewer false


  1. This is a fudge factor, what this does is cover up a boo-boo I made.
  2. 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)
  3. what this lead to was a desired look on dx7 cards, but dx8 and dx7 were washed out, being 20% brighter.
  4. so this fudge factor scales sims in dx8 and dx9 'down' by this amount to bring them into line with the "broken" dx7.
  5. for now, this is a temp fix for E3 2004, but this might live on forever.
  6. in a perfect world, this factor will be removed and the game lighting 're tuned' to use the unscaled lighting.
  7. this will probably need to happen anyway, with new materials and lighting models planned in the expansion packs.

setf simMaterialLightingScale 0.8


define SimSkin()

material

setb simSkinFlag true

#trace "$currentMaterialName simskin"

setb hasSecondUV (hasVertexFormat(texcoord, 1)) #trace "SIMSKIN $currentMaterialName UV2: $hasSecondUV Eye: $eyeGizmoEnable"


# if it has eyes, then it's a face too. # .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) 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... # this is contentViewer case.


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

endif endif

setb bViewerIsThumbnail (viewerRenderType = $kViewerRenderTypeFamilyThumbnail)

# we only want to render thumbnails in fixed function and we want to do two passes to correct alpha for the thumbnail if ($useHWShader2Path and not $bViewerIsThumbnail) create CreateSimStandardMaterialDX9() endif

# if ($useHWShader1Path) # create CreateSimStandardMaterialDX8() # endif

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


if ($useFixedFunctionPath) create CreateSimPerPixelCompositingMaterialFixedFunction() endif

endif


endif #>


end

enddef


  1. set up default params

setb simHairFlag false

define SimHair()

  setb simHairFlag true

if (strcmp("${baseTexture0}","") = 0 or $numTexturesToComposite = 0) create SimStandardMaterial() else create SimSkin() endif

enddef


  1. Any Sim materials (clothes/skin) that do not use composited textures use
  2. the following material.
  1. beginshader SimStandardMaterial
  2. description Similar to standard material, but used on Sims themselves (fewer options).
  3. extraparam enum stdMatAlphaBlendMode none (none blend additive)  ; The transparency mode.
  4. extraparam bool stdMatAlphaTestEnabled 0  ; Can drop pixels, like a 'mask'
  5. extraparam int stdMatAlphaRefValue 127 0 255  ; which alpha value to keep a pixel, 255 is 'white'.
  6. extraparam int stdMatLayer 0 -32 32 ; attrdescription Layer for drawing, use even for opaque and odd for translucent
  7. extraparam enum stdMatEnvCubeMode none (none reflection)  ; add a reflection layer to this material, will not propogate to SimSkin.
  8. endshader SimStandardMaterial


define SimStandardMaterial()


create DetermineHardwareSupport()

  setb bViewerIsThumbnail (viewerRenderType = $kViewerRenderTypeFamilyThumbnail)

if ($useHWShader2Path and not $bViewerIsThumbnail) create CreateSimStandardMaterialDX9() endif


  if ($useSWVertexShaderPath)

create CreateSimStandardMaterialSWVS() endif

if ($useFixedFunctionPath or $useHWShader1Path or ($bViewerIsThumbnail and not $useSWVertexShaderPath)) create CreateSimStandardMaterialFixedFunction() endif


enddef




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



define BumpTextureCount()

seti bumpTextureCount 0


if ($bumpMapping)

if (strcmp("${bumpTexture0}","")!=0) seti bumpTextureCount ($bumpTextureCount +1) endif

if (strcmp("${bumpTexture1}","")!=0) seti bumpTextureCount ($bumpTextureCount +1) endif

if (strcmp("${bumpTexture2}","")!=0) seti bumpTextureCount ($bumpTextureCount +1) endif

if (strcmp("${bumpTexture3}","")!=0) seti bumpTextureCount ($bumpTextureCount +1) endif

if (strcmp("${bumpTexture4}","")!=0) seti bumpTextureCount ($bumpTextureCount +1) endif

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


  1. ==============================================================================
  2. 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

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox