diff --git a/main/resources/DepthComposer.material b/main/resources/DepthComposer.material index 89bdb27..42e0498 100644 --- a/main/resources/DepthComposer.material +++ b/main/resources/DepthComposer.material @@ -2,10 +2,9 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -fragment_program Caelum/DepthComposerFP_Dummy cg +fragment_program Caelum/DepthComposerFP_Dummy glsl hlsl { - source DepthComposer.cg - entry_point MainFP + source DepthComposerMainFP.glsl profiles ps_3_0 arbfp1 default_params @@ -13,29 +12,27 @@ fragment_program Caelum/DepthComposerFP_Dummy cg } } -fragment_program Caelum/DepthComposerFP_DebugDepthRender cg +fragment_program Caelum/DepthComposerFP_DebugDepthRender glsl hlsl { - source DepthComposer.cg - entry_point MainFP + source DepthComposerMainFP.glsl profiles ps_3_0 arbfp1 - compile_arguments -DDEBUG_DEPTH_RENDER=1 + preprocessor_defines DEBUG_DEPTH_RENDER=1 default_params { - param_named invViewProjMatrix float4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + param_named invViewProjMatrix matrix4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } } -fragment_program Caelum/DepthComposerFP_ExpGroundFog cg +fragment_program Caelum/DepthComposerFP_ExpGroundFog glsl hlsl { - source DepthComposer.cg - entry_point MainFP + source DepthComposerMainFP.glsl profiles ps_3_0 arbfp1 - compile_arguments -DEXP_GROUND_FOG=1 + preprocessor_defines EXP_GROUND_FOG=1 default_params { - param_named invViewProjMatrix float4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + param_named invViewProjMatrix matrix4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 param_named worldCameraPos float4 0 0 0 0 @@ -46,39 +43,37 @@ fragment_program Caelum/DepthComposerFP_ExpGroundFog cg } } -fragment_program Caelum/DepthComposerFP_SkyDomeHaze cg +fragment_program Caelum/DepthComposerFP_SkyDomeHaze glsl hlsl { - source DepthComposer.cg - entry_point MainFP + source DepthComposerMainFP.glsl profiles ps_3_0 arbfp1 - compile_arguments -DSKY_DOME_HAZE=1 -DHAZE_DEPTH_TEXTURE=s2 + preprocessor_defines SKY_DOME_HAZE=1 default_params { - param_named invViewProjMatrix float4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + param_named invViewProjMatrix matrix4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 param_named worldCameraPos float4 0 0 0 0 - param_named sunDirection float3 0 1 0 - param_named hazeColour float3 0.1 0.2 0.6 + param_named sunDirection vec3 0 1 0 + param_named hazeColour vec3 0.1 0.2 0.6 } } -fragment_program Caelum/DepthComposerFP_SkyDomeHaze_ExpGroundFog cg +fragment_program Caelum/DepthComposerFP_SkyDomeHaze_ExpGroundFog glsl hlsl { - source DepthComposer.cg - entry_point MainFP + source DepthComposerMainFP.glsl profiles ps_3_0 arbfp1 - compile_arguments -DEXP_GROUND_FOG=1 -DSKY_DOME_HAZE=1 -DHAZE_DEPTH_TEXTURE=s2 + preprocessor_defines EXP_GROUND_FOG=1,SKY_DOME_HAZE=1 default_params { - param_named invViewProjMatrix float4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + param_named invViewProjMatrix matrix4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 param_named worldCameraPos float4 0 0 0 0 - param_named sunDirection float3 0 1 0 - param_named hazeColour float3 0.1 0.2 0.6 + param_named sunDirection vec3 0 1 0 + param_named hazeColour vec3 0.1 0.2 0.6 param_named groundFogDensity float 0.1 param_named groundFogVerticalDecay float 0.2 diff --git a/main/resources/DepthComposerMainFP.glsl b/main/resources/DepthComposerMainFP.glsl new file mode 100644 index 0000000..1b2a64d --- /dev/null +++ b/main/resources/DepthComposerMainFP.glsl @@ -0,0 +1,178 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform SAMPLER2D(screenTexture, 0); + uniform SAMPLER2D(depthTexture, 1); + uniform SAMPLER2D(atmRelativeDepth, 2); // ~ changed from sampler1D + + uniform mat4 invViewProjMatrix; + uniform vec4 worldCameraPos; + +#if EXP_GROUND_FOG + uniform float groundFogDensity; + uniform float groundFogVerticalDecay; + uniform float groundFogBaseLevel; + uniform vec4 groundFogColour; +#endif // EXP_GROUND_FOG + +#if SKY_DOME_HAZE + uniform vec3 hazeColour; + uniform vec3 sunDirection; +#endif // SKY_DOME_HAZE +) + +#ifdef EXP_GROUND_FOG + +// Returns (exp(x) - 1) / x; avoiding division by 0. +// lim when x -> 0 is 1. +float expdiv(float x) { + if (abs(x) < 0.0001) { + return 1; + } else { + return (exp(x) - 1) / x; + } +} + +// Return fogging through a layer of fog which drops exponentially by height. +// +// Standard exp fog with constant density would return (1 - exp(-density * dist)). +// This function assumes a variable density vd = exp(-verticalDecay * h - baseLevel) +// Full computation is exp(density * dist / (h2 - h1) * int(h1, h2, exp(-verticalDecay * (h2 - h1)))). +// +// This will gracefully degrade to standard exp fog in verticalDecay is 0; without throwing NaNs. +float ExpGroundFog ( + float dist, float h1, float h2, + float density, float verticalDecay, float baseLevel) +{ + float deltaH = (h2 - h1); + return 1 - exp (-density * dist * exp(verticalDecay * (baseLevel - h1)) * expdiv(-verticalDecay * deltaH)); +} + +#endif // EXP_GROUND_FOG + +#ifdef SKY_DOME_HAZE + +float bias (float b, float x) +{ + return pow (x, log (b) / log (0.5)); +} + +vec4 sunlightInscatter +( + vec4 sunColour, + float absorption, + float incidenceAngleCos, + float sunlightScatteringFactor +) +{ + float scatteredSunlight = bias (sunlightScatteringFactor * 0.5, incidenceAngleCos); + + sunColour = sunColour * (1 - absorption) * vec4 (0.9, 0.5, 0.09, 1); + + return sunColour * scatteredSunlight; +} + +float fogExp (float z, float density) { + return 1 - clamp (pow (2.71828, -z * density), 0, 1); +} + +vec4 CalcHaze +( + vec3 worldPos, + vec3 worldCamPos, + vec3 hazeColour, + vec3 sunDirection +) +{ + float haze = length (worldCamPos - worldPos); + float incidenceAngleCos = dot (-sunDirection, normalize (worldPos - worldCamPos)); + float y = -sunDirection.y; + + vec4 sunColour = vec4 (3, 2.5, 1, 1); + + // Factor determining the amount of light lost due to absorption + float atmLightAbsorptionFactor = 0.1; + float fogDensity = 15; + + haze = fogExp (haze * 0.005, atmLightAbsorptionFactor); + + // Haze amount calculation + float invHazeHeight = 100; + float hazeAbsorption = fogExp (pow (1 - y, invHazeHeight), fogDensity); + + if (incidenceAngleCos > 0) { + // Factor determining the amount of scattering for the sun light + float sunlightScatteringFactor = 0.1; + // Factor determining the amount of sun light intensity lost due to scattering + float sunlightScatteringLossFactor = 0.3; + + vec4 sunlightInscatterColour = sunlightInscatter ( + sunColour, + clamp ((1 - tex2D (atmRelativeDepth, y).r) * hazeAbsorption, 0, 1), + clamp (incidenceAngleCos, 0, 1), + sunlightScatteringFactor) * (1 - sunlightScatteringLossFactor); + hazeColour = + hazeColour * (1 - sunlightInscatterColour.a) + + sunlightInscatterColour.rgb * sunlightInscatterColour.a * haze; + } + + return vec4(hazeColour.rgb, haze); +} + +#endif // SKY_DOME_HAZE + +MAIN_PARAMETERS + IN(vec2 screenPos, TEXCOORD0) +MAIN_DECLARATION +{ + vec4 inColor = tex2D(screenTexture, screenPos); + float inDepth = tex2D(depthTexture, screenPos).r; + + // Build normalized device coords; after the perspective divide. + //vec4 devicePos = vec4(1 - screenPos.x * 2, screenPos.y * 2 - 1, inDepth, 1); + //vec4 devicePos = vec4(screenPos.x * 2 - 1, 1 - screenPos.y * 2, 2 * inDepth - 1, 1); + vec4 devicePos = vec4(screenPos.x * 2 - 1, 1 - screenPos.y * 2, inDepth, 1); + + // Go back from device to world coordinates. + vec4 worldPos = mul(invViewProjMatrix, devicePos); + + // Now undo the perspective divide and go back to "normal" space. + worldPos /= worldPos.w; + + vec4 color = inColor; + +#if DEBUG_DEPTH_RENDER + //color = abs(vec4(inDepth, inDepth, inDepth, 1)); + color = worldPos * vec4(0.001, 0.01, 0.001, 1); +#endif // DEBUG_DEPTH_RENDER + +#if EXP_GROUND_FOG + // Ye olde ground fog. + float h1 = worldCameraPos.y; + float h2 = worldPos.y; + float dist = length(worldCameraPos - worldPos); + float fogFactor = ExpGroundFog( + dist, h1, h2, + groundFogDensity, groundFogVerticalDecay, groundFogBaseLevel); + color = lerp(color, groundFogColour, fogFactor); +#endif // EXP_GROUND_FOG + +#if SKY_DOME_HAZE + vec4 hazeValue = CalcHaze ( + worldPos.xyz, + worldCameraPos.xyz, + hazeColour, + sunDirection); + color.rgb = lerp(color.rgb, hazeValue.rgb, hazeValue.a); +#endif // SKY_DOME_HAZE + + gl_FragColor = color; +} + + + diff --git a/main/resources/DepthRender.program b/main/resources/DepthRender.program index 9442acd..e91b4a3 100644 --- a/main/resources/DepthRender.program +++ b/main/resources/DepthRender.program @@ -2,11 +2,10 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -vertex_program Caelum/DepthRenderVP cg +vertex_program Caelum/DepthRenderVP glsl hlsl { - source DepthComposer.cg - entry_point DepthRenderVP - profiles vs_2_0 arbvp1 + source DepthRenderVP.glsl + //profiles vs_2_0 arbvp1 default_params { @@ -14,18 +13,16 @@ vertex_program Caelum/DepthRenderVP cg } } -fragment_program Caelum/DepthRenderFP cg +fragment_program Caelum/DepthRenderFP glsl hlsl { - source DepthComposer.cg - entry_point DepthRenderFP - profiles ps_3_0 fp40 arbfp1 + source DepthRenderFP.glsl + //profiles ps_3_0 fp40 arbfp1 } -vertex_program Caelum/DepthRenderAlphaRejectionVP cg +vertex_program Caelum/DepthRenderAlphaRejectionVP glsl hlsl { - source DepthComposer.cg - entry_point DepthRenderAlphaRejectionVP profiles vs_2_0 arbvp1 + source DepthRenderAlphaRejectionVP.glsl default_params { @@ -33,9 +30,8 @@ vertex_program Caelum/DepthRenderAlphaRejectionVP cg } } -fragment_program Caelum/DepthRenderAlphaRejectionFP cg +fragment_program Caelum/DepthRenderAlphaRejectionFP glsl hlsl { - source DepthComposer.cg - entry_point DepthRenderAlphaRejectionFP profiles ps_3_0 fp40 arbfp1 + source DepthRenderAlphaRejectionFP.glsl } diff --git a/main/resources/DepthRenderAlphaRejectionFP.glsl b/main/resources/DepthRenderAlphaRejectionFP.glsl new file mode 100644 index 0000000..d1f9a7b --- /dev/null +++ b/main/resources/DepthRenderAlphaRejectionFP.glsl @@ -0,0 +1,20 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform SAMPLER2D(mainTex, 0); +) + +MAIN_PARAMETERS + IN(vec4 texcoord, TEXCOORD0) + IN(vec4 magic, TEXCOORD1) +MAIN_DECLARATION +{ + vec4 texvalue = tex2D(mainTex, texcoord.xy); +// texvalue.a = sin(100 * texcoord.x) + sin(100 * texcoord.y); + gl_FragColor = vec4(vec3_splat(magic.z / magic.w), texvalue.a); +} \ No newline at end of file diff --git a/main/resources/DepthRenderAlphaRejectionVP.glsl b/main/resources/DepthRenderAlphaRejectionVP.glsl new file mode 100644 index 0000000..83c38a3 --- /dev/null +++ b/main/resources/DepthRenderAlphaRejectionVP.glsl @@ -0,0 +1,29 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 wvpMatrix; +) + +MAIN_PARAMETERS + IN(vec4 inPos, POSITION) + IN(vec4 inTexcoord, TEXCOORD0) + + OUT(vec4 outTexcoord, TEXCOORD0) + OUT(vec4 magic, TEXCOORD1) +MAIN_DECLARATION +{ + // Standard transform. + gl_Position = mul(wvpMatrix, inPos); + + // Depth buffer is z/w. + // Let the GPU lerp the components of gl_Position. + magic = gl_Position; + + outTexcoord = inTexcoord; +} + diff --git a/main/resources/DepthRenderFP.glsl b/main/resources/DepthRenderFP.glsl new file mode 100644 index 0000000..5531f01 --- /dev/null +++ b/main/resources/DepthRenderFP.glsl @@ -0,0 +1,16 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +MAIN_PARAMETERS + IN(vec4 magic, TEXCOORD0) +MAIN_DECLARATION +{ + //ORIG Cg// output = vec4(magic.z / magic.w); ~ error X3014: incorrect number of arguments to numeric-type constructor + gl_FragColor = vec4_splat(magic.z / magic.w); + //output = vec4(magic.xy / magic.w, 1, 1); +} + diff --git a/main/resources/DepthRenderVP.glsl b/main/resources/DepthRenderVP.glsl new file mode 100644 index 0000000..2d63797 --- /dev/null +++ b/main/resources/DepthRenderVP.glsl @@ -0,0 +1,23 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 wvpMatrix; +) + +MAIN_PARAMETERS + IN(vec4 inPos, POSITION) + OUT(vec4 magic, TEXCOORD0) +MAIN_DECLARATION +{ + // Standard transform. + gl_Position = mul(wvpMatrix, inPos); + + // Depth buffer is z/w. + // Let the GPU lerp the components of gl_Position. + magic = gl_Position; +} \ No newline at end of file diff --git a/main/resources/GroundFog.program b/main/resources/GroundFog.program index 6f47354..56d6d68 100644 --- a/main/resources/GroundFog.program +++ b/main/resources/GroundFog.program @@ -2,11 +2,10 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -vertex_program CaelumGroundFogVP cg +vertex_program CaelumGroundFogVP glsl hlsl { - source CaelumGroundFog.cg - entry_point GroundFog_vp - profiles vs_2_x arbvp1 vp30 + source GroundFogVP.glsl + //profiles vs_2_x arbvp1 vp30 default_params { @@ -15,11 +14,10 @@ vertex_program CaelumGroundFogVP cg } } -fragment_program CaelumGroundFogFP cg +fragment_program CaelumGroundFogFP glsl hlsl { - source CaelumGroundFog.cg - entry_point GroundFog_fp - profiles ps_2_x arbfp1 fp30 + source GroundFogFP.glsl + //profiles ps_2_x arbfp1 fp30 default_params { @@ -34,11 +32,10 @@ fragment_program CaelumGroundFogFP cg } } -vertex_program CaelumGroundFogDomeVP cg +vertex_program CaelumGroundFogDomeVP glsl hlsl { - source CaelumGroundFog.cg - entry_point GroundFogDome_vp - profiles vs_2_0 arbvp1 + source GroundFogDomeVP.glsl + //profiles vs_2_0 arbvp1 default_params { @@ -46,11 +43,10 @@ vertex_program CaelumGroundFogDomeVP cg } } -fragment_program CaelumGroundFogDomeFP cg +fragment_program CaelumGroundFogDomeFP glsl hlsl { - source CaelumGroundFog.cg - entry_point GroundFogDome_fp - profiles ps_2_0 arbfp1 + source GroundFogDomeFP.glsl + //profiles ps_2_0 arbfp1 default_params { diff --git a/main/resources/GroundFogDomeFP.glsl b/main/resources/GroundFogDomeFP.glsl new file mode 100644 index 0000000..3ea5f46 --- /dev/null +++ b/main/resources/GroundFogDomeFP.glsl @@ -0,0 +1,52 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +// Just like ExpGroundFog with h2 = positive infinity +// When h2 == negative infinity the value is always +1. +float ExpGroundFogInf ( + float invSinView, float h1, + float density, float verticalDecay, float baseLevel) +{ + return 1 - exp (-density * invSinView * exp(verticalDecay * (baseLevel - h1)) * (1 / verticalDecay)); +} + + +OGRE_UNIFORMS( + uniform float cameraHeight; + uniform vec4 fogColour; + uniform float fogDensity; + uniform float fogVerticalDecay; + uniform float fogGroundLevel; +) + +MAIN_PARAMETERS + IN(vec3 relPosition, TEXCOORD0) +MAIN_DECLARATION +{ + // Fog magic. + float invSinView = 1 / (relPosition.y); + float h1 = cameraHeight; + float aFog; + + if (fogVerticalDecay < 1e-7) { + // A value of zero of fogVerticalDecay would result in maximum (1) aFog everywhere. + // Output 0 zero instead to disable. + aFog = 0; + } else { + if (invSinView < 0) { + // Gazing into the abyss + aFog = 1; + } else { + aFog = saturate (ExpGroundFogInf ( + invSinView, h1, + fogDensity, fogVerticalDecay, fogGroundLevel)); + } + } + + gl_FragColor.a = aFog; + gl_FragColor.rgb = fogColour.rgb; +} \ No newline at end of file diff --git a/main/resources/GroundFogDomeVP.glsl b/main/resources/GroundFogDomeVP.glsl new file mode 100644 index 0000000..f95308a --- /dev/null +++ b/main/resources/GroundFogDomeVP.glsl @@ -0,0 +1,19 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 worldViewProj; +) + +MAIN_PARAMETERS + IN(vec4 position, POSITION) + OUT(vec3 relPosition, TEXCOORD0) +MAIN_DECLARATION +{ + gl_Position = mul(worldViewProj, position); + relPosition = normalize(position.xyz); +} \ No newline at end of file diff --git a/main/resources/GroundFogFP.glsl b/main/resources/GroundFogFP.glsl new file mode 100644 index 0000000..947a8f1 --- /dev/null +++ b/main/resources/GroundFogFP.glsl @@ -0,0 +1,54 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +// Returns (exp(x) - 1) / x; avoiding division by 0. +// lim when x -> 0 is 1. +float expdiv(float x) { + if (abs(x) < 0.0001) { + return 1; + } else { + return (exp(x) - 1) / x; + } +} + +// Return fogging through a layer of fog which drops exponentially by height. +// +// Standard exp fog with constant density would return (1 - exp(-density * dist)). +// This function assumes a variable density vd = exp(-verticalDecay * h - baseLevel) +// Full computation is exp(density * dist / (h2 - h1) * int(h1, h2, exp(-verticalDecay * (h2 - h1)))). +// +// This will gracefully degrade to standard exp fog in verticalDecay is 0; without throwing NaNs. +float ExpGroundFog ( + float dist, float h1, float h2, + float density, float verticalDecay, float baseLevel) +{ + float deltaH = (h2 - h1); + return 1 - exp (-density * dist * exp(verticalDecay * (baseLevel - h1)) * expdiv(-verticalDecay * deltaH)); +} + +OGRE_UNIFORMS( + uniform vec3 camPos; + uniform vec4 fogColour; + uniform float fogDensity; + uniform float fogVerticalDecay; + uniform float fogGroundLevel; +) + +MAIN_PARAMETERS + IN(vec3 worldPos, TEXCOORD0) +MAIN_DECLARATION +{ + float h1 = camPos.y; + float h2 = worldPos.y; + float dist = length(camPos - worldPos); + float fog = ExpGroundFog( + dist, h1, h2, + fogDensity, fogVerticalDecay, fogGroundLevel); + + gl_FragColor.rgb = fogColour.rgb; + gl_FragColor.a = fog; +} \ No newline at end of file diff --git a/main/resources/GroundFogVP.glsl b/main/resources/GroundFogVP.glsl new file mode 100644 index 0000000..c1177ae --- /dev/null +++ b/main/resources/GroundFogVP.glsl @@ -0,0 +1,20 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 worldViewProj; + uniform mat4 world; +) + +MAIN_PARAMETERS + IN(vec4 position, POSITION) + OUT(vec4 worldPos, TEXCOORD0) +MAIN_DECLARATION +{ + gl_Position = mul(worldViewProj, position); + worldPos = mul(world, position); +} \ No newline at end of file diff --git a/main/resources/Haze.program b/main/resources/Haze.program index 6dac8fb..d5645d3 100644 --- a/main/resources/Haze.program +++ b/main/resources/Haze.program @@ -2,11 +2,10 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -vertex_program CaelumHazeVP cg +vertex_program CaelumHazeVP glsl hlsl { - source CaelumSkyDome.cg - entry_point HazeVP - profiles vs_2_0 arbvp1 vp30 + source HazeVP.glsl + //profiles vs_2_0 arbvp1 vp30 default_params { @@ -15,10 +14,9 @@ vertex_program CaelumHazeVP cg } } -fragment_program CaelumHazeFP cg +fragment_program CaelumHazeFP glsl hlsl { - source CaelumSkyDome.cg - entry_point HazeFP + source HazeFP.glsl profiles ps_2_0 arbfp1 fp30 default_params diff --git a/main/resources/HazeFP.glsl b/main/resources/HazeFP.glsl new file mode 100644 index 0000000..ca4b426 --- /dev/null +++ b/main/resources/HazeFP.glsl @@ -0,0 +1,55 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include +#include + +OGRE_UNIFORMS( + uniform SAMPLER2D(atmRelativeDepth, 0); // ~ changed from sampler1D + uniform SAMPLER2D(gradientsMap, 1); + uniform vec4 fogColour; +) + +MAIN_PARAMETERS + IN(float haze, TEXCOORD0) + IN(vec2 sunlight, TEXCOORD1) +MAIN_DECLARATION +{ + float incidenceAngleCos = sunlight.x; + float y = sunlight.y; + + vec4 sunColour = vec4 (3, 2.5, 1, 1); + + // Factor determining the amount of light lost due to absorption + float atmLightAbsorptionFactor = 0.1; + float fogDensity = 15; + + haze = fogExp (haze * 0.005, atmLightAbsorptionFactor); + + // Haze amount calculation + float invHazeHeight = 100; + float hazeAbsorption = fogExp (pow (1 - y, invHazeHeight), fogDensity); + + vec4 hazeColour; + hazeColour = fogColour; + if (incidenceAngleCos > 0) { + // Factor determining the amount of scattering for the sun light + float sunlightScatteringFactor = 0.1; + // Factor determining the amount of sun light intensity lost due to scattering + float sunlightScatteringLossFactor = 0.3; + + vec4 sunlightInscatterColour = sunlightInscatter ( + sunColour, + clamp ((1 - tex2D (atmRelativeDepth, y).r) * hazeAbsorption, 0, 1), + clamp (incidenceAngleCos, 0, 1), + sunlightScatteringFactor) * (1 - sunlightScatteringLossFactor); + hazeColour.rgb = + hazeColour.rgb * (1 - sunlightInscatterColour.a) + + sunlightInscatterColour.rgb * sunlightInscatterColour.a * haze; + } + + gl_FragColor = hazeColour; + gl_FragColor.a = haze; +} \ No newline at end of file diff --git a/main/resources/HazeVP.glsl b/main/resources/HazeVP.glsl new file mode 100644 index 0000000..9274917 --- /dev/null +++ b/main/resources/HazeVP.glsl @@ -0,0 +1,27 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 worldViewProj; + uniform vec4 camPos; + uniform vec3 sunDirection; +) + +MAIN_PARAMETERS + IN(vec4 position, POSITION) + IN(vec4 normal, NORMAL) + + OUT(float haze, TEXCOORD0) + OUT(vec2 sunlight, TEXCOORD1) +MAIN_DECLARATION +{ + sunDirection = normalize (sunDirection); + gl_Position = mul(worldViewProj, position); + haze = length (camPos - position); + sunlight.x = dot (-sunDirection, normalize (position - camPos)); + sunlight.y = -sunDirection.y; +} \ No newline at end of file diff --git a/main/resources/LayeredClouds.material b/main/resources/LayeredClouds.material index ecb13e3..4ec06e8 100644 --- a/main/resources/LayeredClouds.material +++ b/main/resources/LayeredClouds.material @@ -2,11 +2,10 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -vertex_program CaelumLayeredCloudsVP cg +vertex_program CaelumLayeredCloudsVP glsl hlsl { - source CaelumLayeredClouds.cg - entry_point LayeredClouds_vp - profiles vs_3_0 vp40 arbvp1 glslv + source LayeredCloudsVP.glsl + profiles vs_3_0 vp40 arbvp1 default_params { @@ -16,11 +15,10 @@ vertex_program CaelumLayeredCloudsVP cg } } -fragment_program CaelumLayeredCloudsFP cg +fragment_program CaelumLayeredCloudsFP glsl hlsl { - source CaelumLayeredClouds.cg - entry_point LayeredClouds_fp - profiles ps_3_0 fp40 arbfp1 glslf + source LayeredCloudsFP.glsl + profiles ps_3_0 fp40 arbfp1 default_params { diff --git a/main/resources/LayeredCloudsFP.glsl b/main/resources/LayeredCloudsFP.glsl new file mode 100644 index 0000000..3a9e9d8 --- /dev/null +++ b/main/resources/LayeredCloudsFP.glsl @@ -0,0 +1,173 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + // Global cloud textures + uniform SAMPLER2D(cloud_shape1, 0); + uniform SAMPLER2D(cloud_shape2, 1); + uniform SAMPLER2D(cloud_detail, 2); + + uniform float cloudMassInvScale; + uniform float cloudDetailInvScale; + uniform vec2 cloudMassOffset; + uniform vec2 cloudDetailOffset; + uniform float cloudMassBlend; + uniform float cloudDetailBlend; + + uniform float cloudCoverageThreshold; + + uniform vec4 sunLightColour; + uniform vec4 sunSphereColour; + uniform vec4 fogColour; + uniform vec4 sunDirection; + uniform float cloudSharpness; + uniform float cloudThickness; + uniform vec3 camera_position; + + uniform vec3 fadeDistMeasurementVector; + uniform float layerHeight; + uniform float cloudUVFactor; + uniform float heightRedFactor; + + uniform float nearFadeDist; + uniform float farFadeDist; +) + +// Get cloud layer intensity at a certain point. +float LayeredClouds_intensity +( + in vec2 pos, + float cloudMassInvScale, + float cloudDetailInvScale, + vec2 cloudMassOffset, + vec2 cloudDetailOffset, + float cloudMassBlend, + float cloudDetailBlend, + float cloudCoverageThreshold +) +{ + // Calculate the base alpha + vec2 finalMassOffset = cloudMassOffset + pos; + float aCloud = lerp(tex2D(cloud_shape1, finalMassOffset * cloudMassInvScale).r, + tex2D(cloud_shape2, finalMassOffset * cloudMassInvScale).r, + cloudMassBlend); + float aDetail = tex2D(cloud_detail, (cloudDetailOffset + pos) * cloudDetailInvScale).r; + aCloud = (aCloud + aDetail * cloudDetailBlend) / (1 + cloudDetailBlend); + return max(0, aCloud - cloudCoverageThreshold); +} + +vec4 OldCloudColor +( + vec2 uv, + vec3 relPosition, + float sunGlow, + + float cloudMassInvScale, + float cloudDetailInvScale, + vec2 cloudMassOffset, + vec2 cloudDetailOffset, + float cloudMassBlend, + float cloudDetailBlend, + + float cloudCoverageThreshold, + + vec4 sunColour, + vec4 fogColour, + float cloudSharpness, + float cloudThickness + +) { + // Initialize output. + vec4 oCol = vec4(1, 1, 1, 0); + + // Get cloud intensity. + float intensity = LayeredClouds_intensity + ( + uv, + cloudMassInvScale, + cloudDetailInvScale, + cloudMassOffset, + cloudDetailOffset, + cloudMassBlend, + cloudDetailBlend, + cloudCoverageThreshold + ); + + // Opacity is exponential. + float aCloud = saturate(exp(cloudSharpness * intensity) - 1); + + float shine = pow(saturate(sunGlow), 8) / 4; + sunColour.rgb *= 1.5; + vec3 cloudColour = fogColour.rgb * (1 - intensity / 3); + float thickness = saturate(0.8 - exp(-cloudThickness * (intensity + 0.2 - shine))); + + oCol.rgb = lerp(sunColour.rgb, cloudColour.rgb, thickness); + oCol.a = aCloud; + + return oCol; +} + +//Converts a color from RGB to YUV color space +//the rgb color is in [0,1] [0,1] [0,1] range +//the yuv color is in [0,1] [-0.436,0.436] [-0.615,0.615] range +vec3 YUVfromRGB(vec3 col) +{ + return vec3(dot(col, vec3(0.299,0.587,0.114)), + dot(col, vec3(-0.14713,-0.28886,0.436)), + dot(col, vec3(0.615,-0.51499,-0.10001))); +} + +vec3 RGBfromYUV(vec3 col) +{ + return vec3(dot(col,vec3(1,0,1.13983)), + dot(col,vec3(1,-0.39465,-0.58060)), + dot(col,vec3(1,2.03211,0))); +} + +// Creates a color that has the intensity of col1 and the chrominance of col2 +vec3 MagicColorMix(vec3 col1, vec3 col2) +{ + return saturate(RGBfromYUV(vec3(YUVfromRGB(col1).x, YUVfromRGB(col2).yz))); +} + +MAIN_PARAMETERS + IN(vec2 uv, TEXCOORD0) + IN(vec3 relPosition, TEXCOORD1) + IN(float sunGlow, TEXCOORD2) + IN(vec4 worldPosition, TEXCOORD3) +MAIN_DECLARATION +{ + uv *= cloudUVFactor; + + gl_FragColor = OldCloudColor( + uv, relPosition, sunGlow, + cloudMassInvScale, cloudDetailInvScale, + cloudMassOffset, cloudDetailOffset, + cloudMassBlend, cloudDetailBlend, + cloudCoverageThreshold, + sunLightColour, + fogColour, + cloudSharpness, + cloudThickness); + gl_FragColor.r += layerHeight / heightRedFactor; + + //float dist = distance(worldPosition.xyz, camera_position.xyz); + float dist = length((worldPosition - camera_position) * fadeDistMeasurementVector); + float aMod = 1; + if (dist > nearFadeDist) { + aMod = saturate(lerp(0, 1, (farFadeDist - dist) / (farFadeDist - nearFadeDist))); + } + float alfa = gl_FragColor.a * aMod; + + vec3 cloudDir = normalize( + vec3(worldPosition.x, layerHeight, worldPosition.y) - camera_position); + float angleDiff = saturate(dot(cloudDir, normalize(sunDirection.xyz))); + + vec3 lCol = lerp(gl_FragColor.rgb, MagicColorMix(gl_FragColor.rgb, sunSphereColour.rgb), angleDiff); + gl_FragColor.rgb = lerp(lCol, gl_FragColor.rgb, alfa); + gl_FragColor.a = alfa; +} diff --git a/main/resources/LayeredCloudsVP.glsl b/main/resources/LayeredCloudsVP.glsl new file mode 100644 index 0000000..7c510ba --- /dev/null +++ b/main/resources/LayeredCloudsVP.glsl @@ -0,0 +1,36 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 worldViewProj; + uniform mat4 worldMatrix; + uniform vec3 sunDirection; +) + +MAIN_PARAMETERS + IN(vec4 position, POSITION) + IN(vec2 uv, TEXCOORD0) + + OUT(vec2 oUv, TEXCOORD0) + OUT(vec3 relPosition, TEXCOORD1) + OUT(float sunGlow, TEXCOORD2) + OUT(vec4 worldPosition, TEXCOORD3) +MAIN_DECLARATION +{ + + gl_Position = mul(worldViewProj, position); + worldPosition = mul(worldMatrix, position); + oUv = uv; + + // This is the relative position, or view direction. + relPosition = normalize (position.xyz); + + // Calculate the angle between the direction of the sun and the current + // view direction. This we call "glow" and ranges from 1 next to the sun + // to -1 in the opposite direction. + sunGlow = dot (relPosition, normalize (-sunDirection)); +} \ No newline at end of file diff --git a/main/resources/MinimalCompositorVP.cg b/main/resources/MinimalCompositorVP.glsl similarity index 51% rename from main/resources/MinimalCompositorVP.cg rename to main/resources/MinimalCompositorVP.glsl index 902d289..67f4b6a 100644 --- a/main/resources/MinimalCompositorVP.cg +++ b/main/resources/MinimalCompositorVP.glsl @@ -2,22 +2,24 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + // Fixed function does not always work. // This is a the minimal compositor VP required. -void MinimalCompositorVP -( - in float4 in_pos : POSITION, - - uniform float4x4 worldviewproj_matrix, - - out float2 out_uv0 : TEXCOORD0, - out float4 out_pos : POSITION +OGRE_UNIFORMS( + uniform mat4 worldviewproj_matrix; ) + +MAIN_PARAMETERS + IN(vec4 in_pos, POSITION) + OUT(vec2 out_uv0, TEXCOORD0) +MAIN_DECLARATION { // Use standard transform. - out_pos = mul(worldviewproj_matrix, in_pos); + gl_Position = mul(worldviewproj_matrix, in_pos); // Convert to image-space in_pos.xy = sign(in_pos.xy); - out_uv0 = (float2(in_pos.x, -in_pos.y) + 1.0f) * 0.5f; + out_uv0 = (vec2(in_pos.x, -in_pos.y) + 1.0f) * 0.5f; } diff --git a/main/resources/MinimalCompositorVP.program b/main/resources/MinimalCompositorVP.program index c20ad48..51542b3 100644 --- a/main/resources/MinimalCompositorVP.program +++ b/main/resources/MinimalCompositorVP.program @@ -2,11 +2,9 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -vertex_program Caelum/MinimalCompositorVP cg +vertex_program Caelum/MinimalCompositorVP glsl hlsl { - source MinimalCompositorVP.cg - entry_point MinimalCompositorVP - profiles vs_1_1 arbvp1 + source MinimalCompositorVP.glsl default_params { diff --git a/main/resources/PhaseMoonFP.glsl b/main/resources/PhaseMoonFP.glsl new file mode 100644 index 0000000..6bc9beb --- /dev/null +++ b/main/resources/PhaseMoonFP.glsl @@ -0,0 +1,46 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform float phase; + uniform SAMPLER2D(moonDisc, 0); +) + +// Get how much of a certain point on the moon is seen (or not) because of the phase. +// uv is the rect position on moon; as seen from the earth. +// phase ranges from 0 (full moon) to 1 (again fool moon) +float MoonPhaseFactor(vec2 uv, float phase) +{ + // 1. In phase interval [0..1/2) day-to-night terminator appeared on the right side of the moon and moves to the left by cosine law + // 2. In phase interval [1/2..1) night-to-day terminator appeared on the right side of the moon and moves to the left by cosine law + // but if we swapped for simplicity left and right sides of the moon for the second interval than + // 2' In phase interval [1/2..1) night-to-day terminator appeared on the left side of the moon and moves to the right by cosine law + // therefore in such coord system terminator would move from right to left and to the right again, and picture would be like this: + // Moon => (day | night) + + float cY = uv.y - 0.5; // signed + float cX = sqrt(0.25 - cY * cY); // positive, half of disk chord + + float termX = cX * cos((2.0 * 3.1416) * phase); // determine terminator position in our tweaked coord system + float refX = (uv.x - 0.5) * sign(0.5 - phase); // reverse X axis for phase interval [1/2..1) + + return 0.5 * sign(termX - refX) + 0.5; // day if refX < termX +} + +MAIN_PARAMETERS + IN(vec2 uv, TEXCOORD0) +MAIN_DECLARATION +{ + gl_FragColor = tex2D(moonDisc, uv); + float alpha = MoonPhaseFactor(uv, phase); + + // Get luminance from the texture. + float lum = dot(gl_FragColor.rgb, vec3(0.3333, 0.3333, 0.3333)); + //float lum = dot(gl_FragColor.rgb, vec3(0.3, 0.59, 0.11)); + gl_FragColor.a = min(gl_FragColor.a, lum * alpha); + gl_FragColor.rgb /= lum; +} \ No newline at end of file diff --git a/main/resources/PhaseMoonVP.glsl b/main/resources/PhaseMoonVP.glsl new file mode 100644 index 0000000..b70afcc --- /dev/null +++ b/main/resources/PhaseMoonVP.glsl @@ -0,0 +1,21 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 worldviewproj_matrix; +) + +MAIN_PARAMETERS + IN(vec4 iPosition, POSITION) + IN(vec2 iTexCoord, TEXCOORD0) + + OUT(vec2 oTexCoord, TEXCOORD0) +MAIN_DECLARATION +{ + gl_Position = mul(worldviewproj_matrix, iPosition); + oTexCoord = iTexCoord; +} \ No newline at end of file diff --git a/main/resources/PointStarfield.material b/main/resources/PointStarfield.material index 1fe8bd5..37a8ffe 100644 --- a/main/resources/PointStarfield.material +++ b/main/resources/PointStarfield.material @@ -2,11 +2,10 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -vertex_program Caelum/StarPointVP cg +vertex_program Caelum/StarPointVP glsl hlsl { - source CaelumPointStarfield.cg - entry_point StarPointVP - profiles vs_2_0 arbvp1 vp30 glslv + source StarPointVP.glsl + //profiles vs_2_0 arbvp1 vp30 glslv default_params { @@ -22,11 +21,10 @@ vertex_program Caelum/StarPointVP cg } } -fragment_program Caelum/StarPointFP cg +fragment_program Caelum/StarPointFP glsl hlsl { - source CaelumPointStarfield.cg - entry_point StarPointFP - profiles ps_2_0 arbfp1 fp30 glslf + source StarPointFP.glsl + //profiles ps_2_0 arbfp1 fp30 glslf default_params { diff --git a/main/resources/Precipitation.material b/main/resources/Precipitation.material index 68db11c..8c9642a 100644 --- a/main/resources/Precipitation.material +++ b/main/resources/Precipitation.material @@ -2,10 +2,9 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -fragment_program Caelum/PrecipitationFP cg +fragment_program Caelum/PrecipitationFP glsl hlsl { - source Precipitation.cg - entry_point MainFP + source PrecipitationMainFP.glsl profiles ps_3_0 fp40 arbfp1 default_params @@ -13,10 +12,9 @@ fragment_program Caelum/PrecipitationFP cg } } -vertex_program Caelum/PrecipitationVP cg +vertex_program Caelum/PrecipitationVP glsl hlsl { - source Precipitation.cg - entry_point MainVP + source PrecipitationMainVP.glsl profiles vs_3_0 vp40 arbvp1 default_params diff --git a/main/resources/PrecipitationMainFP.glsl b/main/resources/PrecipitationMainFP.glsl new file mode 100644 index 0000000..ab281e6 --- /dev/null +++ b/main/resources/PrecipitationMainFP.glsl @@ -0,0 +1,72 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform SAMPLER2D(scene, 0); + uniform SAMPLER2D(samplerPrec, 1); + + uniform float intensity; + uniform vec4 ambient_light_colour; + + // - - corner + uniform vec4 corner1; + // + - corner + uniform vec4 corner2; + // - + corner + uniform vec4 corner3; + // + + corner + uniform vec4 corner4; + + // The x and y coordinal deviations for all 3 layers of precipitation + uniform vec4 deltaX; + uniform vec4 deltaY; + + uniform vec4 precColor; +) + +// Cartesian to cylindrical coordinates +vec2 CylindricalCoordinates(vec4 dir) { + float R = 0.5; + vec2 res; + //cubical root is used to counteract top/bottom circle effect + dir *= R / pow(length(dir.xz), 0.33); + res.y = -dir.y; + res.x = -atan2(dir.z, dir.x); + return res; +} + +// Returns alpha value of a precipitation +// view_direction is the direction vector resulting from the eye direction,wind direction and possibly other factors +float Precipitation + ( + vec2 cCoords, + float intensity, + vec2 delta + ) { + cCoords -= delta; + vec4 raincol = tex2D(samplerPrec, cCoords); + return (raincol.g + +OGRE_UNIFORMS( + uniform mat4 worldviewproj_matrix; +) + +MAIN_PARAMETERS + IN(vec4 in_pos, POSITION) + OUT(vec2 out_uv0, TEXCOORD0) +MAIN_DECLARATION +{ + // Use standard transform. + gl_Position = mul(worldviewproj_matrix, in_pos); + + // Convert to image-space + in_pos.xy = sign(in_pos.xy); + out_uv0 = (vec2(in_pos.x, -in_pos.y) + 1.0f) * 0.5f; +} diff --git a/main/resources/SkyDome.material b/main/resources/SkyDome.material index 66e496e..b4511a7 100644 --- a/main/resources/SkyDome.material +++ b/main/resources/SkyDome.material @@ -2,11 +2,10 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -fragment_program CaelumSkyDomeFP cg +fragment_program CaelumSkyDomeFP glsl hlsl { - source CaelumSkyDome.cg - entry_point SkyDomeFP - compile_arguments -DHAZE + source SkyDomeFP.glsl + preprocessor_defines HAZE profiles ps_2_0 arbfp1 default_params @@ -17,10 +16,9 @@ fragment_program CaelumSkyDomeFP cg } } -fragment_program CaelumSkyDomeFP_NoHaze cg +fragment_program CaelumSkyDomeFP_NoHaze glsl hlsl { - source CaelumSkyDome.cg - entry_point SkyDomeFP + source SkyDomeFP.glsl profiles ps_2_0 arbfp1 default_params @@ -30,11 +28,10 @@ fragment_program CaelumSkyDomeFP_NoHaze cg } } -vertex_program CaelumSkyDomeVP cg +vertex_program CaelumSkyDomeVP glsl hlsl { - source CaelumSkyDome.cg - entry_point SkyDomeVP - profiles vs_2_0 arbvp1 + source SkyDomeVP.glsl + //profiles vs_2_0 arbvp1 default_params { diff --git a/main/resources/SkyDomeFP.glsl b/main/resources/SkyDomeFP.glsl new file mode 100644 index 0000000..e9d2de7 --- /dev/null +++ b/main/resources/SkyDomeFP.glsl @@ -0,0 +1,55 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include +#include + +OGRE_UNIFORMS( + uniform SAMPLER2D(gradientsMap, 0); + uniform SAMPLER2D(atmRelativeDepth, 1); //~ changed from sampler1D + uniform vec4 hazeColour; + uniform float offset; +) + +MAIN_PARAMETERS + IN(vec4 col, COLOR) + IN(vec2 uv, TEXCOORD0) + IN(float incidenceAngleCos, TEXCOORD1) + IN(float y, TEXCOORD2) + IN(vec3 normal, TEXCOORD3) +MAIN_DECLARATION +{ + vec4 sunColour = vec4 (3, 3, 3, 1); + +#ifdef HAZE + float fogDensity = 15; + // Haze amount calculation + float invHazeHeight = 100; + float haze = fogExp (pow (clamp (1 - normal.y, 0, 1), invHazeHeight), fogDensity); +#endif // HAZE + + // Pass the colour + gl_FragColor = tex2D (gradientsMap, uv + vec2 (offset, 0)) * col; + + // Sunlight inscatter + if (incidenceAngleCos > 0) + { + float sunlightScatteringFactor = 0.05; + float sunlightScatteringLossFactor = 0.1; + float atmLightAbsorptionFactor = 0.1; + + gl_FragColor.rgb += sunlightInscatter ( + sunColour, + clamp (atmLightAbsorptionFactor * (1 - tex2D (atmRelativeDepth, y).r), 0, 1), + clamp (incidenceAngleCos, 0, 1), + sunlightScatteringFactor).rgb * (1 - sunlightScatteringLossFactor); + } + +#ifdef HAZE + // Haze pass + hazeColour.a = 1; + gl_FragColor = gl_FragColor * (1 - haze) + hazeColour * haze; +#endif // HAZE +} \ No newline at end of file diff --git a/main/resources/SkyDomeFPCommon.h b/main/resources/SkyDomeFPCommon.h new file mode 100644 index 0000000..e186ecf --- /dev/null +++ b/main/resources/SkyDomeFPCommon.h @@ -0,0 +1,27 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +float bias (float b, float x) +{ + return pow (x, log (b) / log (0.5)); +} + +vec4 sunlightInscatter +( + vec4 sunColour, + float absorption, + float incidenceAngleCos, + float sunlightScatteringFactor +) +{ + float scatteredSunlight = bias (sunlightScatteringFactor * 0.5, incidenceAngleCos); + + sunColour = sunColour * (1 - absorption) * vec4 (0.9, 0.5, 0.09, 1); + + return sunColour * scatteredSunlight; +} + +float fogExp (float z, float density) { + return 1 - clamp (pow (2.71828, -z * density), 0, 1); +} diff --git a/main/resources/SkyDomeVP.glsl b/main/resources/SkyDomeVP.glsl new file mode 100644 index 0000000..bc6a8fc --- /dev/null +++ b/main/resources/SkyDomeVP.glsl @@ -0,0 +1,37 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform float lightAbsorption; + uniform mat4 worldViewProj; + uniform vec3 sunDirection; +) + +MAIN_PARAMETERS + IN(vec4 position, POSITION) + IN(vec4 normal, NORMAL) + IN(vec2 uv, TEXCOORD0) + + OUT(vec4 oCol, COLOR) + OUT(vec2 oUv, TEXCOORD0) + OUT(float incidenceAngleCos, TEXCOORD1) + OUT(float y, TEXCOORD2) + OUT(vec3 oNormal, TEXCOORD3) +MAIN_DECLARATION +{ + sunDirection = normalize (sunDirection); + normal = normalize (normal); + float cosine = dot (-sunDirection, normal); + incidenceAngleCos = -cosine; + + y = -sunDirection.y; + + gl_Position = mul (worldViewProj, position); + oCol = vec4 (1, 1, 1, 1); + oUv = uv; + oNormal = -normal.xyz; +} \ No newline at end of file diff --git a/main/resources/StarPointFP.glsl b/main/resources/StarPointFP.glsl new file mode 100644 index 0000000..7f9514b --- /dev/null +++ b/main/resources/StarPointFP.glsl @@ -0,0 +1,22 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 wvpMatrix; +) + +MAIN_PARAMETERS + IN(vec4 in_color, COLOR) + IN(vec2 in_texcoord, TEXCOORD0) +MAIN_DECLARATION +{ + gl_FragColor = in_color; + float sqlen = dot(in_texcoord, in_texcoord); + + // A gaussian bell of sorts. + gl_FragColor.a *= 1.5 * exp(-(sqlen * 8)); +} diff --git a/main/resources/StarPointVP.glsl b/main/resources/StarPointVP.glsl new file mode 100644 index 0000000..a3ea786 --- /dev/null +++ b/main/resources/StarPointVP.glsl @@ -0,0 +1,49 @@ +// This file is part of the Caelum project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution. + +OGRE_NATIVE_GLSL_VERSION_DIRECTIVE +#include + +OGRE_UNIFORMS( + uniform mat4 worldviewproj_matrix; + + // These params are in clipspace; not pixels + uniform float mag_scale; + uniform float mag0_size; + uniform float min_size; + uniform float max_size; + uniform float render_target_flipping; + + // width/height + uniform float aspect_ratio; +) + +MAIN_PARAMETERS + IN(vec4 in_position, POSITION) + IN(vec3 in_texcoord, TEXCOORD0) + + OUT(vec2 out_texcoord, TEXCOORD0) + OUT(vec4 out_color, COLOR) +MAIN_DECLARATION +{ + vec4 in_color = vec4(1, 1, 1, 1); + gl_Position = mul(worldviewproj_matrix, in_position); + out_texcoord = in_texcoord.xy; + + float magnitude = in_texcoord.z; + float size = exp(mag_scale * magnitude) * mag0_size; + + // Fade below minSize. + float fade = saturate(size / min_size); + out_color = vec4(in_color.rgb, fade * fade); + + // Clamp size to range. + size = clamp(size, min_size, max_size); + + // Splat the billboard on the screen. + gl_Position.xy += + gl_Position.w * + in_texcoord.xy * + vec2(size, size * aspect_ratio * render_target_flipping); +} \ No newline at end of file diff --git a/main/resources/moon.material b/main/resources/moon.material index 8c0d556..24bb70c 100644 --- a/main/resources/moon.material +++ b/main/resources/moon.material @@ -2,11 +2,10 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -fragment_program Caelum/PhaseMoonFP cg +fragment_program Caelum/PhaseMoonFP glsl hlsl { - source CaelumPhaseMoon.cg - entry_point PhaseMoonFP - profiles ps_2_0 arbfp1 fp30 glslf + source PhaseMoonFP.glsl + //profiles ps_2_0 arbfp1 fp30 glslf default_params { @@ -14,10 +13,9 @@ fragment_program Caelum/PhaseMoonFP cg } } -vertex_program Caelum/PhaseMoonVP cg +vertex_program Caelum/PhaseMoonVP glsl hlsl { - source CaelumPhaseMoon.cg - entry_point PhaseMoonVP + source PhaseMoonVP.glsl profiles vs_2_0 arbvp1 glslv default_params diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 36e31da..1fbad89 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,8 +1,8 @@ configure_file(${CMAKE_SOURCE_DIR}/cmake/resources.cfg.in ${CMAKE_SOURCE_DIR}/bin/resources.cfg) -add_executable(CaelumDemo ${CMAKE_SOURCE_DIR}/samples/src/CaelumDemo.cpp) -target_link_libraries(CaelumDemo PRIVATE Caelum OgreBites) +add_executable(CaelumDemo ${CMAKE_SOURCE_DIR}/samples/src/CaelumDemo.cpp) +target_link_libraries(CaelumDemo PRIVATE Caelum OgreBites OgreTerrain) target_include_directories(CaelumDemo PRIVATE ${CMAKE_SOURCE_DIR}/samples/include) add_executable(CaelumTest ${CMAKE_SOURCE_DIR}/samples/src/CaelumTest.cpp) diff --git a/samples/include/CaelumDemo.h b/samples/include/CaelumDemo.h index 61f608d..3514a67 100644 --- a/samples/include/CaelumDemo.h +++ b/samples/include/CaelumDemo.h @@ -4,6 +4,7 @@ #include "CaelumDemoCommon.h" #include "ExampleApplication.h" +#include "LegacyTerrainLoader.h" class CaelumSampleFrameListener : public OgreBites::InputListener { @@ -133,13 +134,13 @@ class CaelumSampleApplication : public ExampleApplication void createScene () { - mSceneMgr->getRootSceneNode()->attachObject( - mSceneMgr->createEntity("House", "TudorHouse.mesh")); - // needs porting to new terrain system -#if 0 + + SceneNode* houseNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); + houseNode->setPosition(Vector3 (775, 60, 1150)); + houseNode->setScale(0.05, 0.05, 0.05); + houseNode->yaw(Degree(45)); + houseNode->attachObject(mSceneMgr->createEntity("House", "TudorHouse.mesh")); // Put some terrain in the scene - std::string terrain_cfg("CaelumDemoTerrain.cfg"); - mSceneMgr->setWorldGeometry (terrain_cfg); -#endif + loadLegacyTerrain("CaelumDemoTerrain.cfg", mSceneMgr); } }; diff --git a/samples/include/ExampleApplication.h b/samples/include/ExampleApplication.h index 9a6a341..1663965 100644 --- a/samples/include/ExampleApplication.h +++ b/samples/include/ExampleApplication.h @@ -25,6 +25,7 @@ Description: Base class for all the OGRE examples #include "OgreConfigFile.h" #include #include +#include using namespace Ogre; @@ -67,8 +68,7 @@ class ExampleApplication : public OgreBites::ApplicationContext OgreBites::InputListener* mFrameListener; // These internal methods package up the stages in the startup process - /** Sets up the application - returns false if the user chooses to abandon configuration. */ - virtual void setup(void) + void setup(void) override { OgreBites::ApplicationContext::setup(); @@ -86,6 +86,9 @@ class ExampleApplication : public OgreBites::ApplicationContext { // Create the SceneManager, in this case a generic one mSceneMgr = mRoot->createSceneManager("DefaultSceneManager", "ExampleSMInstance"); +#ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM + mShaderGenerator->addSceneManager(mSceneMgr); +#endif } virtual void createCamera(void) { @@ -118,6 +121,13 @@ class ExampleApplication : public OgreBites::ApplicationContext Viewport* vp = getRenderWindow()->addViewport(mCamera); vp->setBackgroundColour(ColourValue(0,0,0)); +#ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM + // Make this viewport work with shader generator scheme. + vp->setMaterialScheme(MSN_SHADERGEN); + // update scheme for FFP supporting rendersystems + MaterialManager::getSingleton().setActiveScheme(vp->getMaterialScheme()); +#endif + // Alter the camera aspect ratio to match the viewport mCamera->setAspectRatio( Real(vp->getActualWidth()) / Real(vp->getActualHeight())); diff --git a/samples/include/LegacyTerrainLoader.h b/samples/include/LegacyTerrainLoader.h new file mode 100644 index 0000000..5825f3d --- /dev/null +++ b/samples/include/LegacyTerrainLoader.h @@ -0,0 +1,99 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd +Also see acknowledgements in Readme.html + +You may use this sample code for anything you like, it is not covered by the +same license as the rest of the engine. +----------------------------------------------------------------------------- +*/ + +#include +#include +#include + +namespace Ogre +{ +class CustomMatGenerator : public Ogre::TerrainMaterialGenerator +{ + MaterialPtr mMaterial; + bool mIsInit; + bool mNormalMapRequired; +public: + CustomMatGenerator(const String& matName) : mIsInit(false), mNormalMapRequired(true) + { + auto terrainGlobals = TerrainGlobalOptions::getSingletonPtr(); + mMaterial = + MaterialManager::getSingleton().getByName(matName, terrainGlobals->getDefaultResourceGroup()); + } + + bool isVertexCompressionSupported() const { return false; } + + void setNormalMapRequired(bool enable) { mNormalMapRequired = enable; } + + MaterialPtr generate(const Terrain* terrain) + { + if (!mIsInit && mNormalMapRequired) + { + // Get default pass + Pass *p = mMaterial->getTechnique(0)->getPass(0); + + // Add terrain's global normalmap to renderpass so the fragment program can find it. + p->createTextureUnitState()->_setTexturePtr(terrain->getTerrainNormalMap()); + + } + mIsInit = true; + + return mMaterial; + } + MaterialPtr generateForCompositeMap(const Terrain* terrain) + { + return terrain->_getCompositeMapMaterial(); + } + void updateCompositeMap(const Terrain* terrain, const Rect& rect) {} + void setLightmapEnabled(bool enabled) {} + uint8 getMaxLayers(const Terrain* terrain) const { return 0; } + + void updateParams(const MaterialPtr& mat, const Terrain* terrain) {} + void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain) {} + void requestOptions(Terrain* terrain) + { + terrain->_setLightMapRequired(false); + terrain->_setCompositeMapRequired(false); + terrain->_setNormalMapRequired(mNormalMapRequired); + } +}; +} // namespace Ogre + +inline Ogre::TerrainGroup* loadLegacyTerrain(const Ogre::String& cfgFileName, Ogre::SceneManager* sceneMgr) +{ + using namespace Ogre; + + auto terrainGroup = new TerrainGroup(sceneMgr); + + ConfigFile cfg; + cfg.loadFromResourceSystem(cfgFileName, terrainGroup->getResourceGroup()); + + auto terrainGlobals = TerrainGlobalOptions::getSingletonPtr(); + if(!terrainGlobals) + terrainGlobals = new TerrainGlobalOptions(); + + const String& customMatName = cfg.getSetting("CustomMaterialName"); + + if(!customMatName.empty()) + { + auto generator = new CustomMatGenerator(customMatName); + generator->setNormalMapRequired(StringConverter::parseBool(cfg.getSetting("VertexNormals"))); + terrainGlobals->setDefaultMaterialGenerator(Ogre::TerrainMaterialGeneratorPtr(generator)); + } + +#if OGRE_VERSION >= ((1 << 16) | (11 << 8) | 6) + terrainGroup->loadLegacyTerrain(cfg); +#endif + + return terrainGroup; +} diff --git a/samples/resources/CaelumSample.cg b/samples/resources/CaelumSample.cg deleted file mode 100644 index 1eaa0cb..0000000 --- a/samples/resources/CaelumSample.cg +++ /dev/null @@ -1,233 +0,0 @@ -// This file is part of the Caelum project. -// It is subject to the license terms in the LICENSE file found in the top-level directory -// of this distribution. - -void PssmShadowCasterVP -( - float4 iPosition : POSITION, -#if PSSM_SHADOW_CASTER_PROPAGATE_ALPHA - in float2 iTexCoord : TEXCOORD0, -#endif - - uniform float4x4 wvpMat, - -#if PSSM_SHADOW_CASTER_PROPAGATE_ALPHA - out float2 oTexCoord : TEXCOORD1, -#endif - out float2 oDepth : TEXCOORD0, - out float4 oPosition : POSITION -) -{ - // this is the view space position - oPosition = mul(wvpMat, iPosition); - - // depth info for the fragment. - oDepth.x = oPosition.z; - oDepth.y = oPosition.w; - -#if PSSM_SHADOW_CASTER_PROPAGATE_ALPHA - // Careful: texture coordinate is moved from TEXCOORD0 to TEXCOORD1 - oTexCoord = iTexCoord; -#endif - - // clamp z to zero. seem to do the trick. :-/ - //oPosition.z = max(oPosition.z, 0); -} - -void PssmShadowCasterFP -( - in float2 depth : TEXCOORD0, -#if PSSM_SHADOW_CASTER_PROPAGATE_ALPHA - in float2 texCoord : TEXCOORD1, - uniform sampler2D mainTexture : register(s0), -#endif - - uniform float4 pssmSplitPoints, - - out float4 oColour : COLOR -) -{ - float finalDepth = depth.x / depth.y; -#if PSSM_SHADOW_CASTER_PROPAGATE_ALPHA - float4 texColour = tex2D (mainTexture, texCoord.xy); - oColour = float4(finalDepth, finalDepth, finalDepth, texColour.a); -#else - oColour = float4(finalDepth, finalDepth, finalDepth, 1); -#endif -} - -float shadowPCF(sampler2D shadowMap, float4 shadowMapPos, float2 offset, float shadowBias) -{ - shadowMapPos = shadowMapPos / shadowMapPos.w; - - float2 uv = shadowMapPos.xy; - float4 o = float4(offset, -offset) * 0.3f; - - float compValue = shadowMapPos.z + shadowBias; - - float result = 0; - result += (compValue <= tex2D(shadowMap, uv.xy + o.xy).r) ? 1 : 0; - result += (compValue <= tex2D(shadowMap, uv.xy + o.xw).r) ? 1 : 0; - result += (compValue <= tex2D(shadowMap, uv.xy + o.zy).r) ? 1 : 0; - result += (compValue <= tex2D(shadowMap, uv.xy + o.zw).r) ? 1 : 0; - return result / 4; -} - -// Vertex program entry point. -void MainVP -( - in float4 iPosition : POSITION, - in float2 iTexCoord : TEXCOORD0, - in float4 iNormal : NORMAL, - -#if PSSM - uniform float4x4 texWorldViewProjMatrix0, - uniform float4x4 texWorldViewProjMatrix1, - uniform float4x4 texWorldViewProjMatrix2, -#endif - uniform float4x4 worldviewproj_matrix, - uniform float4x4 inverse_transpose_worldview_matrix, - -#if PSSM - out float4 oLightPosition2 : TEXCOORD5, - out float4 oLightPosition1 : TEXCOORD4, - out float4 oLightPosition0 : TEXCOORD3, - out float oSplitPoint : TEXCOORD2, -#endif - out float2 oTexCoord : TEXCOORD0, - out float3 oNormal : TEXCOORD1, - out float4 oPosition : POSITION -) { - oPosition = mul(worldviewproj_matrix, iPosition); - oTexCoord = iTexCoord; - oNormal = normalize(mul(inverse_transpose_worldview_matrix, iNormal).xyz); - -#if PSSM - // Split point is eye-space z. - oSplitPoint = oPosition.z; - - // Calculate the position of vertex in light space - oLightPosition0 = mul(texWorldViewProjMatrix0, iPosition); - oLightPosition1 = mul(texWorldViewProjMatrix1, iPosition); - oLightPosition2 = mul(texWorldViewProjMatrix2, iPosition); -#endif -} - -// Fragment program entry point. -void MainFP -( - in float2 iTexcoord : TEXCOORD0, - in float3 iNormal : TEXCOORD1, - -#if PSSM - in float iSplitPoint : TEXCOORD2, - in float4 iLightPosition0 : TEXCOORD3, - in float4 iLightPosition1 : TEXCOORD4, - in float4 iLightPosition2 : TEXCOORD5, -#endif - -#if PSSM - uniform float4 invShadowMapSize0, - uniform float4 invShadowMapSize1, - uniform float4 invShadowMapSize2, - uniform float4 pssmSplitPoints, - uniform float shadowBias, - - uniform sampler2D shadowMap0 : register(s0), - uniform sampler2D shadowMap2 : register(s2), - uniform sampler2D shadowMap1 : register(s1), - uniform sampler mainTexture : register(s3), - #if TERRAIN - uniform sampler detailTexture : register(s4), - #endif -#else - uniform sampler mainTexture : register(s0), - #if TERRAIN - uniform sampler detailTexture : register(s1), - #endif -#endif - -#if AMBIENT - uniform float4 derived_scene_colour, -#endif - - uniform float4 surface_diffuse_colour, - -#if ONE_LIGHT - uniform float4 light_position_view_space, - uniform float4 derived_light_diffuse_colour, -#endif - -#if TWO_LIGHTS - uniform float4 light_position_view_space_0, - uniform float4 derived_light_diffuse_colour_0, - uniform float4 light_position_view_space_1, - uniform float4 derived_light_diffuse_colour_1, -#endif - - out float4 oColour : COLOR -) -{ - // Initialize to 0; then accumulate. - oColour = float4(0, 0, 0, 0); - - // calculate shadow - float shadowing = 1.0f; -#if PSSM - float4 splitColour; - if (iSplitPoint <= pssmSplitPoints.y) { - splitColour = float4(0.1, 0, 0, 1); - shadowing = shadowPCF(shadowMap0, iLightPosition0, invShadowMapSize0.xy, shadowBias); - } else if (iSplitPoint <= pssmSplitPoints.z) { - splitColour = float4(0, 0.1, 0, 1); - shadowing = shadowPCF(shadowMap1, iLightPosition1, invShadowMapSize1.xy, shadowBias); - } else { - splitColour = float4(0.1, 0.1, 0, 1); - shadowing = shadowPCF(shadowMap2, iLightPosition2, invShadowMapSize2.xy, shadowBias); - } - - // Can check that splitting is done correctly: - //oColour += splitColour; -#endif - -#if TERRAIN - // Modulate two scaled textures. - float4 baseColour = - tex2D(mainTexture, iTexcoord * 20) * - tex2D(detailTexture, iTexcoord * 100); -#else - float4 baseColour = tex2D(mainTexture, iTexcoord); -#endif - -#if AMBIENT - oColour += baseColour * derived_scene_colour; -#endif - -#if ONE_LIGHT - float3 normal = normalize(iNormal); - - float diffuse_factor = max(0, dot(float4(normal, 1), light_position_view_space)); - float4 light_colour = diffuse_factor * derived_light_diffuse_colour * shadowing; - - oColour += baseColour * light_colour; -#endif - -#if TWO_LIGHTS - float3 normal = normalize(iNormal); - - // Accumulate two lights - float4 light_colour = float4(0, 0, 0, 0); - - float diffuse_factor_0 = max(0, dot(float4(normal, 1), light_position_view_space_0)); - light_colour += diffuse_factor_0 * derived_light_diffuse_colour_0 * shadowing; - - float diffuse_factor_1 = max(0, dot(float4(normal, 1), light_position_view_space_1)); - light_colour += diffuse_factor_1 * derived_light_diffuse_colour_1 * shadowing; - - oColour += light_colour * baseColour; -#endif - - // In the OpenGL fixed function lighting output alpha is ALWAYS equal to material alpha - // That is a very sensible mode of operation; duplicate that. - oColour.a = surface_diffuse_colour.a * baseColour.a; -} diff --git a/samples/resources/CaelumSample.material b/samples/resources/CaelumSample.material index e49e26d..5a19d50 100644 --- a/samples/resources/CaelumSample.material +++ b/samples/resources/CaelumSample.material @@ -2,214 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution. -vertex_program CaelumSample/PSSM/ShadowCaster/VP cg -{ - source CaelumSample.cg - profiles vs_1_1 arbvp1 - entry_point PssmShadowCasterVP - compile_arguments -DPSSM_SHADOW_CASTER_PROPAGATE_ALPHA=1 - - default_params - { - param_named_auto wvpMat worldviewproj_matrix - } -} - -fragment_program CaelumSample/PSSM/ShadowCaster/FP cg -{ - source CaelumSample.cg - profiles ps_2_0 arbfp1 - entry_point PssmShadowCasterFP - compile_arguments -DPSSM_SHADOW_CASTER_PROPAGATE_ALPHA=1 - - default_params - { - } -} - -// Default shadow caster. -// -// Ogre will automatically adjust this material for culling and alpha-rejection for each pass -// -// This material fetches alpha from the first texture and passes it through -// in order for alpha rejection to work. This happens even for materials that -// don't use alpha rejection and for texture-less materials; even though it is -// not necesarry in those cases; and sub-optimal. Doing things the optimal way -// would a large number of shadow_caster_material instances; perhaps generated -// at runtime. -material CaelumSample/PSSM/ShadowCaster -{ - technique - { - pass - { - // See: http://www.ogre3d.org/phpBB2/viewtopic.php?t=44817 - fog_override true - - vertex_program_ref CaelumSample/PSSM/ShadowCaster/VP - { - } - - fragment_program_ref CaelumSample/PSSM/ShadowCaster/FP - { - } - } - } -} - -vertex_program CaelumSample/BasicVP cg -{ - source CaelumSample.cg - entry_point MainVP - profiles vs_2_0 arbvp1 glslv - compile_arguments -DAMBIENT=1 -DTWO_LIGHTS=1 - default_params - { - param_named_auto worldviewproj_matrix worldviewproj_matrix - param_named_auto inverse_transpose_worldview_matrix inverse_transpose_worldview_matrix - } -} - -fragment_program CaelumSample/BasicFP cg -{ - source CaelumSample.cg - entry_point MainFP - profiles ps_2_x arbfp1 glslf - compile_arguments -DAMBIENT=1 -DTWO_LIGHTS=1 - - default_params - { - param_named_auto surface_diffuse_colour surface_diffuse_colour - param_named_auto derived_scene_colour derived_scene_colour - param_named_auto light_position_view_space_0 light_position_view_space 0 - param_named_auto light_position_view_space_1 light_position_view_space 1 - param_named_auto derived_light_diffuse_colour_0 derived_light_diffuse_colour 0 - param_named_auto derived_light_diffuse_colour_1 derived_light_diffuse_colour 1 - } -} - -fragment_program CaelumSample/BasicFP/Terrain cg -{ - source CaelumSample.cg - entry_point MainFP - profiles ps_2_x arbfp1 - compile_arguments -DTERRAIN=1 -DAMBIENT=1 -DTWO_LIGHTS=1 - - default_params - { - param_named_auto surface_diffuse_colour surface_diffuse_colour - param_named_auto derived_scene_colour derived_scene_colour - param_named_auto light_position_view_space_0 light_position_view_space 0 - param_named_auto light_position_view_space_1 light_position_view_space 1 - param_named_auto derived_light_diffuse_colour_0 derived_light_diffuse_colour 0 - param_named_auto derived_light_diffuse_colour_1 derived_light_diffuse_colour 1 - } -} - -vertex_program CaelumSample/PSSM/AmbientVP cg -{ - source CaelumSample.cg - profiles vs_1_1 arbvp1 - entry_point MainVP - compile_arguments -DPSSM=0 -DAMBIENT=1 - - default_params - { - param_named_auto worldviewproj_matrix worldviewproj_matrix - } -} - -fragment_program CaelumSample/PSSM/AmbientFP cg -{ - source CaelumSample.cg - profiles ps_2_x arbfp1 - entry_point MainFP - compile_arguments -DPSSM=0 -DAMBIENT=1 - - default_params - { - param_named_auto surface_diffuse_colour surface_diffuse_colour - param_named_auto derived_scene_colour derived_scene_colour - } -} - -fragment_program CaelumSample/PSSM/AmbientFP/Terrain cg -{ - source CaelumSample.cg - profiles ps_2_x arbfp1 - entry_point MainFP - compile_arguments -DPSSM=0 -DAMBIENT=1 -DTERRAIN=1 - - default_params - { - param_named_auto surface_diffuse_colour surface_diffuse_colour - param_named_auto derived_scene_colour derived_scene_colour - } -} - -vertex_program CaelumSample/PSSM/OneLightVP cg -{ - source CaelumSample.cg - profiles vs_1_1 arbvp1 - entry_point MainVP - compile_arguments -DPSSM=1 -DONE_LIGHT=1 - - default_params - { - param_named_auto worldviewproj_matrix worldviewproj_matrix - param_named_auto inverse_transpose_worldview_matrix inverse_transpose_worldview_matrix - - param_named_auto texWorldViewProjMatrix0 texture_worldviewproj_matrix 0 - param_named_auto texWorldViewProjMatrix1 texture_worldviewproj_matrix 1 - param_named_auto texWorldViewProjMatrix2 texture_worldviewproj_matrix 2 - } -} - -fragment_program CaelumSample/PSSM/OneLightFP cg -{ - source CaelumSample.cg - profiles ps_2_x arbfp1 - entry_point MainFP - compile_arguments -DPSSM=1 -DONE_LIGHT=1 - - default_params - { - param_named_auto surface_diffuse_colour surface_diffuse_colour - param_named_auto invShadowMapSize0 inverse_texture_size 0 - param_named_auto invShadowMapSize1 inverse_texture_size 1 - param_named_auto invShadowMapSize2 inverse_texture_size 2 - - param_named_auto light_position_view_space light_position_view_space 0 - param_named_auto derived_light_diffuse_colour derived_light_diffuse_colour 0 - - param_named pssmSplitPoints float4 0 0 0 0 - // 0 by default; only used for materials which don't cull backfaces. - param_named shadowBias float 0 - } -} - -fragment_program CaelumSample/PSSM/OneLightFP/Terrain cg -{ - source CaelumSample.cg - profiles ps_2_x arbfp1 - entry_point MainFP - compile_arguments -DPSSM=1 -DONE_LIGHT=1 -DTERRAIN - - default_params - { - param_named_auto surface_diffuse_colour surface_diffuse_colour - param_named_auto invShadowMapSize0 inverse_texture_size 0 - param_named_auto invShadowMapSize1 inverse_texture_size 1 - param_named_auto invShadowMapSize2 inverse_texture_size 2 - - param_named_auto light_position_view_space light_position_view_space 0 - param_named_auto derived_light_diffuse_colour derived_light_diffuse_colour 0 - - param_named pssmSplitPoints float4 0 0 0 0 - param_named shadowBias float 0 - } -} // Base material for Caelum samples // @@ -237,14 +30,6 @@ abstract material CaelumSample/Base specular $SpecularColour emissive $EmissiveColour fog_override true none - - vertex_program_ref CaelumSample/BasicVP - { - } - - fragment_program_ref CaelumSample/BasicFP - { - } texture_unit Main { @@ -253,87 +38,6 @@ abstract material CaelumSample/Base } } } - - technique PSSM - { - scheme PSSM - - pass Ambient - { - fog_override true none - - illumination_stage ambient - ambient $AmbientColour - diffuse $DiffuseColour - specular 0 0 0 0 0 - emissive $EmissiveColour - - vertex_program_ref CaelumSample/PSSM/AmbientVP - { - } - - fragment_program_ref CaelumSample/PSSM/AmbientFP - { - } - - texture_unit Main - { - tex_coord_set 0 - texture $AmbientDiffuseTexture - } - } - - pass Directional - { - fog_override true none - - illumination_stage per_light - max_lights 2 - iteration once_per_light directional - - scene_blend add - - ambient 0 0 0 0 - diffuse $DiffuseColour - specular $SpecularColour - emissive 0 0 0 0 - - vertex_program_ref CaelumSample/PSSM/OneLightVP - { - } - - fragment_program_ref CaelumSample/PSSM/OneLightFP - { - } - - texture_unit shadow_tex0 - { - content_type shadow - tex_address_mode clamp - tex_coord_set 0 - } - - texture_unit shadow_tex1 - { - content_type shadow - tex_address_mode clamp - tex_coord_set 1 - } - - texture_unit shadow_tex2 - { - content_type shadow - tex_address_mode clamp - tex_coord_set 2 - } - - texture_unit Main - { - tex_coord_set 3 - texture $AmbientDiffuseTexture - } - } - } } abstract material CaelumSample/AlphaRejectionBase: CaelumSample/Base @@ -347,25 +51,6 @@ abstract material CaelumSample/AlphaRejectionBase: CaelumSample/Base } } - technique PSSM - { - pass Ambient - { - cull_hardware none - alpha_rejection greater_equal 128 - } - - pass Directional - { - fragment_program_ref * - { - param_named shadowBias float -0.0001 - } - cull_hardware none - alpha_rejection greater_equal 128 - } - } - technique CaelumDepth { scheme CaelumDepth @@ -406,25 +91,6 @@ abstract material CaelumSample/AlphaBlendBase: CaelumSample/Base } } - technique PSSM - { - pass Ambient - { - cull_hardware none - depth_write off - - scene_blend src_alpha one_minus_src_alpha - } - - pass Directional - { - cull_hardware none - depth_write off - - scene_blend src_alpha one - } - } - technique CaelumDepth { scheme CaelumDepth @@ -439,17 +105,10 @@ abstract material CaelumSample/AlphaBlendBase: CaelumSample/Base // Terrain material is special; it has a custom vp/fp and an additional texture. material CaelumSample/Terrain: CaelumSample/Base { - // Silence warnings about unset variables. - set $AmbientDiffuseTexture "terrain_dirt-grass.jpg" - technique Default { pass Main { - fragment_program_ref CaelumSample/BasicFP/Terrain - { - } - texture_unit Main { texture terrain_dirt-grass.jpg @@ -464,67 +123,7 @@ material CaelumSample/Terrain: CaelumSample/Base } } - technique PSSM - { - pass Ambient - { - fragment_program_ref CaelumSample/PSSM/AmbientFP/Terrain - { - } - - texture_unit Main - { - texture terrain_dirt-grass.jpg - tex_coord_set 0 - } - - texture_unit TerrainDetail - { - texture terrain_detail.jpg - tex_coord_set 1 - } - } - - pass Directional - { - fragment_program_ref CaelumSample/PSSM/OneLightFP/Terrain - { - } - - texture_unit shadow_tex0 - { - content_type shadow - tex_address_mode clamp - tex_coord_set 0 - } - - texture_unit shadow_tex1 - { - content_type shadow - tex_address_mode clamp - tex_coord_set 1 - } - - texture_unit shadow_tex2 - { - content_type shadow - tex_address_mode clamp - tex_coord_set 2 - } - - texture_unit Main - { - texture terrain_dirt-grass.jpg - tex_coord_set 3 - } - - texture_unit TerrainDetail - { - texture terrain_detail.jpg - tex_coord_set 4 - } - } - } + } // Materials used in various sample models.