2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-10 03:47:42 +00:00

Initial fog rendering

This commit is contained in:
Jack Andersen
2016-08-07 18:48:18 -10:00
parent 9b9eed39f4
commit a910ddd912
16 changed files with 335 additions and 92 deletions

View File

@@ -5,6 +5,7 @@
#include "optional.hpp"
#include "zeus/CVector3f.hpp"
#include "zeus/CColor.hpp"
#include "Graphics/CGraphics.hpp"
#define URDE_MAX_LIGHTS 16
@@ -36,6 +37,7 @@ public:
Light lights[URDE_MAX_LIGHTS];
zeus::CColor ambient;
zeus::CColor colorRegs[3];
CGraphics::CFogState fog;
};
struct ThermalUniform

View File

@@ -13,6 +13,12 @@ static const char* LightingGLSL =
" vec4 linAtt;\n"
" vec4 angAtt;\n"
"};\n"
"struct Fog\n"
"{\n"
" vec4 color;\n"
" float rangeScale;\n"
" float start;\n"
"};\n"
"\n"
"UBINDING2 uniform LightingUniform\n"
"{\n"
@@ -21,6 +27,7 @@ static const char* LightingGLSL =
" vec4 colorReg0;\n"
" vec4 colorReg1;\n"
" vec4 colorReg2;\n"
" Fog fog;\n"
"};\n"
"\n"
"vec4 LightingFunc(vec4 mvPosIn, vec4 mvNormIn)\n"
@@ -44,6 +51,15 @@ static const char* LightingGLSL =
" return clamp(ret, vec4(0.0,0.0,0.0,0.0), vec4(1.0,1.0,1.0,1.0));\n"
"}\n";
static const char* MainPostGLSL =
"vec4 MainPostFunc(vec4 colorIn)\n"
"{\n"
" float fogZ = (vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" return vec4(fogZ, fogZ, fogZ, 1.0);\n"
" return mix(fog.color, colorIn, clamp(exp2(-8.0 * fogZ), 0.0, 1.0));\n"
"}\n"
"\n";
static const char* ThermalPostGLSL =
"UBINDING2 uniform ThermalUniform\n"
"{\n"
@@ -70,7 +86,7 @@ CModelShaders::GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat)
hecl::Runtime::ShaderCacheExtensions ext(plat);
/* Normal lit shading */
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {}, 3, BlockNames, 0, nullptr,
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, 3, BlockNames, 0, nullptr,
hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original);
/* Thermal Visor shading */