Difference between revisions of "TEST-STRCMP4CODES"
Line 1: | Line 1: | ||
+ | OutputVertex VertexMain( InputVertex inputVertex) | ||
+ | { | ||
+ | // Do Y-direction waves | ||
+ | // r0 = (x, y, z, t) | ||
+ | |||
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 = sin(temp) * waveDataX.z + inputVertex.position.z; | + | float z = sin(temp) * waveDataX.z + inputVertex.position.z; |
− | temp = dot(posAndTime, waveDataY); | + | |
+ | temp = dot(posAndTime, waveDataY); | ||
+ | |||
posAndTime.z = z + sin(temp) * waveDataY.z ;//-0.1f; //The -.01 is a fudge factor to remove some of the edge creep associated with moving the height of the wave. -tom | posAndTime.z = z + sin(temp) * waveDataY.z ;//-0.1f; //The -.01 is a fudge factor to remove some of the edge creep associated with moving the height of the wave. -tom | ||
posAndTime.w = 1.0f; | posAndTime.w = 1.0f; | ||
− | + | ||
outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix); | outputVertex.clipPosition = mul( posAndTime, clipSpaceMatrix); | ||
outputVertex.sPos = float4(0.5f*(outputVertex.clipPosition.ww - outputVertex.clipPosition.xy), outputVertex.clipPosition.ww); | 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 waveNormal = normalize(inputVertex.normal + float3(cos(temp)*waveDataHelper.xy, 0)); |
+ | |||
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 halfVector = normalize(viewVector + lightDirection); | float3 halfVector = normalize(viewVector + lightDirection); | ||
− | outputVertex.specular = lightSpecular*pow(dot(cameraSpaceNormal, halfVector), 50)*nightColor*lightColor*0.5; | + | 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 fTranslation=float2(fmod(frameInfo.w, 100)*0.005, fmod(frameInfo.w, 100)*0.005); | ||
float2 vTexCoords = posAndTime.xy*0.05; | float2 vTexCoords = posAndTime.xy*0.05; | ||
− | + | ||
// Output bump layers texture coordinates | // Output bump layers texture coordinates | ||
float fSinTranslation=sin(fTranslation*100)*0.005; | float fSinTranslation=sin(fTranslation*100)*0.005; | ||
Line 31: | Line 39: | ||
float2 vTranslation1=fTranslation-fSinTranslation; | float2 vTranslation1=fTranslation-fSinTranslation; | ||
float2 vTranslation2=fTranslation; | float2 vTranslation2=fTranslation; | ||
− | + | ||
// Scale texture coordinates to get mix of low/high frequency details | // Scale texture coordinates to get mix of low/high frequency details | ||
outputVertex.Wave0.xy = vTexCoords.xy*0.01+fTranslation*2.0; | outputVertex.Wave0.xy = vTexCoords.xy*0.01+fTranslation*2.0; | ||
outputVertex.Wave1.xy = vTexCoords.xy+fTranslation*2.5; | outputVertex.Wave1.xy = vTexCoords.xy+fTranslation*2.5; | ||
outputVertex.Wave2.xy = vTexCoords.xy+fTranslation*-2.3; | outputVertex.Wave2.xy = vTexCoords.xy+fTranslation*-2.3; | ||
− | outputVertex.Wave3.xy = vTexCoords.xy*0.1+fTranslation*1.5; | + | outputVertex.Wave3.xy = vTexCoords.xy*0.1+fTranslation*1.5; |
− | + | ||
+ | |||
// compute binormal | // compute binormal | ||
float3 binormal = normalize(cross(waveNormal, float3(1.0f, 0.0f, 0.0f))); | float3 binormal = normalize(cross(waveNormal, float3(1.0f, 0.0f, 0.0f))); | ||
float3 tangent = normalize(cross(binormal, waveNormal)); | float3 tangent = normalize(cross(binormal, waveNormal)); | ||
− | + | ||
// tangent space matrix | // tangent space matrix | ||
float3x3 objToTangentSpace = float3x3(tangent, binormal, waveNormal); | float3x3 objToTangentSpace = float3x3(tangent, binormal, waveNormal); | ||
− | + | ||
float3 viewVectorInObjSpace = mul(viewVector, (float3x3)cameraToGeomMatrix); | float3 viewVectorInObjSpace = mul(viewVector, (float3x3)cameraToGeomMatrix); | ||
− | + | ||
outputVertex.Eye.xyz = mul(objToTangentSpace, viewVectorInObjSpace); | outputVertex.Eye.xyz = mul(objToTangentSpace, viewVectorInObjSpace); | ||
outputVertex.colorTint = waterTint; | outputVertex.colorTint = waterTint; | ||
outputVertex.colorTint.a = inputVertex.alpha.xxxx; | outputVertex.colorTint.a = inputVertex.alpha.xxxx; | ||
// outputVertex.color = waterTint.xxxx; | // outputVertex.color = waterTint.xxxx; | ||
− | + | ||
return(outputVertex); | return(outputVertex); | ||
} | } | ||
− | + | ||
endShaderSource | endShaderSource | ||
end # shaderProgram | end # shaderProgram |
Revision as of 05:40, 7 September 2007
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); float z = sin(temp) * waveDataX.z + inputVertex.position.z;
temp = dot(posAndTime, waveDataY);
posAndTime.z = z + sin(temp) * waveDataY.z ;//-0.1f; //The -.01 is a fudge factor to remove some of the edge creep associated with moving the height of the wave. -tom 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*0.01+fTranslation*2.0; outputVertex.Wave1.xy = vTexCoords.xy+fTranslation*2.5; outputVertex.Wave2.xy = vTexCoords.xy+fTranslation*-2.3; outputVertex.Wave3.xy = vTexCoords.xy*0.1+fTranslation*1.5;
// 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); outputVertex.colorTint = waterTint; outputVertex.colorTint.a = inputVertex.alpha.xxxx; // outputVertex.color = waterTint.xxxx;
return(outputVertex); }
endShaderSource end # shaderProgram