From 2e9f0981581c30d13d2283f6b8e2dbd6e4db5bc3 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sat, 16 Feb 2019 17:21:33 +0100 Subject: [PATCH 01/16] restore terrain in sample using LegacyTerrainLoader --- samples/include/CaelumDemo.h | 15 ++-- samples/include/LegacyTerrainLoader.h | 99 +++++++++++++++++++++++++++ samples/resources/CaelumSample.cg | 13 ++-- 3 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 samples/include/LegacyTerrainLoader.h 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/LegacyTerrainLoader.h b/samples/include/LegacyTerrainLoader.h new file mode 100644 index 0000000..e94ec36 --- /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 CustomMatProfile : public Ogre::TerrainMaterialGenerator::Profile +{ + MaterialPtr mMaterial; + bool mIsInit; + bool mNormalMapRequired; +public: + CustomMatProfile(const String& matName) : Profile(NULL, "", ""), 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 profile = new CustomMatProfile(customMatName); + profile->setNormalMapRequired(StringConverter::parseBool(cfg.getSetting("VertexNormals"))); + terrainGlobals->getDefaultMaterialGenerator()->setActiveProfile(profile); + } + +#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 index 1eaa0cb..cce6301 100644 --- a/samples/resources/CaelumSample.cg +++ b/samples/resources/CaelumSample.cg @@ -144,6 +144,7 @@ void MainFP uniform sampler mainTexture : register(s0), #if TERRAIN uniform sampler detailTexture : register(s1), + uniform sampler normalTexture : register(s2), #endif #endif @@ -203,9 +204,15 @@ void MainFP oColour += baseColour * derived_scene_colour; #endif -#if ONE_LIGHT - float3 normal = normalize(iNormal); +#if ONE_LIGHT || TWO_LIGHTS + #if TERRAIN + float3 normal = tex2D(normalTexture, iTexcoord).rgb * 2 - 1; + #else + float3 normal = normalize(iNormal); + #endif +#endif +#if ONE_LIGHT float diffuse_factor = max(0, dot(float4(normal, 1), light_position_view_space)); float4 light_colour = diffuse_factor * derived_light_diffuse_colour * shadowing; @@ -213,8 +220,6 @@ void MainFP #endif #if TWO_LIGHTS - float3 normal = normalize(iNormal); - // Accumulate two lights float4 light_colour = float4(0, 0, 0, 0); From 14b18ff5ee2b05f9dcdd7d771bafd16251226e47 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 01:20:49 +0200 Subject: [PATCH 02/16] Fixed CaelumDemo to build & run with OGRE 14.4+ --- samples/CMakeLists.txt | 4 ++-- samples/include/ExampleApplication.h | 14 ++++++++++++-- samples/include/LegacyTerrainLoader.h | 10 +++++----- 3 files changed, 19 insertions(+), 9 deletions(-) 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/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 index e94ec36..5825f3d 100644 --- a/samples/include/LegacyTerrainLoader.h +++ b/samples/include/LegacyTerrainLoader.h @@ -18,13 +18,13 @@ same license as the rest of the engine. namespace Ogre { -class CustomMatProfile : public Ogre::TerrainMaterialGenerator::Profile +class CustomMatGenerator : public Ogre::TerrainMaterialGenerator { MaterialPtr mMaterial; bool mIsInit; bool mNormalMapRequired; public: - CustomMatProfile(const String& matName) : Profile(NULL, "", ""), mIsInit(false), mNormalMapRequired(true) + CustomMatGenerator(const String& matName) : mIsInit(false), mNormalMapRequired(true) { auto terrainGlobals = TerrainGlobalOptions::getSingletonPtr(); mMaterial = @@ -86,9 +86,9 @@ inline Ogre::TerrainGroup* loadLegacyTerrain(const Ogre::String& cfgFileName, Og if(!customMatName.empty()) { - auto profile = new CustomMatProfile(customMatName); - profile->setNormalMapRequired(StringConverter::parseBool(cfg.getSetting("VertexNormals"))); - terrainGlobals->getDefaultMaterialGenerator()->setActiveProfile(profile); + 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) From 66532aa6847709fe215781c155572282f3c7e851 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 14:15:52 +0200 Subject: [PATCH 03/16] WIP MinimalCompositorVP --- ...mpositorVP.cg => MinimalCompositorVP.glsl} | 21 +++++++++++-------- main/resources/MinimalCompositorVP.program | 6 ++---- 2 files changed, 14 insertions(+), 13 deletions(-) rename main/resources/{MinimalCompositorVP.cg => MinimalCompositorVP.glsl} (56%) diff --git a/main/resources/MinimalCompositorVP.cg b/main/resources/MinimalCompositorVP.glsl similarity index 56% rename from main/resources/MinimalCompositorVP.cg rename to main/resources/MinimalCompositorVP.glsl index 902d289..e7cefc1 100644 --- a/main/resources/MinimalCompositorVP.cg +++ b/main/resources/MinimalCompositorVP.glsl @@ -2,22 +2,25 @@ // 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) + OUT(vec4 out_pos, POSITION) +MAIN_DECLARATION { // Use standard transform. out_pos = 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 { From a8373885895da73b571ae8dc80c3c8a7295d6ef3 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 15:12:27 +0200 Subject: [PATCH 04/16] WIP DepthRender --- main/resources/DepthRender.program | 24 +++++++-------- .../DepthRenderAlphaRejectionFP.glsl | 21 ++++++++++++++ .../DepthRenderAlphaRejectionVP.glsl | 29 +++++++++++++++++++ main/resources/DepthRenderFP.glsl | 15 ++++++++++ main/resources/DepthRenderVP.glsl | 23 +++++++++++++++ 5 files changed, 98 insertions(+), 14 deletions(-) create mode 100644 main/resources/DepthRenderAlphaRejectionFP.glsl create mode 100644 main/resources/DepthRenderAlphaRejectionVP.glsl create mode 100644 main/resources/DepthRenderFP.glsl create mode 100644 main/resources/DepthRenderVP.glsl 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..73174dd --- /dev/null +++ b/main/resources/DepthRenderAlphaRejectionFP.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 SAMPLER2D mainTex +) + +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(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..d0794ac --- /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..2153b59 --- /dev/null +++ b/main/resources/DepthRenderFP.glsl @@ -0,0 +1,15 @@ +// 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 +{ + gl_FragColor = vec4(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..5844284 --- /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 outPos. + magic = outPos; +} \ No newline at end of file From c6c66c51191c45ba3d879564a6f935f615debbbd Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 15:12:46 +0200 Subject: [PATCH 05/16] WIP DepthComposer --- main/resources/DepthComposer.material | 61 ++++---- main/resources/DepthComposerMainFP.glsl | 176 ++++++++++++++++++++++++ 2 files changed, 204 insertions(+), 33 deletions(-) create mode 100644 main/resources/DepthComposerMainFP.glsl diff --git a/main/resources/DepthComposer.material b/main/resources/DepthComposer.material index 89bdb27..6dbbb54 100644 --- a/main/resources/DepthComposer.material +++ b/main/resources/DepthComposer.material @@ -2,88 +2,83 @@ // 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 - profiles ps_3_0 arbfp1 + source DepthComposerMainFP.glsl + //profiles ps_3_0 arbfp1 default_params { } } -fragment_program Caelum/DepthComposerFP_DebugDepthRender cg +fragment_program Caelum/DepthComposerFP_DebugDepthRender glsl hlsl { - source DepthComposer.cg - entry_point MainFP - profiles ps_3_0 arbfp1 + source DepthComposerMainFP.glsl + //profiles ps_3_0 arbfp1 compile_arguments -DDEBUG_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 mat4 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 - profiles ps_3_0 arbfp1 + source DepthComposerMainFP.glsl + //profiles ps_3_0 arbfp1 compile_arguments -DEXP_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 mat4 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 worldCameraPos vec4 0 0 0 0 param_named groundFogDensity float 0.1 param_named groundFogVerticalDecay float 0.2 param_named groundFogBaseLevel float 5 - param_named groundFogColour float4 1 0 1 1 + param_named groundFogColour vec4 1 0 1 1 } } -fragment_program Caelum/DepthComposerFP_SkyDomeHaze cg +fragment_program Caelum/DepthComposerFP_SkyDomeHaze glsl hlsl { - source DepthComposer.cg - entry_point MainFP - profiles ps_3_0 arbfp1 + source DepthComposerMainFP.glsl + //profiles ps_3_0 arbfp1 compile_arguments -DSKY_DOME_HAZE=1 -DHAZE_DEPTH_TEXTURE=s2 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 mat4 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 worldCameraPos vec4 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 - profiles ps_3_0 arbfp1 + source DepthComposerMainFP.glsl + //profiles ps_3_0 arbfp1 compile_arguments -DEXP_GROUND_FOG=1 -DSKY_DOME_HAZE=1 -DHAZE_DEPTH_TEXTURE=s2 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 mat4 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 worldCameraPos vec4 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 param_named groundFogBaseLevel float 5 - param_named groundFogColour float4 1 0 1 1 + param_named groundFogColour vec4 1 0 1 1 } } diff --git a/main/resources/DepthComposerMainFP.glsl b/main/resources/DepthComposerMainFP.glsl new file mode 100644 index 0000000..37cf458 --- /dev/null +++ b/main/resources/DepthComposerMainFP.glsl @@ -0,0 +1,176 @@ +// 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. + +#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 - tex1D (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 + +//void MainFP +OGRE_UNIFORMS( + uniform SAMPLER2D screenTexture //: register(s0), + uniform SAMPLER2D depthTexture //: register(s1), + uniform SAMPLER1D atmRelativeDepth // : register(HAZE_DEPTH_TEXTURE); + + 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 +) + +MAIN_PARAMETERS + IN(float2 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; +} + + + From e04459d061f9079feff8183002ac8cc420c77ddb Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 15:29:40 +0200 Subject: [PATCH 06/16] WIP SkyDome --- main/resources/CaelumSkyDomeFPCommon.h | 27 +++++++++++++ main/resources/SkyDome.material | 21 +++++----- main/resources/SkyDomeFP.glsl | 55 ++++++++++++++++++++++++++ main/resources/SkyDomeVP.glsl | 37 +++++++++++++++++ 4 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 main/resources/CaelumSkyDomeFPCommon.h create mode 100644 main/resources/SkyDomeFP.glsl create mode 100644 main/resources/SkyDomeVP.glsl diff --git a/main/resources/CaelumSkyDomeFPCommon.h b/main/resources/CaelumSkyDomeFPCommon.h new file mode 100644 index 0000000..e186ecf --- /dev/null +++ b/main/resources/CaelumSkyDomeFPCommon.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/SkyDome.material b/main/resources/SkyDome.material index 66e496e..299f6fc 100644 --- a/main/resources/SkyDome.material +++ b/main/resources/SkyDome.material @@ -2,12 +2,11 @@ // 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 + source SkyDomeFP.glsl compile_arguments -DHAZE - profiles ps_2_0 arbfp1 + //profiles ps_2_0 arbfp1 default_params { @@ -17,11 +16,10 @@ fragment_program CaelumSkyDomeFP cg } } -fragment_program CaelumSkyDomeFP_NoHaze cg +fragment_program CaelumSkyDomeFP_NoHaze glsl hlsl { - source CaelumSkyDome.cg - entry_point SkyDomeFP - profiles ps_2_0 arbfp1 + 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..8e95e8b --- /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 //: register(s0), + uniform SAMPLER1D atmRelativeDepth //: register(s1), + uniform vec4 hazeColour + uniform float offset +) + +MAIN_PARAMETERS + IN(vec4 col, COLOR) + IN(float2 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 + oCol = tex2D (gradientsMap, uv + float2 (offset, 0)) * col; + + // Sunlight inscatter + if (incidenceAngleCos > 0) + { + float sunlightScatteringFactor = 0.05; + float sunlightScatteringLossFactor = 0.1; + float atmLightAbsorptionFactor = 0.1; + + oCol.rgb += sunlightInscatter ( + sunColour, + clamp (atmLightAbsorptionFactor * (1 - tex1D (atmRelativeDepth, y).r), 0, 1), + clamp (incidenceAngleCos, 0, 1), + sunlightScatteringFactor).rgb * (1 - sunlightScatteringLossFactor); + } + +#ifdef HAZE + // Haze pass + hazeColour.a = 1; + oCol = oCol * (1 - haze) + hazeColour * haze; +#endif // HAZE +} \ No newline at end of file diff --git a/main/resources/SkyDomeVP.glsl b/main/resources/SkyDomeVP.glsl new file mode 100644 index 0000000..f6c3c59 --- /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(float2 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 From c68fa68107dec72670aee9d0aa547edbd76255bb Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 15:45:16 +0200 Subject: [PATCH 07/16] WIP Haze --- main/resources/Haze.program | 14 +++++----- main/resources/HazeFP.glsl | 54 +++++++++++++++++++++++++++++++++++++ main/resources/HazeVP.glsl | 27 +++++++++++++++++++ 3 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 main/resources/HazeFP.glsl create mode 100644 main/resources/HazeVP.glsl diff --git a/main/resources/Haze.program b/main/resources/Haze.program index 6dac8fb..cf8e5c3 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,11 +14,10 @@ vertex_program CaelumHazeVP cg } } -fragment_program CaelumHazeFP cg +fragment_program CaelumHazeFP glsl hlsl { - source CaelumSkyDome.cg - entry_point HazeFP - profiles ps_2_0 arbfp1 fp30 + 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..fadcc7d --- /dev/null +++ b/main/resources/HazeFP.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 + +OGRE_UNIFORMS( + uniform SAMPLER1D atmRelativeDepth //: register(s0), + uniform SAMPLER2D gradientsMap //: register (s1), + uniform vec4 fogColour +) + +MAIN_PARAMETERS + IN(float haze, TEXCOORD0) + IN(float2 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 - tex1D (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..6bbbba7 --- /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(float2 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 From 9575cbe6cf8decd1a77fa3d3f832710ae82428b2 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 15:58:56 +0200 Subject: [PATCH 08/16] WIP Precipitation --- main/resources/Precipitation.material | 14 +++-- main/resources/PrecipitationMainFP.glsl | 71 +++++++++++++++++++++++++ main/resources/PrecipitationMainVP.glsl | 23 ++++++++ 3 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 main/resources/PrecipitationMainFP.glsl create mode 100644 main/resources/PrecipitationMainVP.glsl diff --git a/main/resources/Precipitation.material b/main/resources/Precipitation.material index 68db11c..b3c1a91 100644 --- a/main/resources/Precipitation.material +++ b/main/resources/Precipitation.material @@ -2,22 +2,20 @@ // 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 - profiles ps_3_0 fp40 arbfp1 + source PrecipitationMainFP.glsl + //profiles ps_3_0 fp40 arbfp1 default_params { } } -vertex_program Caelum/PrecipitationVP cg +vertex_program Caelum/PrecipitationVP glsl hlsl { - source Precipitation.cg - entry_point MainVP - profiles vs_3_0 vp40 arbvp1 + 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..11c845d --- /dev/null +++ b/main/resources/PrecipitationMainFP.glsl @@ -0,0 +1,71 @@ +// 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//: register(s0); + uniform SAMPLER2D samplerPrec//: register(s1); + + 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 +float2 CylindricalCoordinates(vec4 dir) { + float R = 0.5; + float2 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 + ( + float2 cCoords, + float intensity, + float2 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 = (float2(in_pos.x, -in_pos.y) + 1.0f) * 0.5f; +} From f090dbda3b4a95a9bc5720617a10ffbd9ce4b989 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 16:47:33 +0200 Subject: [PATCH 09/16] WIP GroundFog --- main/resources/GroundFog.program | 28 +++++++-------- main/resources/GroundFogDomeFP.glsl | 52 +++++++++++++++++++++++++++ main/resources/GroundFogDomeVP.glsl | 19 ++++++++++ main/resources/GroundFogFP.glsl | 54 +++++++++++++++++++++++++++++ main/resources/GroundFogVP.glsl | 20 +++++++++++ 5 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 main/resources/GroundFogDomeFP.glsl create mode 100644 main/resources/GroundFogDomeVP.glsl create mode 100644 main/resources/GroundFogFP.glsl create mode 100644 main/resources/GroundFogVP.glsl 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..531b0a6 --- /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..bc6bb3d --- /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..9010068 --- /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..cfb14f5 --- /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 From d7f966d933272a1caacb47770130f799d5daf638 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 17:09:30 +0200 Subject: [PATCH 10/16] WIP LayeredClouds --- main/resources/LayeredClouds.material | 14 +-- main/resources/LayeredCloudsFP.glsl | 173 ++++++++++++++++++++++++++ main/resources/LayeredCloudsVP.glsl | 36 ++++++ 3 files changed, 215 insertions(+), 8 deletions(-) create mode 100644 main/resources/LayeredCloudsFP.glsl create mode 100644 main/resources/LayeredCloudsVP.glsl diff --git a/main/resources/LayeredClouds.material b/main/resources/LayeredClouds.material index ecb13e3..2d1be35 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 glslv 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 glslf default_params { diff --git a/main/resources/LayeredCloudsFP.glsl b/main/resources/LayeredCloudsFP.glsl new file mode 100644 index 0000000..0e4dcc3 --- /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 //: register(s0); + uniform SAMPLER2D cloud_shape2 //: register(s1); + uniform SAMPLER2D cloud_detail //: register(s2); + + uniform float cloudMassInvScale + uniform float cloudDetailInvScale + uniform float2 cloudMassOffset + uniform float2 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 float2 pos, + float cloudMassInvScale, + float cloudDetailInvScale, + float2 cloudMassOffset, + float2 cloudDetailOffset, + float cloudMassBlend, + float cloudDetailBlend, + float cloudCoverageThreshold +) +{ + // Calculate the base alpha + float2 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 +( + float2 uv, + vec3 relPosition, + float sunGlow, + + float cloudMassInvScale, + float cloudDetailInvScale, + float2 cloudMassOffset, + float2 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(float2 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..08eb941 --- /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(float2 uv, TEXCOORD0) + + OUT(float2 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 From f207e4958f32fa533fc0f83de0b2b96c96a5e3c0 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 17:15:14 +0200 Subject: [PATCH 11/16] WIP PhaseMoon --- main/resources/PhaseMoonFP.glsl | 46 +++++++++++++++++++++++++++++++++ main/resources/PhaseMoonVP.glsl | 21 +++++++++++++++ main/resources/moon.material | 12 ++++----- 3 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 main/resources/PhaseMoonFP.glsl create mode 100644 main/resources/PhaseMoonVP.glsl diff --git a/main/resources/PhaseMoonFP.glsl b/main/resources/PhaseMoonFP.glsl new file mode 100644 index 0000000..0771ea6 --- /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 //: register(s0), +) + +// 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(float2 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 + int(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..a5f6331 --- /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/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 From 7b9a852c43ce1f764156affcde29eed3cd2f7ea3 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 17:23:23 +0200 Subject: [PATCH 12/16] WIP StarPoint --- main/resources/PointStarfield.material | 14 ++++---- main/resources/StarPointFP.glsl | 22 ++++++++++++ main/resources/StarPointVP.glsl | 49 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 main/resources/StarPointFP.glsl create mode 100644 main/resources/StarPointVP.glsl 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/StarPointFP.glsl b/main/resources/StarPointFP.glsl new file mode 100644 index 0000000..7961c72 --- /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..1d8bdc3 --- /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(float2 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 * + float2(size, size * aspect_ratio * render_target_flipping); +} \ No newline at end of file From e6fddfe741f805572196de88494b4465266e7754 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 18:38:16 +0200 Subject: [PATCH 13/16] Shader compile errors --- main/resources/DepthComposer.material | 4 +- main/resources/DepthComposerMainFP.glsl | 46 +++++++-------- .../DepthRenderAlphaRejectionFP.glsl | 2 +- .../DepthRenderAlphaRejectionVP.glsl | 2 +- main/resources/DepthRenderFP.glsl | 3 +- main/resources/DepthRenderVP.glsl | 6 +- main/resources/GroundFogDomeFP.glsl | 10 ++-- main/resources/GroundFogDomeVP.glsl | 2 +- main/resources/GroundFogFP.glsl | 10 ++-- main/resources/GroundFogVP.glsl | 4 +- main/resources/HazeFP.glsl | 7 ++- main/resources/HazeVP.glsl | 6 +- main/resources/LayeredCloudsFP.glsl | 56 +++++++++---------- main/resources/LayeredCloudsVP.glsl | 6 +- main/resources/MinimalCompositorVP.glsl | 5 +- main/resources/PhaseMoonFP.glsl | 4 +- main/resources/PhaseMoonVP.glsl | 2 +- main/resources/PrecipitationMainFP.glsl | 4 +- main/resources/PrecipitationMainVP.glsl | 2 +- main/resources/SkyDomeFP.glsl | 8 +-- ...lumSkyDomeFPCommon.h => SkyDomeFPCommon.h} | 0 main/resources/SkyDomeVP.glsl | 20 +++---- main/resources/StarPointFP.glsl | 2 +- main/resources/StarPointVP.glsl | 14 ++--- 24 files changed, 114 insertions(+), 111 deletions(-) rename main/resources/{CaelumSkyDomeFPCommon.h => SkyDomeFPCommon.h} (100%) diff --git a/main/resources/DepthComposer.material b/main/resources/DepthComposer.material index 6dbbb54..d6f41ff 100644 --- a/main/resources/DepthComposer.material +++ b/main/resources/DepthComposer.material @@ -47,7 +47,7 @@ fragment_program Caelum/DepthComposerFP_SkyDomeHaze glsl hlsl { source DepthComposerMainFP.glsl //profiles ps_3_0 arbfp1 - compile_arguments -DSKY_DOME_HAZE=1 -DHAZE_DEPTH_TEXTURE=s2 + compile_arguments -DSKY_DOME_HAZE=1 default_params { @@ -64,7 +64,7 @@ fragment_program Caelum/DepthComposerFP_SkyDomeHaze_ExpGroundFog glsl hlsl { source DepthComposerMainFP.glsl //profiles ps_3_0 arbfp1 - compile_arguments -DEXP_GROUND_FOG=1 -DSKY_DOME_HAZE=1 -DHAZE_DEPTH_TEXTURE=s2 + compile_arguments -DEXP_GROUND_FOG=1 -DSKY_DOME_HAZE=1 default_params { diff --git a/main/resources/DepthComposerMainFP.glsl b/main/resources/DepthComposerMainFP.glsl index 37cf458..7480755 100644 --- a/main/resources/DepthComposerMainFP.glsl +++ b/main/resources/DepthComposerMainFP.glsl @@ -2,6 +2,30 @@ // 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. @@ -102,28 +126,6 @@ vec4 CalcHaze #endif // SKY_DOME_HAZE -//void MainFP -OGRE_UNIFORMS( - uniform SAMPLER2D screenTexture //: register(s0), - uniform SAMPLER2D depthTexture //: register(s1), - uniform SAMPLER1D atmRelativeDepth // : register(HAZE_DEPTH_TEXTURE); - - 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 -) - MAIN_PARAMETERS IN(float2 screenPos, TEXCOORD0) MAIN_DECLARATION diff --git a/main/resources/DepthRenderAlphaRejectionFP.glsl b/main/resources/DepthRenderAlphaRejectionFP.glsl index 73174dd..99eeb71 100644 --- a/main/resources/DepthRenderAlphaRejectionFP.glsl +++ b/main/resources/DepthRenderAlphaRejectionFP.glsl @@ -6,7 +6,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform SAMPLER2D mainTex + uniform SAMPLER2D(mainTex, 0); ) MAIN_PARAMETERS diff --git a/main/resources/DepthRenderAlphaRejectionVP.glsl b/main/resources/DepthRenderAlphaRejectionVP.glsl index d0794ac..83c38a3 100644 --- a/main/resources/DepthRenderAlphaRejectionVP.glsl +++ b/main/resources/DepthRenderAlphaRejectionVP.glsl @@ -6,7 +6,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 wvpMatrix + uniform mat4 wvpMatrix; ) MAIN_PARAMETERS diff --git a/main/resources/DepthRenderFP.glsl b/main/resources/DepthRenderFP.glsl index 2153b59..5531f01 100644 --- a/main/resources/DepthRenderFP.glsl +++ b/main/resources/DepthRenderFP.glsl @@ -9,7 +9,8 @@ MAIN_PARAMETERS IN(vec4 magic, TEXCOORD0) MAIN_DECLARATION { - gl_FragColor = vec4(magic.z / magic.w); + //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 index 5844284..2d63797 100644 --- a/main/resources/DepthRenderVP.glsl +++ b/main/resources/DepthRenderVP.glsl @@ -6,7 +6,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 wvpMatrix + uniform mat4 wvpMatrix; ) MAIN_PARAMETERS @@ -18,6 +18,6 @@ MAIN_DECLARATION gl_Position = mul(wvpMatrix, inPos); // Depth buffer is z/w. - // Let the GPU lerp the components of outPos. - magic = outPos; + // Let the GPU lerp the components of gl_Position. + magic = gl_Position; } \ No newline at end of file diff --git a/main/resources/GroundFogDomeFP.glsl b/main/resources/GroundFogDomeFP.glsl index 531b0a6..3ea5f46 100644 --- a/main/resources/GroundFogDomeFP.glsl +++ b/main/resources/GroundFogDomeFP.glsl @@ -16,11 +16,11 @@ float ExpGroundFogInf ( OGRE_UNIFORMS( - uniform float cameraHeight - uniform vec4 fogColour - uniform float fogDensity - uniform float fogVerticalDecay - uniform float fogGroundLevel + uniform float cameraHeight; + uniform vec4 fogColour; + uniform float fogDensity; + uniform float fogVerticalDecay; + uniform float fogGroundLevel; ) MAIN_PARAMETERS diff --git a/main/resources/GroundFogDomeVP.glsl b/main/resources/GroundFogDomeVP.glsl index bc6bb3d..f95308a 100644 --- a/main/resources/GroundFogDomeVP.glsl +++ b/main/resources/GroundFogDomeVP.glsl @@ -6,7 +6,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 worldViewProj + uniform mat4 worldViewProj; ) MAIN_PARAMETERS diff --git a/main/resources/GroundFogFP.glsl b/main/resources/GroundFogFP.glsl index 9010068..947a8f1 100644 --- a/main/resources/GroundFogFP.glsl +++ b/main/resources/GroundFogFP.glsl @@ -31,11 +31,11 @@ float ExpGroundFog ( } OGRE_UNIFORMS( - uniform vec3 camPos - uniform vec4 fogColour - uniform float fogDensity - uniform float fogVerticalDecay - uniform float fogGroundLevel + uniform vec3 camPos; + uniform vec4 fogColour; + uniform float fogDensity; + uniform float fogVerticalDecay; + uniform float fogGroundLevel; ) MAIN_PARAMETERS diff --git a/main/resources/GroundFogVP.glsl b/main/resources/GroundFogVP.glsl index cfb14f5..c1177ae 100644 --- a/main/resources/GroundFogVP.glsl +++ b/main/resources/GroundFogVP.glsl @@ -6,8 +6,8 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 worldViewProj - uniform mat4 world + uniform mat4 worldViewProj; + uniform mat4 world; ) MAIN_PARAMETERS diff --git a/main/resources/HazeFP.glsl b/main/resources/HazeFP.glsl index fadcc7d..a1ab9d2 100644 --- a/main/resources/HazeFP.glsl +++ b/main/resources/HazeFP.glsl @@ -4,11 +4,12 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include +#include OGRE_UNIFORMS( - uniform SAMPLER1D atmRelativeDepth //: register(s0), - uniform SAMPLER2D gradientsMap //: register (s1), - uniform vec4 fogColour + uniform SAMPLER2D(atmRelativeDepth, 0); // ~ changed from sampler1D + uniform SAMPLER2D(gradientsMap, 1); + uniform vec4 fogColour; ) MAIN_PARAMETERS diff --git a/main/resources/HazeVP.glsl b/main/resources/HazeVP.glsl index 6bbbba7..b4f37d8 100644 --- a/main/resources/HazeVP.glsl +++ b/main/resources/HazeVP.glsl @@ -6,9 +6,9 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 worldViewProj - uniform vec4 camPos - uniform vec3 sunDirection + uniform mat4 worldViewProj; + uniform vec4 camPos; + uniform vec3 sunDirection; ) MAIN_PARAMETERS diff --git a/main/resources/LayeredCloudsFP.glsl b/main/resources/LayeredCloudsFP.glsl index 0e4dcc3..eb17c42 100644 --- a/main/resources/LayeredCloudsFP.glsl +++ b/main/resources/LayeredCloudsFP.glsl @@ -7,34 +7,34 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE OGRE_UNIFORMS( // Global cloud textures - uniform SAMPLER2D cloud_shape1 //: register(s0); - uniform SAMPLER2D cloud_shape2 //: register(s1); - uniform SAMPLER2D cloud_detail //: register(s2); - - uniform float cloudMassInvScale - uniform float cloudDetailInvScale - uniform float2 cloudMassOffset - uniform float2 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 + uniform SAMPLER2D(cloud_shape1, 0); + uniform SAMPLER2D(cloud_shape2, 1); + uniform SAMPLER2D(cloud_detail, 2); + + uniform float cloudMassInvScale; + uniform float cloudDetailInvScale; + uniform float2 cloudMassOffset; + uniform float2 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. diff --git a/main/resources/LayeredCloudsVP.glsl b/main/resources/LayeredCloudsVP.glsl index 08eb941..1d97f1a 100644 --- a/main/resources/LayeredCloudsVP.glsl +++ b/main/resources/LayeredCloudsVP.glsl @@ -6,9 +6,9 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 worldViewProj - uniform mat4 worldMatrix - uniform vec3 sunDirection + uniform mat4 worldViewProj; + uniform mat4 worldMatrix; + uniform vec3 sunDirection; ) MAIN_PARAMETERS diff --git a/main/resources/MinimalCompositorVP.glsl b/main/resources/MinimalCompositorVP.glsl index e7cefc1..67f4b6a 100644 --- a/main/resources/MinimalCompositorVP.glsl +++ b/main/resources/MinimalCompositorVP.glsl @@ -8,17 +8,16 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE // Fixed function does not always work. // This is a the minimal compositor VP required. OGRE_UNIFORMS( - uniform mat4 worldviewproj_matrix + uniform mat4 worldviewproj_matrix; ) MAIN_PARAMETERS IN(vec4 in_pos, POSITION) OUT(vec2 out_uv0, TEXCOORD0) - OUT(vec4 out_pos, POSITION) 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); diff --git a/main/resources/PhaseMoonFP.glsl b/main/resources/PhaseMoonFP.glsl index 0771ea6..4c38915 100644 --- a/main/resources/PhaseMoonFP.glsl +++ b/main/resources/PhaseMoonFP.glsl @@ -6,8 +6,8 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform float phase - uniform SAMPLER2D moonDisc //: register(s0), + 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. diff --git a/main/resources/PhaseMoonVP.glsl b/main/resources/PhaseMoonVP.glsl index a5f6331..b70afcc 100644 --- a/main/resources/PhaseMoonVP.glsl +++ b/main/resources/PhaseMoonVP.glsl @@ -6,7 +6,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 worldviewproj_matrix + uniform mat4 worldviewproj_matrix; ) MAIN_PARAMETERS diff --git a/main/resources/PrecipitationMainFP.glsl b/main/resources/PrecipitationMainFP.glsl index 11c845d..0951fc5 100644 --- a/main/resources/PrecipitationMainFP.glsl +++ b/main/resources/PrecipitationMainFP.glsl @@ -6,8 +6,8 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform SAMPLER2D scene//: register(s0); - uniform SAMPLER2D samplerPrec//: register(s1); + uniform SAMPLER2D(scene, 0); + uniform SAMPLER2D(samplerPrec, 0); uniform float intensity; uniform vec4 ambient_light_colour; diff --git a/main/resources/PrecipitationMainVP.glsl b/main/resources/PrecipitationMainVP.glsl index 6c5d2b4..5eb0778 100644 --- a/main/resources/PrecipitationMainVP.glsl +++ b/main/resources/PrecipitationMainVP.glsl @@ -6,7 +6,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 worldviewproj_matrix + uniform mat4 worldviewproj_matrix; ) MAIN_PARAMETERS diff --git a/main/resources/SkyDomeFP.glsl b/main/resources/SkyDomeFP.glsl index 8e95e8b..59fe28e 100644 --- a/main/resources/SkyDomeFP.glsl +++ b/main/resources/SkyDomeFP.glsl @@ -7,10 +7,10 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform SAMPLER2D gradientsMap //: register(s0), - uniform SAMPLER1D atmRelativeDepth //: register(s1), - uniform vec4 hazeColour - uniform float offset + uniform SAMPLER2D(gradientsMap, 0); + uniform SAMPLER2D(atmRelativeDepth, 1); ~ changed from sampler1D + uniform vec4 hazeColour; + uniform float offset; ) MAIN_PARAMETERS diff --git a/main/resources/CaelumSkyDomeFPCommon.h b/main/resources/SkyDomeFPCommon.h similarity index 100% rename from main/resources/CaelumSkyDomeFPCommon.h rename to main/resources/SkyDomeFPCommon.h diff --git a/main/resources/SkyDomeVP.glsl b/main/resources/SkyDomeVP.glsl index f6c3c59..bc6a8fc 100644 --- a/main/resources/SkyDomeVP.glsl +++ b/main/resources/SkyDomeVP.glsl @@ -6,21 +6,21 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform float lightAbsorption - uniform mat4 worldViewProj - uniform vec3 sunDirection + uniform float lightAbsorption; + uniform mat4 worldViewProj; + uniform vec3 sunDirection; ) MAIN_PARAMETERS IN(vec4 position, POSITION) - IN(vec4 normal : NORMAL) - IN(float2 uv : TEXCOORD0, + 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) + 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); diff --git a/main/resources/StarPointFP.glsl b/main/resources/StarPointFP.glsl index 7961c72..7f9514b 100644 --- a/main/resources/StarPointFP.glsl +++ b/main/resources/StarPointFP.glsl @@ -6,7 +6,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 wvpMatrix + uniform mat4 wvpMatrix; ) MAIN_PARAMETERS diff --git a/main/resources/StarPointVP.glsl b/main/resources/StarPointVP.glsl index 1d8bdc3..6ec57b2 100644 --- a/main/resources/StarPointVP.glsl +++ b/main/resources/StarPointVP.glsl @@ -6,17 +6,17 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE #include OGRE_UNIFORMS( - uniform mat4 worldviewproj_matrix, + 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, + 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, + uniform float aspect_ratio; ) MAIN_PARAMETERS From 896d551c0ebadb4902d87916fbc23eb6c2c0a5a5 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 20:07:34 +0200 Subject: [PATCH 14/16] Shader/material fixes --- main/resources/DepthComposer.material | 26 +++++++++---------- main/resources/DepthComposerMainFP.glsl | 4 +-- .../DepthRenderAlphaRejectionFP.glsl | 3 +-- main/resources/Haze.program | 2 +- main/resources/HazeFP.glsl | 4 +-- main/resources/HazeVP.glsl | 2 +- main/resources/LayeredCloudsFP.glsl | 20 +++++++------- main/resources/LayeredCloudsVP.glsl | 4 +-- main/resources/PhaseMoonFP.glsl | 4 +-- main/resources/PrecipitationMainFP.glsl | 19 +++++++------- main/resources/PrecipitationMainVP.glsl | 2 +- main/resources/SkyDomeFP.glsl | 12 ++++----- main/resources/StarPointVP.glsl | 4 +-- 13 files changed, 53 insertions(+), 53 deletions(-) diff --git a/main/resources/DepthComposer.material b/main/resources/DepthComposer.material index d6f41ff..d27f971 100644 --- a/main/resources/DepthComposer.material +++ b/main/resources/DepthComposer.material @@ -16,11 +16,11 @@ fragment_program Caelum/DepthComposerFP_DebugDepthRender glsl hlsl { 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 mat4 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 } } @@ -28,18 +28,18 @@ fragment_program Caelum/DepthComposerFP_ExpGroundFog glsl hlsl { 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 mat4 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 vec4 0 0 0 0 + param_named worldCameraPos float4 0 0 0 0 param_named groundFogDensity float 0.1 param_named groundFogVerticalDecay float 0.2 param_named groundFogBaseLevel float 5 - param_named groundFogColour vec4 1 0 1 1 + param_named groundFogColour float4 1 0 1 1 } } @@ -47,13 +47,13 @@ fragment_program Caelum/DepthComposerFP_SkyDomeHaze glsl hlsl { source DepthComposerMainFP.glsl //profiles ps_3_0 arbfp1 - compile_arguments -DSKY_DOME_HAZE=1 + preprocessor_defines SKY_DOME_HAZE=1 default_params { - param_named invViewProjMatrix mat4 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 vec4 0 0 0 0 + param_named worldCameraPos float4 0 0 0 0 param_named sunDirection vec3 0 1 0 param_named hazeColour vec3 0.1 0.2 0.6 @@ -64,13 +64,13 @@ fragment_program Caelum/DepthComposerFP_SkyDomeHaze_ExpGroundFog glsl hlsl { source DepthComposerMainFP.glsl //profiles ps_3_0 arbfp1 - compile_arguments -DEXP_GROUND_FOG=1 -DSKY_DOME_HAZE=1 + preprocessor_defines EXP_GROUND_FOG=1,SKY_DOME_HAZE=1 default_params { - param_named invViewProjMatrix mat4 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 vec4 0 0 0 0 + param_named worldCameraPos float4 0 0 0 0 param_named sunDirection vec3 0 1 0 param_named hazeColour vec3 0.1 0.2 0.6 @@ -78,7 +78,7 @@ fragment_program Caelum/DepthComposerFP_SkyDomeHaze_ExpGroundFog glsl hlsl param_named groundFogDensity float 0.1 param_named groundFogVerticalDecay float 0.2 param_named groundFogBaseLevel float 5 - param_named groundFogColour vec4 1 0 1 1 + param_named groundFogColour float4 1 0 1 1 } } diff --git a/main/resources/DepthComposerMainFP.glsl b/main/resources/DepthComposerMainFP.glsl index 7480755..1b2a64d 100644 --- a/main/resources/DepthComposerMainFP.glsl +++ b/main/resources/DepthComposerMainFP.glsl @@ -113,7 +113,7 @@ vec4 CalcHaze vec4 sunlightInscatterColour = sunlightInscatter ( sunColour, - clamp ((1 - tex1D (atmRelativeDepth, y).r) * hazeAbsorption, 0, 1), + clamp ((1 - tex2D (atmRelativeDepth, y).r) * hazeAbsorption, 0, 1), clamp (incidenceAngleCos, 0, 1), sunlightScatteringFactor) * (1 - sunlightScatteringLossFactor); hazeColour = @@ -127,7 +127,7 @@ vec4 CalcHaze #endif // SKY_DOME_HAZE MAIN_PARAMETERS - IN(float2 screenPos, TEXCOORD0) + IN(vec2 screenPos, TEXCOORD0) MAIN_DECLARATION { vec4 inColor = tex2D(screenTexture, screenPos); diff --git a/main/resources/DepthRenderAlphaRejectionFP.glsl b/main/resources/DepthRenderAlphaRejectionFP.glsl index 99eeb71..d1f9a7b 100644 --- a/main/resources/DepthRenderAlphaRejectionFP.glsl +++ b/main/resources/DepthRenderAlphaRejectionFP.glsl @@ -12,10 +12,9 @@ OGRE_UNIFORMS( 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(magic.z / magic.w), texvalue.a); + gl_FragColor = vec4(vec3_splat(magic.z / magic.w), texvalue.a); } \ No newline at end of file diff --git a/main/resources/Haze.program b/main/resources/Haze.program index cf8e5c3..d5645d3 100644 --- a/main/resources/Haze.program +++ b/main/resources/Haze.program @@ -17,7 +17,7 @@ vertex_program CaelumHazeVP glsl hlsl fragment_program CaelumHazeFP glsl hlsl { source HazeFP.glsl - //profiles ps_2_0 arbfp1 fp30 + profiles ps_2_0 arbfp1 fp30 default_params { diff --git a/main/resources/HazeFP.glsl b/main/resources/HazeFP.glsl index a1ab9d2..ca4b426 100644 --- a/main/resources/HazeFP.glsl +++ b/main/resources/HazeFP.glsl @@ -14,7 +14,7 @@ OGRE_UNIFORMS( MAIN_PARAMETERS IN(float haze, TEXCOORD0) - IN(float2 sunlight, TEXCOORD1) + IN(vec2 sunlight, TEXCOORD1) MAIN_DECLARATION { float incidenceAngleCos = sunlight.x; @@ -42,7 +42,7 @@ MAIN_DECLARATION vec4 sunlightInscatterColour = sunlightInscatter ( sunColour, - clamp ((1 - tex1D (atmRelativeDepth, y).r) * hazeAbsorption, 0, 1), + clamp ((1 - tex2D (atmRelativeDepth, y).r) * hazeAbsorption, 0, 1), clamp (incidenceAngleCos, 0, 1), sunlightScatteringFactor) * (1 - sunlightScatteringLossFactor); hazeColour.rgb = diff --git a/main/resources/HazeVP.glsl b/main/resources/HazeVP.glsl index b4f37d8..9274917 100644 --- a/main/resources/HazeVP.glsl +++ b/main/resources/HazeVP.glsl @@ -16,7 +16,7 @@ MAIN_PARAMETERS IN(vec4 normal, NORMAL) OUT(float haze, TEXCOORD0) - OUT(float2 sunlight, TEXCOORD1) + OUT(vec2 sunlight, TEXCOORD1) MAIN_DECLARATION { sunDirection = normalize (sunDirection); diff --git a/main/resources/LayeredCloudsFP.glsl b/main/resources/LayeredCloudsFP.glsl index eb17c42..3a9e9d8 100644 --- a/main/resources/LayeredCloudsFP.glsl +++ b/main/resources/LayeredCloudsFP.glsl @@ -13,8 +13,8 @@ OGRE_UNIFORMS( uniform float cloudMassInvScale; uniform float cloudDetailInvScale; - uniform float2 cloudMassOffset; - uniform float2 cloudDetailOffset; + uniform vec2 cloudMassOffset; + uniform vec2 cloudDetailOffset; uniform float cloudMassBlend; uniform float cloudDetailBlend; @@ -40,18 +40,18 @@ OGRE_UNIFORMS( // Get cloud layer intensity at a certain point. float LayeredClouds_intensity ( - in float2 pos, + in vec2 pos, float cloudMassInvScale, float cloudDetailInvScale, - float2 cloudMassOffset, - float2 cloudDetailOffset, + vec2 cloudMassOffset, + vec2 cloudDetailOffset, float cloudMassBlend, float cloudDetailBlend, float cloudCoverageThreshold ) { // Calculate the base alpha - float2 finalMassOffset = cloudMassOffset + pos; + vec2 finalMassOffset = cloudMassOffset + pos; float aCloud = lerp(tex2D(cloud_shape1, finalMassOffset * cloudMassInvScale).r, tex2D(cloud_shape2, finalMassOffset * cloudMassInvScale).r, cloudMassBlend); @@ -62,14 +62,14 @@ float LayeredClouds_intensity vec4 OldCloudColor ( - float2 uv, + vec2 uv, vec3 relPosition, float sunGlow, float cloudMassInvScale, float cloudDetailInvScale, - float2 cloudMassOffset, - float2 cloudDetailOffset, + vec2 cloudMassOffset, + vec2 cloudDetailOffset, float cloudMassBlend, float cloudDetailBlend, @@ -135,7 +135,7 @@ vec3 MagicColorMix(vec3 col1, vec3 col2) } MAIN_PARAMETERS - IN(float2 uv, TEXCOORD0) + IN(vec2 uv, TEXCOORD0) IN(vec3 relPosition, TEXCOORD1) IN(float sunGlow, TEXCOORD2) IN(vec4 worldPosition, TEXCOORD3) diff --git a/main/resources/LayeredCloudsVP.glsl b/main/resources/LayeredCloudsVP.glsl index 1d97f1a..7c510ba 100644 --- a/main/resources/LayeredCloudsVP.glsl +++ b/main/resources/LayeredCloudsVP.glsl @@ -13,9 +13,9 @@ OGRE_UNIFORMS( MAIN_PARAMETERS IN(vec4 position, POSITION) - IN(float2 uv, TEXCOORD0) + IN(vec2 uv, TEXCOORD0) - OUT(float2 oUv, TEXCOORD0) + OUT(vec2 oUv, TEXCOORD0) OUT(vec3 relPosition, TEXCOORD1) OUT(float sunGlow, TEXCOORD2) OUT(vec4 worldPosition, TEXCOORD3) diff --git a/main/resources/PhaseMoonFP.glsl b/main/resources/PhaseMoonFP.glsl index 4c38915..6bc9beb 100644 --- a/main/resources/PhaseMoonFP.glsl +++ b/main/resources/PhaseMoonFP.glsl @@ -13,7 +13,7 @@ OGRE_UNIFORMS( // 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(float2 uv, float phase) +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 @@ -32,7 +32,7 @@ float MoonPhaseFactor(float2 uv, float phase) } MAIN_PARAMETERS - int(vec2 uv, TEXCOORD0) + IN(vec2 uv, TEXCOORD0) MAIN_DECLARATION { gl_FragColor = tex2D(moonDisc, uv); diff --git a/main/resources/PrecipitationMainFP.glsl b/main/resources/PrecipitationMainFP.glsl index 0951fc5..ab281e6 100644 --- a/main/resources/PrecipitationMainFP.glsl +++ b/main/resources/PrecipitationMainFP.glsl @@ -7,7 +7,7 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE OGRE_UNIFORMS( uniform SAMPLER2D(scene, 0); - uniform SAMPLER2D(samplerPrec, 0); + uniform SAMPLER2D(samplerPrec, 1); uniform float intensity; uniform vec4 ambient_light_colour; @@ -29,9 +29,9 @@ OGRE_UNIFORMS( ) // Cartesian to cylindrical coordinates -float2 CylindricalCoordinates(vec4 dir) { +vec2 CylindricalCoordinates(vec4 dir) { float R = 0.5; - float2 res; + vec2 res; //cubical root is used to counteract top/bottom circle effect dir *= R / pow(length(dir.xz), 0.33); res.y = -dir.y; @@ -43,9 +43,9 @@ float2 CylindricalCoordinates(vec4 dir) { // view_direction is the direction vector resulting from the eye direction,wind direction and possibly other factors float Precipitation ( - float2 cCoords, + vec2 cCoords, float intensity, - float2 delta + vec2 delta ) { cCoords -= delta; vec4 raincol = tex2D(samplerPrec, cCoords); @@ -55,16 +55,17 @@ float Precipitation MAIN_PARAMETERS IN(vec2 scr_pos, TEXCOORD0) MAIN_DECLARATION +{ vec4 eye = lerp ( lerp(corner1, corner3, scr_pos.y), lerp(corner2, corner4, scr_pos.y), scr_pos.x ) ; vec4 scenecol = tex2D(scene, scr_pos); - float2 cCoords = CylindricalCoordinates(eye); - float prec1 = Precipitation(cCoords, intensity/4, float2(deltaX.x,deltaY.x)); - float prec2 = Precipitation(cCoords, intensity/4, float2(deltaX.y,deltaY.y)); - float prec3 = Precipitation(cCoords, intensity/4, float2(deltaX.z,deltaY.z)); + vec2 cCoords = CylindricalCoordinates(eye); + float prec1 = Precipitation(cCoords, intensity/4, vec2(deltaX.x,deltaY.x)); + float prec2 = Precipitation(cCoords, intensity/4, vec2(deltaX.y,deltaY.y)); + float prec3 = Precipitation(cCoords, intensity/4, vec2(deltaX.z,deltaY.z)); float prec = min( min (prec1, prec2), prec3); gl_FragColor = lerp(precColor, scenecol, prec ); } diff --git a/main/resources/PrecipitationMainVP.glsl b/main/resources/PrecipitationMainVP.glsl index 5eb0778..0e9abe4 100644 --- a/main/resources/PrecipitationMainVP.glsl +++ b/main/resources/PrecipitationMainVP.glsl @@ -19,5 +19,5 @@ MAIN_DECLARATION // 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/SkyDomeFP.glsl b/main/resources/SkyDomeFP.glsl index 59fe28e..e9d2de7 100644 --- a/main/resources/SkyDomeFP.glsl +++ b/main/resources/SkyDomeFP.glsl @@ -8,14 +8,14 @@ OGRE_NATIVE_GLSL_VERSION_DIRECTIVE OGRE_UNIFORMS( uniform SAMPLER2D(gradientsMap, 0); - uniform SAMPLER2D(atmRelativeDepth, 1); ~ changed from sampler1D + uniform SAMPLER2D(atmRelativeDepth, 1); //~ changed from sampler1D uniform vec4 hazeColour; uniform float offset; ) MAIN_PARAMETERS IN(vec4 col, COLOR) - IN(float2 uv, TEXCOORD0) + IN(vec2 uv, TEXCOORD0) IN(float incidenceAngleCos, TEXCOORD1) IN(float y, TEXCOORD2) IN(vec3 normal, TEXCOORD3) @@ -31,7 +31,7 @@ MAIN_DECLARATION #endif // HAZE // Pass the colour - oCol = tex2D (gradientsMap, uv + float2 (offset, 0)) * col; + gl_FragColor = tex2D (gradientsMap, uv + vec2 (offset, 0)) * col; // Sunlight inscatter if (incidenceAngleCos > 0) @@ -40,9 +40,9 @@ MAIN_DECLARATION float sunlightScatteringLossFactor = 0.1; float atmLightAbsorptionFactor = 0.1; - oCol.rgb += sunlightInscatter ( + gl_FragColor.rgb += sunlightInscatter ( sunColour, - clamp (atmLightAbsorptionFactor * (1 - tex1D (atmRelativeDepth, y).r), 0, 1), + clamp (atmLightAbsorptionFactor * (1 - tex2D (atmRelativeDepth, y).r), 0, 1), clamp (incidenceAngleCos, 0, 1), sunlightScatteringFactor).rgb * (1 - sunlightScatteringLossFactor); } @@ -50,6 +50,6 @@ MAIN_DECLARATION #ifdef HAZE // Haze pass hazeColour.a = 1; - oCol = oCol * (1 - haze) + hazeColour * haze; + gl_FragColor = gl_FragColor * (1 - haze) + hazeColour * haze; #endif // HAZE } \ No newline at end of file diff --git a/main/resources/StarPointVP.glsl b/main/resources/StarPointVP.glsl index 6ec57b2..a3ea786 100644 --- a/main/resources/StarPointVP.glsl +++ b/main/resources/StarPointVP.glsl @@ -23,7 +23,7 @@ MAIN_PARAMETERS IN(vec4 in_position, POSITION) IN(vec3 in_texcoord, TEXCOORD0) - OUT(float2 out_texcoord, TEXCOORD0) + OUT(vec2 out_texcoord, TEXCOORD0) OUT(vec4 out_color, COLOR) MAIN_DECLARATION { @@ -45,5 +45,5 @@ MAIN_DECLARATION gl_Position.xy += gl_Position.w * in_texcoord.xy * - float2(size, size * aspect_ratio * render_target_flipping); + vec2(size, size * aspect_ratio * render_target_flipping); } \ No newline at end of file From 0ebf574eb217fdaba0b6263a2915464c6a29cc49 Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 20:43:29 +0200 Subject: [PATCH 15/16] Uncommented profiles again --- main/resources/DepthComposer.material | 10 +++++----- main/resources/LayeredClouds.material | 4 ++-- main/resources/Precipitation.material | 4 ++-- main/resources/SkyDome.material | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/main/resources/DepthComposer.material b/main/resources/DepthComposer.material index d27f971..42e0498 100644 --- a/main/resources/DepthComposer.material +++ b/main/resources/DepthComposer.material @@ -5,7 +5,7 @@ fragment_program Caelum/DepthComposerFP_Dummy glsl hlsl { source DepthComposerMainFP.glsl - //profiles ps_3_0 arbfp1 + profiles ps_3_0 arbfp1 default_params { @@ -15,7 +15,7 @@ fragment_program Caelum/DepthComposerFP_Dummy glsl hlsl fragment_program Caelum/DepthComposerFP_DebugDepthRender glsl hlsl { source DepthComposerMainFP.glsl - //profiles ps_3_0 arbfp1 + profiles ps_3_0 arbfp1 preprocessor_defines DEBUG_DEPTH_RENDER=1 default_params @@ -27,7 +27,7 @@ fragment_program Caelum/DepthComposerFP_DebugDepthRender glsl hlsl fragment_program Caelum/DepthComposerFP_ExpGroundFog glsl hlsl { source DepthComposerMainFP.glsl - //profiles ps_3_0 arbfp1 + profiles ps_3_0 arbfp1 preprocessor_defines EXP_GROUND_FOG=1 default_params @@ -46,7 +46,7 @@ fragment_program Caelum/DepthComposerFP_ExpGroundFog glsl hlsl fragment_program Caelum/DepthComposerFP_SkyDomeHaze glsl hlsl { source DepthComposerMainFP.glsl - //profiles ps_3_0 arbfp1 + profiles ps_3_0 arbfp1 preprocessor_defines SKY_DOME_HAZE=1 default_params @@ -63,7 +63,7 @@ fragment_program Caelum/DepthComposerFP_SkyDomeHaze glsl hlsl fragment_program Caelum/DepthComposerFP_SkyDomeHaze_ExpGroundFog glsl hlsl { source DepthComposerMainFP.glsl - //profiles ps_3_0 arbfp1 + profiles ps_3_0 arbfp1 preprocessor_defines EXP_GROUND_FOG=1,SKY_DOME_HAZE=1 default_params diff --git a/main/resources/LayeredClouds.material b/main/resources/LayeredClouds.material index 2d1be35..4ec06e8 100644 --- a/main/resources/LayeredClouds.material +++ b/main/resources/LayeredClouds.material @@ -5,7 +5,7 @@ vertex_program CaelumLayeredCloudsVP glsl hlsl { source LayeredCloudsVP.glsl - //profiles vs_3_0 vp40 arbvp1 glslv + profiles vs_3_0 vp40 arbvp1 default_params { @@ -18,7 +18,7 @@ vertex_program CaelumLayeredCloudsVP glsl hlsl fragment_program CaelumLayeredCloudsFP glsl hlsl { source LayeredCloudsFP.glsl - //profiles ps_3_0 fp40 arbfp1 glslf + profiles ps_3_0 fp40 arbfp1 default_params { diff --git a/main/resources/Precipitation.material b/main/resources/Precipitation.material index b3c1a91..8c9642a 100644 --- a/main/resources/Precipitation.material +++ b/main/resources/Precipitation.material @@ -5,7 +5,7 @@ fragment_program Caelum/PrecipitationFP glsl hlsl { source PrecipitationMainFP.glsl - //profiles ps_3_0 fp40 arbfp1 + profiles ps_3_0 fp40 arbfp1 default_params { @@ -15,7 +15,7 @@ fragment_program Caelum/PrecipitationFP glsl hlsl vertex_program Caelum/PrecipitationVP glsl hlsl { source PrecipitationMainVP.glsl - //profiles vs_3_0 vp40 arbvp1 + profiles vs_3_0 vp40 arbvp1 default_params { diff --git a/main/resources/SkyDome.material b/main/resources/SkyDome.material index 299f6fc..b4511a7 100644 --- a/main/resources/SkyDome.material +++ b/main/resources/SkyDome.material @@ -5,8 +5,8 @@ fragment_program CaelumSkyDomeFP glsl hlsl { source SkyDomeFP.glsl - compile_arguments -DHAZE - //profiles ps_2_0 arbfp1 + preprocessor_defines HAZE + profiles ps_2_0 arbfp1 default_params { @@ -19,7 +19,7 @@ fragment_program CaelumSkyDomeFP glsl hlsl fragment_program CaelumSkyDomeFP_NoHaze glsl hlsl { source SkyDomeFP.glsl - //profiles ps_2_0 arbfp1 + profiles ps_2_0 arbfp1 default_params { From fdcd3c26270bbc9f88d8c151ec4ae010454144ff Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Sun, 12 Oct 2025 20:47:00 +0200 Subject: [PATCH 16/16] Removed CaelumSample.cg (only Default materials left) --- samples/resources/CaelumSample.cg | 238 -------------- samples/resources/CaelumSample.material | 403 +----------------------- 2 files changed, 1 insertion(+), 640 deletions(-) delete mode 100644 samples/resources/CaelumSample.cg diff --git a/samples/resources/CaelumSample.cg b/samples/resources/CaelumSample.cg deleted file mode 100644 index cce6301..0000000 --- a/samples/resources/CaelumSample.cg +++ /dev/null @@ -1,238 +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), - uniform sampler normalTexture : register(s2), - #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 || TWO_LIGHTS - #if TERRAIN - float3 normal = tex2D(normalTexture, iTexcoord).rgb * 2 - 1; - #else - float3 normal = normalize(iNormal); - #endif -#endif - -#if ONE_LIGHT - 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 - // 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.