float4x4 viewProjMatrix; float time; float3 eyePosition; float3 eyePositionPushedBack; float3 lightPosition; float4x4 shipViewProjMatrix; float4x4 shipWorldMatrix; float3 worldCornerCar0; float3 worldCornerCar1; float3 worldCornerCar2; float3 worldCornerCar3; float4 diffuseColor; textureCUBE environmentCubeTexture; texture2D waterTexture; samplerCUBE environmentCubeSampler = sampler_state { texture = ; MipFilter = Linear; MagFilter = Linear; MinFilter = Linear; }; sampler2D waterSampler = sampler_state { texture = ; MipFilter = Linear; MagFilter = Linear; MinFilter = Linear; AddressU = WRAP; AddressV = WRAP; }; //illumination calculation: //float4 Illumination(float3 light, float3 normal, float3 view, float2 texcoord, float3 lightIntensity) float4 Illumination(float3 light, float3 normal, float3 view, float4 diffuse, float3 lightIntensity) { float3 hv = normalize(view + light); float costheta = dot(normal, light); if(costheta < 0) costheta = 0; float cosdelta = dot(hv, normal); if(cosdelta < 0 || costheta < 0) cosdelta = 0; //compute the diffuse color here using the textures... missing ATM float3 ks = float3(1,1,1); float shininess = 200; float3 color = (diffuse * costheta + ks * pow(cosdelta, shininess)) * lightIntensity; return float4(color,1); }; float4x4 shipLocations[2]; #define WAVE_FX #include "waves.h" #undef WAVE_FX struct vsOceanInput { float4 pos : POSITION; }; struct vsOceanOutput { float4 pos : POSITION; float3 normal : NORMAL; float3 worldPos : TEXCOORD0; float3 tangent : TEXCOORD1; float3 binormal : TEXCOORD2; float2 bumpCoord0 : TEXCOORD3; float2 bumpCoord1 : TEXCOORD4; float2 bumpCoord2 : TEXCOORD5; float foam : TEXCOORD6; }; vsOceanOutput vsOcean(vsOceanInput input) { vsOceanOutput output = (vsOceanOutput)0; float3 inventedVariable = lerp(lerp(worldCornerCar0, worldCornerCar1, input.pos.x), lerp(worldCornerCar2, worldCornerCar3, input.pos.x), input.pos.z); if(inventedVariable.y * eyePositionPushedBack.y > 0) //looking above the horizon { input.pos.xyz = eyePositionPushedBack + inventedVariable * 1000000; input.pos.y = +1; } else input.pos.xyz = eyePositionPushedBack - (eyePositionPushedBack.y/inventedVariable.y) * inventedVariable; float t = fmod(time, 100.0); output.bumpCoord0.xy = input.pos.xz*0.006 + t*(0.02); output.bumpCoord1.xy = input.pos.xz*0.012 + t*(0.03); output.bumpCoord2.xy = input.pos.xz*0.024 + t*(0.04); float3 du = float3(1, 0, 0); float3 dv = float3(0, 0, 1); for (int i=0;i 0) { discriminant = sqrt(discriminant); float t1 = (-b + discriminant) / 2 / a; float t2 = (-b - discriminant) / 2 / a; if(min(t1,t2) > 0) reflectedColor = float4(1.0, 0.5, 0.0, 1.0); } } float facing = 1.0 - max(dot(-viewDir, normalWorld),0); float fresnel = .02 + .98 * pow(facing, 5); float4 shallowColor = float4 (0.34, 0.5, 0.33,0); float4 deepColor = float4(0.07, 0.19, 0.16,0); float4 waterColor = lerp (deepColor, shallowColor, facing); return reflectedColor * fresnel * 0.5 + waterColor * .75;// * (1 + max(0, -0.5 - input.foam / 6.0)); } /***************************************************************************************************************************/ struct vsShipInput { float4 pos : POSITION; float3 normal : NORMAL0; float3 oceanTangent : TEXCOORD0; float3 oceanBinormal : TEXCOORD1; float3 shipPos : TEXCOORD2; }; struct vsShipOutput { float4 pos : POSITION; float3 normal : NORMAL; float4 worldPos : TEXCOORD1; float3 view : TEXCOORD2; float2 texcoords : TEXCOORD3; //reserved }; vsShipOutput vsShip(vsShipInput input) { vsShipOutput output = (vsShipOutput)0; output.worldPos = mul(input.pos, shipWorldMatrix); output.worldPos /= output.worldPos.w; //test the sphere ship float3 oceanNormal = normalize(cross(input.oceanTangent, input.oceanBinormal)); output.worldPos.xyz = input.oceanTangent * output.worldPos.z + input.oceanBinormal * output.worldPos.x + oceanNormal * output.worldPos.y; output.worldPos += float4(input.shipPos, 0); output.view = eyePosition - output.worldPos; output.normal = mul(input.normal, shipWorldMatrix); output.pos = mul(output.worldPos, viewProjMatrix); return output; }; float4 psShip(vsShipOutput input) : COLOR0 { float3 light = normalize(lightPosition); float3 normal = normalize(input.normal); float3 view = normalize(input.view); //Illumination: (light, normal, view, diffuse(or texture color), light intensity) return float4(1.0, 0.6, 0.3, 1.0); return Illumination(light, normal, view, float4(0.1,0.1,0.6,1), float3(3,3,3)); }; technique ocean { pass P0 { VertexShader = compile vs_3_0 vsOcean(); PixelShader = compile ps_3_0 psOcean(); } }; technique ship { pass P0 { VertexShader = compile vs_3_0 vsShip(); PixelShader = compile ps_3_0 psShip(); } }; #include "terrain.fx"