Difference between revisions of "ShaderPool"
From SimsWiki
(EP5-SS) |
(GunMod_GMRLS21-Chocolate_Pi_RLS-2.2_RC1) |
||
| Line 1: | Line 1: | ||
<PRE> | <PRE> | ||
| − | + | GunMod_GMRLS21-Chocolate_Pi_RLS-2.2_RC1 | |
0xCD7FE87A | 0xCD7FE87A | ||
0x1C0532FA | 0x1C0532FA | ||
0x6852819C | 0x6852819C | ||
0xFF76EA99 | 0xFF76EA99 | ||
| − | |||
| − | ### | + | #outdoordaytime-envcube #pretty good |
| + | #marble-blue could make a good refraction tile | ||
# Pool Water | # Pool Water | ||
| − | |||
seti poolWaterLayer 5 | seti poolWaterLayer 5 | ||
| − | + | setf wmTransparency 1 | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | setf wmTransparency | + | |
| − | + | ||
| − | + | ||
setf wmXSpeed 3 # min:0 max:100 | setf wmXSpeed 3 # min:0 max:100 | ||
| − | + | setf wmXRepeat 5 # min:0 max:100 | |
| − | setf wmXRepeat | + | setf wmXWaveHeight 0.02 # min:0 max:100 |
| − | + | ||
| − | setf wmXWaveHeight 0. | + | |
| − | + | ||
| − | + | ||
setf wmYSpeed 5 # min:0 max:100 | setf wmYSpeed 5 # min:0 max:100 | ||
| − | + | setf wmYRepeat 5 # min:0 max:100 | |
| − | setf wmYRepeat | + | setf wmYWaveHeight 0.01 # min:0 max:100 |
| − | + | ||
| − | setf wmYWaveHeight 0. | + | |
| − | + | ||
| − | set wmReflectionTexture | + | set wmReflectionTexture water_spec |
| − | + | setb wmRefractionEnabled true | |
| − | + | set wmRefractionTexture water_spec | |
| − | setb wmRefractionEnabled | + | |
| − | + | ||
| − | + | ||
| − | set wmRefractionTexture | + | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
define PoolWaterSurfaceMaterial() | define PoolWaterSurfaceMaterial() | ||
| − | material | + | material |
shader -layer $poolWaterLayer | shader -layer $poolWaterLayer | ||
validateRenderShaderContext -vertexFormat position 0 required | validateRenderShaderContext -vertexFormat position 0 required | ||
| − | |||
create DetermineHardwareSupport() | create DetermineHardwareSupport() | ||
| − | + | # create RegularWavesHLSL() | |
| − | + | create GunModWaves() | |
| − | + | end | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | end | + | |
| − | + | ||
# basic fallback. | # basic fallback. | ||
shader -layer $poolWaterLayer | shader -layer $poolWaterLayer | ||
| − | create SimplifiedWaterSurface() | + | create SimplifiedWaterSurface() |
| − | end | + | end |
| − | + | end | |
| − | end | + | |
enddef | enddef | ||
define SimplifiedWaterSurface() | define SimplifiedWaterSurface() | ||
| − | pass -fixedFunction | + | pass -fixedFunction |
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) | alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) | ||
depthTest true -enableDepthWrite false | depthTest true -enableDepthWrite false | ||
| − | colorScalar (0.2,0.3,1.0) 0.4 | + | colorScalar (0.2,0.3,1.0) 0.4 |
stage | stage | ||
textureBlend select(colorScalar) select(colorScalar) | textureBlend select(colorScalar) select(colorScalar) | ||
| Line 103: | Line 52: | ||
define RegularWavesHLSL() | define RegularWavesHLSL() | ||
| − | + | ||
#DRIVERBUG | #DRIVERBUG | ||
| − | # | + | #-clipAlways |
| − | + | pass -modifiedEachFrameHint | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | pass | + | |
| − | + | ||
alphaBlend srcFactor(one) add dstFactor(one) | alphaBlend srcFactor(one) add dstFactor(one) | ||
| − | seti textureLights (numLightsOfType(environmentCube)) | + | seti textureLights (numLightsOfType(environmentCube)) |
| − | + | ||
shaderProgram -target vertexProgram -method compile -version 1_1 | shaderProgram -target vertexProgram -method compile -version 1_1 | ||
| − | |||
bindConstants 0 -bindingID geomToClip -constantCount 4 | bindConstants 0 -bindingID geomToClip -constantCount 4 | ||
bindConstants 4 -bindingID geomToCamera -constantCount 3 | bindConstants 4 -bindingID geomToCamera -constantCount 3 | ||
| − | + | bindConstants 7 -bindingID frameInfo | |
| − | bindConstants 7 -bindingID frameInfo | + | |
| − | + | ||
bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed) | bindConstants 11 -bindingID immediateData -data ($wmXRepeat, 0, $wmXWaveHeight, $wmXSpeed) | ||
bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed) | bindConstants 12 -bindingID immediateData -data (0, $wmYRepeat, $wmYWaveHeight, $wmYSpeed) | ||
| − | |||
| − | |||
setf xscale (-$wmXRepeat * $wmXWaveHeight) | setf xscale (-$wmXRepeat * $wmXWaveHeight) | ||
setf yscale (-$wmYRepeat * $wmYWaveHeight) | setf yscale (-$wmYRepeat * $wmYWaveHeight) | ||
| Line 134: | Line 69: | ||
bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float | bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float | ||
bindConstants 18 -bindingID cameraToGlobal -constantCount 3 | bindConstants 18 -bindingID cameraToGlobal -constantCount 3 | ||
| − | + | if (tsIsDay) | |
| − | if (tsIsDay) | + | bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1) |
| − | bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1) | + | |
else | else | ||
| − | bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1) | + | bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1) |
endif | endif | ||
| − | |||
shaderSource | shaderSource | ||
| − | |||
float4 frameInfo : register(c7); | float4 frameInfo : register(c7); | ||
float4 waveDataX : register(c11); | float4 waveDataX : register(c11); | ||
| Line 150: | Line 82: | ||
float4x3 cameraSpaceMatrix : register(c4); | float4x3 cameraSpaceMatrix : register(c4); | ||
float4x3 cameraToGlobalMatrix : register(c18); | float4x3 cameraToGlobalMatrix : register(c18); | ||
| − | + | float4 nightColor: register(c25); | |
| − | + | ||
| − | + | ||
float4 lightDirection : register(c14); | float4 lightDirection : register(c14); | ||
float4 lightColor : register(c15); | float4 lightColor : register(c15); | ||
const static float4 refractionWeights={1,1,2,0}; | const static float4 refractionWeights={1,1,2,0}; | ||
| − | |||
const static float4 layerBlue={0.3, 0.7, 1.0, 1}; | const static float4 layerBlue={0.3, 0.7, 1.0, 1}; | ||
| − | |||
struct InputVertex | struct InputVertex | ||
{ | { | ||
| Line 164: | Line 92: | ||
float3 normal : NORMAL0; | float3 normal : NORMAL0; | ||
}; | }; | ||
| − | |||
struct OutputVertex | struct OutputVertex | ||
{ | { | ||
| Line 171: | Line 98: | ||
float4 specularColor: COLOR1; | float4 specularColor: COLOR1; | ||
float3 reflection : TEXCOORD0; | float3 reflection : TEXCOORD0; | ||
| − | |||
}; | }; | ||
| − | |||
| − | |||
| − | |||
OutputVertex VertexMain( InputVertex inputVertex) | OutputVertex VertexMain( InputVertex inputVertex) | ||
{ | { | ||
| − | |||
| − | |||
| − | |||
OutputVertex outputVertex; | OutputVertex outputVertex; | ||
| − | |||
float4 posAndTime; | float4 posAndTime; | ||
posAndTime.xyz = inputVertex.position; | posAndTime.xyz = inputVertex.position; | ||
posAndTime.w = frameInfo.w; | posAndTime.w = frameInfo.w; | ||
| − | |||
float temp = dot(posAndTime, waveDataX); | float temp = dot(posAndTime, waveDataX); | ||
| − | |||
| − | |||
| − | |||
float z; | float z; | ||
| − | |||
| − | |||
| − | |||
float3 waveNormal; | float3 waveNormal; | ||
| − | |||
z = sin(temp) * waveDataX.z + inputVertex.position.z; | z = sin(temp) * waveDataX.z + inputVertex.position.z; | ||
| − | |||
waveNormal.x = cos(temp) * waveDataHelper.x + inputVertex.normal.x; | waveNormal.x = cos(temp) * waveDataHelper.x + inputVertex.normal.x; | ||
| − | |||
temp = dot(posAndTime, waveDataY); | temp = dot(posAndTime, waveDataY); | ||
| − | |||
| − | |||
z += sin(temp) * waveDataY.z; | z += sin(temp) * waveDataY.z; | ||
| − | |||
waveNormal.y = cos(temp) * waveDataHelper.y + inputVertex.normal.y; | waveNormal.y = cos(temp) * waveDataHelper.y + inputVertex.normal.y; | ||
| − | |||
waveNormal.z = inputVertex.normal.z; | waveNormal.z = inputVertex.normal.z; | ||
| − | |||
waveNormal = normalize(waveNormal); | waveNormal = normalize(waveNormal); | ||
| − | |||
posAndTime.w = 1.0; | posAndTime.w = 1.0; | ||
posAndTime.z = z; | posAndTime.z = z; | ||
| − | |||
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix); | outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix); | ||
| − | |||
float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix)); | float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix)); | ||
| − | |||
float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix); | float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix); | ||
| − | |||
float3 viewVector = normalize(-cameraSpacePosition); | float3 viewVector = normalize(-cameraSpacePosition); | ||
| − | |||
float3 R = reflect(viewVector, cameraSpaceNormal); | float3 R = reflect(viewVector, cameraSpaceNormal); | ||
| − | |||
outputVertex.reflection = mul( -R, cameraToGlobalMatrix); | outputVertex.reflection = mul( -R, cameraToGlobalMatrix); | ||
| − | |||
| − | |||
float fresnel = dot(viewVector , cameraSpaceNormal); | float fresnel = dot(viewVector , cameraSpaceNormal); | ||
| − | |||
float rdotl = saturate(dot(R, lightDirection)); | float rdotl = saturate(dot(R, lightDirection)); | ||
| − | |||
float I = pow(rdotl+0.1, 15); // fudge factor to punch up the highlights. | float I = pow(rdotl+0.1, 15); // fudge factor to punch up the highlights. | ||
| − | + | nightColor = nightColor * 2; | |
| − | nightColor = nightColor * 2; | + | outputVertex.diffuseColor = ((1.0 + fresnel) * saturate(nightColor) * 0.5) * layerBlue; |
| − | + | ||
| − | outputVertex.diffuseColor = ((1.0 | + | |
| − | + | ||
outputVertex.specularColor = I; | outputVertex.specularColor = I; | ||
return(outputVertex); | return(outputVertex); | ||
| − | |||
} | } | ||
| − | + | endShaderSource | |
| − | + | end | |
| − | endShaderSource | + | |
| − | end | + | |
| − | + | ||
stage | stage | ||
texture $wmReflectionTexture | texture $wmReflectionTexture | ||
| Line 252: | Line 138: | ||
textureBlend multiply(texture diffuse) select(diffuse) | textureBlend multiply(texture diffuse) select(diffuse) | ||
end | end | ||
| − | |||
| − | |||
addSpecular true | addSpecular true | ||
| − | + | end | |
| − | end | + | |
| − | + | ||
| − | + | ||
enddef | enddef | ||
| + | define GunModWaves() | ||
| − | + | pass | |
| − | + | ||
| − | + | ||
#fillmode wireframe | #fillmode wireframe | ||
| − | alphaBlend srcFactor( | + | alphaBlend srcFactor(one) add dstFactor(one) |
| − | + | ||
| − | + | 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 | ||
| − | + | shaderSource | |
| − | + | ||
| − | + | float4 frameInfo : register(c7); | |
| − | + | float4 waveDataX : register(c11); | |
| − | + | float4 waveDataY : register(c12); | |
| − | + | float4 waveDataHelper : register(c13); | |
| − | + | float4x4 clipSpaceMatrix : register(c0); | |
| − | + | float4x3 cameraSpaceMatrix : register(c4); | |
| − | + | float4x3 cameraToGlobalMatrix : register(c18); | |
| − | + | ||
| − | + | float4 lightDirection : register(c14); | |
| − | + | float4 lightColor : register(c15); | |
| − | + | const static float4 refractionWeights={1,1,2,0}; | |
| − | + | ||
| − | + | struct InputVertex | |
| − | + | { | |
| − | + | float4 position: POSITION0; | |
| + | float3 normal : NORMAL0; | ||
| + | float2 texc : TEXCOORD0; | ||
| + | }; | ||
| + | |||
| + | struct OutputVertex | ||
| + | { | ||
| + | float4 clipPosition : POSITION; | ||
| + | float3 normal : TEXCOORD0; | ||
| + | float3 viewVector : TEXCOORD1; | ||
| − | + | }; | |
| − | + | ||
| − | + | static float2 waveCenter1 = {0.0, 0.0}; | |
| − | + | static float2 waveCenter2 = {-0.6, 0.2}; | |
| − | + | ||
| + | static float2 timeScale = {2,1}; | ||
| + | static float2 waveHeight = {0.04, 0.02}; | ||
| + | static float2 distScale = {12, 8}; | ||
| + | |||
| + | |||
| + | |||
| + | float4 ComputeWavePositionTwoWay(float2 pos1, float2 pos2) | ||
| + | { | ||
| + | |||
| + | float2 vec; | ||
| + | float4 dist; | ||
| + | |||
| + | vec = waveCenter1 - pos1; | ||
| + | dist.x = dot(vec, vec); | ||
| + | |||
| + | vec = waveCenter2 - pos1; | ||
| + | dist.y = dot(vec,vec); | ||
| + | |||
| + | vec = waveCenter2 - pos2; | ||
| + | dist.z = dot(vec, vec); | ||
| + | |||
| + | vec = waveCenter2 - pos2; | ||
| + | dist.w = dot(vec,vec); | ||
| + | |||
| + | dist *= distScale.xyxy; | ||
| + | |||
| + | float4 sinResult = sin(dist + frameInfo.w * timeScale.xyxy); | ||
| − | + | //sinResult = 1.0- abs(sinResult); | |
| + | |||
| + | return(sinResult); | ||
| + | |||
| + | } | ||
| + | |||
| + | float2 ComputeWavePosition(float2 pos1) | ||
| + | { | ||
| + | |||
| + | float2 vec; | ||
| + | float2 dist; | ||
| + | |||
| + | vec = waveCenter1 - pos1; | ||
| + | dist.x = dot(vec, vec); | ||
| + | |||
| + | vec = waveCenter2 - pos1; | ||
| + | dist.y = dot(vec,vec); | ||
| + | |||
| + | dist *= distScale.xy; | ||
| + | |||
| + | float2 sinResult = sin(dist + frameInfo.w * timeScale); | ||
| − | + | //sinResult = 1.0- abs(sinResult); | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| + | return(sinResult); | ||
| − | + | } | |
| − | + | OutputVertex VertexMain( InputVertex inputVertex) | |
| − | + | { | |
| − | + | // Do Y-direction waves | |
| − | + | // r0 = (x, y, z, t) | |
| + | |||
| + | OutputVertex outputVertex; | ||
| + | |||
| + | float4 pos = inputVertex.position; | ||
| − | + | float2 sample1, sample2, sample3; | |
| − | + | sample1 = inputVertex.position; | |
| − | + | sample2 = inputVertex.position; | |
| − | + | sample3 = inputVertex.position; | |
| − | + | sample2.x += 0.1; | |
| − | + | sample3.y += 0.1; | |
| + | |||
| + | float4 heights1=ComputeWavePositionTwoWay(sample1, sample2); | ||
| + | float2 heights2=ComputeWavePosition(sample3); | ||
| + | |||
| + | |||
| + | float3 pos1, pos2; | ||
| + | pos1 = pos; | ||
| + | pos2 = pos; | ||
| + | |||
| + | pos.z += (heights1.x* waveHeight.x);// + heights1.y * waveHeight.y); | ||
| + | pos1.z += (heights1.z* waveHeight.x);// + heights1.w * waveHeight.y); | ||
| + | pos2.z += (heights2.x* waveHeight.x);// + heights2.y * waveHeight.y); | ||
| − | + | pos1.x +=0.1; | |
| − | + | pos2.y +=0.1; | |
| − | + | float3 vec1, vec2; | |
| − | + | vec1 = normalize(pos1 - pos); | |
| − | + | vec2 = normalize(pos2 - pos); | |
| − | + | ||
| − | + | float3 normal = cross(vec1, vec2); | |
| − | + | ||
| − | + | normal = mul(normal, (float3x3)cameraSpaceMatrix); | |
| − | + | ||
| − | + | float3 viewVector = mul(pos, cameraSpaceMatrix); | |
| + | |||
| + | outputVertex.viewVector = normalize(-viewVector); | ||
| + | |||
| + | outputVertex.clipPosition = mul(pos, clipSpaceMatrix); | ||
| + | outputVertex.normal = normal; | ||
| + | return(outputVertex); | ||
| + | |||
| + | } | ||
| − | + | endShaderSource | |
| − | + | ||
| − | + | end # end shaderProgram | |
| − | + | ||
| − | + | shaderProgram -target pixelProgram -method assemble | |
| − | + | bindConstants 0 -bindingID allStandardLightData -constantCount 4 -constantType float | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | shaderSource | |
| − | + | ps_2_0 | |
| − | + | def c10,20,4,0,0 | |
| + | def c11, 0,0.5,1,2 | ||
| + | dcl t0 | ||
| + | dcl t1 ; v | ||
| + | dcl_cube s0 | ||
| + | |||
| + | nrm r0, t0 ; n | ||
| + | |||
| + | add r1, r0, r0 ; 2N | ||
| + | |||
| + | dp3 r1.w, r0, t1 ; N.V | ||
| + | mad r2.xyz, r1, r1.w, -t1 ; 2N * (N.V) -V | ||
| + | |||
| + | texld r5, r2, s0 | ||
| + | |||
| + | dp3 r3.x, r2, c0 ; R.L | ||
| + | pow r4, r3.x, c10.x | ||
| + | |||
| + | mov_sat r1.x, r1.w | ||
| + | |||
| + | add r6.x, c11.z, -r1.x ; 1 - Fresnel | ||
| + | |||
| + | pow r3.y, r6.x, c10.y ; N.V ^ 4 | ||
| − | + | mul r7, r5, r3.y | |
| − | + | mad r4, r4, r3.y, r7 | |
| − | + | mul r4, r4, c11.y | |
| − | + | ||
| − | + | mov oC0, r4 | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
endShaderSource | endShaderSource | ||
| − | end | + | end |
| − | sampler | + | sampler 0 |
| − | + | texture $wmReflectionTexture | |
| − | + | textureAddressing clamp clamp clamp | |
| − | end | + | end |
| − | + | end # pass | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
enddef | enddef | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
# Caustics | # Caustics | ||
| − | |||
define TiledTextureAnimShaderProgram(tilesX tilesY speed) | define TiledTextureAnimShaderProgram(tilesX tilesY speed) | ||
shaderProgram -target vertexProgram -method assemble | shaderProgram -target vertexProgram -method assemble | ||
| − | |||
bindConstants 0 -bindingID frameInfo # for time in .w | bindConstants 0 -bindingID frameInfo # for time in .w | ||
bindConstants 1 -data (&tilesX, &tilesY, &speed, 1) # tx, ty, speed | 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 | + | bindConstants 2 -data ((1/&tilesX), (1/&tilesY), (&tilesY - 1), 1) # 1/tx 1/ty ty-1 |
if (tsIsDay) | if (tsIsDay) | ||
bindConstants 3 -bindingID immediateData -data (0.75, 0.75, 0.75, 1) | bindConstants 3 -bindingID immediateData -data (0.75, 0.75, 0.75, 1) | ||
| Line 493: | Line 366: | ||
bindConstants 3 -bindingID immediateData -data (0.2, 0.2, 0.2, 1) | bindConstants 3 -bindingID immediateData -data (0.2, 0.2, 0.2, 1) | ||
endif | endif | ||
| − | |||
shaderSource | shaderSource | ||
vs_1_1 | vs_1_1 | ||
dcl_position v0 | dcl_position v0 | ||
dcl_texcoord v1 | dcl_texcoord v1 | ||
| − | |||
mov oPos, v0 # clip space quad, no transforms needed. | mov oPos, v0 # clip space quad, no transforms needed. | ||
| − | |||
| − | |||
mov r0, c0 | mov r0, c0 | ||
mul r1, c1.z, r0.w | mul r1, c1.z, r0.w | ||
frc r5.y, r1.y | frc r5.y, r1.y | ||
| − | |||
mul r1, c1.y, r5.y # f -> [0, ty) | mul r1, c1.y, r5.y # f -> [0, ty) | ||
frc r5.y, r1 | frc r5.y, r1 | ||
sub r3.y, r1, r5.y # v' = floor(f) | sub r3.y, r1, r5.y # v' = floor(f) | ||
| − | |||
mul r1, c1.x, r5.y # f -> [0, tx) | mul r1, c1.x, r5.y # f -> [0, tx) | ||
frc r5.y, r1 | frc r5.y, r1 | ||
sub r3.x, r1, r5.y # u' = floor(f) | sub r3.x, r1, r5.y # u' = floor(f) | ||
| − | |||
add r8.xy, v1.xy, r3.xy | add r8.xy, v1.xy, r3.xy | ||
mul oT0.xy, r8.xy, c2.xy | mul oT0.xy, r8.xy, c2.xy | ||
| − | |||
mov oD0, c3 # also spit out diffuse color with modcolor information | mov oD0, c3 # also spit out diffuse color with modcolor information | ||
| − | |||
endShaderSource | endShaderSource | ||
| − | + | end | |
| − | end | + | |
enddef | enddef | ||
| − | define CausticsGeneratorMaterial() | + | define CausticsGeneratorMaterial() |
| − | material | + | material |
# This material updates a render target with the current frame | # This material updates a render target with the current frame | ||
# of the tile animation. This is the only way to handle a repeated | # of the tile animation. This is the only way to handle a repeated | ||
# animating texture (not to mention using it for projective texturing) | # animating texture (not to mention using it for projective texturing) | ||
# in the absence of clip maps. | # in the absence of clip maps. | ||
| − | + | ||
create DetermineHardwareSupport() | create DetermineHardwareSupport() | ||
| − | |||
if ($causticsEnabled and $useFixedFunctionPath = false and $useSWVertexShaderPath = false) | if ($causticsEnabled and $useFixedFunctionPath = false and $useSWVertexShaderPath = false) | ||
| − | + | shader -layer +9999 | |
| − | shader -layer +9999 | + | pass |
| − | + | ||
| − | pass | + | |
renderClipSpaceRect | renderClipSpaceRect | ||
| − | |||
renderTarget causticsTile -fixed (64, 64) -allocateDepthBuffer false -undo | renderTarget causticsTile -fixed (64, 64) -allocateDepthBuffer false -undo | ||
| − | |||
create TiledTextureAnimShaderProgram(8 4 1) | create TiledTextureAnimShaderProgram(8 4 1) | ||
| − | |||
alphaBlend srcFactor(one) add dstFactor(zero) | alphaBlend srcFactor(one) add dstFactor(zero) | ||
alphaTest false 0 | alphaTest false 0 | ||
alphaTestFunction acceptIfGreater | alphaTestFunction acceptIfGreater | ||
| − | |||
depthTest false -enableDepthWrite false | depthTest false -enableDepthWrite false | ||
depthTestFunction accept | depthTestFunction accept | ||
| − | + | # 7/24/2004 Fix bug with kRenderTypeNormal default stencil state and nv40. | |
| − | # 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. |
| − | # 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. | # This stencil call will break pixo, but pixo does not show caustics. | ||
stencil false | stencil false | ||
| − | + | fillmode $stdMatFillMode | |
| − | fillmode $stdMatFillMode | + | shaderProgram -target pixelProgram -method compile -version 1_1 |
| − | + | shaderSource | |
| − | shaderProgram -target pixelProgram -method compile -version 1_1 | + | |
| − | shaderSource | + | |
sampler caustics; | sampler caustics; | ||
struct cInputPixel | struct cInputPixel | ||
| Line 567: | Line 420: | ||
}; | }; | ||
float4 PixelMain(cInputPixel pi) : COLOR | float4 PixelMain(cInputPixel pi) : COLOR | ||
| − | { | + | { |
| − | float4 texColor = tex2D(caustics, pi.tc0); | + | float4 texColor = tex2D(caustics, pi.tc0); |
| − | return texColor*pi.color; | + | return texColor*pi.color; |
} | } | ||
endShaderSource | endShaderSource | ||
| − | end | + | end |
| − | + | ||
sampler 0 | sampler 0 | ||
texture causticsTiled | texture causticsTiled | ||
| − | textureAddressing tile tile | + | textureAddressing tile tile |
end | end | ||
| − | + | end | |
| − | end | + | |
end | end | ||
else | else | ||
shader | shader | ||
| − | |||
end | end | ||
endif | endif | ||
end | end | ||
enddef | enddef | ||
| − | + | ||
setf causticsStrength 0.8 | setf causticsStrength 0.8 | ||
setf causticsBaseStrength 0.5 | setf causticsBaseStrength 0.5 | ||
| − | |||
################################################### | ################################################### | ||
# Materials | # Materials | ||
# | # | ||
| − | |||
# Pool surface materials | # Pool surface materials | ||
materialDefinition "poolWater-0" | materialDefinition "poolWater-0" | ||
setDefinition PoolWaterSurfaceMaterial | setDefinition PoolWaterSurfaceMaterial | ||
| − | addParam stdMatDiffCoef (0, 0, 1) | + | addParam stdMatDiffCoef (0, 0, 1) |
addParam wmRefractionEnabled true | addParam wmRefractionEnabled true | ||
end | end | ||
materialDefinition "poolWater-1" | materialDefinition "poolWater-1" | ||
| − | setDefinition PoolWaterSurfaceMaterial | + | setDefinition PoolWaterSurfaceMaterial |
addParam stdMatLightingEnabled false | addParam stdMatLightingEnabled false | ||
addParam stdMatLayer 0 | addParam stdMatLayer 0 | ||
| − | + | addParam stdMatDiffCoef (1, 1, 1) | |
| − | addParam stdMatDiffCoef (1, 1, 1) | + | addParam wmReflectionTexture water_spec |
| − | + | addParam wmTransparency 1 | |
| − | addParam wmReflectionTexture | + | |
| − | + | ||
| − | addParam wmTransparency | + | |
| − | + | ||
addParam wmXSpeed 3 | addParam wmXSpeed 3 | ||
addParam wmXRepeat 5 | addParam wmXRepeat 5 | ||
| − | addParam wmXWaveHeight 0.01 | + | addParam wmXWaveHeight 0.01 |
| − | + | ||
addParam wmYSpeed 3 | addParam wmYSpeed 3 | ||
| − | addParam wmYRepeat | + | addParam wmYRepeat 5 |
| − | addParam wmYWaveHeight 0. | + | addParam wmYWaveHeight 0.02 |
end | end | ||
| Line 629: | Line 472: | ||
addParam stdMatLightingEnabled false | addParam stdMatLightingEnabled false | ||
addParam stdMatLayer 0 | addParam stdMatLayer 0 | ||
| − | + | addParam stdMatDiffCoef (0, 0, 1) | |
| − | addParam stdMatDiffCoef (0, 0, 1) | + | addParam wmTransparency 1 |
| − | + | ||
| − | addParam wmTransparency | + | |
| − | + | ||
addParam wmXSpeed 3 | addParam wmXSpeed 3 | ||
| − | addParam wmXRepeat | + | addParam wmXRepeat 5 |
| − | addParam wmXWaveHeight | + | addParam wmXWaveHeight 0.016 |
| − | + | ||
addParam wmYSpeed 3 | addParam wmYSpeed 3 | ||
| − | addParam wmYRepeat | + | addParam wmYRepeat 5 |
| − | addParam wmYWaveHeight | + | addParam wmYWaveHeight 0.011 |
end | end | ||
| Line 654: | Line 493: | ||
# is too constrained. We need a layer less than 7, or we'll | # is too constrained. We need a layer less than 7, or we'll | ||
# render over transparent areas of Sims (e.g. hair) when | # render over transparent areas of Sims (e.g. hair) when | ||
| − | # they're in the pool at a shallow view angle. | + | # they're in the pool at a shallow view angle. |
setc poolLayerColour (0, 0.5, 1.0, 1.0) | setc poolLayerColour (0, 0.5, 1.0, 1.0) | ||
define PoolDepthLayerMaterial() | define PoolDepthLayerMaterial() | ||
| − | material | + | material |
| − | create DetermineHardwareSupport() | + | create DetermineHardwareSupport() |
if ($useSWVertexShaderPath or $useFixedFunctionPath) | if ($useSWVertexShaderPath or $useFixedFunctionPath) | ||
shader | shader | ||
| Line 666: | Line 505: | ||
validateRenderShaderContext -vertexFormat position 0 required | validateRenderShaderContext -vertexFormat position 0 required | ||
validateRenderShaderContext -vertexFormat texcoord 0 required | validateRenderShaderContext -vertexFormat texcoord 0 required | ||
| − | + | ||
pass | pass | ||
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) | alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha) | ||
depthTest true -enableDepthWrite false | depthTest true -enableDepthWrite false | ||
| − | + | shaderProgram -target vertexProgram -method compile -version 1_1 | |
| − | + | ||
bindConstants 0 -bindingID geomToClip -constantCount 4 | bindConstants 0 -bindingID geomToClip -constantCount 4 | ||
bindConstants 4 -bindingID immediateData -data ($poolLayerColour) | bindConstants 4 -bindingID immediateData -data ($poolLayerColour) | ||
| − | |||
shaderSource | shaderSource | ||
float4x4 clipSpaceMatrix : register(c0); | float4x4 clipSpaceMatrix : register(c0); | ||
float4 poolLayer : register(c4); | float4 poolLayer : register(c4); | ||
| − | |||
struct cVertexIn | struct cVertexIn | ||
{ | { | ||
| − | float3 mPosition : POSITION0; | + | float3 mPosition : POSITION0; |
| − | float2 alpha : TEXCOORD0; | + | float2 alpha : TEXCOORD0; |
}; | }; | ||
| − | |||
struct cVertexOut | struct cVertexOut | ||
{ | { | ||
| − | float4 mClipPosition : POSITION; | + | float4 mClipPosition : POSITION; |
float4 mColor : COLOR0; | float4 mColor : COLOR0; | ||
}; | }; | ||
| − | |||
cVertexOut VertexMain(cVertexIn vertexIn) | cVertexOut VertexMain(cVertexIn vertexIn) | ||
| − | { | + | { |
| − | cVertexOut result; | + | cVertexOut result; |
| − | result.mClipPosition = mul(float4(vertexIn.mPosition, 1), clipSpaceMatrix); | + | result.mClipPosition = mul(float4(vertexIn.mPosition, 1), clipSpaceMatrix); |
| − | result.mColor = float4(poolLayer.r, poolLayer.g, poolLayer.b, poolLayer.a * vertexIn.alpha.x); | + | result.mColor = float4(poolLayer.r, poolLayer.g, poolLayer.b, poolLayer.a * vertexIn.alpha.x); |
| − | return result; | + | return result; |
} | } | ||
| − | |||
endShaderSource | endShaderSource | ||
| − | end | + | end |
| − | + | ||
shaderProgram -target pixelProgram -method compile -version 1_1 | shaderProgram -target pixelProgram -method compile -version 1_1 | ||
| − | shaderSource | + | shaderSource |
float4 PixelMain(float4 color : COLOR) : COLOR | float4 PixelMain(float4 color : COLOR) : COLOR | ||
| − | { | + | { |
return color; | return color; | ||
} | } | ||
endShaderSource | endShaderSource | ||
| − | end | + | end |
| − | end | + | end |
end | end | ||
endif | endif | ||
| Line 718: | Line 550: | ||
materialDefinition "poolWaterLayer-0" | materialDefinition "poolWaterLayer-0" | ||
# this layer does nothing but create the caustics tile. | # this layer does nothing but create the caustics tile. | ||
| − | setDefinition CausticsGeneratorMaterial | + | setDefinition CausticsGeneratorMaterial |
| − | end | + | end |
materialDefinition "poolWaterLayer-1" | materialDefinition "poolWaterLayer-1" | ||
| − | setDefinition PoolDepthLayerMaterial | + | setDefinition PoolDepthLayerMaterial |
| − | addParam poolLayerColour (0, 0.5, 1.0, | + | addParam poolLayerColour (0, 0.5, 1.0, 1) |
end | end | ||
| − | materialDefinition "poolWaterLayer-2" | + | materialDefinition "poolWaterLayer-2" |
| − | setDefinition PoolDepthLayerMaterial | + | setDefinition PoolDepthLayerMaterial |
| − | addParam poolLayerColour (0, 0.5, 1.0, | + | addParam poolLayerColour (0, 0.5, 1.0, 1) |
end | end | ||
materialDefinition "poolWaterLayer-3" | materialDefinition "poolWaterLayer-3" | ||
setDefinition PoolDepthLayerMaterial | setDefinition PoolDepthLayerMaterial | ||
| − | addParam poolLayerColour (0, 0.5, 1.0, | + | addParam poolLayerColour (0, 0.5, 1.0, 1) |
end | end | ||
materialDefinition mtl_0 | materialDefinition mtl_0 | ||
setDefinition CausticsGeneratorMaterial | setDefinition CausticsGeneratorMaterial | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
</PRE> | </PRE> | ||
Revision as of 07:42, 27 April 2007
GunMod_GMRLS21-Chocolate_Pi_RLS-2.2_RC1
0xCD7FE87A
0x1C0532FA
0x6852819C
0xFF76EA99
#outdoordaytime-envcube #pretty good
#marble-blue could make a good refraction tile
# Pool Water
seti poolWaterLayer 5
setf wmTransparency 1
setf wmXSpeed 3 # min:0 max:100
setf wmXRepeat 5 # min:0 max:100
setf wmXWaveHeight 0.02 # min:0 max:100
setf wmYSpeed 5 # min:0 max:100
setf wmYRepeat 5 # min:0 max:100
setf wmYWaveHeight 0.01 # min:0 max:100
set wmReflectionTexture water_spec
setb wmRefractionEnabled true
set wmRefractionTexture water_spec
define PoolWaterSurfaceMaterial()
material
shader -layer $poolWaterLayer
validateRenderShaderContext -vertexFormat position 0 required
create DetermineHardwareSupport()
# create RegularWavesHLSL()
create GunModWaves()
end
# basic fallback.
shader -layer $poolWaterLayer
create SimplifiedWaterSurface()
end
end
enddef
define SimplifiedWaterSurface()
pass -fixedFunction
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
depthTest true -enableDepthWrite false
colorScalar (0.2,0.3,1.0) 0.4
stage
textureBlend select(colorScalar) select(colorScalar)
end
end
enddef
define RegularWavesHLSL()
#DRIVERBUG
#-clipAlways
pass -modifiedEachFrameHint
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)
setf xscale (-$wmXRepeat * $wmXWaveHeight)
setf yscale (-$wmYRepeat * $wmYWaveHeight)
bindConstants 13 -bindingID immediateData -data ($xscale,$yscale, 1,0)
bindConstants 14 -bindingID allStandardLightData -constantCount 4 -constantType float
bindConstants 18 -bindingID cameraToGlobal -constantCount 3
if (tsIsDay)
bindConstants 25 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)
else
bindConstants 25 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)
endif
shaderSource
float4 frameInfo : register(c7);
float4 waveDataX : register(c11);
float4 waveDataY : register(c12);
float4 waveDataHelper : register(c13);
float4x4 clipSpaceMatrix : register(c0);
float4x3 cameraSpaceMatrix : register(c4);
float4x3 cameraToGlobalMatrix : register(c18);
float4 nightColor: register(c25);
float4 lightDirection : register(c14);
float4 lightColor : register(c15);
const static float4 refractionWeights={1,1,2,0};
const static float4 layerBlue={0.3, 0.7, 1.0, 1};
struct InputVertex
{
float3 position: POSITION0;
float3 normal : NORMAL0;
};
struct OutputVertex
{
float4 clipPosition : POSITION;
float4 diffuseColor: COLOR0;
float4 specularColor: COLOR1;
float3 reflection : TEXCOORD0;
};
OutputVertex VertexMain( InputVertex inputVertex)
{
OutputVertex outputVertex;
float4 posAndTime;
posAndTime.xyz = inputVertex.position;
posAndTime.w = frameInfo.w;
float temp = dot(posAndTime, waveDataX);
float z;
float3 waveNormal;
z = sin(temp) * waveDataX.z + inputVertex.position.z;
waveNormal.x = cos(temp) * waveDataHelper.x + inputVertex.normal.x;
temp = dot(posAndTime, waveDataY);
z += sin(temp) * waveDataY.z;
waveNormal.y = cos(temp) * waveDataHelper.y + inputVertex.normal.y;
waveNormal.z = inputVertex.normal.z;
waveNormal = normalize(waveNormal);
posAndTime.w = 1.0;
posAndTime.z = z;
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix);
float3 cameraSpaceNormal = normalize(mul(waveNormal, cameraSpaceMatrix));
float3 cameraSpacePosition = mul( posAndTime, cameraSpaceMatrix);
float3 viewVector = normalize(-cameraSpacePosition);
float3 R = reflect(viewVector, cameraSpaceNormal);
outputVertex.reflection = mul( -R, cameraToGlobalMatrix);
float fresnel = dot(viewVector , cameraSpaceNormal);
float rdotl = saturate(dot(R, lightDirection));
float I = pow(rdotl+0.1, 15); // fudge factor to punch up the highlights.
nightColor = nightColor * 2;
outputVertex.diffuseColor = ((1.0 + fresnel) * saturate(nightColor) * 0.5) * layerBlue;
outputVertex.specularColor = I;
return(outputVertex);
}
endShaderSource
end
stage
texture $wmReflectionTexture
textureAddressing clamp clamp clamp
textureBlend multiply(texture diffuse) select(diffuse)
end
addSpecular true
end
enddef
define GunModWaves()
pass
#fillmode wireframe
alphaBlend srcFactor(one) add dstFactor(one)
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
shaderSource
float4 frameInfo : register(c7);
float4 waveDataX : register(c11);
float4 waveDataY : register(c12);
float4 waveDataHelper : register(c13);
float4x4 clipSpaceMatrix : register(c0);
float4x3 cameraSpaceMatrix : register(c4);
float4x3 cameraToGlobalMatrix : register(c18);
float4 lightDirection : register(c14);
float4 lightColor : register(c15);
const static float4 refractionWeights={1,1,2,0};
struct InputVertex
{
float4 position: POSITION0;
float3 normal : NORMAL0;
float2 texc : TEXCOORD0;
};
struct OutputVertex
{
float4 clipPosition : POSITION;
float3 normal : TEXCOORD0;
float3 viewVector : TEXCOORD1;
};
static float2 waveCenter1 = {0.0, 0.0};
static float2 waveCenter2 = {-0.6, 0.2};
static float2 timeScale = {2,1};
static float2 waveHeight = {0.04, 0.02};
static float2 distScale = {12, 8};
float4 ComputeWavePositionTwoWay(float2 pos1, float2 pos2)
{
float2 vec;
float4 dist;
vec = waveCenter1 - pos1;
dist.x = dot(vec, vec);
vec = waveCenter2 - pos1;
dist.y = dot(vec,vec);
vec = waveCenter2 - pos2;
dist.z = dot(vec, vec);
vec = waveCenter2 - pos2;
dist.w = dot(vec,vec);
dist *= distScale.xyxy;
float4 sinResult = sin(dist + frameInfo.w * timeScale.xyxy);
//sinResult = 1.0- abs(sinResult);
return(sinResult);
}
float2 ComputeWavePosition(float2 pos1)
{
float2 vec;
float2 dist;
vec = waveCenter1 - pos1;
dist.x = dot(vec, vec);
vec = waveCenter2 - pos1;
dist.y = dot(vec,vec);
dist *= distScale.xy;
float2 sinResult = sin(dist + frameInfo.w * timeScale);
//sinResult = 1.0- abs(sinResult);
return(sinResult);
}
OutputVertex VertexMain( InputVertex inputVertex)
{
// Do Y-direction waves
// r0 = (x, y, z, t)
OutputVertex outputVertex;
float4 pos = inputVertex.position;
float2 sample1, sample2, sample3;
sample1 = inputVertex.position;
sample2 = inputVertex.position;
sample3 = inputVertex.position;
sample2.x += 0.1;
sample3.y += 0.1;
float4 heights1=ComputeWavePositionTwoWay(sample1, sample2);
float2 heights2=ComputeWavePosition(sample3);
float3 pos1, pos2;
pos1 = pos;
pos2 = pos;
pos.z += (heights1.x* waveHeight.x);// + heights1.y * waveHeight.y);
pos1.z += (heights1.z* waveHeight.x);// + heights1.w * waveHeight.y);
pos2.z += (heights2.x* waveHeight.x);// + heights2.y * waveHeight.y);
pos1.x +=0.1;
pos2.y +=0.1;
float3 vec1, vec2;
vec1 = normalize(pos1 - pos);
vec2 = normalize(pos2 - pos);
float3 normal = cross(vec1, vec2);
normal = mul(normal, (float3x3)cameraSpaceMatrix);
float3 viewVector = mul(pos, cameraSpaceMatrix);
outputVertex.viewVector = normalize(-viewVector);
outputVertex.clipPosition = mul(pos, clipSpaceMatrix);
outputVertex.normal = normal;
return(outputVertex);
}
endShaderSource
end # end shaderProgram
shaderProgram -target pixelProgram -method assemble
bindConstants 0 -bindingID allStandardLightData -constantCount 4 -constantType float
shaderSource
ps_2_0
def c10,20,4,0,0
def c11, 0,0.5,1,2
dcl t0
dcl t1 ; v
dcl_cube s0
nrm r0, t0 ; n
add r1, r0, r0 ; 2N
dp3 r1.w, r0, t1 ; N.V
mad r2.xyz, r1, r1.w, -t1 ; 2N * (N.V) -V
texld r5, r2, s0
dp3 r3.x, r2, c0 ; R.L
pow r4, r3.x, c10.x
mov_sat r1.x, r1.w
add r6.x, c11.z, -r1.x ; 1 - Fresnel
pow r3.y, r6.x, c10.y ; N.V ^ 4
mul r7, r5, r3.y
mad r4, r4, r3.y, r7
mul r4, r4, c11.y
mov oC0, r4
endShaderSource
end
sampler 0
texture $wmReflectionTexture
textureAddressing clamp clamp clamp
end
end # pass
enddef
# Caustics
define TiledTextureAnimShaderProgram(tilesX tilesY speed)
shaderProgram -target vertexProgram -method assemble
bindConstants 0 -bindingID frameInfo # for time in .w
bindConstants 1 -data (&tilesX, &tilesY, &speed, 1) # tx, ty, speed
bindConstants 2 -data ((1/&tilesX), (1/&tilesY), (&tilesY - 1), 1) # 1/tx 1/ty ty-1
if (tsIsDay)
bindConstants 3 -bindingID immediateData -data (0.75, 0.75, 0.75, 1)
else
bindConstants 3 -bindingID immediateData -data (0.2, 0.2, 0.2, 1)
endif
shaderSource
vs_1_1
dcl_position v0
dcl_texcoord v1
mov oPos, v0 # clip space quad, no transforms needed.
mov r0, c0
mul r1, c1.z, r0.w
frc r5.y, r1.y
mul r1, c1.y, r5.y # f -> [0, ty)
frc r5.y, r1
sub r3.y, r1, r5.y # v' = floor(f)
mul r1, c1.x, r5.y # f -> [0, tx)
frc r5.y, r1
sub r3.x, r1, r5.y # u' = floor(f)
add r8.xy, v1.xy, r3.xy
mul oT0.xy, r8.xy, c2.xy
mov oD0, c3 # also spit out diffuse color with modcolor information
endShaderSource
end
enddef
define CausticsGeneratorMaterial()
material
# This material updates a render target with the current frame
# of the tile animation. This is the only way to handle a repeated
# animating texture (not to mention using it for projective texturing)
# in the absence of clip maps.
create DetermineHardwareSupport()
if ($causticsEnabled and $useFixedFunctionPath = false and $useSWVertexShaderPath = false)
shader -layer +9999
pass
renderClipSpaceRect
renderTarget causticsTile -fixed (64, 64) -allocateDepthBuffer false -undo
create TiledTextureAnimShaderProgram(8 4 1)
alphaBlend srcFactor(one) add dstFactor(zero)
alphaTest false 0
alphaTestFunction acceptIfGreater
depthTest false -enableDepthWrite false
depthTestFunction accept
# 7/24/2004 Fix bug with kRenderTypeNormal default stencil state and nv40.
# It reads random stencil values even this target has no depth stencil target.
# This stencil call will break pixo, but pixo does not show caustics.
stencil false
fillmode $stdMatFillMode
shaderProgram -target pixelProgram -method compile -version 1_1
shaderSource
sampler caustics;
struct cInputPixel
{
float4 color : COLOR;
float2 tc0 : TEXCOORD0;
};
float4 PixelMain(cInputPixel pi) : COLOR
{
float4 texColor = tex2D(caustics, pi.tc0);
return texColor*pi.color;
}
endShaderSource
end
sampler 0
texture causticsTiled
textureAddressing tile tile
end
end
end
else
shader
end
endif
end
enddef
setf causticsStrength 0.8
setf causticsBaseStrength 0.5
###################################################
# Materials
#
# Pool surface materials
materialDefinition "poolWater-0"
setDefinition PoolWaterSurfaceMaterial
addParam stdMatDiffCoef (0, 0, 1)
addParam wmRefractionEnabled true
end
materialDefinition "poolWater-1"
setDefinition PoolWaterSurfaceMaterial
addParam stdMatLightingEnabled false
addParam stdMatLayer 0
addParam stdMatDiffCoef (1, 1, 1)
addParam wmReflectionTexture water_spec
addParam wmTransparency 1
addParam wmXSpeed 3
addParam wmXRepeat 5
addParam wmXWaveHeight 0.01
addParam wmYSpeed 3
addParam wmYRepeat 5
addParam wmYWaveHeight 0.02
end
materialDefinition "poolWater-2"
setDefinition PoolWaterSurfaceMaterial
addParam stdMatLightingEnabled false
addParam stdMatLayer 0
addParam stdMatDiffCoef (0, 0, 1)
addParam wmTransparency 1
addParam wmXSpeed 3
addParam wmXRepeat 5
addParam wmXWaveHeight 0.016
addParam wmYSpeed 3
addParam wmYRepeat 5
addParam wmYWaveHeight 0.011
end
materialDefinition "poolWater-4"
setDefinition WaterAnimatingTextures
addParam waterSpeed 0.3
end
# Pool depth layer materials
# this is here soley because the layering on standard material
# is too constrained. We need a layer less than 7, or we'll
# render over transparent areas of Sims (e.g. hair) when
# they're in the pool at a shallow view angle.
setc poolLayerColour (0, 0.5, 1.0, 1.0)
define PoolDepthLayerMaterial()
material
create DetermineHardwareSupport()
if ($useSWVertexShaderPath or $useFixedFunctionPath)
shader
end
else
shader -layer $poolWaterLayer
validateRenderShaderContext -vertexFormat position 0 required
validateRenderShaderContext -vertexFormat texcoord 0 required
pass
alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
depthTest true -enableDepthWrite false
shaderProgram -target vertexProgram -method compile -version 1_1
bindConstants 0 -bindingID geomToClip -constantCount 4
bindConstants 4 -bindingID immediateData -data ($poolLayerColour)
shaderSource
float4x4 clipSpaceMatrix : register(c0);
float4 poolLayer : register(c4);
struct cVertexIn
{
float3 mPosition : POSITION0;
float2 alpha : TEXCOORD0;
};
struct cVertexOut
{
float4 mClipPosition : POSITION;
float4 mColor : COLOR0;
};
cVertexOut VertexMain(cVertexIn vertexIn)
{
cVertexOut result;
result.mClipPosition = mul(float4(vertexIn.mPosition, 1), clipSpaceMatrix);
result.mColor = float4(poolLayer.r, poolLayer.g, poolLayer.b, poolLayer.a * vertexIn.alpha.x);
return result;
}
endShaderSource
end
shaderProgram -target pixelProgram -method compile -version 1_1
shaderSource
float4 PixelMain(float4 color : COLOR) : COLOR
{
return color;
}
endShaderSource
end
end
end
endif
end
enddef
materialDefinition "poolWaterLayer-0"
# this layer does nothing but create the caustics tile.
setDefinition CausticsGeneratorMaterial
end
materialDefinition "poolWaterLayer-1"
setDefinition PoolDepthLayerMaterial
addParam poolLayerColour (0, 0.5, 1.0, 1)
end
materialDefinition "poolWaterLayer-2"
setDefinition PoolDepthLayerMaterial
addParam poolLayerColour (0, 0.5, 1.0, 1)
end
materialDefinition "poolWaterLayer-3"
setDefinition PoolDepthLayerMaterial
addParam poolLayerColour (0, 0.5, 1.0, 1)
end
materialDefinition mtl_0
setDefinition CausticsGeneratorMaterial
end