Difference between revisions of "TEST-STRCMP4CODES"
Line 1: | Line 1: | ||
− | # | + | seti GMpoolWaterLayer 5 |
− | # | + | setf GMwmTransparency 1 |
+ | setf wmXSpeedGM 3 # min:0 max:100 | ||
+ | setf wmXRepeatGM 5 # min:0 max:100 | ||
+ | setf wmXWaveHeightGM 0.02 # min:0 max:100 | ||
+ | setf wmYSpeedGM 5 # min:0 max:100 | ||
+ | setf wmYRepeatGM 5 # min:0 max:100 | ||
+ | setf wmYWaveHeightGM 0.01 # min:0 max:100 | ||
− | + | set wmReflectionTextureGM water_spec | |
− | + | setb wmRefractionGMEnabled true | |
− | + | set wmRefractionTextureGM water_spec | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | define PoolWaterSurfaceMaterialGunModWaves() | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | define | + | |
material | material | ||
− | # | + | shader -layer $GMpoolWaterLayer |
− | # | + | validateRenderShaderContext -vertexFormat position 0 required |
− | # | + | |
− | + | create DetermineHardwareSupport() | |
+ | create GunModWaves() | ||
+ | end #end shader PoolWaterSurfaceMaterialGunModWaves | ||
+ | |||
+ | # fallback shader | ||
+ | shader -layer $GMpoolWaterLayer | ||
+ | if | ||
+ | if ($useSWVertexShaderPath or $useFixedFunctionPath) | ||
+ | create SimplifiedWaterSurfaceEP3() # common fallback | ||
+ | else | ||
+ | create RegularWavesHLSL() | ||
+ | endif | ||
+ | else | ||
+ | create SimplifiedWaterSurface() # basic fallback. | ||
+ | endif | ||
+ | end #end shader # fallback shader | ||
+ | end #end material | ||
+ | enddef # PoolWaterSurfaceMaterialGunModWaves | ||
+ | |||
+ | |||
+ | 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 ($wmXRepeatGM, 0, $wmXWaveHeightGM, $wmXSpeedGM) | |
+ | bindConstants 12 -bindingID immediateData -data (0, $wmYRepeatGM, $wmYWaveHeightGM, $wmYSpeedGM) | ||
+ | |||
+ | # pre-evaluate these | ||
+ | setf xscale (-$wmXRepeatGM * $wmXWaveHeightGM) | ||
+ | setf yscale (-$wmYRepeatGM * $wmYWaveHeightGM) | ||
+ | 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 $wmReflectionTextureGM | ||
+ | textureAddressing clamp clamp clamp | ||
+ | end | ||
+ | end # pass | ||
+ | |||
+ | enddef # GunModWaves |
Revision as of 23:56, 2 September 2007
seti GMpoolWaterLayer 5 setf GMwmTransparency 1 setf wmXSpeedGM 3 # min:0 max:100 setf wmXRepeatGM 5 # min:0 max:100 setf wmXWaveHeightGM 0.02 # min:0 max:100 setf wmYSpeedGM 5 # min:0 max:100 setf wmYRepeatGM 5 # min:0 max:100 setf wmYWaveHeightGM 0.01 # min:0 max:100
set wmReflectionTextureGM water_spec setb wmRefractionGMEnabled true set wmRefractionTextureGM water_spec
define PoolWaterSurfaceMaterialGunModWaves()
material shader -layer $GMpoolWaterLayer validateRenderShaderContext -vertexFormat position 0 required create DetermineHardwareSupport() create GunModWaves() end #end shader PoolWaterSurfaceMaterialGunModWaves
# fallback shader shader -layer $GMpoolWaterLayer if if ($useSWVertexShaderPath or $useFixedFunctionPath) create SimplifiedWaterSurfaceEP3() # common fallback else create RegularWavesHLSL() endif else create SimplifiedWaterSurface() # basic fallback. endif end #end shader # fallback shader end #end material
enddef # PoolWaterSurfaceMaterialGunModWaves
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 ($wmXRepeatGM, 0, $wmXWaveHeightGM, $wmXSpeedGM) bindConstants 12 -bindingID immediateData -data (0, $wmYRepeatGM, $wmYWaveHeightGM, $wmYSpeedGM) # pre-evaluate these setf xscale (-$wmXRepeatGM * $wmXWaveHeightGM) setf yscale (-$wmYRepeatGM * $wmYWaveHeightGM) 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 $wmReflectionTextureGM textureAddressing clamp clamp clamp
end end # pass
enddef # GunModWaves