//-------------------------------------------------------------------------------------- // Input and Output structs //-------------------------------------------------------------------------------------- struct VertexInput { float4 position: POSITION; float3 normal: NORMAL; float3 color: COLOR; float2 texcoord: TEXCOORD0; }; // vtx output struct vtxout { float4 position: POSITION; // eye space float4 texCoord: TEXCOORD0; float4 color: COLOR0; float4 worldPos: TEXCOORD1; // world position float3 normal: TEXCOORD2; float4 mypos: TEXCOORD3; }; struct pixel { float4 col: COLOR0; float4 pos: COLOR1; float4 norm: COLOR2; }; // fragment input struct fragin { float4 color: COLOR0; float4 position: POSITION; // eye space float4 texCoord: TEXCOORD0; float4 projPos: WPOS; float4 worldPos: TEXCOORD1; // world position float3 normal: TEXCOORD2; float4 mypos: TEXCOORD3; }; //-------------------------------------------------------------------------------------- // Vertex Shaders //-------------------------------------------------------------------------------------- vtxout default_vs(VertexInput IN, uniform float3 lightDir, uniform float2 thetaSun, uniform float3 zenithColor, uniform float3 aColor, uniform float3 bColor, uniform float3 cColor, uniform float3 dColor, uniform float3 eColor, uniform float4x4 ModelView) { vtxout OUT; OUT.position = mul(glstate.matrix.mvp, IN.position); const float dotLN = dot(lightDir, IN.normal); const float cos2gamma = dotLN * dotLN; const float gamma = acos(dotLN); const float theta = dot(float3(0.0, 0.0, 1.0), IN.normal); float3 num = (1.0 + aColor * exp(bColor / theta)) * (1.0 + cColor * exp(dColor * gamma) + eColor * cos2gamma); float3 den = (1.0 + aColor * exp(bColor)) * (1.0 + cColor * exp(dColor * thetaSun.x) + eColor * thetaSun.y); float3 xyY = (num / den) * zenithColor; float3 XYZ; XYZ.x = (xyY.x / xyY.y) * xyY.z; XYZ.y = xyY.z; XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z; const static float3x3 conv_Mat = float3x3(3.240479, -1.537150, -0.498535, -0.969256, 1.875992, 0.041556, 0.055648, -0.204043, 1.057311); float3 hcol = mul(conv_Mat, XYZ); OUT.color = float4(hcol, 1.0); OUT.color.rgb *= 5e-5f; //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position); OUT.worldPos = mul(ModelView, IN.position); OUT.normal = IN.normal; OUT.mypos = OUT.position; return OUT; } pixel frag_skydome(fragin IN) { pixel pix; pix.col = IN.color; pix.pos = IN.worldPos * 1e20;// * maxDepth; pix.norm.xyz = IN.normal; // hack: squeeze some information about the ambient term into the target pix.norm.w = 1; pix.pos.w = IN.mypos.w; // the projected depth pix.col.w = IN.mypos.z / IN.mypos.w; return pix; }