summaryrefslogtreecommitdiffstats
path: root/o3d/samples/beachdemo
diff options
context:
space:
mode:
authoramarinichev@chromium.org <amarinichev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-21 23:47:35 +0000
committeramarinichev@chromium.org <amarinichev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-21 23:47:35 +0000
commit2b0be6b101b9a079da9d48ee20499ef4e181122a (patch)
tree19a1d1265ccfc00af525229e152c1e785a4f8496 /o3d/samples/beachdemo
parent31f8713186cbb21398cd78c1de0db6a3789bb3ba (diff)
downloadchromium_src-2b0be6b101b9a079da9d48ee20499ef4e181122a.zip
chromium_src-2b0be6b101b9a079da9d48ee20499ef4e181122a.tar.gz
chromium_src-2b0be6b101b9a079da9d48ee20499ef4e181122a.tar.bz2
Review URL: http://codereview.chromium.org/1736003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45262 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/beachdemo')
-rw-r--r--o3d/samples/beachdemo/beachdemo.html1078
-rw-r--r--o3d/samples/beachdemo/beachdemo.js73
-rw-r--r--o3d/samples/beachdemo/shaders_cg/diffuse.cg79
-rw-r--r--o3d/samples/beachdemo/shaders_cg/diffuse_bump.cg98
-rw-r--r--o3d/samples/beachdemo/shaders_cg/diffuse_bump_2textures.cg103
-rw-r--r--o3d/samples/beachdemo/shaders_cg/diffuse_bump_blend.cg116
-rw-r--r--o3d/samples/beachdemo/shaders_cg/diffuse_bump_blend_underwater.cg115
-rw-r--r--o3d/samples/beachdemo/shaders_cg/diffuse_bump_specular.cg97
-rw-r--r--o3d/samples/beachdemo/shaders_cg/imageshader.cg61
-rw-r--r--o3d/samples/beachdemo/shaders_cg/just_color.cg81
-rw-r--r--o3d/samples/beachdemo/shaders_cg/particleshader.cg102
-rw-r--r--o3d/samples/beachdemo/shaders_cg/proxy.cg81
-rw-r--r--o3d/samples/beachdemo/shaders_cg/simpleshader.cg55
-rw-r--r--o3d/samples/beachdemo/shaders_cg/skydomeshader.cg62
-rw-r--r--o3d/samples/beachdemo/shaders_cg/underwatershader.cg80
-rw-r--r--o3d/samples/beachdemo/shaders_cg/watercolorandskyshader.cg131
-rw-r--r--o3d/samples/beachdemo/shaders_cg/waterfallshader.cg80
-rw-r--r--o3d/samples/beachdemo/shaders_cg/watershader.cg157
-rw-r--r--o3d/samples/beachdemo/shaders_cg/waterstyle2.cg73
19 files changed, 1624 insertions, 1098 deletions
diff --git a/o3d/samples/beachdemo/beachdemo.html b/o3d/samples/beachdemo/beachdemo.html
index b4e61aa..67db3bd 100644
--- a/o3d/samples/beachdemo/beachdemo.html
+++ b/o3d/samples/beachdemo/beachdemo.html
@@ -144,1084 +144,6 @@ textarea {
</div>
</div>
</div>
-<script type="text/o3deffect" id="watershader">
-// The 4x4 world view projection matrix.
-float4x4 world : WORLD;
-float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-float4x4 view : VIEW;
-float4x4 viewProjection : VIEWPROJECTION;
-float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-float3 viewPosition;
-float4 waterColor;
-float reflectionRefractionOffset;
-float clock;
-
-samplerCUBE environmentSampler;
-sampler2D fresnelSampler; // TODO: should be 1D.
-sampler2D refractionSampler; // This is a render target.
-sampler2D reflectionSampler; // This is a render target.
-sampler2D noiseSampler;
-sampler2D noiseSampler2;
-sampler2D noiseSampler3;
-
-// input parameters for our vertex shader
-struct VertexShaderInput {
- float4 position : POSITION;
- float2 texcoord : TEXCOORD0;
-};
-
-// input parameters for our pixel shader
-// also the output parameters for our vertex shader
-struct PixelShaderInput {
- float4 position : POSITION;
- float2 texcoord : TEXCOORD0;
- float3 viewVector : TEXCOORD1;
- float3 screenPosition : TEXCOORD2;
-};
-
-/**
- * Vertex Shader
- */
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- /**
- * We transform each vertex by the world view projection matrix to bring
- * it from world space to projection space.
- *
- * We return its color unchanged.
- */
- PixelShaderInput output;
-
- float4 worldPosition = mul(input.position, world);
- output.position = mul(worldPosition, viewProjection);
- output.viewVector = normalize(worldPosition.xyz - viewPosition.xyz);
- output.texcoord = input.texcoord;
-
- float4 tpos = mul(float4(worldPosition.x, worldPosition.y, 0, 1),
- viewProjection);
- output.screenPosition = tpos.xyz / tpos.w;
- output.screenPosition.xy = 0.5 + 0.5 * output.screenPosition.xy *
- float2(1, -1);
- output.screenPosition.z = reflectionRefractionOffset /
- output.screenPosition.z;
-
- return output;
-}
-/**
- * Pixel Shader - pixel shader does nothing but return the color.
- */
-float4 pixelShaderFunction(PixelShaderInput input): COLOR {
- float3 viewVector = float3(input.viewVector.x,
- input.viewVector.z,
- -input.viewVector.y);
-
- float2 texcoord = input.texcoord * 4;
- float3 n1 = tex2D(noiseSampler,
- texcoord +
- float2(clock * 0.01, clock * 0.02));
- float3 n2 = tex2D(noiseSampler2,
- texcoord +
- float2(clock * 0.03, clock * 0.01));
- float3 n3 = tex2D(noiseSampler3,
- texcoord +
- float2(clock * 0.005, clock * 0.007));
-
- float3 N = normalize(n1 + n2 * 2 + n3 * 4 + float3(-3.5, 16, -3.5));
-
- float3 R = normalize(reflect(viewVector, N));
- R.y = R.y < 0.01 ? 0.01 : R.y;
-
- //float f = tex1D(fresnelSampler, dot(R, N));
- float f = tex2D(fresnelSampler, float2(dot(R, N), 0.5)).x;
- float4 reflection = tex2D(
- reflectionSampler,
- input.screenPosition.xy - input.screenPosition.z * N.xy + float2(0, 0.1));
- // I still don't understand where my math is wrong such that I need this 0.1
- // fudge factor.
-
- // Lookup the sky color
- float3 skyReflection = texCUBE(environmentSampler, R);
-
- // lerping with reflection.a means that where there is terrain reflected
- // we get terrain, otherwise we get sky.
- float3 color = lerp(skyReflection,
- reflection.rgb, reflection.a);
-
- // lookup the refraction color.
- float3 refraction = tex2D(
- refractionSampler,
- (input.screenPosition.xy - input.screenPosition.z * N.xz +
- float2(0, 0.05)) * float2(1, 0.95)); // fudge
-
- float3 finalColor = lerp(refraction, color, f);
-
- // Uncomment any one of the lines below to see just part of the water
- // calculation.
-
- //finalColor = skyReflection; // sky only.
- //finalColor = reflection.xyz; // reflection only.
- //finalColor = refraction; // refraction only.
- //finalColor = lerp(float3(0,1,0), float3(1,0,0), f); // reflection/refraction mix
- //finalColor = color; // sky only.
- return float4(finalColor, 1);
-}
-
-// Here we tell our effect file the functions
-// which specify our vertex and pixel shaders.
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="watercolorandskyshader">
-// The 4x4 world view projection matrix.
-float4x4 world : WORLD;
-float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-float4x4 view : VIEW;
-float4x4 viewProjection : VIEWPROJECTION;
-float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-float3 viewPosition;
-float4 waterColor;
-float reflectionRefractionOffset;
-float clock;
-
-samplerCUBE environmentSampler;
-sampler2D fresnelSampler; // TODO: should be 1D.
-sampler2D noiseSampler;
-sampler2D noiseSampler2;
-sampler2D noiseSampler3;
-
-// input parameters for our vertex shader
-struct VertexShaderInput {
- float4 position : POSITION;
- float2 texcoord : TEXCOORD0;
-};
-
-// input parameters for our pixel shader
-// also the output parameters for our vertex shader
-struct PixelShaderInput {
- float4 position : POSITION;
- float2 texcoord : TEXCOORD0;
- float3 viewVector : TEXCOORD1;
- float3 screenPosition : TEXCOORD2;
-};
-
-/**
- * Vertex Shader
- */
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- /**
- * We transform each vertex by the world view projection matrix to bring
- * it from world space to projection space.
- *
- * We return its color unchanged.
- */
- PixelShaderInput output;
-
- float4 worldPosition = mul(input.position, world);
- output.position = mul(worldPosition, viewProjection);
- output.viewVector = normalize(worldPosition.xyz - viewPosition.xyz);
- output.texcoord = input.texcoord;
-
- float4 tpos = mul(float4(worldPosition.x, worldPosition.y, 0, 1),
- viewProjection);
- output.screenPosition = tpos.xyz / tpos.w;
- output.screenPosition.xy = 0.5 + 0.5 * output.screenPosition.xy *
- float2(1, -1);
- output.screenPosition.z = reflectionRefractionOffset /
- output.screenPosition.z;
-
- return output;
-}
-/**
- * Pixel Shader - pixel shader does nothing but return the color.
- */
-float4 pixelShaderFunction(PixelShaderInput input): COLOR {
- float3 viewVector = float3(input.viewVector.x,
- input.viewVector.z,
- -input.viewVector.y);
-
- float2 texcoord = input.texcoord * 4;
- float3 n1 = tex2D(noiseSampler,
- texcoord +
- float2(clock * 0.01, clock * 0.02));
- float3 n2 = tex2D(noiseSampler2,
- texcoord +
- float2(clock * 0.03, clock * 0.01));
- float3 n3 = tex2D(noiseSampler3,
- texcoord +
- float2(clock * 0.005, clock * 0.007));
-
- float3 N = normalize(n1 + n2 * 2 + n3 * 4 + float3(-3.5, 16, -3.5));
-
- float3 R = normalize(reflect(viewVector, N));
- R.y = R.y < 0.01 ? 0.01 : R.y;
-
- //float f = tex1D(fresnelSampler, dot(R, N));
- float f = tex2D(fresnelSampler, float2(dot(R, N), 0.5)).x;
-
- // Lookup the sky color
- float3 skyReflection = texCUBE(environmentSampler, R);
-
- float3 color = lerp(waterColor.xyz, skyReflection, f);
-
- return float4(color, 1);
-}
-
-// Here we tell our effect file the functions
-// which specify our vertex and pixel shaders.
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="waterstyle2">
-// The 4x4 world view projection matrix.
-float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-
-// input parameters for our vertex shader
-struct VertexShaderInput {
- float4 position : POSITION;
-};
-
-// input parameters for our pixel shader
-// also the output parameters for our vertex shader
-struct PixelShaderInput {
- float4 position : POSITION;
-};
-
-/**
- * Vertex Shader
- */
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- /**
- * We transform each vertex by the world view projection matrix to bring
- * it from world space to projection space.
- *
- * We return its color unchanged.
- */
- PixelShaderInput output;
-
- output.position = mul(input.position, worldViewProjection);
- return output;
-}
-/**
- * Pixel Shader - pixel shader does nothing but return the color.
- */
-float4 pixelShaderFunction(PixelShaderInput input): COLOR {
- return float4(0, 0, 0.5, 1);
-}
-
-// Here we tell our effect file the functions
-// which specify our vertex and pixel shaders.
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="underwatershader">
-uniform float4x4 world : WORLD;
-uniform float4x4 viewProjection : VIEWPROJECTION;
-uniform float4 waterColor;
-uniform float3 sunVector;
-uniform float fadeFudge;
-
-sampler diffuseSampler;
-
-// input parameters for our vertex shader
-struct VertexShaderInput {
- float4 position : POSITION;
- float3 normal : NORMAL;
- float2 texcoord : TEXCOORD0;
-};
-
-// input parameters for our pixel shader
-// also the output parameters for our vertex shader
-struct PixelShaderInput {
- float4 position : POSITION;
- float2 texcoord : TEXCOORD0;
- float fade : TEXCOORD1;
- float4 color : TEXCOORD2;
- float4 worldPosition : TEXCOORD3;
-};
-
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- PixelShaderInput output;
- float4 worldPosition = mul(input.position, world);
- output.position = mul(float4(worldPosition.xyz, 1), viewProjection);
- output.worldPosition = worldPosition;
- output.texcoord = input.texcoord;
- output.color = dot(sunVector,
- normalize(mul(float4(input.normal, 0), world)));
- output.fade = 0.2 + 0.8 * saturate(worldPosition.z * fadeFudge);
-
- return output;
-}
-
-float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
- float4 color = tex2D(diffuseSampler, input.texcoord);
-// float4 diffuse = tex2D(diffuseSampler, input.texcoord);
-// float4 color = lerp(diffuse * input.color, waterColor, input.fade);
- float alpha = input.worldPosition.z < 100 ? color.a : 0;
- return float4(color.xyz, alpha);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="skydomeshader">
-uniform float4x4 worldViewProjectionInverse : VIEWPROJECTIONINVERSE;
-uniform float4x4 viewInverse : VIEWINVERSE;
-samplerCUBE environmentSampler;
-
-struct VertexShaderInput {
- float4 position : POSITION;
-};
-
-struct PixelShaderInput {
- float4 position : POSITION;
- float3 worldPosition : TEXCOORD0;
-};
-
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- PixelShaderInput output;
- output.position = input.position;
- float4 temp = mul(input.position, worldViewProjectionInverse);
- output.worldPosition = temp.xyz / temp.w;
- return output;
-}
-
-float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
- float3 viewVector = normalize(viewInverse[3].xyz - input.worldPosition);
- return texCUBE(environmentSampler, float3(viewVector.x,
- abs(-viewVector.z) + 0.01,
- -viewVector.y));
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="waterfallshader">
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float4x4 world : WORLD;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float3 lightWorldPos;
-uniform float vOffset;
-
-sampler diffuseSampler;
-
-struct VertexShaderInput {
- float4 position : POSITION;
- float4 normal : NORMAL;
- float2 texcoord : TEXCOORD0;
-};
-
-struct PixelShaderInput {
- float4 position : POSITION;
- float3 normal : TEXCOORD0;
- float3 worldPosition : TEXCOORD1;
- float2 texcoord : TEXCOORD2;
-};
-
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- PixelShaderInput output;
- output.position = mul(input.position, worldViewProjection);
- float3 worldPosition = mul(input.position, world).xyz;
- output.normal = mul(input.normal, worldInverseTranspose).xyz;
- output.worldPosition = worldPosition;
- output.texcoord = input.texcoord;
- return output;
-}
-
-float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 worldNormal = normalize(input.normal);
- float3 surfaceToView = normalize(viewInverse[3].xyz - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litResult = lit(dot(worldNormal, surfaceToLight),
- dot(worldNormal, halfVector), 0);
- float4 diffuse = tex2D(diffuseSampler, float2(input.texcoord.x,
- input.texcoord.y + vOffset));
- float4 outColor = (diffuse * litResult.y);
- return diffuse;
- //return float4(outColor.rgb, 1);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="imageshader">
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-
-float4 colorMult;
-sampler diffuseSampler;
-
-
-struct VertexShaderInput {
- float4 position : POSITION;
- float2 texcoord : TEXCOORD0;
-};
-
-struct PixelShaderInput {
- float4 position : POSITION;
- float2 texcoord : TEXCOORD2;
-};
-
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- PixelShaderInput output;
- output.position = mul(input.position, worldViewProjection);
- output.texcoord = input.texcoord;
- return output;
-}
-
-float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
- return tex2D(diffuseSampler, input.texcoord) * colorMult;
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="simpleshader">
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float4 simpleColor;
-
-struct VertexShaderInput {
- float4 position : POSITION;
-};
-
-struct PixelShaderInput {
- float4 position : POSITION;
-};
-
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- PixelShaderInput output;
- output.position = mul(input.position, worldViewProjection);
- return output;
-}
-
-float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
- return simpleColor;
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="particleshader">
-float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-float4x4 viewInverse : VIEWINVERSE;
-float timeRange;
-float time;
-
-// We need to implement 1D!
-sampler rampSampler;
-sampler colorSampler;
-
-struct VertexShaderInput {
- float4 uvLifeTimeStartTime : POSITION; // u, v, lifeTime, startTime
- float4 positionSpinSpeed : TEXCOORD0; // position.xyz, spinSpeed
- float4 velocityStartSize : TEXCOORD1; // velocity.xyz, startSize
- float4 accelerationEndSize : TEXCOORD2; // acceleration.xyz, endSize
- float4 colorMult : COLOR; //
-};
-
-struct PixelShaderInput {
- float4 position : POSITION;
- float2 texcoord : TEXCOORD0;
- float1 percentLife : TEXCOORD1;
- float4 colorMult: TEXCOORD2;
-};
-
-PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
- PixelShaderInput output;
-
- float2 uv = input.uvLifeTimeStartTime.xy;
- float lifeTime = input.uvLifeTimeStartTime.z;
- float startTime = input.uvLifeTimeStartTime.w;
- float3 position = input.positionSpinSpeed.xyz;
- float spinSpeed = input.positionSpinSpeed.w;
- float3 velocity = input.velocityStartSize.xyz;
- float startSize = input.velocityStartSize.w;
- float3 acceleration = input.accelerationEndSize.xyz;
- float endSize = input.accelerationEndSize.w;
-
- output.texcoord = float4(uv + 0.5, 0, 0);
- output.colorMult = input.colorMult;
-
- float localTime = (time - startTime) % timeRange;
- float percentLife = localTime / lifeTime;
-
- float3 basisX = viewInverse[0].xyz;
- float3 basisZ = viewInverse[1].xyz;
-
- float size = lerp(startSize, endSize, percentLife);
- float s = sin(spinSpeed * localTime);
- float c = cos(spinSpeed * localTime);
-
- float2 rotatedPoint = float2(uv.x * c + uv.y * s, -uv.x * s + uv.y * c);
- float3 localPosition = float3(basisX * rotatedPoint.x +
- basisZ * rotatedPoint.y) * size +
- velocity * localTime +
- acceleration * pow(localTime, 2) + position;
-
- output.position = mul(float4(localPosition, 1) , worldViewProjection);
- output.percentLife = percentLife;
- return output;
-}
-
-float4 pixelShaderFunction(PixelShaderInput input): COLOR {
- float4 colorMult = tex2D(rampSampler, float2(input.percentLife, 0.5)) *
- input.colorMult;
- float4 color = tex2D(colorSampler, input.texcoord) * colorMult;
- return color;
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="diffuse_bump">
-uniform float4x4 world : WORLD;
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float3 lightWorldPos;
-uniform float4 lightColor;
-uniform float clipHeight;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float4 emissive;
-uniform float4 ambient;
-sampler2D diffuseSampler;
-uniform float4 specular;
-sampler2D bumpSampler;
-uniform float shininess;
-
-struct InVertex {
- float4 position : POSITION;
- float4 normal : NORMAL;
- float2 diffuseUV : TEXCOORD0;
- float3 tangent : TANGENT;
- float3 binormal : BINORMAL;
-};
-
-struct OutVertex {
- float4 position : POSITION;
- float2 diffuseUV : TEXCOORD0;
- float3 tangent : TEXCOORD1;
- float3 binormal : TEXCOORD2;
- float4 worldPosition: TEXCOORD3;
- float3 normal : TEXCOORD4;
-};
-
-OutVertex vertexShaderFunction(InVertex input) {
- OutVertex output;
- output.position = mul(input.position, worldViewProjection);
- output.worldPosition = mul(input.position, world);
- output.diffuseUV = input.diffuseUV;
- output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
- output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
- output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
- return output;
-}
-
-float4 pixelShaderFunction(OutVertex input) : COLOR {
- float4 diffuse = tex2D(diffuseSampler, input.diffuseUV);
- float3x3 tangentToWorld = float3x3(input.tangent,
- input.binormal,
- input.normal);
- float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
- float3(0.5, 0.5, 0.5);
- float3 normal = mul(tangentNormal, tangentToWorld);
- normal = normalize(normal);
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litR = lit(dot(normal, surfaceToLight),
- dot(normal, halfVector),
- shininess);
- float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
- return float4((emissive + lightColor *
- (ambient * diffuse +
- diffuse * litR.y +
- specular * litR.z)).rgb, alpha);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="diffuse_bump_blend">
-uniform float4x4 world : WORLD;
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float3 lightWorldPos;
-uniform float4 lightColor;
-uniform float clipHeight;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float4 emissive;
-uniform float4 ambient;
-sampler2D diffuseSampler;
-sampler2D diffuse2Sampler;
-uniform float4 specular;
-sampler2D bumpSampler;
-uniform float shininess;
-
-struct InVertex {
- float4 position : POSITION;
- float4 normal : NORMAL;
- float2 diffuseUV : TEXCOORD0;
- float2 diffuse2UV : TEXCOORD1;
- float3 tangent : TANGENT;
- float3 tangent2 : TANGENT1;
- float3 binormal : BINORMAL;
- float3 binormal2 : BINORMAL1;
- float4 color : COLOR;
-};
-
-struct OutVertex {
- float4 position : POSITION;
- float4 diffuseUV : TEXCOORD0;
- float3 tangent : TEXCOORD1;
- float3 tangent2 : TEXCOORD2;
- float3 binormal : TEXCOORD3;
- float3 binormal2 : TEXCOORD4;
- float4 worldPosition: TEXCOORD5;
- float3 normal : TEXCOORD6;
- float4 color : COLOR;
-};
-
-OutVertex vertexShaderFunction(InVertex input) {
- OutVertex output;
- output.position = mul(input.position, worldViewProjection);
- output.worldPosition = mul(input.position, world);
- output.diffuseUV = float4(input.diffuseUV, input.diffuse2UV);
- output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
- output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
- output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
- output.binormal2 = mul(float4(input.binormal2,0), worldInverseTranspose).xyz;
- output.tangent2 = mul(float4(input.tangent2,0), worldInverseTranspose).xyz;
- output.color = output.color;
- return output;
-}
-
-float4 pixelShaderFunction(OutVertex input) : COLOR {
- float4 diffuse1 = tex2D(diffuseSampler, input.diffuseUV.xy);
- float4 diffuse2 = tex2D(diffuse2Sampler, input.diffuseUV.zw);
- float3x3 tangentToWorld = float3x3(input.tangent,
- input.binormal,
- input.normal);
- float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
- float3(0.5, 0.5, 0.5);
- float3 normal = mul(tangentNormal, tangentToWorld);
- normal = normalize(normal);
- tangentToWorld = float3x3(input.tangent2, input.binormal2, input.normal);
- tangentNormal = tex2D(bumpSampler, input.diffuseUV.zw).xyz -
- float3(0.5, 0.5, 0.5);
- float3 normal2 = mul(tangentNormal, tangentToWorld);
- normal2 = normalize(normal2);
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litR = lit(dot(normal, surfaceToLight),
- dot(normal, halfVector),
- shininess);
- float4 diffuse = lerp(diffuse1, diffuse2, input.color.a);
- float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
- return float4((emissive + lightColor *
- (ambient * diffuse +
- diffuse * litR.y +
- specular * litR.z)).rgb, alpha);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="diffuse_bump_blend_underwater">
-uniform float4x4 world : WORLD;
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float3 lightWorldPos;
-uniform float4 lightColor;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float4 emissive;
-uniform float4 ambient;
-sampler2D diffuseSampler;
-sampler2D diffuse2Sampler;
-uniform float4 specular;
-sampler2D bumpSampler;
-uniform float shininess;
-
-struct InVertex {
- float4 position : POSITION;
- float4 normal : NORMAL;
- float2 diffuseUV : TEXCOORD0;
- float2 diffuse2UV : TEXCOORD1;
- float3 tangent : TANGENT;
- float3 tangent2 : TANGENT1;
- float3 binormal : BINORMAL;
- float3 binormal2 : BINORMAL1;
- float4 color : COLOR;
-};
-
-struct OutVertex {
- float4 position : POSITION;
- float4 diffuseUV : TEXCOORD0;
- float3 tangent : TEXCOORD1;
- float3 tangent2 : TEXCOORD2;
- float3 binormal : TEXCOORD3;
- float3 binormal2 : TEXCOORD4;
- float4 worldPosition: TEXCOORD5;
- float3 normal : TEXCOORD6;
- float4 color : COLOR;
-};
-
-OutVertex vertexShaderFunction(InVertex input) {
- OutVertex output;
- output.position = mul(input.position, worldViewProjection);
- output.worldPosition = mul(input.position, world);
- output.diffuseUV = float4(input.diffuseUV, input.diffuse2UV);
- output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
- output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
- output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
- output.binormal2 = mul(float4(input.binormal2,0), worldInverseTranspose).xyz;
- output.tangent2 = mul(float4(input.tangent2,0), worldInverseTranspose).xyz;
- output.color = output.color;
- return output;
-}
-
-float4 pixelShaderFunction(OutVertex input) : COLOR {
- float4 diffuse1 = tex2D(diffuseSampler, input.diffuseUV.xy);
- float4 diffuse2 = tex2D(diffuse2Sampler, input.diffuseUV.zw);
- float3x3 tangentToWorld = float3x3(input.tangent,
- input.binormal,
- input.normal);
- float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
- float3(0.5, 0.5, 0.5);
- float3 normal = mul(tangentNormal, tangentToWorld);
- normal = normalize(normal);
- tangentToWorld = float3x3(input.tangent2, input.binormal2, input.normal);
- tangentNormal = tex2D(bumpSampler, input.diffuseUV.zw).xyz -
- float3(0.5, 0.5, 0.5);
- float3 normal2 = mul(tangentNormal, tangentToWorld);
- normal2 = normalize(normal2);
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litR = lit(dot(normal, surfaceToLight),
- dot(normal, halfVector),
- shininess);
- float4 diffuse = lerp(diffuse1, diffuse2, input.color.a);
- float alpha = input.worldPosition.z > 0 ? 0 : diffuse.a;
- return float4((emissive + lightColor *
- (ambient * diffuse +
- diffuse * litR.y +
- specular * litR.z)).rgb, alpha);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="diffuse_bump_2textures">
-uniform float4x4 world : WORLD;
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float3 lightWorldPos;
-uniform float4 lightColor;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float4 emissive;
-uniform float4 ambient;
-sampler2D diffuseSampler;
-sampler2D diffuse2Sampler;
-uniform float4 specular;
-sampler2D bumpSampler;
-uniform float shininess;
-
-struct InVertex {
- float4 position : POSITION;
- float4 normal : NORMAL;
- float2 diffuseUV : TEXCOORD0;
- float3 tangent : TANGENT;
- float3 binormal : BINORMAL;
- float4 color : COLOR;
-};
-
-struct OutVertex {
- float4 position : POSITION;
- float2 diffuseUV : TEXCOORD0;
- float3 tangent : TEXCOORD1;
- float3 binormal : TEXCOORD2;
- float4 worldPosition: TEXCOORD3;
- float3 normal : TEXCOORD4;
- float4 color : COLOR;
-};
-
-OutVertex vertexShaderFunction(InVertex input) {
- OutVertex output;
- output.position = mul(input.position, worldViewProjection);
- output.worldPosition = mul(input.position, world);
- output.diffuseUV = input.diffuseUV;
- output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
- output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
- output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
- output.color = input.color;
- return output;
-}
-
-float4 pixelShaderFunction(OutVertex input) : COLOR {
- float4 diffuse = tex2D(diffuseSampler, input.diffuseUV);
- float4 diffuse2 = tex2D(diffuse2Sampler, input.diffuseUV);
- diffuse = lerp(diffuse, diffuse2, input.color);
- float3x3 tangentToWorld = float3x3(input.tangent,
- input.binormal,
- input.normal);
- float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
- float3(0.5, 0.5, 0.5);
- float3 normal = mul(tangentNormal, tangentToWorld);
- normal = normalize(normal);
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litR = lit(dot(normal, surfaceToLight),
- dot(normal, halfVector),
- shininess);
- float alpha = input.worldPosition.z < 0 ? diffuse.a : 0;
- return float4((emissive +
- (ambient * diffuse +
- diffuse * litR.y +
- specular * litR.z)).rgb, alpha);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="diffuse">
-uniform float4x4 world : WORLD;
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float3 lightWorldPos;
-uniform float4 lightColor;
-uniform float clipHeight;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float4 emissive;
-uniform float4 ambient;
-sampler2D diffuseSampler;
-uniform float4 specular;
-uniform float shininess;
-
-struct InVertex {
- float4 position : POSITION;
- float4 normal : NORMAL;
- float2 diffuseUV : TEXCOORD0;
-};
-
-struct OutVertex {
- float4 position : POSITION;
- float2 diffuseUV : TEXCOORD0;
- float4 worldPosition: TEXCOORD1;
- float3 normal : TEXCOORD2;
-};
-
-OutVertex vertexShaderFunction(InVertex input) {
- OutVertex output;
- output.position = mul(input.position, worldViewProjection);
- output.worldPosition = mul(input.position, world);
- output.diffuseUV = input.diffuseUV;
- output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
- return output;
-}
-
-float4 pixelShaderFunction(OutVertex input) : COLOR {
- float4 diffuse = tex2D(diffuseSampler, input.diffuseUV);
- float3 normal = normalize(input.normal);
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litR = lit(dot(normal, surfaceToLight), dot(normal, halfVector), shininess);
- float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
- return float4((emissive + lightColor * (ambient * diffuse + diffuse * litR.y + specular * litR.z)).rgb, alpha);
-}
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="diffuse_bump_specular">
-uniform float4x4 world : WORLD;
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float3 lightWorldPos;
-uniform float4 lightColor;
-uniform float clipHeight;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float4 emissive;
-uniform float4 ambient;
-sampler2D diffuseSampler;
-sampler2D specularSampler;
-sampler2D bumpSampler;
-uniform float shininess;
-
-struct InVertex {
- float4 position : POSITION;
- float4 normal : NORMAL;
- float2 diffuseUV : TEXCOORD0;
- float3 tangent : TANGENT;
- float3 binormal : BINORMAL;
-};
-
-struct OutVertex {
- float4 position : POSITION;
- float2 diffuseUV : TEXCOORD0;
- float3 tangent : TEXCOORD1;
- float3 binormal : TEXCOORD2;
- float4 worldPosition: TEXCOORD3;
- float3 normal : TEXCOORD4;
-};
-
-OutVertex vertexShaderFunction(InVertex input) {
- OutVertex output;
- output.position = mul(input.position, worldViewProjection);
- output.worldPosition = mul(input.position, world);
- output.diffuseUV = input.diffuseUV;
- output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
- output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
- output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
- return output;
-}
-
-float4 pixelShaderFunction(OutVertex input) : COLOR {
- float4 diffuse = tex2D(diffuseSampler, input.diffuseUV);
- float4 specular = tex2D(specularSampler, input.diffuseUV);
- float3x3 tangentToWorld = float3x3(input.tangent, input.binormal, input.normal);
- float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
- float3(0.5, 0.5, 0.5);
- float3 normal = mul(tangentNormal, tangentToWorld);
- normal = normalize(normal);
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litR = lit(dot(normal, surfaceToLight),
- dot(normal, halfVector),
- shininess);
- float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
- return float4((emissive + lightColor *
- (ambient * diffuse +
- diffuse * litR.y +
- specular * litR.z)).rgb, alpha);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="just_color">
-uniform float4x4 world : WORLD;
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float3 lightWorldPos;
-uniform float4 lightColor;
-uniform float clipHeight;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float4 emissive;
-uniform float4 ambient;
-uniform float4 diffuse;
-uniform float4 specular;
-uniform float shininess;
-
-struct InVertex {
- float4 position : POSITION;
- float4 normal : NORMAL;
-};
-
-struct OutVertex {
- float4 position : POSITION;
- float4 worldPosition: TEXCOORD0;
- float3 normal : TEXCOORD1;
-};
-
-OutVertex vertexShaderFunction(InVertex input) {
- OutVertex output;
- output.position = mul(input.position, worldViewProjection);
- output.worldPosition = mul(input.position, world);
- output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
- return output;
-}
-
-float4 pixelShaderFunction(OutVertex input) : COLOR {
- float3 normal = normalize(input.normal);
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litR = lit(dot(normal, surfaceToLight),
- dot(normal, halfVector),
- shininess);
- float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
- return float4((emissive + lightColor *
- (ambient * diffuse +
- diffuse * litR.y +
- specular * litR.z)).rgb, alpha);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
-<script type="text/o3deffect" id="proxy">
-uniform float4x4 world : WORLD;
-uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
-uniform float3 lightWorldPos;
-uniform float4 lightColor;
-uniform float4x4 viewInverse : VIEWINVERSE;
-uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
-uniform float4 emissive;
-uniform float4 ambient;
-uniform float4 diffuse;
-uniform float4 specular;
-uniform float shininess;
-uniform float offset;
-
-struct InVertex {
- float4 position : POSITION;
- float4 normal : NORMAL;
-};
-
-struct OutVertex {
- float4 position : POSITION;
- float4 worldPosition: TEXCOORD0;
- float3 normal : TEXCOORD1;
-};
-
-OutVertex vertexShaderFunction(InVertex input) {
- OutVertex output;
- output.position = mul(input.position, worldViewProjection);
- output.worldPosition = mul(input.position, world);
- output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
- return output;
-}
-
-float4 pixelShaderFunction(OutVertex input) : COLOR {
- float3 normal = normalize(input.normal);
- float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
- float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
- float3 halfVector = normalize(surfaceToLight + surfaceToView);
- float4 litR = lit(dot(normal, surfaceToLight),
- dot(normal, halfVector),
- shininess);
- float alpha = input.worldPosition.z > offset ? 0 : diffuse.a;
- return float4((emissive + lightColor *
- (ambient * diffuse +
- diffuse * litR.y +
- specular * litR.z)).rgb, alpha);
-}
-
-// #o3d VertexShaderEntryPoint vertexShaderFunction
-// #o3d PixelShaderEntryPoint pixelShaderFunction
-// #o3d MatrixLoadOrder RowMajor
-</script>
</body>
</html>
diff --git a/o3d/samples/beachdemo/beachdemo.js b/o3d/samples/beachdemo/beachdemo.js
index 6692697..8e313d1 100644
--- a/o3d/samples/beachdemo/beachdemo.js
+++ b/o3d/samples/beachdemo/beachdemo.js
@@ -50,6 +50,7 @@ o3djs.require('o3djs.fps');
o3djs.require('o3djs.debug');
o3djs.require('o3djs.particles');
o3djs.require('o3djs.performance');
+o3djs.require('o3djs.io');
var PROXY_HEIGHT = 5150;
@@ -185,6 +186,7 @@ var g_sceneTexturesByURI;
var g_renderTargetWidth = 256;
var g_renderTargetHeight = 256;
var g_perfMon;
+var g_shaders = {};
var g_camera = {
farPlane: 80000,
@@ -1074,8 +1076,7 @@ function toggleSimpleMaterials(e) {
g_math.pseudoRandom();
g_math.pseudoRandom();
var newEffect = g_mainPack.createObject('Effect');
- newEffect.loadFromFXString(
- o3djs.util.getElementContentById('simpleshader'));
+ newEffect.loadFromFXString(g_shaders.simpleshader);
newEffect.createUniformParameters(newEffect);
newEffect.getParam('simpleColor').value = [
g_math.pseudoRandom(),
@@ -1341,7 +1342,7 @@ function setupSceneMaterials() {
if (!effect) {
effect = g_scenePack.createObject('Effect');
effect.name = info.effect;
- var fxString = o3djs.util.getElementContentById(info.effect);
+ var fxString = g_shaders[info.effect];
effect.loadFromFXString(fxString);
g_sceneEffects[info.effect] = effect;
g_editableEffects.push(effect);
@@ -1387,7 +1388,7 @@ function loadProxy() {
var material = pack.getObjectsByClassName('o3d.Material')[0];
var effect = g_mainPack.createObject('Effect');
- effect.loadFromFXString(o3djs.util.getElementContentById('proxy'));
+ effect.loadFromFXString(g_shaders.proxy);
effect.createUniformParameters(material);
setParam(material, 'lightWorldPos', [0, -100000, 200000]);
setParam(material, 'ambient', [0, 0, 0, 0]);
@@ -1935,10 +1936,43 @@ function decreaseRenderTargetResolution() {
}
/**
+ * Loads shader files into g_shaders object.
+ */
+function loadShaders() {
+ var ii;
+ var n;
+ var names = [
+ 'diffuse',
+ 'diffuse_bump',
+ 'diffuse_bump_2textures',
+ 'diffuse_bump_blend',
+ 'diffuse_bump_blend_underwater',
+ 'diffuse_bump_specular',
+ 'imageshader',
+ 'just_color',
+ 'particleshader',
+ 'proxy',
+ 'simpleshader',
+ 'skydomeshader',
+ 'underwatershader',
+ 'watercolorandskyshader',
+ 'waterfallshader',
+ 'watershader',
+ 'waterstyle2',
+ ];
+ for (ii = 0; ii < names.length; ++ii) {
+ n = names[ii];
+ g_shaders[n] = o3djs.io.loadTextFileSynchronous('shaders_cg/' + n + '.cg');
+ }
+}
+
+/**
* Initializes O3D and loads the scene into the transform graph.
* @param {Array} clientElements Array of o3d object elements.
*/
function initStep2(clientElements) {
+ loadShaders();
+
g_materialPanelElement = o3djs.util.getElementById('materialpanel');
g_propPanelElement = o3djs.util.getElementById('proppanel');
g_effectPanelElement = o3djs.util.getElementById('effectpanel');
@@ -2125,9 +2159,8 @@ function initStep2(clientElements) {
* @return {!o3d.Sampler} Sampler attached to material.
*/
function loadTexture(loader, pack, material, samplerName, textureName) {
- var samplerParam = material.getParam(samplerName);
var sampler = pack.createObject('Sampler');
- samplerParam.value = sampler;
+ setParam(material, samplerName, sampler);
var url = o3djs.util.getAbsoluteURI('assets/' + textureName);
loader.loadTexture(pack, url, function(texture, success) {
@@ -2148,7 +2181,7 @@ function setupWaterfall() {
// UVs.
var effect = g_mainPack.createObject('Effect');
effect.name = 'waterfall';
- effect.loadFromFXString(o3djs.util.getElementContentById('waterfallshader'));
+ effect.loadFromFXString(g_shaders.waterfallshader);
effect.createUniformParameters(material);
g_editableEffects.push(effect);
@@ -2184,7 +2217,7 @@ function setupWaterfall() {
function setupUnderwater() {
var effect = g_mainPack.createObject('Effect');
effect.name = 'underwater';
- effect.loadFromFXString(o3djs.util.getElementContentById('underwatershader'));
+ effect.loadFromFXString(g_shaders.underwatershader);
g_editableEffects.push(effect);
// make 2 materials, one for zOrdered, one for performance.
@@ -2198,10 +2231,10 @@ function setupUnderwater() {
material.effect = effect;
effect.createUniformParameters(material);
- material.getParam('sunVector').bind(g_lightDirectionParam);
- material.getParam('waterColor').value = g_waterColor;
- material.getParam('fadeFudge').value = -1 / 1800;
- material.getParam('clock').bind(g_globalClockParam);
+ bindParam(material, 'sunVector', g_lightDirectionParam);
+ setParam(material, 'waterColor', g_waterColor);
+ setParam(material, 'fadeFudge', -1 / 1800);
+ bindParam(material, 'clock', g_globalClockParam);
g_fadeParams[ii] = material.getParam('fadeFudge');
materials[ii] = material;
@@ -2263,7 +2296,7 @@ function setupWater() {
var name = waterEffects[ee]
var effect = g_mainPack.createObject('Effect');
effect.name = name;
- effect.loadFromFXString(o3djs.util.getElementContentById(name));
+ effect.loadFromFXString(g_shaders[name]);
effects[ee] = effect;
g_editableEffects.push(effect);
}
@@ -2284,8 +2317,8 @@ function setupWater() {
// var counter = g_mainPack.createObject('SecondCounter');
// For selenium testing we need a global clock.
- material.getParam('waterColor').value = g_waterColor;
- material.getParam('reflectionRefractionOffset').value = 0.1;
+ setParam(material, 'waterColor', g_waterColor);
+ setParam(material, 'reflectionRefractionOffset', 0.1);
//material.getParam('clock').bind(counter.getParam('count'));
material.getParam('clock').bind(g_globalClockParam);
g_viewPositionParam = material.getParam('viewPosition');
@@ -2294,12 +2327,12 @@ function setupWater() {
sampler.texture = g_refractionTexture;
sampler.addressModeU = g_o3d.Sampler.MIRROR;
sampler.addressModeV = g_o3d.Sampler.MIRROR;
- material.getParam('refractionSampler').value = sampler;
+ setParam(material, 'refractionSampler', sampler);
sampler = g_mainPack.createObject('Sampler');
sampler.texture = g_reflectionTexture;
sampler.addressModeU = g_o3d.Sampler.MIRROR;
sampler.addressModeV = g_o3d.Sampler.MIRROR;
- material.getParam('reflectionSampler').value = sampler;
+ setParam(material, 'reflectionSampler', sampler);
var shape = o3djs.primitives.createPlane(g_mainPack, material,
100000, 100000, 100, 100,
@@ -2366,7 +2399,7 @@ function setupWater() {
texture.set(0, pixels);
var sampler = g_mainPack.createObject('Sampler');
sampler.texture = texture;
- material.getParam(info.name).value = sampler;
+ setParam(material, info.name, sampler);
}
loader.finish();
@@ -2505,7 +2538,7 @@ function setupSkyDome() {
// Create the skydome effect.
var effect = g_mainPack.createObject('Effect');
effect.name = 'skydome';
- effect.loadFromFXString(o3djs.util.getElementContentById('skydomeshader'));
+ effect.loadFromFXString(g_shaders.skydomeshader);
g_editableEffects.push(effect);
var material = g_mainPack.createObject('Material');
@@ -2575,7 +2608,7 @@ function Image(parent, texture, opt_topLeft) {
function setupHud() {
var effect = g_mainPack.createObject('Effect');
effect.name = 'hud';
- effect.loadFromFXString(o3djs.util.getElementContentById('imageshader'));
+ effect.loadFromFXString(g_shaders.imageshader);
g_editableEffects.push(effect);
// Make the default colorMult 1, 1, 1, 1 uncase it is not supplied by the
// material.
diff --git a/o3d/samples/beachdemo/shaders_cg/diffuse.cg b/o3d/samples/beachdemo/shaders_cg/diffuse.cg
new file mode 100644
index 0000000..e530cf4
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/diffuse.cg
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float3 lightWorldPos;
+uniform float4 lightColor;
+uniform float clipHeight;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float4 emissive;
+uniform float4 ambient;
+sampler2D diffuseSampler;
+uniform float4 specular;
+uniform float shininess;
+
+struct InVertex {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+ float2 diffuseUV : TEXCOORD0;
+};
+
+struct OutVertex {
+ float4 position : POSITION;
+ float2 diffuseUV : TEXCOORD0;
+ float4 worldPosition: TEXCOORD1;
+ float3 normal : TEXCOORD2;
+};
+
+OutVertex vertexShaderFunction(InVertex input) {
+ OutVertex output;
+ output.position = mul(input.position, worldViewProjection);
+ output.worldPosition = mul(input.position, world);
+ output.diffuseUV = input.diffuseUV;
+ output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
+ return output;
+}
+
+float4 pixelShaderFunction(OutVertex input) : COLOR {
+ float4 diffuse = tex2D(diffuseSampler, input.diffuseUV);
+ float3 normal = normalize(input.normal);
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litR = lit(dot(normal, surfaceToLight), dot(normal, halfVector), shininess);
+ float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
+ return float4((emissive + lightColor * (ambient * diffuse + diffuse * litR.y + specular * litR.z)).rgb, alpha);
+}
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/diffuse_bump.cg b/o3d/samples/beachdemo/shaders_cg/diffuse_bump.cg
new file mode 100644
index 0000000..a0b943c
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/diffuse_bump.cg
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float3 lightWorldPos;
+uniform float4 lightColor;
+uniform float clipHeight;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float4 emissive;
+uniform float4 ambient;
+sampler2D diffuseSampler;
+uniform float4 specular;
+sampler2D bumpSampler;
+uniform float shininess;
+
+struct InVertex {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+ float2 diffuseUV : TEXCOORD0;
+ float3 tangent : TANGENT;
+ float3 binormal : BINORMAL;
+};
+
+struct OutVertex {
+ float4 position : POSITION;
+ float2 diffuseUV : TEXCOORD0;
+ float3 tangent : TEXCOORD1;
+ float3 binormal : TEXCOORD2;
+ float4 worldPosition: TEXCOORD3;
+ float3 normal : TEXCOORD4;
+};
+
+OutVertex vertexShaderFunction(InVertex input) {
+ OutVertex output;
+ output.position = mul(input.position, worldViewProjection);
+ output.worldPosition = mul(input.position, world);
+ output.diffuseUV = input.diffuseUV;
+ output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
+ output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
+ output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
+ return output;
+}
+
+float4 pixelShaderFunction(OutVertex input) : COLOR {
+ float4 diffuse = tex2D(diffuseSampler, input.diffuseUV);
+ float3x3 tangentToWorld = float3x3(input.tangent,
+ input.binormal,
+ input.normal);
+ float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
+ float3(0.5, 0.5, 0.5);
+ float3 normal = mul(tangentNormal, tangentToWorld);
+ normal = normalize(normal);
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litR = lit(dot(normal, surfaceToLight),
+ dot(normal, halfVector),
+ shininess);
+ float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
+ return float4((emissive + lightColor *
+ (ambient * diffuse +
+ diffuse * litR.y +
+ specular * litR.z)).rgb, alpha);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/diffuse_bump_2textures.cg b/o3d/samples/beachdemo/shaders_cg/diffuse_bump_2textures.cg
new file mode 100644
index 0000000..efd71be
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/diffuse_bump_2textures.cg
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float3 lightWorldPos;
+uniform float4 lightColor;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float4 emissive;
+uniform float4 ambient;
+sampler2D diffuseSampler;
+sampler2D diffuse2Sampler;
+uniform float4 specular;
+sampler2D bumpSampler;
+uniform float shininess;
+
+struct InVertex {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+ float2 diffuseUV : TEXCOORD0;
+ float3 tangent : TANGENT;
+ float3 binormal : BINORMAL;
+ float4 color : COLOR;
+};
+
+struct OutVertex {
+ float4 position : POSITION;
+ float2 diffuseUV : TEXCOORD0;
+ float3 tangent : TEXCOORD1;
+ float3 binormal : TEXCOORD2;
+ float4 worldPosition: TEXCOORD3;
+ float3 normal : TEXCOORD4;
+ float4 color : COLOR;
+};
+
+OutVertex vertexShaderFunction(InVertex input) {
+ OutVertex output;
+ output.position = mul(input.position, worldViewProjection);
+ output.worldPosition = mul(input.position, world);
+ output.diffuseUV = input.diffuseUV;
+ output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
+ output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
+ output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
+ output.color = input.color;
+ return output;
+}
+
+float4 pixelShaderFunction(OutVertex input) : COLOR {
+ float4 diffuse = tex2D(diffuseSampler, input.diffuseUV);
+ float4 diffuse2 = tex2D(diffuse2Sampler, input.diffuseUV);
+ diffuse = lerp(diffuse, diffuse2, input.color);
+ float3x3 tangentToWorld = float3x3(input.tangent,
+ input.binormal,
+ input.normal);
+ float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
+ float3(0.5, 0.5, 0.5);
+ float3 normal = mul(tangentNormal, tangentToWorld);
+ normal = normalize(normal);
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litR = lit(dot(normal, surfaceToLight),
+ dot(normal, halfVector),
+ shininess);
+ float alpha = input.worldPosition.z < 0 ? diffuse.a : 0;
+ return float4((emissive +
+ (ambient * diffuse +
+ diffuse * litR.y +
+ specular * litR.z)).rgb, alpha);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/diffuse_bump_blend.cg b/o3d/samples/beachdemo/shaders_cg/diffuse_bump_blend.cg
new file mode 100644
index 0000000..6f9c18b
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/diffuse_bump_blend.cg
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float3 lightWorldPos;
+uniform float4 lightColor;
+uniform float clipHeight;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float4 emissive;
+uniform float4 ambient;
+sampler2D diffuseSampler;
+sampler2D diffuse2Sampler;
+uniform float4 specular;
+sampler2D bumpSampler;
+uniform float shininess;
+
+struct InVertex {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+ float2 diffuseUV : TEXCOORD0;
+ float2 diffuse2UV : TEXCOORD1;
+ float3 tangent : TANGENT;
+ float3 tangent2 : TANGENT1;
+ float3 binormal : BINORMAL;
+ float3 binormal2 : BINORMAL1;
+ float4 color : COLOR;
+};
+
+struct OutVertex {
+ float4 position : POSITION;
+ float4 diffuseUV : TEXCOORD0;
+ float3 tangent : TEXCOORD1;
+ float3 tangent2 : TEXCOORD2;
+ float3 binormal : TEXCOORD3;
+ float3 binormal2 : TEXCOORD4;
+ float4 worldPosition: TEXCOORD5;
+ float3 normal : TEXCOORD6;
+ float4 color : COLOR;
+};
+
+OutVertex vertexShaderFunction(InVertex input) {
+ OutVertex output;
+ output.position = mul(input.position, worldViewProjection);
+ output.worldPosition = mul(input.position, world);
+ output.diffuseUV = float4(input.diffuseUV, input.diffuse2UV);
+ output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
+ output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
+ output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
+ output.binormal2 = mul(float4(input.binormal2,0), worldInverseTranspose).xyz;
+ output.tangent2 = mul(float4(input.tangent2,0), worldInverseTranspose).xyz;
+ output.color = output.color;
+ return output;
+}
+
+float4 pixelShaderFunction(OutVertex input) : COLOR {
+ float4 diffuse1 = tex2D(diffuseSampler, input.diffuseUV.xy);
+ float4 diffuse2 = tex2D(diffuse2Sampler, input.diffuseUV.zw);
+ float3x3 tangentToWorld = float3x3(input.tangent,
+ input.binormal,
+ input.normal);
+ float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
+ float3(0.5, 0.5, 0.5);
+ float3 normal = mul(tangentNormal, tangentToWorld);
+ normal = normalize(normal);
+ tangentToWorld = float3x3(input.tangent2, input.binormal2, input.normal);
+ tangentNormal = tex2D(bumpSampler, input.diffuseUV.zw).xyz -
+ float3(0.5, 0.5, 0.5);
+ float3 normal2 = mul(tangentNormal, tangentToWorld);
+ normal2 = normalize(normal2);
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litR = lit(dot(normal, surfaceToLight),
+ dot(normal, halfVector),
+ shininess);
+ float4 diffuse = lerp(diffuse1, diffuse2, input.color.a);
+ float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
+ return float4((emissive + lightColor *
+ (ambient * diffuse +
+ diffuse * litR.y +
+ specular * litR.z)).rgb, alpha);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/diffuse_bump_blend_underwater.cg b/o3d/samples/beachdemo/shaders_cg/diffuse_bump_blend_underwater.cg
new file mode 100644
index 0000000..eb782e9
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/diffuse_bump_blend_underwater.cg
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float3 lightWorldPos;
+uniform float4 lightColor;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float4 emissive;
+uniform float4 ambient;
+sampler2D diffuseSampler;
+sampler2D diffuse2Sampler;
+uniform float4 specular;
+sampler2D bumpSampler;
+uniform float shininess;
+
+struct InVertex {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+ float2 diffuseUV : TEXCOORD0;
+ float2 diffuse2UV : TEXCOORD1;
+ float3 tangent : TANGENT;
+ float3 tangent2 : TANGENT1;
+ float3 binormal : BINORMAL;
+ float3 binormal2 : BINORMAL1;
+ float4 color : COLOR;
+};
+
+struct OutVertex {
+ float4 position : POSITION;
+ float4 diffuseUV : TEXCOORD0;
+ float3 tangent : TEXCOORD1;
+ float3 tangent2 : TEXCOORD2;
+ float3 binormal : TEXCOORD3;
+ float3 binormal2 : TEXCOORD4;
+ float4 worldPosition: TEXCOORD5;
+ float3 normal : TEXCOORD6;
+ float4 color : COLOR;
+};
+
+OutVertex vertexShaderFunction(InVertex input) {
+ OutVertex output;
+ output.position = mul(input.position, worldViewProjection);
+ output.worldPosition = mul(input.position, world);
+ output.diffuseUV = float4(input.diffuseUV, input.diffuse2UV);
+ output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
+ output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
+ output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
+ output.binormal2 = mul(float4(input.binormal2,0), worldInverseTranspose).xyz;
+ output.tangent2 = mul(float4(input.tangent2,0), worldInverseTranspose).xyz;
+ output.color = output.color;
+ return output;
+}
+
+float4 pixelShaderFunction(OutVertex input) : COLOR {
+ float4 diffuse1 = tex2D(diffuseSampler, input.diffuseUV.xy);
+ float4 diffuse2 = tex2D(diffuse2Sampler, input.diffuseUV.zw);
+ float3x3 tangentToWorld = float3x3(input.tangent,
+ input.binormal,
+ input.normal);
+ float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
+ float3(0.5, 0.5, 0.5);
+ float3 normal = mul(tangentNormal, tangentToWorld);
+ normal = normalize(normal);
+ tangentToWorld = float3x3(input.tangent2, input.binormal2, input.normal);
+ tangentNormal = tex2D(bumpSampler, input.diffuseUV.zw).xyz -
+ float3(0.5, 0.5, 0.5);
+ float3 normal2 = mul(tangentNormal, tangentToWorld);
+ normal2 = normalize(normal2);
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litR = lit(dot(normal, surfaceToLight),
+ dot(normal, halfVector),
+ shininess);
+ float4 diffuse = lerp(diffuse1, diffuse2, input.color.a);
+ float alpha = input.worldPosition.z > 0 ? 0 : diffuse.a;
+ return float4((emissive + lightColor *
+ (ambient * diffuse +
+ diffuse * litR.y +
+ specular * litR.z)).rgb, alpha);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/diffuse_bump_specular.cg b/o3d/samples/beachdemo/shaders_cg/diffuse_bump_specular.cg
new file mode 100644
index 0000000..c3a1e13
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/diffuse_bump_specular.cg
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float3 lightWorldPos;
+uniform float4 lightColor;
+uniform float clipHeight;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float4 emissive;
+uniform float4 ambient;
+sampler2D diffuseSampler;
+sampler2D specularSampler;
+sampler2D bumpSampler;
+uniform float shininess;
+
+struct InVertex {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+ float2 diffuseUV : TEXCOORD0;
+ float3 tangent : TANGENT;
+ float3 binormal : BINORMAL;
+};
+
+struct OutVertex {
+ float4 position : POSITION;
+ float2 diffuseUV : TEXCOORD0;
+ float3 tangent : TEXCOORD1;
+ float3 binormal : TEXCOORD2;
+ float4 worldPosition: TEXCOORD3;
+ float3 normal : TEXCOORD4;
+};
+
+OutVertex vertexShaderFunction(InVertex input) {
+ OutVertex output;
+ output.position = mul(input.position, worldViewProjection);
+ output.worldPosition = mul(input.position, world);
+ output.diffuseUV = input.diffuseUV;
+ output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
+ output.binormal = mul(float4(input.binormal,0), worldInverseTranspose).xyz;
+ output.tangent = mul(float4(input.tangent,0), worldInverseTranspose).xyz;
+ return output;
+}
+
+float4 pixelShaderFunction(OutVertex input) : COLOR {
+ float4 diffuse = tex2D(diffuseSampler, input.diffuseUV);
+ float4 specular = tex2D(specularSampler, input.diffuseUV);
+ float3x3 tangentToWorld = float3x3(input.tangent, input.binormal, input.normal);
+ float3 tangentNormal = tex2D(bumpSampler, input.diffuseUV.xy).xyz -
+ float3(0.5, 0.5, 0.5);
+ float3 normal = mul(tangentNormal, tangentToWorld);
+ normal = normalize(normal);
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litR = lit(dot(normal, surfaceToLight),
+ dot(normal, halfVector),
+ shininess);
+ float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
+ return float4((emissive + lightColor *
+ (ambient * diffuse +
+ diffuse * litR.y +
+ specular * litR.z)).rgb, alpha);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/imageshader.cg b/o3d/samples/beachdemo/shaders_cg/imageshader.cg
new file mode 100644
index 0000000..37aaa94
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/imageshader.cg
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+
+float4 colorMult;
+sampler diffuseSampler;
+
+
+struct VertexShaderInput {
+ float4 position : POSITION;
+ float2 texcoord : TEXCOORD0;
+};
+
+struct PixelShaderInput {
+ float4 position : POSITION;
+ float2 texcoord : TEXCOORD2;
+};
+
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ PixelShaderInput output;
+ output.position = mul(input.position, worldViewProjection);
+ output.texcoord = input.texcoord;
+ return output;
+}
+
+float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
+ return tex2D(diffuseSampler, input.texcoord) * colorMult;
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/just_color.cg b/o3d/samples/beachdemo/shaders_cg/just_color.cg
new file mode 100644
index 0000000..030e2f1
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/just_color.cg
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float3 lightWorldPos;
+uniform float4 lightColor;
+uniform float clipHeight;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float4 emissive;
+uniform float4 ambient;
+uniform float4 diffuse;
+uniform float4 specular;
+uniform float shininess;
+
+struct InVertex {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+};
+
+struct OutVertex {
+ float4 position : POSITION;
+ float4 worldPosition: TEXCOORD0;
+ float3 normal : TEXCOORD1;
+};
+
+OutVertex vertexShaderFunction(InVertex input) {
+ OutVertex output;
+ output.position = mul(input.position, worldViewProjection);
+ output.worldPosition = mul(input.position, world);
+ output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
+ return output;
+}
+
+float4 pixelShaderFunction(OutVertex input) : COLOR {
+ float3 normal = normalize(input.normal);
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litR = lit(dot(normal, surfaceToLight),
+ dot(normal, halfVector),
+ shininess);
+ float alpha = input.worldPosition.z > clipHeight ? 0 : diffuse.a;
+ return float4((emissive + lightColor *
+ (ambient * diffuse +
+ diffuse * litR.y +
+ specular * litR.z)).rgb, alpha);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/particleshader.cg b/o3d/samples/beachdemo/shaders_cg/particleshader.cg
new file mode 100644
index 0000000..d8c37f5
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/particleshader.cg
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+float4x4 viewInverse : VIEWINVERSE;
+float timeRange;
+float time;
+
+// We need to implement 1D!
+sampler rampSampler;
+sampler colorSampler;
+
+struct VertexShaderInput {
+ float4 uvLifeTimeStartTime : POSITION; // u, v, lifeTime, startTime
+ float4 positionSpinSpeed : TEXCOORD0; // position.xyz, spinSpeed
+ float4 velocityStartSize : TEXCOORD1; // velocity.xyz, startSize
+ float4 accelerationEndSize : TEXCOORD2; // acceleration.xyz, endSize
+ float4 colorMult : COLOR; //
+};
+
+struct PixelShaderInput {
+ float4 position : POSITION;
+ float2 texcoord : TEXCOORD0;
+ float1 percentLife : TEXCOORD1;
+ float4 colorMult: TEXCOORD2;
+};
+
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ PixelShaderInput output;
+
+ float2 uv = input.uvLifeTimeStartTime.xy;
+ float lifeTime = input.uvLifeTimeStartTime.z;
+ float startTime = input.uvLifeTimeStartTime.w;
+ float3 position = input.positionSpinSpeed.xyz;
+ float spinSpeed = input.positionSpinSpeed.w;
+ float3 velocity = input.velocityStartSize.xyz;
+ float startSize = input.velocityStartSize.w;
+ float3 acceleration = input.accelerationEndSize.xyz;
+ float endSize = input.accelerationEndSize.w;
+
+ output.texcoord = float4(uv + 0.5, 0, 0);
+ output.colorMult = input.colorMult;
+
+ float localTime = (time - startTime) % timeRange;
+ float percentLife = localTime / lifeTime;
+
+ float3 basisX = viewInverse[0].xyz;
+ float3 basisZ = viewInverse[1].xyz;
+
+ float size = lerp(startSize, endSize, percentLife);
+ float s = sin(spinSpeed * localTime);
+ float c = cos(spinSpeed * localTime);
+
+ float2 rotatedPoint = float2(uv.x * c + uv.y * s, -uv.x * s + uv.y * c);
+ float3 localPosition = float3(basisX * rotatedPoint.x +
+ basisZ * rotatedPoint.y) * size +
+ velocity * localTime +
+ acceleration * pow(localTime, 2) + position;
+
+ output.position = mul(float4(localPosition, 1) , worldViewProjection);
+ output.percentLife = percentLife;
+ return output;
+}
+
+float4 pixelShaderFunction(PixelShaderInput input): COLOR {
+ float4 colorMult = tex2D(rampSampler, float2(input.percentLife, 0.5)) *
+ input.colorMult;
+ float4 color = tex2D(colorSampler, input.texcoord) * colorMult;
+ return color;
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/proxy.cg b/o3d/samples/beachdemo/shaders_cg/proxy.cg
new file mode 100644
index 0000000..1c5ca59
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/proxy.cg
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float3 lightWorldPos;
+uniform float4 lightColor;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float4 emissive;
+uniform float4 ambient;
+uniform float4 diffuse;
+uniform float4 specular;
+uniform float shininess;
+uniform float offset;
+
+struct InVertex {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+};
+
+struct OutVertex {
+ float4 position : POSITION;
+ float4 worldPosition: TEXCOORD0;
+ float3 normal : TEXCOORD1;
+};
+
+OutVertex vertexShaderFunction(InVertex input) {
+ OutVertex output;
+ output.position = mul(input.position, worldViewProjection);
+ output.worldPosition = mul(input.position, world);
+ output.normal = mul(float4(input.normal.xyz,0), worldInverseTranspose).xyz;
+ return output;
+}
+
+float4 pixelShaderFunction(OutVertex input) : COLOR {
+ float3 normal = normalize(input.normal);
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 surfaceToView = normalize(viewInverse[3] - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litR = lit(dot(normal, surfaceToLight),
+ dot(normal, halfVector),
+ shininess);
+ float alpha = input.worldPosition.z > offset ? 0 : diffuse.a;
+ return float4((emissive + lightColor *
+ (ambient * diffuse +
+ diffuse * litR.y +
+ specular * litR.z)).rgb, alpha);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/simpleshader.cg b/o3d/samples/beachdemo/shaders_cg/simpleshader.cg
new file mode 100644
index 0000000..7698b75
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/simpleshader.cg
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float4 simpleColor;
+
+struct VertexShaderInput {
+ float4 position : POSITION;
+};
+
+struct PixelShaderInput {
+ float4 position : POSITION;
+};
+
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ PixelShaderInput output;
+ output.position = mul(input.position, worldViewProjection);
+ return output;
+}
+
+float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
+ return simpleColor;
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/skydomeshader.cg b/o3d/samples/beachdemo/shaders_cg/skydomeshader.cg
new file mode 100644
index 0000000..da10332
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/skydomeshader.cg
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 worldViewProjectionInverse : VIEWPROJECTIONINVERSE;
+uniform float4x4 viewInverse : VIEWINVERSE;
+samplerCUBE environmentSampler;
+
+struct VertexShaderInput {
+ float4 position : POSITION;
+};
+
+struct PixelShaderInput {
+ float4 position : POSITION;
+ float3 worldPosition : TEXCOORD0;
+};
+
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ PixelShaderInput output;
+ output.position = input.position;
+ float4 temp = mul(input.position, worldViewProjectionInverse);
+ output.worldPosition = temp.xyz / temp.w;
+ return output;
+}
+
+float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
+ float3 viewVector = normalize(viewInverse[3].xyz - input.worldPosition);
+ return texCUBE(environmentSampler, float3(viewVector.x,
+ abs(-viewVector.z) + 0.01,
+ -viewVector.y));
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/underwatershader.cg b/o3d/samples/beachdemo/shaders_cg/underwatershader.cg
new file mode 100644
index 0000000..2b05598
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/underwatershader.cg
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 world : WORLD;
+uniform float4x4 viewProjection : VIEWPROJECTION;
+uniform float4 waterColor;
+uniform float3 sunVector;
+uniform float fadeFudge;
+
+sampler diffuseSampler;
+
+// input parameters for our vertex shader
+struct VertexShaderInput {
+ float4 position : POSITION;
+ float3 normal : NORMAL;
+ float2 texcoord : TEXCOORD0;
+};
+
+// input parameters for our pixel shader
+// also the output parameters for our vertex shader
+struct PixelShaderInput {
+ float4 position : POSITION;
+ float2 texcoord : TEXCOORD0;
+ float fade : TEXCOORD1;
+ float4 color : TEXCOORD2;
+ float4 worldPosition : TEXCOORD3;
+};
+
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ PixelShaderInput output;
+ float4 worldPosition = mul(input.position, world);
+ output.position = mul(float4(worldPosition.xyz, 1), viewProjection);
+ output.worldPosition = worldPosition;
+ output.texcoord = input.texcoord;
+ output.color = dot(sunVector,
+ normalize(mul(float4(input.normal, 0), world)));
+ output.fade = 0.2 + 0.8 * saturate(worldPosition.z * fadeFudge);
+
+ return output;
+}
+
+float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
+ float4 color = tex2D(diffuseSampler, input.texcoord);
+// float4 diffuse = tex2D(diffuseSampler, input.texcoord);
+// float4 color = lerp(diffuse * input.color, waterColor, input.fade);
+ float alpha = input.worldPosition.z < 100 ? color.a : 0;
+ return float4(color.xyz, alpha);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/watercolorandskyshader.cg b/o3d/samples/beachdemo/shaders_cg/watercolorandskyshader.cg
new file mode 100644
index 0000000..64e1d2a
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/watercolorandskyshader.cg
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// The 4x4 world view projection matrix.
+float4x4 world : WORLD;
+float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+float4x4 view : VIEW;
+float4x4 viewProjection : VIEWPROJECTION;
+float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+float3 viewPosition;
+float4 waterColor;
+float reflectionRefractionOffset;
+float clock;
+
+samplerCUBE environmentSampler;
+sampler2D fresnelSampler; // TODO: should be 1D.
+sampler2D noiseSampler;
+sampler2D noiseSampler2;
+sampler2D noiseSampler3;
+
+// input parameters for our vertex shader
+struct VertexShaderInput {
+ float4 position : POSITION;
+ float2 texcoord : TEXCOORD0;
+};
+
+// input parameters for our pixel shader
+// also the output parameters for our vertex shader
+struct PixelShaderInput {
+ float4 position : POSITION;
+ float2 texcoord : TEXCOORD0;
+ float3 viewVector : TEXCOORD1;
+ float3 screenPosition : TEXCOORD2;
+};
+
+/**
+ * Vertex Shader
+ */
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ /**
+ * We transform each vertex by the world view projection matrix to bring
+ * it from world space to projection space.
+ *
+ * We return its color unchanged.
+ */
+ PixelShaderInput output;
+
+ float4 worldPosition = mul(input.position, world);
+ output.position = mul(worldPosition, viewProjection);
+ output.viewVector = normalize(worldPosition.xyz - viewPosition.xyz);
+ output.texcoord = input.texcoord;
+
+ float4 tpos = mul(float4(worldPosition.x, worldPosition.y, 0, 1),
+ viewProjection);
+ output.screenPosition = tpos.xyz / tpos.w;
+ output.screenPosition.xy = 0.5 + 0.5 * output.screenPosition.xy *
+ float2(1, -1);
+ output.screenPosition.z = reflectionRefractionOffset /
+ output.screenPosition.z;
+
+ return output;
+}
+/**
+ * Pixel Shader - pixel shader does nothing but return the color.
+ */
+float4 pixelShaderFunction(PixelShaderInput input): COLOR {
+ float3 viewVector = float3(input.viewVector.x,
+ input.viewVector.z,
+ -input.viewVector.y);
+
+ float2 texcoord = input.texcoord * 4;
+ float3 n1 = tex2D(noiseSampler,
+ texcoord +
+ float2(clock * 0.01, clock * 0.02));
+ float3 n2 = tex2D(noiseSampler2,
+ texcoord +
+ float2(clock * 0.03, clock * 0.01));
+ float3 n3 = tex2D(noiseSampler3,
+ texcoord +
+ float2(clock * 0.005, clock * 0.007));
+
+ float3 N = normalize(n1 + n2 * 2 + n3 * 4 + float3(-3.5, 16, -3.5));
+
+ float3 R = normalize(reflect(viewVector, N));
+ R.y = R.y < 0.01 ? 0.01 : R.y;
+
+ //float f = tex1D(fresnelSampler, dot(R, N));
+ float f = tex2D(fresnelSampler, float2(dot(R, N), 0.5)).x;
+
+ // Lookup the sky color
+ float3 skyReflection = texCUBE(environmentSampler, R);
+
+ float3 color = lerp(waterColor.xyz, skyReflection, f);
+
+ return float4(color, 1);
+}
+
+// Here we tell our effect file the functions
+// which specify our vertex and pixel shaders.
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/waterfallshader.cg b/o3d/samples/beachdemo/shaders_cg/waterfallshader.cg
new file mode 100644
index 0000000..a5071fa
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/waterfallshader.cg
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uniform float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+uniform float4x4 world : WORLD;
+uniform float4x4 viewInverse : VIEWINVERSE;
+uniform float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+uniform float3 lightWorldPos;
+uniform float vOffset;
+
+sampler diffuseSampler;
+
+struct VertexShaderInput {
+ float4 position : POSITION;
+ float4 normal : NORMAL;
+ float2 texcoord : TEXCOORD0;
+};
+
+struct PixelShaderInput {
+ float4 position : POSITION;
+ float3 normal : TEXCOORD0;
+ float3 worldPosition : TEXCOORD1;
+ float2 texcoord : TEXCOORD2;
+};
+
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ PixelShaderInput output;
+ output.position = mul(input.position, worldViewProjection);
+ float3 worldPosition = mul(input.position, world).xyz;
+ output.normal = mul(input.normal, worldInverseTranspose).xyz;
+ output.worldPosition = worldPosition;
+ output.texcoord = input.texcoord;
+ return output;
+}
+
+float4 pixelShaderFunction(PixelShaderInput input) : COLOR {
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+ float3 worldNormal = normalize(input.normal);
+ float3 surfaceToView = normalize(viewInverse[3].xyz - input.worldPosition);
+ float3 halfVector = normalize(surfaceToLight + surfaceToView);
+ float4 litResult = lit(dot(worldNormal, surfaceToLight),
+ dot(worldNormal, halfVector), 0);
+ float4 diffuse = tex2D(diffuseSampler, float2(input.texcoord.x,
+ input.texcoord.y + vOffset));
+ float4 outColor = (diffuse * litResult.y);
+ return diffuse;
+ //return float4(outColor.rgb, 1);
+}
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/watershader.cg b/o3d/samples/beachdemo/shaders_cg/watershader.cg
new file mode 100644
index 0000000..9d4d07c
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/watershader.cg
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// The 4x4 world view projection matrix.
+float4x4 world : WORLD;
+float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
+float4x4 view : VIEW;
+float4x4 viewProjection : VIEWPROJECTION;
+float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+float3 viewPosition;
+float4 waterColor;
+float reflectionRefractionOffset;
+float clock;
+
+samplerCUBE environmentSampler;
+sampler2D fresnelSampler; // TODO: should be 1D.
+sampler2D refractionSampler; // This is a render target.
+sampler2D reflectionSampler; // This is a render target.
+sampler2D noiseSampler;
+sampler2D noiseSampler2;
+sampler2D noiseSampler3;
+
+// input parameters for our vertex shader
+struct VertexShaderInput {
+ float4 position : POSITION;
+ float2 texcoord : TEXCOORD0;
+};
+
+// input parameters for our pixel shader
+// also the output parameters for our vertex shader
+struct PixelShaderInput {
+ float4 position : POSITION;
+ float2 texcoord : TEXCOORD0;
+ float3 viewVector : TEXCOORD1;
+ float3 screenPosition : TEXCOORD2;
+};
+
+/**
+ * Vertex Shader
+ */
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ /**
+ * We transform each vertex by the world view projection matrix to bring
+ * it from world space to projection space.
+ *
+ * We return its color unchanged.
+ */
+ PixelShaderInput output;
+
+ float4 worldPosition = mul(input.position, world);
+ output.position = mul(worldPosition, viewProjection);
+ output.viewVector = normalize(worldPosition.xyz - viewPosition.xyz);
+ output.texcoord = input.texcoord;
+
+ float4 tpos = mul(float4(worldPosition.x, worldPosition.y, 0, 1),
+ viewProjection);
+ output.screenPosition = tpos.xyz / tpos.w;
+ output.screenPosition.xy = 0.5 + 0.5 * output.screenPosition.xy *
+ float2(1, -1);
+ output.screenPosition.z = reflectionRefractionOffset /
+ output.screenPosition.z;
+
+ return output;
+}
+/**
+ * Pixel Shader - pixel shader does nothing but return the color.
+ */
+float4 pixelShaderFunction(PixelShaderInput input): COLOR {
+ float3 viewVector = float3(input.viewVector.x,
+ input.viewVector.z,
+ -input.viewVector.y);
+
+ float2 texcoord = input.texcoord * 4;
+ float3 n1 = tex2D(noiseSampler,
+ texcoord +
+ float2(clock * 0.01, clock * 0.02));
+ float3 n2 = tex2D(noiseSampler2,
+ texcoord +
+ float2(clock * 0.03, clock * 0.01));
+ float3 n3 = tex2D(noiseSampler3,
+ texcoord +
+ float2(clock * 0.005, clock * 0.007));
+
+ float3 N = normalize(n1 + n2 * 2 + n3 * 4 + float3(-3.5, 16, -3.5));
+
+ float3 R = normalize(reflect(viewVector, N));
+ R.y = R.y < 0.01 ? 0.01 : R.y;
+
+ //float f = tex1D(fresnelSampler, dot(R, N));
+ float f = tex2D(fresnelSampler, float2(dot(R, N), 0.5)).x;
+ float4 reflection = tex2D(
+ reflectionSampler,
+ input.screenPosition.xy - input.screenPosition.z * N.xy + float2(0, 0.1));
+ // I still don't understand where my math is wrong such that I need this 0.1
+ // fudge factor.
+
+ // Lookup the sky color
+ float3 skyReflection = texCUBE(environmentSampler, R);
+
+ // lerping with reflection.a means that where there is terrain reflected
+ // we get terrain, otherwise we get sky.
+ float3 color = lerp(skyReflection,
+ reflection.rgb, reflection.a);
+
+ // lookup the refraction color.
+ float3 refraction = tex2D(
+ refractionSampler,
+ (input.screenPosition.xy - input.screenPosition.z * N.xz +
+ float2(0, 0.05)) * float2(1, 0.95)); // fudge
+
+ float3 finalColor = lerp(refraction, color, f);
+
+ // Uncomment any one of the lines below to see just part of the water
+ // calculation.
+
+ //finalColor = skyReflection; // sky only.
+ //finalColor = reflection.xyz; // reflection only.
+ //finalColor = refraction; // refraction only.
+ //finalColor = lerp(float3(0,1,0), float3(1,0,0), f); // reflection/refraction mix
+ //finalColor = color; // sky only.
+ return float4(finalColor, 1);
+}
+
+// Here we tell our effect file the functions
+// which specify our vertex and pixel shaders.
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor
diff --git a/o3d/samples/beachdemo/shaders_cg/waterstyle2.cg b/o3d/samples/beachdemo/shaders_cg/waterstyle2.cg
new file mode 100644
index 0000000..196c358
--- /dev/null
+++ b/o3d/samples/beachdemo/shaders_cg/waterstyle2.cg
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// The 4x4 world view projection matrix.
+float4x4 worldViewProjection : WORLDVIEWPROJECTION;
+
+// input parameters for our vertex shader
+struct VertexShaderInput {
+ float4 position : POSITION;
+};
+
+// input parameters for our pixel shader
+// also the output parameters for our vertex shader
+struct PixelShaderInput {
+ float4 position : POSITION;
+};
+
+/**
+ * Vertex Shader
+ */
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ /**
+ * We transform each vertex by the world view projection matrix to bring
+ * it from world space to projection space.
+ *
+ * We return its color unchanged.
+ */
+ PixelShaderInput output;
+
+ output.position = mul(input.position, worldViewProjection);
+ return output;
+}
+/**
+ * Pixel Shader - pixel shader does nothing but return the color.
+ */
+float4 pixelShaderFunction(PixelShaderInput input): COLOR {
+ return float4(0, 0, 0.5, 1);
+}
+
+// Here we tell our effect file the functions
+// which specify our vertex and pixel shaders.
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor