2016-04-04 02:32:57 +00:00
|
|
|
#include "CModelShaders.hpp"
|
2016-04-04 05:02:09 +00:00
|
|
|
#include "hecl/Backend/GLSL.hpp"
|
2016-04-04 02:32:57 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
static const char* LightingGLSL =
|
|
|
|
"struct Light\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 pos;\n"
|
|
|
|
" vec4 dir;\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
" vec4 linAtt;\n"
|
|
|
|
" vec4 angAtt;\n"
|
|
|
|
"};\n"
|
2016-08-08 04:48:18 +00:00
|
|
|
"struct Fog\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
" float rangeScale;\n"
|
|
|
|
" float start;\n"
|
|
|
|
"};\n"
|
2016-04-04 02:32:57 +00:00
|
|
|
"\n"
|
|
|
|
"UBINDING2 uniform LightingUniform\n"
|
|
|
|
"{\n"
|
|
|
|
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
|
|
|
|
" vec4 ambient;\n"
|
2016-07-21 05:21:45 +00:00
|
|
|
" vec4 colorReg0;\n"
|
|
|
|
" vec4 colorReg1;\n"
|
|
|
|
" vec4 colorReg2;\n"
|
2017-02-10 09:00:57 +00:00
|
|
|
" vec4 mulColor;\n"
|
2016-08-08 04:48:18 +00:00
|
|
|
" Fog fog;\n"
|
2016-04-04 02:32:57 +00:00
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"vec4 LightingFunc(vec4 mvPosIn, vec4 mvNormIn)\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 ret = ambient;\n"
|
|
|
|
" \n"
|
|
|
|
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" vec3 delta = mvPosIn.xyz - lights[i].pos.xyz;\n"
|
|
|
|
" float dist = length(delta);\n"
|
2016-04-04 05:02:09 +00:00
|
|
|
" float angDot = clamp(dot(normalize(delta), lights[i].dir.xyz), 0.0, 1.0);\n"
|
2016-04-04 02:32:57 +00:00
|
|
|
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
|
|
|
|
" lights[i].linAtt[1] * dist +\n"
|
|
|
|
" lights[i].linAtt[0]);\n"
|
|
|
|
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
|
|
|
|
" lights[i].angAtt[1] * angDot +\n"
|
|
|
|
" lights[i].angAtt[0];\n"
|
2016-04-04 05:02:09 +00:00
|
|
|
" ret += lights[i].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn.xyz), 0.0, 1.0);\n"
|
2016-04-04 02:32:57 +00:00
|
|
|
" }\n"
|
|
|
|
" \n"
|
|
|
|
" return clamp(ret, vec4(0.0,0.0,0.0,0.0), vec4(1.0,1.0,1.0,1.0));\n"
|
|
|
|
"}\n";
|
|
|
|
|
2017-10-01 04:26:46 +00:00
|
|
|
static const char* LightingShadowGLSL =
|
|
|
|
"struct Light\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 pos;\n"
|
|
|
|
" vec4 dir;\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
" 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"
|
|
|
|
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
|
|
|
|
" vec4 ambient;\n"
|
|
|
|
" vec4 colorReg0;\n"
|
|
|
|
" vec4 colorReg1;\n"
|
|
|
|
" vec4 colorReg2;\n"
|
|
|
|
" vec4 mulColor;\n"
|
|
|
|
" Fog fog;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"vec4 LightingShadowFunc(vec4 mvPosIn, vec4 mvNormIn)\n"
|
|
|
|
"{\n"
|
2018-01-16 06:42:28 +00:00
|
|
|
" vec2 shadowUV = vtf.extTcgs[0];\n"
|
|
|
|
" shadowUV.y = 1.0 - shadowUV.y;\n"
|
|
|
|
" \n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" vec4 ret = ambient;\n"
|
|
|
|
" \n"
|
2017-10-15 05:44:07 +00:00
|
|
|
" vec3 delta = mvPosIn.xyz - lights[0].pos.xyz;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" float dist = length(delta);\n"
|
2017-10-15 05:44:07 +00:00
|
|
|
" float angDot = clamp(dot(normalize(delta), lights[0].dir.xyz), 0.0, 1.0);\n"
|
|
|
|
" float att = 1.0 / (lights[0].linAtt[2] * dist * dist +\n"
|
|
|
|
" lights[0].linAtt[1] * dist +\n"
|
|
|
|
" lights[0].linAtt[0]);\n"
|
|
|
|
" float angAtt = lights[0].angAtt[2] * angDot * angDot +\n"
|
|
|
|
" lights[0].angAtt[1] * angDot +\n"
|
|
|
|
" lights[0].angAtt[0];\n"
|
|
|
|
" ret += lights[0].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn.xyz), 0.0, 1.0) *\n"
|
2018-01-16 06:42:28 +00:00
|
|
|
" texture(extTex7, shadowUV).r;\n"
|
2017-10-01 04:26:46 +00:00
|
|
|
" \n"
|
|
|
|
" for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
|
|
|
|
" {\n"
|
|
|
|
" vec3 delta = mvPosIn.xyz - lights[i].pos.xyz;\n"
|
|
|
|
" float dist = length(delta);\n"
|
|
|
|
" float angDot = clamp(dot(normalize(delta), lights[i].dir.xyz), 0.0, 1.0);\n"
|
|
|
|
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
|
|
|
|
" lights[i].linAtt[1] * dist +\n"
|
|
|
|
" lights[i].linAtt[0]);\n"
|
|
|
|
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
|
|
|
|
" lights[i].angAtt[1] * angDot +\n"
|
|
|
|
" lights[i].angAtt[0];\n"
|
|
|
|
" ret += lights[i].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn.xyz), 0.0, 1.0);\n"
|
|
|
|
" }\n"
|
|
|
|
" \n"
|
|
|
|
" return clamp(ret, vec4(0.0,0.0,0.0,0.0), vec4(1.0,1.0,1.0,1.0));\n"
|
|
|
|
"}\n";
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
static const char* MainPostGLSL =
|
|
|
|
"vec4 MainPostFunc(vec4 colorIn)\n"
|
|
|
|
"{\n"
|
2016-08-08 18:23:12 +00:00
|
|
|
" float fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
|
2016-08-08 04:48:18 +00:00
|
|
|
" return mix(fog.color, colorIn, clamp(exp2(-8.0 * fogZ), 0.0, 1.0));\n"
|
|
|
|
"}\n"
|
|
|
|
"\n";
|
|
|
|
|
2016-07-31 02:06:47 +00:00
|
|
|
static const char* ThermalPostGLSL =
|
|
|
|
"UBINDING2 uniform ThermalUniform\n"
|
|
|
|
"{\n"
|
2017-02-10 09:09:06 +00:00
|
|
|
" vec4 tmulColor;\n"
|
2016-07-31 02:06:47 +00:00
|
|
|
" vec4 addColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"vec4 ThermalPostFunc(vec4 colorIn)\n"
|
|
|
|
"{\n"
|
2018-02-05 06:56:09 +00:00
|
|
|
" return vec4(texture(extTex7, vtf.extTcgs[0]).rrr * tmulColor.rgb + addColor.rgb, tmulColor.a + addColor.a);\n"
|
2016-07-31 02:06:47 +00:00
|
|
|
"}\n"
|
|
|
|
"\n";
|
|
|
|
|
2017-03-05 07:57:12 +00:00
|
|
|
static const char* SolidPostGLSL =
|
|
|
|
"UBINDING2 uniform SolidUniform\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 solidColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"vec4 SolidPostFunc(vec4 colorIn)\n"
|
|
|
|
"{\n"
|
|
|
|
" return solidColor;\n"
|
|
|
|
"}\n"
|
|
|
|
"\n";
|
|
|
|
|
|
|
|
static const char* MBShadowPostGLSL =
|
|
|
|
"UBINDING2 uniform MBShadowUniform\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 shadowUp;\n"
|
|
|
|
" float shadowId;\n"
|
|
|
|
"};\n"
|
|
|
|
"vec4 MBShadowPostFunc(vec4 colorIn)\n"
|
|
|
|
"{\n"
|
2017-03-05 23:03:23 +00:00
|
|
|
" float idTexel = texture(extTex0, vtf.extTcgs[0]).a;\n"
|
|
|
|
" float sphereTexel = texture(extTex1, vtf.extTcgs[1]).a;\n"
|
|
|
|
" float fadeTexel = texture(extTex2, vtf.extTcgs[2]).a;\n"
|
2017-03-05 07:57:12 +00:00
|
|
|
" float val = ((abs(idTexel - shadowId) < 0.001) ?\n"
|
|
|
|
" (dot(vtf.mvNorm.xyz, shadowUp.xyz) * shadowUp.w) : 0.0) *\n"
|
|
|
|
" sphereTexel * fadeTexel;\n"
|
|
|
|
" return vec4(0.0, 0.0, 0.0, val);\n"
|
|
|
|
"}\n"
|
|
|
|
"\n";
|
|
|
|
|
2016-04-15 03:26:01 +00:00
|
|
|
static const char* BlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME,
|
|
|
|
HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME,
|
|
|
|
"LightingUniform"};
|
|
|
|
|
2016-07-31 02:06:47 +00:00
|
|
|
static const char* ThermalBlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME,
|
|
|
|
HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME,
|
|
|
|
"ThermalUniform"};
|
|
|
|
|
2017-03-05 07:57:12 +00:00
|
|
|
static const char* SolidBlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME,
|
|
|
|
HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME,
|
|
|
|
"SolidUniform"};
|
|
|
|
|
|
|
|
static const char* MBShadowBlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME,
|
|
|
|
HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME,
|
|
|
|
"MBShadowUniform"};
|
|
|
|
|
2016-04-04 02:32:57 +00:00
|
|
|
hecl::Runtime::ShaderCacheExtensions
|
|
|
|
CModelShaders::GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat)
|
|
|
|
{
|
|
|
|
hecl::Runtime::ShaderCacheExtensions ext(plat);
|
2016-07-31 02:06:47 +00:00
|
|
|
|
|
|
|
/* Normal lit shading */
|
2017-01-30 04:16:20 +00:00
|
|
|
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
|
|
|
|
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::Original,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Backface, false, false, true);
|
2016-07-31 02:06:47 +00:00
|
|
|
|
|
|
|
/* Thermal Visor shading */
|
2017-01-30 04:16:20 +00:00
|
|
|
ext.registerExtensionSlot({}, {ThermalPostGLSL, "ThermalPostFunc"}, 3, ThermalBlockNames,
|
|
|
|
1, ThermalTextures, hecl::Backend::BlendFactor::One,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
|
2018-02-05 06:56:09 +00:00
|
|
|
hecl::Backend::CullMode::Backface, false, false, false, true);
|
2017-01-30 04:16:20 +00:00
|
|
|
|
|
|
|
/* Forced alpha shading */
|
|
|
|
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
|
|
|
|
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Backface, false, false, true);
|
2017-01-30 04:16:20 +00:00
|
|
|
|
|
|
|
/* Forced additive shading */
|
|
|
|
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
|
2017-11-18 19:59:49 +00:00
|
|
|
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Backface, true, false, true);
|
2016-07-31 02:06:47 +00:00
|
|
|
|
2017-03-14 07:03:58 +00:00
|
|
|
/* Solid color */
|
2017-03-05 07:57:12 +00:00
|
|
|
ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"},
|
|
|
|
3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::One,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Backface, false, false, false);
|
2017-03-14 07:03:58 +00:00
|
|
|
|
2017-09-21 05:10:18 +00:00
|
|
|
/* Solid color additive */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"},
|
|
|
|
3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Backface, true, false, true);
|
2017-09-21 05:10:18 +00:00
|
|
|
|
2017-03-14 07:03:58 +00:00
|
|
|
/* Alpha-only Solid color frontface cull, LEqual */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"},
|
|
|
|
3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Frontface, false, true, false);
|
2017-03-14 07:03:58 +00:00
|
|
|
|
|
|
|
/* Alpha-only Solid color frontface cull, Always, No Z-write */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"},
|
|
|
|
3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Frontface, true, true, false);
|
2017-03-14 07:03:58 +00:00
|
|
|
|
|
|
|
/* Alpha-only Solid color backface cull, LEqual */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"},
|
|
|
|
3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Backface, false, true, false);
|
2017-03-14 07:03:58 +00:00
|
|
|
|
|
|
|
/* Alpha-only Solid color backface cull, Greater, No Z-write */
|
|
|
|
ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"},
|
|
|
|
3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Backface, true, true, false);
|
2017-03-05 07:57:12 +00:00
|
|
|
|
|
|
|
/* MorphBall shadow shading */
|
|
|
|
ext.registerExtensionSlot({}, {MBShadowPostGLSL, "MBShadowPostFunc"},
|
|
|
|
3, MBShadowBlockNames, 3, BallFadeTextures,
|
|
|
|
hecl::Backend::BlendFactor::SrcAlpha,
|
2017-03-14 07:03:58 +00:00
|
|
|
hecl::Backend::BlendFactor::InvSrcAlpha,
|
|
|
|
hecl::Backend::ZTest::Equal,
|
2018-02-05 06:56:09 +00:00
|
|
|
hecl::Backend::CullMode::Backface, false, false, true, false, true);
|
2017-10-01 04:26:46 +00:00
|
|
|
|
|
|
|
/* World shadow shading (modified lighting) */
|
|
|
|
ext.registerExtensionSlot({LightingShadowGLSL, "LightingShadowFunc"}, {MainPostGLSL, "MainPostFunc"},
|
|
|
|
3, BlockNames, 1, WorldShadowTextures, hecl::Backend::BlendFactor::Original,
|
|
|
|
hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original,
|
2017-12-10 05:30:01 +00:00
|
|
|
hecl::Backend::CullMode::Backface, false, false, true);
|
|
|
|
|
|
|
|
/* Forced alpha shading without culling */
|
|
|
|
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
|
|
|
|
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
|
|
|
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
|
2018-01-06 06:50:42 +00:00
|
|
|
hecl::Backend::CullMode::None, false, false, true);
|
2017-12-10 05:30:01 +00:00
|
|
|
|
|
|
|
/* Forced additive shading without culling */
|
2018-01-06 06:50:42 +00:00
|
|
|
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
|
|
|
|
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
|
|
|
|
hecl::Backend::CullMode::None, false, false, true);
|
|
|
|
|
|
|
|
/* Forced alpha shading without culling or Z-write */
|
|
|
|
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
|
|
|
|
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
|
|
|
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
|
|
|
|
hecl::Backend::CullMode::None, true, false, true);
|
|
|
|
|
|
|
|
/* Forced additive shading without culling or Z-write */
|
2017-12-10 05:30:01 +00:00
|
|
|
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
|
|
|
|
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
|
|
|
|
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
|
|
|
|
hecl::Backend::CullMode::None, true, false, true);
|
2017-10-01 04:26:46 +00:00
|
|
|
|
2016-04-04 02:32:57 +00:00
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|