2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 15:04:56 +00:00

Convert to pragma once

This commit is contained in:
Jack Andersen
2018-10-06 17:42:33 -10:00
parent 9461e98512
commit c91e5df986
818 changed files with 815 additions and 4978 deletions

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CBOORENDERER_HPP__
#define __URDE_CBOORENDERER_HPP__
#pragma once
#include <functional>
#include "IRenderer.hpp"
@@ -311,4 +310,3 @@ public:
}
#endif // __URDE_CBOORENDERER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CDRAWABLE_HPP__
#define __URDE_CDRAWABLE_HPP__
#pragma once
#include "GCNTypes.hpp"
#include "zeus/CAABox.hpp"
@@ -34,4 +33,3 @@ public:
};
}
#endif // __URDE_CDRAWABLE_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CDRAWABLEOBJECT_HPP__
#define __URDE_CDRAWABLEOBJECT_HPP__
#pragma once
#include "CDrawable.hpp"
#include "zeus/CPlane.hpp"
@@ -23,4 +22,3 @@ public:
};
}
#endif // __URDE_CDRAWABLEOBJECT_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CGRAPHICS_HPP__
#define __URDE_CGRAPHICS_HPP__
#pragma once
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "boo/graphicsdev/IGraphicsCommandQueue.hpp"
@@ -408,4 +407,3 @@ public:
}
#endif // __URDE_CGRAPHICS_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CGRAPHICSPALETTE_HPP__
#define __URDE_CGRAPHICSPALETTE_HPP__
#pragma once
#include <memory>
#include "RetroTypes.hpp"
@@ -39,4 +38,3 @@ public:
}
#endif // __URDE_CGRAPHICSPALETTE_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CLIGHT_HPP__
#define __URDE_CLIGHT_HPP__
#pragma once
#include "zeus/CVector3f.hpp"
#include "zeus/CColor.hpp"
@@ -143,4 +142,3 @@ public:
}
#endif // __URDE_CLIGHT_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CLINERENDERER_HPP__
#define __URDE_CLINERENDERER_HPP__
#pragma once
#include "RetroTypes.hpp"
#include "zeus/CVector3f.hpp"
@@ -99,4 +98,3 @@ public:
}
#endif // __URDE_CLINERENDERER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CMETROIDMODELINSTANCE_HPP__
#define __URDE_CMETROIDMODELINSTANCE_HPP__
#pragma once
#include <vector>
#include "RetroTypes.hpp"
@@ -42,4 +41,3 @@ public:
}
#endif // __URDE_CMETROIDMODELINSTANCE_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CMODEL_HPP__
#define __URDE_CMODEL_HPP__
#pragma once
#include "RetroTypes.hpp"
#include "zeus/CColor.hpp"
@@ -332,4 +331,3 @@ CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag,
}
#endif // __URDE_CMODEL_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CMOVIEPLAYER_HPP__
#define __URDE_CMOVIEPLAYER_HPP__
#pragma once
#include "RetroTypes.hpp"
#include "CDvdFile.hpp"
@@ -173,4 +172,3 @@ public:
}
#endif // __URDE_CMOVIEPLAYER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CPVSAREASET_HPP__
#define __URDE_CPVSAREASET_HPP__
#pragma once
#include "RetroTypes.hpp"
#include "CPVSVisOctree.hpp"
@@ -42,4 +41,3 @@ public:
}
#endif // __URDE_CPVSAREASET_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CPVSVISOCTREE_HPP__
#define __URDE_CPVSVISOCTREE_HPP__
#pragma once
#include "RetroTypes.hpp"
#include "zeus/CVector3f.hpp"
@@ -33,4 +32,3 @@ public:
}
#endif // __URDE_CPVSVISOCTREE_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CPVSVISSET_HPP__
#define __URDE_CPVSVISSET_HPP__
#pragma once
#include "RetroTypes.hpp"
#include "zeus/CAABox.hpp"
@@ -33,4 +32,3 @@ public:
}
#endif // __URDE_CPVSVISSET_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef URDE_CRAINSPLASHGENERATOR_HPP
#define URDE_CRAINSPLASHGENERATOR_HPP
#pragma once
#include "RetroTypes.hpp"
#include "CRandom16.hpp"
@@ -74,4 +73,3 @@ public:
}
#endif // URDE_CRAINSPLASHGENERATOR_HPP

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CSIMPLESHADOW_HPP__
#define __URDE_CSIMPLESHADOW_HPP__
#pragma once
#include "zeus/CAABox.hpp"
#include "Graphics/Shaders/CTexturedQuadFilter.hpp"
@@ -36,4 +35,3 @@ public:
};
}
#endif // __URDE_CSIMPLESHADOW_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CSKINNEDMODEL_HPP__
#define __URDE_CSKINNEDMODEL_HPP__
#pragma once
#include "CToken.hpp"
#include "CModel.hpp"
@@ -70,4 +69,3 @@ public:
}
#endif // __URDE_CSKINNEDMODEL_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CTEXTURE_HPP__
#define __URDE_CTEXTURE_HPP__
#pragma once
#include "GCNTypes.hpp"
#include "CFactoryMgr.hpp"
@@ -83,4 +82,3 @@ CFactoryFnReturn FTextureFactory(const urde::SObjectTag& tag,
}
#endif // __URDE_CTEXTURE_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CVERTEXMORPHEFFECT_HPP__
#define __URDE_CVERTEXMORPHEFFECT_HPP__
#pragma once
#include "CToken.hpp"
#include "Character/CPoseAsTransforms.hpp"
@@ -22,4 +21,3 @@ public:
}
#endif // __URDE_CVERTEXMORPHEFFECT_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_IRENDERER_HPP__
#define __URDE_IRENDERER_HPP__
#pragma once
#include <vector>
#include "../RetroTypes.hpp"
@@ -112,4 +111,3 @@ public:
}
#endif // __URDE_IRENDERER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_IWEAPONRENDERER_HPP__
#define __URDE_IWEAPONRENDERER_HPP__
#pragma once
namespace urde
{
@@ -20,4 +19,3 @@ public:
}
#endif // __URDE_IWEAPONRENDERER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CAABOXSHADER_HPP__
#define __URDE_CAABOXSHADER_HPP__
#pragma once
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "zeus/CMatrix4f.hpp"
@@ -31,4 +30,3 @@ public:
}
#endif // __URDE_CAABOXSHADER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CCAMERABLURFILTER_HPP__
#define __URDE_CCAMERABLURFILTER_HPP__
#pragma once
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "zeus/CMatrix4f.hpp"
@@ -35,4 +34,3 @@ public:
}
#endif // __URDE_CCAMERABLURFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CCOLOREDQUADFILTER_HPP__
#define __URDE_CCOLOREDQUADFILTER_HPP__
#pragma once
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
@@ -50,4 +49,3 @@ public:
}
#endif // __URDE_CCOLOREDQUADFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CDECALSHADERS_HPP__
#define __URDE_CDECALSHADERS_HPP__
#pragma once
#include "Graphics/CGraphics.hpp"
@@ -25,4 +24,3 @@ public:
}
#endif // __URDE_CDECALSHADERS_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CELEMENTGENSHADERS_HPP__
#define __URDE_CELEMENTGENSHADERS_HPP__
#pragma once
#include "Graphics/CGraphics.hpp"
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
@@ -56,4 +55,3 @@ public:
}
#endif // __URDE_CELEMENTGENSHADERS_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CENERGYBARSHADER_HPP__
#define __URDE_CENERGYBARSHADER_HPP__
#pragma once
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
@@ -43,4 +42,3 @@ public:
}
#endif // __URDE_CENERGYBARSHADER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef CFLUIDPLANESHADER_HPP
#define CFLUIDPLANESHADER_HPP
#pragma once
#include "RetroTypes.hpp"
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
@@ -199,4 +198,3 @@ public:
}
#endif // CFLUIDPLANESHADER_HPP

View File

@@ -1,958 +0,0 @@
#include "CFluidPlaneShader.hpp"
namespace urde
{
static const char* VS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"layout(location=0) in vec4 posIn;\n"
"layout(location=1) in vec4 normalIn;\n"
"layout(location=2) in vec4 binormalIn;\n"
"layout(location=3) in vec4 tangentIn;\n"
"layout(location=4) in vec4 colorIn;\n"
"\n"
"UBINDING0 uniform FluidPlaneUniform\n"
"{\n"
" mat4 mv;\n"
" mat4 mvNorm;\n"
" mat4 proj;\n"
" mat4 texMtxs[6];\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" vec4 mvPos;\n"
" vec4 mvNorm;\n"
" vec4 mvBinorm;\n"
" vec4 mvTangent;\n"
" vec4 color;\n"
" vec2 uvs[7];\n"
"};\n"
"\n"
"SBINDING(0) out VertToFrag vtf;\n"
"void main()\n"
"{\n"
" vec4 pos = vec4(posIn.xyz, 1.0);\n"
" vtf.mvPos = mv * pos;\n"
" gl_Position = proj * vtf.mvPos;\n"
" vtf.mvNorm = mvNorm * normalIn;\n"
" vtf.mvBinorm = mvNorm * binormalIn;\n"
" vtf.mvTangent = mvNorm * tangentIn;\n"
" vtf.color = vec4(colorIn.xyz, 1.0);\n"
" vtf.uvs[0] = (texMtxs[0] * pos).xy;\n"
" vtf.uvs[1] = (texMtxs[1] * pos).xy;\n"
" vtf.uvs[2] = (texMtxs[2] * pos).xy;\n"
"%s" // Additional TCGs here
"}\n";
static const char* TessVS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"\n"
"layout(location=0) in vec4 posIn;\n"
"layout(location=1) in vec4 outerLevelsIn;\n"
"layout(location=2) in vec2 innerLevelsIn;\n"
"\n"
"struct VertToControl\n"
"{\n"
" vec4 minMaxPos;\n"
" vec4 outerLevels;\n"
" vec2 innerLevels;\n"
"};\n"
"\n"
"SBINDING(0) out VertToControl vtc;\n"
"\n"
"void main()\n"
"{\n"
" vtc.minMaxPos = posIn;\n"
" vtc.outerLevels = outerLevelsIn;\n"
" vtc.innerLevels = innerLevelsIn;\n"
"}\n";
static const char* TessCS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"#extension GL_ARB_tessellation_shader: enable\n"
"layout(vertices = 1) out;\n"
"\n"
"struct VertToControl\n"
"{\n"
" vec4 minMaxPos;\n"
" vec4 outerLevels;\n"
" vec2 innerLevels;\n"
"};\n"
"\n"
"SBINDING(0) in VertToControl vtc[];\n"
"SBINDING(0) patch out vec4 minMaxPos;\n"
"\n"
"void main()\n"
"{\n"
" minMaxPos = vtc[gl_InvocationID].minMaxPos;\n"
" for (int i=0 ; i<4 ; ++i)\n"
" gl_TessLevelOuter[i] = vtc[gl_InvocationID].outerLevels[i];\n"
" for (int i=0 ; i<2 ; ++i)\n"
" gl_TessLevelInner[i] = vtc[gl_InvocationID].innerLevels[i];\n"
"}";
static const char* TessES =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"#extension GL_ARB_tessellation_shader: enable\n"
"layout(quads, equal_spacing) in;\n"
"\n"
"struct Ripple\n"
"{\n"
" vec4 center; // time, distFalloff\n"
" vec4 params; // amplitude, lookupPhase, lookupTime\n"
"};\n"
"\n"
"UBINDING0 uniform FluidPlaneUniform\n"
"{\n"
" mat4 mv;\n"
" mat4 mvNorm;\n"
" mat4 proj;\n"
" mat4 texMtxs[6];\n"
" Ripple ripples[20];\n"
" vec4 colorMul;\n"
" float rippleNormResolution;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" vec4 mvPos;\n"
" vec4 mvNorm;\n"
" vec4 mvBinorm;\n"
" vec4 mvTangent;\n"
" vec4 color;\n"
" vec2 uvs[7];\n"
"};\n"
"\n"
"SBINDING(0) patch in vec4 minMaxPos;\n"
"SBINDING(0) out VertToFrag vtf;\n"
"\n"
"TBINDING%d uniform sampler2D RippleMap;\n"
"\n"
"const float PI_X2 = 6.283185307179586;\n"
"\n"
"void ApplyRipple(in Ripple ripple, in vec2 pos, inout float height)\n"
"{\n"
" float dist = length(ripple.center.xy - pos);\n"
" float rippleV = textureLod(RippleMap, vec2(dist * ripple.center.w, ripple.center.z), 0.0).r;\n"
" height += rippleV * ripple.params.x * sin((dist * ripple.params.y + ripple.params.z) * PI_X2);\n"
"}\n"
"\n"
"void main()\n"
"{\n"
" vec2 posIn = vec2(mix(minMaxPos.x, minMaxPos.z, gl_TessCoord.x),\n"
" mix(minMaxPos.y, minMaxPos.w, gl_TessCoord.y));\n"
" float height = 0.0;\n"
" float upHeight = 0.0;\n"
" float downHeight = 0.0;\n"
" float rightHeight = 0.0;\n"
" float leftHeight = 0.0;\n"
" for (int i=0 ; i<20 ; ++i)\n"
" {\n"
" ApplyRipple(ripples[i], posIn, height);\n"
" ApplyRipple(ripples[i], posIn + vec2(0.0, rippleNormResolution), upHeight);\n"
" ApplyRipple(ripples[i], posIn - vec2(0.0, rippleNormResolution), downHeight);\n"
" ApplyRipple(ripples[i], posIn + vec2(rippleNormResolution, 0.0), rightHeight);\n"
" ApplyRipple(ripples[i], posIn - vec2(rippleNormResolution, 0.0), leftHeight);\n"
" }\n"
" vec4 normalIn = vec4(normalize(vec3((leftHeight - rightHeight),\n"
" (downHeight - upHeight),\n"
" rippleNormResolution)), 1.0);\n"
" vec4 binormalIn = vec4(normalIn.x, normalIn.z, -normalIn.y, 1.0);\n"
" vec4 tangentIn = vec4(normalIn.z, normalIn.y, -normalIn.x, 1.0);\n"
" vec4 pos = vec4(posIn, height, 1.0);\n"
" vtf.mvPos = mv * pos;\n"
" gl_Position = proj * vtf.mvPos;\n"
" vtf.mvNorm = mvNorm * normalIn;\n"
" vtf.mvBinorm = mvNorm * binormalIn;\n"
" vtf.mvTangent = mvNorm * tangentIn;\n"
" vtf.color = max(height, 0.0) * colorMul;\n"
" vtf.color.a = 1.0;\n"
" vtf.uvs[0] = (texMtxs[0] * pos).xy;\n"
" vtf.uvs[1] = (texMtxs[1] * pos).xy;\n"
" vtf.uvs[2] = (texMtxs[2] * pos).xy;\n"
"%s\n" // Additional TCGs here
"}\n";
static const char* FS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"\n"
"struct Light\n"
"{\n"
" vec4 pos;\n"
" vec4 dir;\n"
" vec4 color;\n"
" vec4 linAtt;\n"
" vec4 angAtt;\n"
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" int mode;\n"
" vec4 color;\n"
" float indScale;\n"
" float start;\n"
"};\n"
"\n"
"UBINDING2 uniform LightingUniform\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" vec4 ambient;\n"
" vec4 kColor0;\n"
" vec4 kColor1;\n"
" vec4 kColor2;\n"
" vec4 kColor3;\n"
" Fog fog;\n"
"};\n"
"\n"
"vec4 LightingFunc(vec3 mvPosIn, vec3 mvNormIn)\n"
"{\n"
" vec4 ret = ambient;\n"
" \n"
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
" {\n"
" vec3 delta = mvPosIn - 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), 0.0, 1.0);\n"
" }\n"
" \n"
" return ret;\n"
"}\n"
"\n"
"struct VertToFrag\n"
"{\n"
" vec4 mvPos;\n"
" vec4 mvNorm;\n"
" vec4 mvBinorm;\n"
" vec4 mvTangent;\n"
" vec4 color;\n"
" vec2 uvs[7];\n"
"};\n"
"\n"
"SBINDING(0) in VertToFrag vtf;\n"
"layout(location=0) out vec4 colorOut;\n"
"%s" // Textures here
"void main()\n"
"{\n"
" vec4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n"
"%s" // Combiner expression here
"}\n";
static const char* FSDoor =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"\n"
"struct Light\n"
"{\n"
" vec4 pos;\n"
" vec4 dir;\n"
" vec4 color;\n"
" vec4 linAtt;\n"
" vec4 angAtt;\n"
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" int mode;\n"
" vec4 color;\n"
" float indScale;\n"
" float start;\n"
"};\n"
"\n"
"UBINDING2 uniform LightingUniform\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" vec4 ambient;\n"
" vec4 kColor0;\n"
" vec4 kColor1;\n"
" vec4 kColor2;\n"
" vec4 kColor3;\n"
" Fog fog;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" vec4 mvPos;\n"
" vec4 mvNorm;\n"
" vec4 mvBinorm;\n"
" vec4 mvTangent;\n"
" vec4 color;\n"
" vec2 uvs[7];\n"
"};\n"
"\n"
"SBINDING(0) in VertToFrag vtf;\n"
"layout(location=0) out vec4 colorOut;\n"
"%s" // Textures here
"void main()\n"
"{\n"
"%s" // Combiner expression here
"}\n";
static void _BuildFragShader(std::string& finalFS, int& nextTex, const char* texNames[8],
const SFluidPlaneShaderInfo& info)
{
std::string textures;
std::string combiner;
int nextTCG = 3;
int bumpMapUv, envBumpMapUv, envMapUv, lightmapUv;
if (info.m_hasPatternTex1)
{
texNames[nextTex] = "patternTex1";
textures += hecl::Format("TBINDING%d uniform sampler2D patternTex1;\n", nextTex++);
}
if (info.m_hasPatternTex2)
{
texNames[nextTex] = "patternTex2";
textures += hecl::Format("TBINDING%d uniform sampler2D patternTex2;\n", nextTex++);
}
if (info.m_hasColorTex)
{
texNames[nextTex] = "colorTex";
textures += hecl::Format("TBINDING%d uniform sampler2D colorTex;\n", nextTex++);
}
if (info.m_hasBumpMap)
{
texNames[nextTex] = "bumpMap";
textures += hecl::Format("TBINDING%d uniform sampler2D bumpMap;\n", nextTex++);
}
if (info.m_hasEnvMap)
{
texNames[nextTex] = "envMap";
textures += hecl::Format("TBINDING%d uniform sampler2D envMap;\n", nextTex++);
}
if (info.m_hasEnvBumpMap)
{
texNames[nextTex] = "envBumpMap";
textures += hecl::Format("TBINDING%d uniform sampler2D envBumpMap;\n", nextTex++);
}
if (info.m_hasLightmap)
{
texNames[nextTex] = "lightMap";
textures += hecl::Format("TBINDING%d uniform sampler2D lightMap;\n", nextTex++);
}
if (info.m_hasBumpMap)
{
bumpMapUv = nextTCG++;
}
if (info.m_hasEnvBumpMap)
{
envBumpMapUv = nextTCG++;
}
if (info.m_hasEnvMap)
{
envMapUv = nextTCG++;
}
if (info.m_hasLightmap)
{
lightmapUv = nextTCG;
}
switch (info.m_type)
{
case EFluidType::NormalWater:
case EFluidType::PhazonFluid:
case EFluidType::Four:
if (info.m_hasLightmap)
{
combiner += hecl::Format(" vec4 lightMapTexel = texture(lightMap, vtf.uvs[%d]);\n", lightmapUv);
// 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1
// ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS
// Output reg 2
// KColor 2
if (info.m_doubleLightmapBlend)
{
// 1: Tex4TCG2, Tex4, GX_COLOR1A1
// C2, TEX, KONST, RAS
// Output reg 2
// KColor 3
// Tex * K2 + Lighting
combiner += " lighting += mix(lightMapTexel * kColor2, lightMapTexel, kColor3);\n";
}
else
{
// mix(Tex * K2, Tex, K3) + Lighting
combiner += " lighting += lightMapTexel * kColor2;\n";
}
}
// Next: Tex0TCG, Tex0, GX_COLOR1A1
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// Next: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// Next: Tex2TCG, Tex2, GX_COLOR1A1
// ZERO, TEX, hasTex4 ? C2 : RAS, PREV
// Output reg prev
// (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + lighting) *\n"
" texture(patternTex2, vtf.uvs[1]) + vtf.color;\n";
else
combiner += " colorOut = lighting * texture(patternTex2, vtf.uvs[1]) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex && !info.m_hasEnvMap && info.m_hasEnvBumpMap)
{
// Make previous stage indirect, mtx0
combiner += hecl::Format(" vec2 indUvs = (texture(envBumpMap, vtf.uvs[%d]).ra - vec2(0.5, 0.5)) *\n"
" vec2(fog.indScale, -fog.indScale);\n", envBumpMapUv);
combiner += " colorOut += texture(colorTex, indUvs + vtf.uvs[2]) * lighting;\n";
}
else if (info.m_hasEnvMap)
{
// Next: envTCG, envTex, NULL
// PREV, TEX, KONST, ZERO
// Output reg prev
// KColor 1
// Make previous stage indirect, mtx0
if (info.m_hasColorTex)
combiner += " colorOut += texture(colorTex, vtf.uvs[2]) * lighting;\n";
combiner += hecl::Format(" vec2 indUvs = (texture(envBumpMap, vtf.uvs[%d]).ra - vec2(0.5, 0.5)) *\n"
" vec2(fog.indScale, -fog.indScale);\n", envBumpMapUv);
combiner += hecl::Format(" colorOut = mix(colorOut, texture(envMap, indUvs + vtf.uvs[%d]), kColor1);\n",
envMapUv);
}
else if (info.m_hasColorTex)
{
combiner += " colorOut += texture(colorTex, vtf.uvs[2]) * lighting;\n";
}
break;
case EFluidType::PoisonWater:
if (info.m_hasLightmap)
{
combiner += hecl::Format(" vec4 lightMapTexel = texture(lightMap, vtf.uvs[%d]);\n", lightmapUv);
// 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1
// ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS
// Output reg 2
// KColor 2
if (info.m_doubleLightmapBlend)
{
// 1: Tex4TCG2, Tex4, GX_COLOR1A1
// C2, TEX, KONST, RAS
// Output reg 2
// KColor 3
// Tex * K2 + Lighting
combiner += " lighting += mix(lightMapTexel * kColor2, lightMapTexel, kColor3);\n";
}
else
{
// mix(Tex * K2, Tex, K3) + Lighting
combiner += " lighting += lightMapTexel * kColor2;\n";
}
}
// Next: Tex0TCG, Tex0, GX_COLOR1A1
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// Next: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// Next: Tex2TCG, Tex2, GX_COLOR1A1
// ZERO, TEX, hasTex4 ? C2 : RAS, PREV
// Output reg prev
// (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + lighting) *\n"
" texture(patternTex2, vtf.uvs[1]) + vtf.color;\n";
else
combiner += " colorOut = lighting * texture(patternTex2, vtf.uvs[1]) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
{
if (info.m_hasEnvBumpMap)
{
// Make previous stage indirect, mtx0
combiner += hecl::Format(" vec2 indUvs = (texture(envBumpMap, vtf.uvs[%d]).ra - vec2(0.5, 0.5)) *\n"
" vec2(fog.indScale, -fog.indScale);\n", envBumpMapUv);
combiner += " colorOut += texture(colorTex, indUvs + vtf.uvs[2]) * lighting;\n";
}
else
{
combiner += " colorOut += texture(colorTex, vtf.uvs[2]) * lighting;\n";
}
}
break;
case EFluidType::Lava:
// 0: Tex0TCG, Tex0, GX_COLOR0A0
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// 1: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// 2: Tex2TCG, Tex2, NULL
// ZERO, TEX, ONE, PREV
// Output reg prev
// (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + vtf.color) *\n"
" texture(patternTex2, vtf.uvs[1]) + vtf.color;\n";
else
combiner += " colorOut = vtf.color * texture(patternTex2, vtf.uvs[1]) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
combiner += " colorOut += texture(colorTex, vtf.uvs[2]);\n";
if (info.m_hasBumpMap)
{
// 3: bumpMapTCG, bumpMap, NULL
// ZERO, TEX, ONE, HALF
// Output reg 0, no clamp, no bias
// 4: bumpMapTCG2, bumpMap, NULL
// ZERO, TEX, ONE, C0
// Output reg 0, subtract, clamp, no bias
combiner += " vec3 lightVec = lights[3].pos.xyz - vtf.mvPos.xyz;\n"
" float lx = dot(vtf.mvTangent, lightVec);\n"
" float ly = dot(vtf.mvBinorm, lightVec);\n";
combiner += hecl::Format(" vec4 emboss1 = texture(bumpMap, vtf.uvs[%d]) + vec4(0.5);\n"
" vec4 emboss2 = texture(bumpMap, vtf.uvs[%d] + vec2(lx, ly));\n",
bumpMapUv, bumpMapUv);
// 5: NULL, NULL, NULL
// ZERO, PREV, C0, ZERO
// Output reg prev, scale 2, clamp
// colorOut * clamp(emboss1 + 0.5 - emboss2, 0.0, 1.0) * 2.0
combiner += "colorOut *= clamp((emboss1 + vec4(0.5) - emboss2) * vec4(2.0), vec4(0.0), vec4(1.0));\n";
}
break;
case EFluidType::ThickLava:
// 0: Tex0TCG, Tex0, GX_COLOR0A0
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// 1: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// 2: Tex2TCG, Tex2, NULL
// ZERO, TEX, ONE, PREV
// Output reg prev
// (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + vtf.color) *\n"
" texture(patternTex2, vtf.uvs[1]) + vtf.color;\n";
else
combiner += " colorOut = vtf.color * texture(patternTex2, vtf.uvs[1]) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
combiner += " colorOut += texture(colorTex, vtf.uvs[2]);\n";
if (info.m_hasBumpMap)
{
// 3: bumpMapTCG, bumpMap, NULL
// ZERO, TEX, PREV, ZERO
// Output reg prev, scale 2
combiner += hecl::Format(" vec4 emboss1 = texture(bumpMap, vtf.uvs[%d]) + vec4(0.5);\n", bumpMapUv);
combiner += "colorOut *= emboss1 * vec4(2.0);\n";
}
break;
}
combiner += " colorOut.a = kColor0.a;\n";
char *finalFSs;
asprintf(&finalFSs, FS, textures.c_str(), combiner.c_str());
finalFS = finalFSs;
free(finalFSs);
}
static std::string _BuildAdditionalTCGs(const SFluidPlaneShaderInfo& info)
{
std::string additionalTCGs;
int nextTCG = 3;
int nextMtx = 4;
if (info.m_hasBumpMap)
{
additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[0] * pos).xy;\n", nextTCG++);
}
if (info.m_hasEnvBumpMap)
{
additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[3] * vec4(normalIn.xyz, 1.0)).xy;\n", nextTCG++);
}
if (info.m_hasEnvMap)
{
additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[%d] * pos).xy;\n", nextTCG++, nextMtx++);
}
if (info.m_hasLightmap)
{
additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[%d] * pos).xy;\n", nextTCG, nextMtx);
}
return additionalTCGs;
}
static void _BuildShader(std::string& finalVS, std::string& finalFS, int& nextTex, const char* texNames[8],
const SFluidPlaneShaderInfo& info)
{
std::string additionalTCGs = _BuildAdditionalTCGs(info);
char *finalVSs;
asprintf(&finalVSs, VS, additionalTCGs.c_str());
finalVS = finalVSs;
free(finalVSs);
_BuildFragShader(finalFS, nextTex, texNames, info);
}
static void _BuildTessellationShader(std::string& finalTessES, int& nextTex, const char* texNames[8],
const SFluidPlaneShaderInfo& info)
{
std::string additionalTCGs = _BuildAdditionalTCGs(info);
texNames[nextTex] = "RippleMap";
char *finalESs;
asprintf(&finalESs, TessES, nextTex, additionalTCGs.c_str());
finalTessES = finalESs;
free(finalESs);
++nextTex;
}
static void _BuildShader(std::string& finalVS, std::string& finalFS, int& nextTex, const char* texNames[3],
const SFluidPlaneDoorShaderInfo& info)
{
std::string additionalTCGs;
std::string textures;
std::string combiner;
if (info.m_hasPatternTex1)
{
texNames[nextTex] = "patternTex1";
textures += hecl::Format("TBINDING%d uniform sampler2D patternTex1;\n", nextTex++);
}
if (info.m_hasPatternTex2)
{
texNames[nextTex] = "patternTex2";
textures += hecl::Format("TBINDING%d uniform sampler2D patternTex2;\n", nextTex++);
}
if (info.m_hasColorTex)
{
texNames[nextTex] = "colorTex";
textures += hecl::Format("TBINDING%d uniform sampler2D colorTex;\n", nextTex++);
}
// Tex0 * kColor0 * Tex1 + Tex2
if (info.m_hasPatternTex1 && info.m_hasPatternTex2)
{
combiner += " colorOut = texture(patternTex1, vtf.uvs[0]) * kColor0 *\n"
" texture(patternTex2, vtf.uvs[1]);\n";
}
else
{
combiner += " colorOut = vec4(0.0);\n";
}
if (info.m_hasColorTex)
{
combiner += " colorOut += texture(colorTex, vtf.uvs[2]);\n";
}
combiner += " colorOut.a = kColor0.a;\n";
char *finalVSs, *finalFSs;
asprintf(&finalVSs, VS, additionalTCGs.c_str());
asprintf(&finalFSs, FSDoor, textures.c_str(), combiner.c_str());
finalVS = finalVSs;
finalFS = finalFSs;
free(finalVSs);
free(finalFSs);
}
CFluidPlaneShader::ShaderPair
CFluidPlaneShader::BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info)
{
int nextTex = 0;
const char* texNames[8] = {};
std::string finalVS, finalFS;
_BuildShader(finalVS, finalFS, nextTex, texNames, info);
const char* uniNames[] = {"FluidPlaneUniform", "FluidPlaneUniform", "LightingUniform"};
auto regular = ctx.newShaderPipeline(finalVS.c_str(), finalFS.c_str(),
size_t(nextTex), texNames, 3, uniNames,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None);
boo::ObjToken<boo::IShaderPipeline> tessellation;
if (info.m_tessellation)
{
std::string finalTessES;
_BuildTessellationShader(finalTessES, nextTex, texNames, info);
tessellation = ctx.newTessellationShaderPipeline(
TessVS, finalFS.c_str(), TessCS, finalTessES.c_str(),
size_t(nextTex), texNames, 3, uniNames,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
1, boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
}
return {regular, tessellation};
}
CFluidPlaneShader::ShaderPair
CFluidPlaneShader::BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info)
{
int nextTex = 0;
const char* texNames[3] = {};
std::string finalVS, finalFS;
_BuildShader(finalVS, finalFS, nextTex, texNames, info);
const char* uniNames[] = {"FluidPlaneUniform", "FluidPlaneUniform", "LightingUniform"};
return {ctx.newShaderPipeline(finalVS.c_str(), finalFS.c_str(), size_t(nextTex), texNames, 3, uniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None), {}};
}
template <>
void CFluidPlaneShader::_Shutdown<boo::GLDataFactory>() {}
#if BOO_HAS_VULKAN
static boo::ObjToken<boo::IVertexFormat> s_vtxFmt;
static boo::ObjToken<boo::IVertexFormat> s_vtxFmtTess;
CFluidPlaneShader::ShaderPair
CFluidPlaneShader::BuildShader(boo::VulkanDataFactory::Context& ctx,
const SFluidPlaneShaderInfo& info)
{
if (!s_vtxFmt)
{
boo::VertexElementDescriptor elements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 0},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 1},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 2},
{nullptr, nullptr, boo::VertexSemantic::Color}
};
s_vtxFmt = ctx.newVertexFormat(5, elements);
}
int nextTex = 0;
const char* texNames[8] = {};
std::string finalVS, finalFS;
_BuildShader(finalVS, finalFS, nextTex, texNames, info);
auto regular = ctx.newShaderPipeline(finalVS.c_str(), finalFS.c_str(), s_vtxFmt,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None);
boo::ObjToken<boo::IShaderPipeline> tessellation;
if (info.m_tessellation)
{
if (!s_vtxFmtTess)
{
boo::VertexElementDescriptor elements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::UV4, 0},
{nullptr, nullptr, boo::VertexSemantic::UV4, 1}
};
s_vtxFmtTess = ctx.newVertexFormat(3, elements);
}
std::string finalTessES;
_BuildTessellationShader(finalTessES, nextTex, texNames, info);
tessellation = ctx.newTessellationShaderPipeline(
TessVS, finalFS.c_str(), TessCS, finalTessES.c_str(), s_vtxFmtTess,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
1, boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
}
return {regular, tessellation};
}
CFluidPlaneShader::ShaderPair
CFluidPlaneShader::BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info)
{
if (!s_vtxFmt)
{
boo::VertexElementDescriptor elements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 0},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 1},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 2},
{nullptr, nullptr, boo::VertexSemantic::Color}
};
s_vtxFmt = ctx.newVertexFormat(5, elements);
}
int nextTex = 0;
const char* texNames[3] = {};
std::string finalVS, finalFS;
_BuildShader(finalVS, finalFS, nextTex, texNames, info);
auto regular = ctx.newShaderPipeline(finalVS.c_str(), finalFS.c_str(), s_vtxFmt,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None);
return {regular, {}};
}
template <>
void CFluidPlaneShader::_Shutdown<boo::VulkanDataFactory>()
{
s_vtxFmt.reset();
s_vtxFmtTess.reset();
}
#endif
CFluidPlaneShader::BindingPair
CFluidPlaneShader::BuildBinding(boo::GLDataFactory::Context& ctx, const ShaderPair& pipeline)
{
boo::VertexElementDescriptor elements[] =
{
{m_vbo.get(), nullptr, boo::VertexSemantic::Position4},
{m_vbo.get(), nullptr, boo::VertexSemantic::Normal4, 0},
{m_vbo.get(), nullptr, boo::VertexSemantic::Normal4, 1},
{m_vbo.get(), nullptr, boo::VertexSemantic::Normal4, 2},
{m_vbo.get(), nullptr, boo::VertexSemantic::Color}
};
boo::ObjToken<boo::IVertexFormat> vtxFmt = ctx.newVertexFormat(5, elements);
boo::ObjToken<boo::IGraphicsBuffer> ubufs[] = { m_uniBuf.get(), m_uniBuf.get(), m_uniBuf.get() };
boo::PipelineStage ubufStages[] = { boo::PipelineStage::Vertex, boo::PipelineStage::Vertex,
boo::PipelineStage::Fragment };
size_t ubufOffs[] = {0, 0, 1280};
size_t ubufSizes[] = {1280, 1280, sizeof(CModelShaders::LightingUniform)};
size_t texCount = 0;
boo::ObjToken<boo::ITexture> texs[8];
if (m_patternTex1)
texs[texCount++] = m_patternTex1->GetBooTexture();
if (m_patternTex2)
texs[texCount++] = m_patternTex2->GetBooTexture();
if (m_colorTex)
texs[texCount++] = m_colorTex->GetBooTexture();
if (m_bumpMap)
texs[texCount++] = m_bumpMap->GetBooTexture();
if (m_envMap)
texs[texCount++] = m_envMap->GetBooTexture();
if (m_envBumpMap)
texs[texCount++] = m_envBumpMap->GetBooTexture();
if (m_lightmap)
texs[texCount++] = m_lightmap->GetBooTexture();
auto regular = ctx.newShaderDataBinding(pipeline.m_regular, vtxFmt, m_vbo.get(), nullptr, nullptr, 3,
ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
boo::ObjToken<boo::IShaderDataBinding> tessellation;
if (pipeline.m_tessellation)
{
boo::VertexElementDescriptor tessElements[] =
{
{m_pvbo.get(), nullptr, boo::VertexSemantic::Position4},
{m_pvbo.get(), nullptr, boo::VertexSemantic::UV4, 0},
{m_pvbo.get(), nullptr, boo::VertexSemantic::UV4, 1}
};
boo::ObjToken<boo::IVertexFormat> vtxFmtTess = ctx.newVertexFormat(3, tessElements);
texs[texCount++] = m_rippleMap.get();
tessellation = ctx.newShaderDataBinding(pipeline.m_tessellation, vtxFmtTess, m_pvbo.get(), nullptr, nullptr, 3,
ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
}
return {regular, tessellation};
}
#if BOO_HAS_VULKAN
CFluidPlaneShader::BindingPair
CFluidPlaneShader::BuildBinding(boo::VulkanDataFactory::Context& ctx, const ShaderPair& pipeline)
{
boo::ObjToken<boo::IGraphicsBuffer> ubufs[] = { m_uniBuf.get(), m_uniBuf.get(), m_uniBuf.get() };
boo::PipelineStage ubufStages[] = { boo::PipelineStage::Vertex, boo::PipelineStage::Vertex,
boo::PipelineStage::Fragment };
size_t ubufOffs[] = {0, 0, 1280};
size_t ubufSizes[] = {1280, 1280, sizeof(CModelShaders::LightingUniform)};
size_t texCount = 0;
boo::ObjToken<boo::ITexture> texs[8] = {};
if (m_patternTex1)
texs[texCount++] = m_patternTex1->GetBooTexture();
if (m_patternTex2)
texs[texCount++] = m_patternTex2->GetBooTexture();
if (m_colorTex)
texs[texCount++] = m_colorTex->GetBooTexture();
if (m_bumpMap)
texs[texCount++] = m_bumpMap->GetBooTexture();
if (m_envMap)
texs[texCount++] = m_envMap->GetBooTexture();
if (m_envBumpMap)
texs[texCount++] = m_envBumpMap->GetBooTexture();
if (m_lightmap)
texs[texCount++] = m_lightmap->GetBooTexture();
auto regular = ctx.newShaderDataBinding(pipeline.m_regular, s_vtxFmt, m_vbo.get(), nullptr, nullptr,
3, ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
boo::ObjToken<boo::IShaderDataBinding> tessellation;
if (pipeline.m_tessellation)
{
texs[texCount++] = m_rippleMap.get();
tessellation = ctx.newShaderDataBinding(pipeline.m_tessellation, s_vtxFmtTess, m_pvbo.get(), nullptr, nullptr,
3, ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
}
return {regular, tessellation};
}
#endif
}

View File

@@ -1,791 +0,0 @@
#include "CFluidPlaneShader.hpp"
namespace urde
{
static boo::ObjToken<boo::IVertexFormat> s_vtxFmt;
static boo::ObjToken<boo::IVertexFormat> s_vtxFmtTess;
static const char* VS =
"struct VertData\n"
"{\n"
" float4 posIn : POSITION;\n"
" float4 normalIn : NORMAL0;\n"
" float4 binormalIn : NORMAL1;\n"
" float4 tangentIn : NORMAL2;\n"
" float4 colorIn : COLOR;\n"
"};\n"
"\n"
"cbuffer FluidPlaneUniform : register(b0)\n"
"{\n"
" float4x4 mv;\n"
" float4x4 mvNorm;\n"
" float4x4 proj;\n"
" float4x4 texMtxs[6];\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" float4 pos : SV_Position;\n"
" float4 mvPos : POSITION;\n"
" float4 mvNorm : NORMAL;\n"
" float4 mvBinorm : BINORMAL;\n"
" float4 mvTangent : TANGENT;\n"
" float4 color : COLOR;\n"
" float2 uvs[7] : UV;\n"
"};\n"
"\n"
"VertToFrag main(in VertData v)\n"
"{\n"
" VertToFrag vtf;\n"
" float4 pos = float4(v.posIn.xyz, 1.0);\n"
" float4 normalIn = v.normalIn;\n"
" vtf.mvPos = mul(mv, pos);\n"
" vtf.pos = mul(proj, vtf.mvPos);\n"
" vtf.mvNorm = mul(mvNorm, v.normalIn);\n"
" vtf.mvBinorm = mul(mvNorm, v.binormalIn);\n"
" vtf.mvTangent = mul(mvNorm, v.tangentIn);\n"
" vtf.color = float4(v.colorIn.xyz, 1.0);\n"
" vtf.uvs[0] = mul(texMtxs[0], pos).xy;\n"
" vtf.uvs[1] = mul(texMtxs[1], pos).xy;\n"
" vtf.uvs[2] = mul(texMtxs[2], pos).xy;\n"
"%s" // Additional TCGs here
" return vtf;\n"
"}\n";
static const char* TessVS =
"struct VertData\n"
"{\n"
" float4 posIn : POSITION;\n"
" float4 outerLevelsIn : UV0;\n"
" float2 innerLevelsIn : UV1;\n"
"};\n"
"\n"
"struct VertToControl\n"
"{\n"
" float4 minMaxPos : POSITION;\n"
" float4 outerLevels : OUTERLEVELS;\n"
" float2 innerLevels : INNERLEVELS;\n"
"};\n"
"\n"
"VertToControl main(in VertData v)\n"
"{\n"
" VertToControl vtc;\n"
" vtc.minMaxPos = v.posIn;\n"
" vtc.outerLevels = v.outerLevelsIn;\n"
" vtc.innerLevels = v.innerLevelsIn;\n"
" return vtc;\n"
"}\n";
static const char* TessCS =
"struct VertToControl\n"
"{\n"
" float4 minMaxPos : POSITION;\n"
" float4 outerLevels : OUTERLEVELS;\n"
" float2 innerLevels : INNERLEVELS;\n"
"};\n"
"\n"
"struct ControlToEvaluation\n"
"{\n"
" float4 minMaxPos : POSITION;\n"
" float outerLevels[4] : SV_TessFactor;\n"
" float innerLevels[2] : SV_InsideTessFactor;\n"
"};\n"
"\n"
"struct ControlPoint\n"
"{};\n"
"\n"
"ControlToEvaluation patchmain(InputPatch<VertToControl, 1> vtc, uint id : SV_PrimitiveID)\n"
"{\n"
" ControlToEvaluation cte;\n"
" cte.minMaxPos = vtc[id].minMaxPos;\n"
" for (int i=0 ; i<4 ; ++i)\n"
" cte.outerLevels[i] = vtc[id].outerLevels[i];\n"
" for (int i=0 ; i<2 ; ++i)\n"
" cte.innerLevels[i] = vtc[id].innerLevels[i];\n"
" return cte;\n"
"}\n"
"\n"
"[domain(\"quad\")]\n"
"[partitioning(\"integer\")]\n"
"[outputtopology(\"triangle_cw\")]\n"
"[outputcontrolpoints(1)]\n"
"[patchconstantfunc(\"patchmain\")]\n"
"ControlPoint main(InputPatch<VertToControl, 1> vtc, uint i : SV_OutputControlPointID, uint id : SV_PrimitiveID)\n"
"{\n"
" ControlPoint pt;\n"
" return pt;\n"
"}\n";
static const char* TessES =
"struct Ripple\n"
"{\n"
" float4 center; // time, distFalloff\n"
" float4 params; // amplitude, lookupPhase, lookupTime\n"
"};\n"
"\n"
"cbuffer FluidPlaneUniform : register(b0)\n"
"{\n"
" float4x4 mv;\n"
" float4x4 mvNorm;\n"
" float4x4 proj;\n"
" float4x4 texMtxs[6];\n"
" Ripple ripples[20];\n"
" float4 colorMul;\n"
" float rippleNormResolution;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" float4 pos : SV_Position;\n"
" float4 mvPos : POSITION;\n"
" float4 mvNorm : NORMAL;\n"
" float4 mvBinorm : BINORMAL;\n"
" float4 mvTangent : TANGENT;\n"
" float4 color : COLOR;\n"
" float2 uvs[7] : UV;\n"
"};\n"
"\n"
"struct ControlToEvaluation\n"
"{\n"
" float4 minMaxPos : POSITION;\n"
" float outerLevels[4] : SV_TessFactor;\n"
" float innerLevels[2] : SV_InsideTessFactor;\n"
"};\n"
"\n"
"struct ControlPoint\n"
"{};\n"
"\n"
"Texture2D RippleMap : register(t%d);\n"
"SamplerState samp : register(s2);\n"
"\n"
"static const float PI_X2 = 6.283185307179586;\n"
"\n"
"static void ApplyRipple(in Ripple ripple, in float2 pos, inout float height)\n"
"{\n"
" float dist = length(ripple.center.xy - pos);\n"
" float rippleV = RippleMap.SampleLevel(samp, float2(dist * ripple.center.w, ripple.center.z), 0.0).r;\n"
" height += rippleV * ripple.params.x * sin((dist * ripple.params.y + ripple.params.z) * PI_X2);\n"
"}\n"
"\n"
"[domain(\"quad\")]\n"
"VertToFrag main(in ControlToEvaluation cte, in float2 TessCoord : SV_DomainLocation,\n"
" const OutputPatch<ControlPoint, 1> bezpatch)\n"
"{\n"
" float2 posIn = float2(lerp(cte.minMaxPos.x, cte.minMaxPos.z, TessCoord.x),\n"
" lerp(cte.minMaxPos.y, cte.minMaxPos.w, TessCoord.y));\n"
" float height = 0.0;\n"
" float upHeight = 0.0;\n"
" float downHeight = 0.0;\n"
" float rightHeight = 0.0;\n"
" float leftHeight = 0.0;\n"
" for (int i=0 ; i<20 ; ++i)\n"
" {\n"
" ApplyRipple(ripples[i], posIn, height);\n"
" ApplyRipple(ripples[i], posIn + float2(0.0, rippleNormResolution), upHeight);\n"
" ApplyRipple(ripples[i], posIn - float2(0.0, rippleNormResolution), downHeight);\n"
" ApplyRipple(ripples[i], posIn + float2(rippleNormResolution, 0.0), rightHeight);\n"
" ApplyRipple(ripples[i], posIn - float2(rippleNormResolution, 0.0), leftHeight);\n"
" }\n"
" float4 normalIn = float4(normalize(float3((leftHeight - rightHeight),\n"
" (downHeight - upHeight),\n"
" rippleNormResolution)), 1.0);\n"
" float4 binormalIn = float4(normalIn.x, normalIn.z, -normalIn.y, 1.0);\n"
" float4 tangentIn = float4(normalIn.z, normalIn.y, -normalIn.x, 1.0);\n"
" float4 pos = float4(posIn, height, 1.0);\n"
" VertToFrag vtf;\n"
" vtf.mvPos = mul(mv, pos);\n"
" vtf.pos = mul(proj, vtf.mvPos);\n"
" vtf.mvNorm = mul(mvNorm, normalIn);\n"
" vtf.mvBinorm = mul(mvNorm, binormalIn);\n"
" vtf.mvTangent = mul(mvNorm, tangentIn);\n"
" vtf.color = max(height, 0.0) * colorMul;\n"
" vtf.color.a = 1.0;\n"
" vtf.uvs[0] = mul(texMtxs[0], pos).xy;\n"
" vtf.uvs[1] = mul(texMtxs[1], pos).xy;\n"
" vtf.uvs[2] = mul(texMtxs[2], pos).xy;\n"
"%s\n" // Additional TCGs here
" return vtf;\n"
"}\n";
static const char* FS =
"struct Light\n"
"{\n"
" float4 pos;\n"
" float4 dir;\n"
" float4 color;\n"
" float4 linAtt;\n"
" float4 angAtt;\n"
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" int mode;\n"
" float4 color;\n"
" float indScale;\n"
" float start;\n"
"};\n"
"\n"
"cbuffer LightingUniform : register(b2)\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" float4 ambient;\n"
" float4 kColor0;\n"
" float4 kColor1;\n"
" float4 kColor2;\n"
" float4 kColor3;\n"
" Fog fog;\n"
"};\n"
"\n"
"static float4 LightingFunc(float3 mvPosIn, float3 mvNormIn)\n"
"{\n"
" float4 ret = ambient;\n"
" \n"
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
" {\n"
" float3 delta = mvPosIn - 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), 0.0, 1.0);\n"
" }\n"
" \n"
" return ret;\n"
"}\n"
"\n"
"struct VertToFrag\n"
"{\n"
" float4 pos : SV_Position;\n"
" float4 mvPos : POSITION;\n"
" float4 mvNorm : NORMAL;\n"
" float4 mvBinorm : BINORMAL;\n"
" float4 mvTangent : TANGENT;\n"
" float4 color : COLOR;\n"
" float2 uvs[7] : UV;\n"
"};\n"
"\n"
"SamplerState samp : register(s0);\n"
"%s" // Textures here
"float4 main(in VertToFrag vtf) : SV_Target0\n"
"{\n"
" float4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n"
" float4 colorOut;\n"
"%s" // Combiner expression here
" return colorOut;\n"
"}\n";
static const char* FSDoor =
"struct Light\n"
"{\n"
" float4 pos;\n"
" float4 dir;\n"
" float4 color;\n"
" float4 linAtt;\n"
" float4 angAtt;\n"
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" int mode;\n"
" float4 color;\n"
" float indScale;\n"
" float start;\n"
"};\n"
"\n"
"cbuffer LightingUniform : register(b2)\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" float4 ambient;\n"
" float4 kColor0;\n"
" float4 kColor1;\n"
" float4 kColor2;\n"
" float4 kColor3;\n"
" Fog fog;\n"
"};\n"
"struct VertToFrag\n"
"{\n"
" float4 pos : SV_Position;\n"
" float4 mvPos : POSITION;\n"
" float4 mvNorm : NORMAL;\n"
" float4 mvBinorm : BINORMAL;\n"
" float4 mvTangent : TANGENT;\n"
" float4 color : COLOR;\n"
" float2 uvs[7] : UV;\n"
"};\n"
"\n"
"SamplerState samp : register(s0);\n"
"%s" // Textures here
"float4 main(in VertToFrag vtf) : SV_Target0\n"
"{\n"
" float4 colorOut;\n"
"%s" // Combiner expression here
" return colorOut;\n"
"}\n";
CFluidPlaneShader::ShaderPair
CFluidPlaneShader::BuildShader(boo::D3DDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info)
{
if (!s_vtxFmt)
{
boo::VertexElementDescriptor elements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 0},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 1},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 2},
{nullptr, nullptr, boo::VertexSemantic::Color}
};
s_vtxFmt = ctx.newVertexFormat(5, elements);
}
std::string additionalTCGs;
std::string textures;
std::string combiner;
int nextTex = 0;
int nextTCG = 3;
int nextMtx = 4;
int bumpMapUv, envBumpMapUv, envMapUv, lightmapUv;
if (info.m_hasPatternTex1)
textures += hecl::Format("Texture2D patternTex1 : register(t%d);\n", nextTex++);
if (info.m_hasPatternTex2)
textures += hecl::Format("Texture2D patternTex2 : register(t%d);\n", nextTex++);
if (info.m_hasColorTex)
textures += hecl::Format("Texture2D colorTex : register(t%d);\n", nextTex++);
if (info.m_hasBumpMap)
textures += hecl::Format("Texture2D bumpMap : register(t%d);\n", nextTex++);
if (info.m_hasEnvMap)
textures += hecl::Format("Texture2D envMap : register(t%d);\n", nextTex++);
if (info.m_hasEnvBumpMap)
textures += hecl::Format("Texture2D envBumpMap : register(t%d);\n", nextTex++);
if (info.m_hasLightmap)
textures += hecl::Format("Texture2D lightMap : register(t%d);\n", nextTex++);
if (info.m_hasBumpMap)
{
bumpMapUv = nextTCG;
additionalTCGs += hecl::Format(" vtf.uvs[%d] = mul(texMtxs[0], pos).xy;\n", nextTCG++);
}
if (info.m_hasEnvBumpMap)
{
envBumpMapUv = nextTCG;
additionalTCGs += hecl::Format(" vtf.uvs[%d] = mul(texMtxs[3], float4(normalIn.xyz, 1.0)).xy;\n", nextTCG++);
}
if (info.m_hasEnvMap)
{
envMapUv = nextTCG;
additionalTCGs += hecl::Format(" vtf.uvs[%d] = mul(texMtxs[%d], pos).xy;\n", nextTCG++, nextMtx++);
}
if (info.m_hasLightmap)
{
lightmapUv = nextTCG;
additionalTCGs += hecl::Format(" vtf.uvs[%d] = mul(texMtxs[%d], pos).xy;\n", nextTCG++, nextMtx++);
}
switch (info.m_type)
{
case EFluidType::NormalWater:
case EFluidType::PhazonFluid:
case EFluidType::Four:
if (info.m_hasLightmap)
{
combiner += hecl::Format(" float4 lightMapTexel = lightMap.Sample(samp, vtf.uvs[%d]);\n", lightmapUv);
// 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1
// ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS
// Output reg 2
// KColor 2
if (info.m_doubleLightmapBlend)
{
// 1: Tex4TCG2, Tex4, GX_COLOR1A1
// C2, TEX, KONST, RAS
// Output reg 2
// KColor 3
// Tex * K2 + Lighting
combiner += " lighting += lerp(lightMapTexel * kColor2, lightMapTexel, kColor3);\n";
}
else
{
// mix(Tex * K2, Tex, K3) + Lighting
combiner += " lighting += lightMapTexel * kColor2;\n";
}
}
// Next: Tex0TCG, Tex0, GX_COLOR1A1
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// Next: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// Next: Tex2TCG, Tex2, GX_COLOR1A1
// ZERO, TEX, hasTex4 ? C2 : RAS, PREV
// Output reg prev
// (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + lighting) *\n"
" patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n";
else
combiner += " colorOut = lighting * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex && !info.m_hasEnvMap && info.m_hasEnvBumpMap)
{
// Make previous stage indirect, mtx0
combiner += hecl::Format(" float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[%d]).ra - float2(0.5, 0.5)) *\n"
" float2(fog.indScale, -fog.indScale);\n", envBumpMapUv);
combiner += " colorOut += colorTex.Sample(samp, indUvs + vtf.uvs[2]) * lighting;\n";
}
else if (info.m_hasEnvMap)
{
// Next: envTCG, envTex, NULL
// PREV, TEX, KONST, ZERO
// Output reg prev
// KColor 1
// Make previous stage indirect, mtx0
if (info.m_hasColorTex)
combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;\n";
combiner += hecl::Format(" float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[%d]).ra - float2(0.5, 0.5)) *\n"
" float2(fog.indScale, -fog.indScale);\n", envBumpMapUv);
combiner += hecl::Format(" colorOut = lerp(colorOut, envMap.Sample(samp, indUvs + vtf.uvs[%d]), kColor1);\n",
envMapUv);
}
else if (info.m_hasColorTex)
{
combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;\n";
}
break;
case EFluidType::PoisonWater:
if (info.m_hasLightmap)
{
combiner += hecl::Format(" float4 lightMapTexel = lightMap.Sample(samp, vtf.uvs[%d]);\n", lightmapUv);
// 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1
// ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS
// Output reg 2
// KColor 2
if (info.m_doubleLightmapBlend)
{
// 1: Tex4TCG2, Tex4, GX_COLOR1A1
// C2, TEX, KONST, RAS
// Output reg 2
// KColor 3
// Tex * K2 + Lighting
combiner += " lighting += lerp(lightMapTexel * kColor2, lightMapTexel, kColor3);\n";
}
else
{
// mix(Tex * K2, Tex, K3) + Lighting
combiner += " lighting += lightMapTexel * kColor2;\n";
}
}
// Next: Tex0TCG, Tex0, GX_COLOR1A1
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// Next: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// Next: Tex2TCG, Tex2, GX_COLOR1A1
// ZERO, TEX, hasTex4 ? C2 : RAS, PREV
// Output reg prev
// (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + lighting) *\n"
" patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n";
else
combiner += " colorOut = lighting * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
{
if (info.m_hasEnvBumpMap)
{
// Make previous stage indirect, mtx0
combiner += hecl::Format(" float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[%d]).ra - float2(0.5, 0.5)) *\n"
" float2(fog.indScale, -fog.indScale);\n", envBumpMapUv);
combiner += " colorOut += colorTex.Sample(samp, indUvs + vtf.uvs[2]) * lighting;\n";
}
else
{
combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;\n";
}
}
break;
case EFluidType::Lava:
// 0: Tex0TCG, Tex0, GX_COLOR0A0
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// 1: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// 2: Tex2TCG, Tex2, NULL
// ZERO, TEX, ONE, PREV
// Output reg prev
// (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + vtf.color) *\n"
" patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n";
else
combiner += " colorOut = vtf.color * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]);\n";
if (info.m_hasBumpMap)
{
// 3: bumpMapTCG, bumpMap, NULL
// ZERO, TEX, ONE, HALF
// Output reg 0, no clamp, no bias
// 4: bumpMapTCG2, bumpMap, NULL
// ZERO, TEX, ONE, C0
// Output reg 0, subtract, clamp, no bias
combiner += " float3 lightVec = lights[3].pos.xyz - vtf.mvPos.xyz;\n"
" float lx = dot(vtf.mvTangent.xyz, lightVec);\n"
" float ly = dot(vtf.mvBinorm.xyz, lightVec);\n";
combiner += hecl::Format(" float4 emboss1 = bumpMap.Sample(samp, vtf.uvs[%d]) + float4(0.5);\n"
" float4 emboss2 = bumpMap.Sample(samp, vtf.uvs[%d] + float2(lx, ly));\n",
bumpMapUv, bumpMapUv);
// 5: NULL, NULL, NULL
// ZERO, PREV, C0, ZERO
// Output reg prev, scale 2, clamp
// colorOut * clamp(emboss1 + 0.5 - emboss2, 0.0, 1.0) * 2.0
combiner += "colorOut *= clamp((emboss1 + float4(0.5) - emboss2) * float4(2.0), float4(0.0), float4(1.0));\n";
}
break;
case EFluidType::ThickLava:
// 0: Tex0TCG, Tex0, GX_COLOR0A0
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// 1: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// 2: Tex2TCG, Tex2, NULL
// ZERO, TEX, ONE, PREV
// Output reg prev
// (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + vtf.color) *\n"
" patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n";
else
combiner += " colorOut = vtf.color * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]);\n";
if (info.m_hasBumpMap)
{
// 3: bumpMapTCG, bumpMap, NULL
// ZERO, TEX, PREV, ZERO
// Output reg prev, scale 2
combiner += hecl::Format(" float4 emboss1 = bumpMap.Sample(samp, vtf.uvs[%d]) + float4(0.5);\n", bumpMapUv);
combiner += "colorOut *= emboss1 * float4(2.0);\n";
}
break;
}
combiner += " colorOut.a = kColor0.a;\n";
char *finalVS, *finalFS;
asprintf(&finalVS, VS, additionalTCGs.c_str());
asprintf(&finalFS, FS, textures.c_str(), combiner.c_str());
auto regular = ctx.newShaderPipeline(finalVS, finalFS, nullptr, nullptr, nullptr, s_vtxFmt,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None);
boo::ObjToken<boo::IShaderPipeline> tessellation;
if (info.m_tessellation)
{
if (!s_vtxFmtTess)
{
boo::VertexElementDescriptor elements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::UV4, 0},
{nullptr, nullptr, boo::VertexSemantic::UV4, 1}
};
s_vtxFmtTess = ctx.newVertexFormat(3, elements);
}
char *finalESs;
asprintf(&finalESs, TessES, nextTex, additionalTCGs.c_str());
tessellation = ctx.newTessellationShaderPipeline(
TessVS, finalFS, TessCS, finalESs,
nullptr, nullptr, nullptr, nullptr, nullptr, s_vtxFmtTess,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
1, boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
free(finalESs);
}
free(finalVS);
free(finalFS);
return {regular, tessellation};
}
CFluidPlaneShader::ShaderPair
CFluidPlaneShader::BuildShader(boo::D3DDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info)
{
if (!s_vtxFmt)
{
boo::VertexElementDescriptor elements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 0},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 1},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 2},
{nullptr, nullptr, boo::VertexSemantic::Color}
};
s_vtxFmt = ctx.newVertexFormat(5, elements);
}
std::string additionalTCGs;
std::string textures;
std::string combiner;
int nextTex = 0;
if (info.m_hasPatternTex1)
textures += hecl::Format("Texture2D patternTex1 : register(t%d);\n", nextTex++);
if (info.m_hasPatternTex2)
textures += hecl::Format("Texture2D patternTex2 : register(t%d);\n", nextTex++);
if (info.m_hasColorTex)
textures += hecl::Format("Texture2D colorTex : register(t%d);\n", nextTex++);
// Tex0 * kColor0 * Tex1 + Tex2
if (info.m_hasPatternTex1 && info.m_hasPatternTex2)
{
combiner += " colorOut = patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 *\n"
" patternTex2.Sample(samp, vtf.uvs[1]);\n";
}
else
{
combiner += " colorOut = float4(0.0);\n";
}
if (info.m_hasColorTex)
{
combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]);\n";
}
combiner += " colorOut.a = kColor0.a;\n";
char *finalVS, *finalFS;
asprintf(&finalVS, VS, additionalTCGs.c_str());
asprintf(&finalFS, FSDoor, textures.c_str(), combiner.c_str());
auto ret = ctx.newShaderPipeline(finalVS, finalFS, nullptr, nullptr, nullptr, s_vtxFmt,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None);
free(finalVS);
free(finalFS);
return {ret, {}};
}
template <>
void CFluidPlaneShader::_Shutdown<boo::D3DDataFactory>()
{
s_vtxFmt.reset();
s_vtxFmtTess.reset();
}
CFluidPlaneShader::BindingPair
CFluidPlaneShader::BuildBinding(boo::D3DDataFactory::Context& ctx, const ShaderPair& pipeline)
{
boo::ObjToken<boo::IGraphicsBuffer> ubufs[] = { m_uniBuf.get(), m_uniBuf.get(), m_uniBuf.get() };
boo::PipelineStage ubufStages[] = { boo::PipelineStage::Vertex, boo::PipelineStage::Vertex,
boo::PipelineStage::Fragment };
size_t ubufOffs[] = {0, 0, 1280};
size_t ubufSizes[] = {1280, 1280, sizeof(CModelShaders::LightingUniform)};
size_t texCount = 0;
boo::ObjToken<boo::ITexture> texs[8] = {};
if (m_patternTex1)
texs[texCount++] = m_patternTex1->GetBooTexture();
if (m_patternTex2)
texs[texCount++] = m_patternTex2->GetBooTexture();
if (m_colorTex)
texs[texCount++] = m_colorTex->GetBooTexture();
if (m_bumpMap)
texs[texCount++] = m_bumpMap->GetBooTexture();
if (m_envMap)
texs[texCount++] = m_envMap->GetBooTexture();
if (m_envBumpMap)
texs[texCount++] = m_envBumpMap->GetBooTexture();
if (m_lightmap)
texs[texCount++] = m_lightmap->GetBooTexture();
auto regular = ctx.newShaderDataBinding(pipeline.m_regular, s_vtxFmt, m_vbo.get(), nullptr, nullptr, 3,
ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
boo::ObjToken<boo::IShaderDataBinding> tessellation;
if (pipeline.m_tessellation)
{
texs[texCount++] = m_rippleMap.get();
tessellation = ctx.newShaderDataBinding(pipeline.m_tessellation, s_vtxFmtTess, m_pvbo.get(), nullptr, nullptr,
3, ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
}
return {regular, tessellation};
}
}

View File

@@ -1,799 +0,0 @@
#include "CFluidPlaneShader.hpp"
namespace urde
{
static boo::ObjToken<boo::IVertexFormat> s_vtxFmt;
static boo::ObjToken<boo::IVertexFormat> s_tessVtxFmt;
static const char* VS =
"#include <metal_stdlib>\n"
"using namespace metal;\n"
"struct VertData\n"
"{\n"
" float4 posIn [[ attribute(0) ]];\n"
" float4 normalIn [[ attribute(1) ]];\n"
" float4 binormalIn [[ attribute(2) ]];\n"
" float4 tangentIn [[ attribute(3) ]];\n"
" float4 colorIn [[ attribute(4) ]];\n"
"};\n"
"\n"
"struct FluidPlaneUniform\n"
"{\n"
" float4x4 mv;\n"
" float4x4 mvNorm;\n"
" float4x4 proj;\n"
" float4x4 texMtxs[6];\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" float4 pos [[ position ]];\n"
" float4 mvPos;\n"
" float4 mvNorm;\n"
" float4 mvBinorm;\n"
" float4 mvTangent;\n"
" float4 color;\n"
" float2 uv0;\n"
" float2 uv1;\n"
" float2 uv2;\n"
" float2 uv3;\n"
" float2 uv4;\n"
" float2 uv5;\n"
" float2 uv6;\n"
"};\n"
"\n"
"vertex VertToFrag vmain(VertData v [[ stage_in ]],\n"
" constant FluidPlaneUniform& fu [[ buffer(2) ]])\n"
"{\n"
" VertToFrag vtf;\n"
" float4 pos = float4(v.posIn.xyz, 1.0);\n"
" float4 normalIn = v.normalIn;\n"
" vtf.mvPos = fu.mv * pos;\n"
" vtf.pos = fu.proj * vtf.mvPos;\n"
" vtf.mvNorm = fu.mvNorm * v.normalIn;\n"
" vtf.mvBinorm = fu.mvNorm * v.binormalIn;\n"
" vtf.mvTangent = fu.mvNorm * v.tangentIn;\n"
" vtf.color = v.colorIn;\n"
" vtf.uv0 = (fu.texMtxs[0] * pos).xy;\n"
" vtf.uv1 = (fu.texMtxs[1] * pos).xy;\n"
" vtf.uv2 = (fu.texMtxs[2] * pos).xy;\n"
"%s" // Additional TCGs here
" return vtf;\n"
"}\n";
static const char* TessCS =
"#include <metal_stdlib>\n"
"using namespace metal;\n"
"struct VertData\n"
"{\n"
" float4 minMaxPos [[ attribute(0) ]];\n"
" float4 outerLevelsIn [[ attribute(1) ]];\n"
" float2 innerLevelsIn [[ attribute(2) ]];\n"
"};\n"
"\n"
"struct KernelPatchInfo {\n"
" uint numPatches; // total number of patches to process.\n"
" // we need this because this value may\n"
" // not be a multiple of threadgroup size.\n"
" ushort numPatchesInThreadGroup; // number of patches processed by a\n"
" // thread-group\n"
" ushort numControlPointsPerPatch;\n"
"};\n"
"\n"
"kernel void\n"
"cmain(VertData v [[ stage_in ]],\n"
" constant KernelPatchInfo& patchInfo [[ buffer(2) ]],\n"
" device MTLQuadTessellationFactorsHalf* tessellationFactorBuffer [[ buffer(3) ]],\n"
" ushort lID [[ thread_position_in_threadgroup ]],\n"
" ushort groupID [[ threadgroup_position_in_grid ]])\n"
"{\n"
" uint patchGroupID = groupID * patchInfo.numPatchesInThreadGroup;\n"
"\n"
" // execute the per-patch hull function\n"
" if (lID < patchInfo.numPatchesInThreadGroup)\n"
" {\n"
" uint patchID = patchGroupID + lID;\n"
" device MTLQuadTessellationFactorsHalf& patchOut = tessellationFactorBuffer[patchID];\n"
" for (int i=0 ; i<4 ; ++i)\n"
" patchOut.edgeTessellationFactor[i] = v.outerLevelsIn[i];\n"
" for (int i=0 ; i<2 ; ++i)\n"
" patchOut.insideTessellationFactor[i] = v.innerLevelsIn[i];\n"
" }\n"
"}\n";
static const char* TessES =
"#include <metal_stdlib>\n"
"using namespace metal;\n"
"struct Ripple\n"
"{\n"
" float4 center; // time, distFalloff\n"
" float4 params; // amplitude, lookupPhase, lookupTime\n"
"};\n"
"\n"
"struct FluidPlaneUniform\n"
"{\n"
" float4x4 mv;\n"
" float4x4 mvNorm;\n"
" float4x4 proj;\n"
" float4x4 texMtxs[6];\n"
" Ripple ripples[20];\n"
" float4 colorMul;\n"
" float rippleNormResolution;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" float4 pos [[ position ]];\n"
" float4 mvPos;\n"
" float4 mvNorm;\n"
" float4 mvBinorm;\n"
" float4 mvTangent;\n"
" float4 color;\n"
" float2 uv0;\n"
" float2 uv1;\n"
" float2 uv2;\n"
" float2 uv3;\n"
" float2 uv4;\n"
" float2 uv5;\n"
" float2 uv6;\n"
"};\n"
"\n"
"struct VertData\n"
"{\n"
" float4 minMaxPos [[ attribute(0) ]];\n"
" float4 outerLevelsIn [[ attribute(1) ]];\n"
" float2 innerLevelsIn [[ attribute(2) ]];\n"
"};\n"
"\n"
"#define PI_X2 6.283185307179586\n"
"\n"
"static void ApplyRipple(constant Ripple& ripple, float2 pos, thread float& height,\n"
" sampler samp, texture2d<float> RippleMap)\n"
"{\n"
" float dist = length(ripple.center.xy - pos);\n"
" float rippleV = RippleMap.sample(samp, float2(dist * ripple.center.w, ripple.center.z), level(0.0)).r;\n"
" height += rippleV * ripple.params.x * sin((dist * ripple.params.y + ripple.params.z) * PI_X2);\n"
"}\n"
"\n"
"[[ patch(quad, 1) ]]\n"
"vertex VertToFrag emain(VertData v [[ stage_in ]], float2 TessCoord [[ position_in_patch ]],\n"
" constant FluidPlaneUniform& fu [[ buffer(2) ]],\n"
" sampler samp [[ sampler(2) ]],\n"
" texture2d<float> RippleMap [[ texture(%d) ]])\n"
"{\n"
" float2 posIn = float2(mix(v.minMaxPos.x, v.minMaxPos.z, TessCoord.x),\n"
" mix(v.minMaxPos.y, v.minMaxPos.w, TessCoord.y));\n"
" float height = 0.0;\n"
" float upHeight = 0.0;\n"
" float downHeight = 0.0;\n"
" float rightHeight = 0.0;\n"
" float leftHeight = 0.0;\n"
" for (int i=0 ; i<20 ; ++i)\n"
" {\n"
" ApplyRipple(fu.ripples[i], posIn, height, samp, RippleMap);\n"
" ApplyRipple(fu.ripples[i], posIn + float2(0.0, fu.rippleNormResolution), upHeight, samp, RippleMap);\n"
" ApplyRipple(fu.ripples[i], posIn - float2(0.0, fu.rippleNormResolution), downHeight, samp, RippleMap);\n"
" ApplyRipple(fu.ripples[i], posIn + float2(fu.rippleNormResolution, 0.0), rightHeight, samp, RippleMap);\n"
" ApplyRipple(fu.ripples[i], posIn - float2(fu.rippleNormResolution, 0.0), leftHeight, samp, RippleMap);\n"
" }\n"
" float4 normalIn = float4(normalize(float3((leftHeight - rightHeight),\n"
" (downHeight - upHeight),\n"
" fu.rippleNormResolution)), 1.0);\n"
" float4 binormalIn = float4(normalIn.x, normalIn.z, -normalIn.y, 1.0);\n"
" float4 tangentIn = float4(normalIn.z, normalIn.y, -normalIn.x, 1.0);\n"
" float4 pos = float4(posIn, height, 1.0);\n"
" VertToFrag vtf;\n"
" vtf.mvPos = (fu.mv * pos);\n"
" vtf.pos = (fu.proj * vtf.mvPos);\n"
" vtf.mvNorm = (fu.mvNorm * normalIn);\n"
" vtf.mvBinorm = (fu.mvNorm * binormalIn);\n"
" vtf.mvTangent = (fu.mvNorm * tangentIn);\n"
" vtf.color = max(height, 0.0) * fu.colorMul;\n"
" vtf.color.a = 1.0;\n"
" vtf.uv0 = (fu.texMtxs[0] * pos).xy;\n"
" vtf.uv1 = (fu.texMtxs[1] * pos).xy;\n"
" vtf.uv2 = (fu.texMtxs[2] * pos).xy;\n"
"%s\n" // Additional TCGs here
" return vtf;\n"
"}\n";
static const char* FS =
"#include <metal_stdlib>\n"
"using namespace metal;\n"
"\n"
"struct Light\n"
"{\n"
" float4 pos;\n"
" float4 dir;\n"
" float4 color;\n"
" float4 linAtt;\n"
" float4 angAtt;\n"
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" int mode;\n"
" float4 color;\n"
" float indScale;\n"
" float start;\n"
"};\n"
"\n"
"struct LightingUniform\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" float4 ambient;\n"
" float4 kColor0;\n"
" float4 kColor1;\n"
" float4 kColor2;\n"
" float4 kColor3;\n"
" Fog fog;\n"
"};\n"
"\n"
"static float4 LightingFunc(constant LightingUniform& lu, float3 mvPosIn, float3 mvNormIn)\n"
"{\n"
" float4 ret = lu.ambient;\n"
" \n"
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
" {\n"
" float3 delta = mvPosIn - lu.lights[i].pos.xyz;\n"
" float dist = length(delta);\n"
" float angDot = clamp(dot(normalize(delta), lu.lights[i].dir.xyz), 0.0, 1.0);\n"
" float att = 1.0 / (lu.lights[i].linAtt[2] * dist * dist +\n"
" lu.lights[i].linAtt[1] * dist +\n"
" lu.lights[i].linAtt[0]);\n"
" float angAtt = lu.lights[i].angAtt[2] * angDot * angDot +\n"
" lu.lights[i].angAtt[1] * angDot +\n"
" lu.lights[i].angAtt[0];\n"
" ret += lu.lights[i].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn), 0.0, 1.0);\n"
" }\n"
" \n"
" return ret;\n"
"}\n"
"\n"
"struct VertToFrag\n"
"{\n"
" float4 pos [[ position ]];\n"
" float4 mvPos;\n"
" float4 mvNorm;\n"
" float4 mvBinorm;\n"
" float4 mvTangent;\n"
" float4 color;\n"
" float2 uv0;\n"
" float2 uv1;\n"
" float2 uv2;\n"
" float2 uv3;\n"
" float2 uv4;\n"
" float2 uv5;\n"
" float2 uv6;\n"
"};\n"
"\n"
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
" sampler samp [[ sampler(0) ]],\n"
" constant LightingUniform& lu [[ buffer(4) ]]%s)\n" // Textures here
"{\n"
" float4 lighting = LightingFunc(lu, vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n"
" float4 colorOut;\n"
"%s" // Combiner expression here
" return colorOut;\n"
"}\n";
static const char* FSDoor =
"#include <metal_stdlib>\n"
"using namespace metal;\n"
"\n"
"struct Light\n"
"{\n"
" float4 pos;\n"
" float4 dir;\n"
" float4 color;\n"
" float4 linAtt;\n"
" float4 angAtt;\n"
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" int mode;\n"
" float4 color;\n"
" float indScale;\n"
" float start;\n"
"};\n"
"\n"
"struct LightingUniform\n"
"{\n"
" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n"
" float4 ambient;\n"
" float4 kColor0;\n"
" float4 kColor1;\n"
" float4 kColor2;\n"
" float4 kColor3;\n"
" Fog fog;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" float4 pos [[ position ]];\n"
" float4 mvPos;\n"
" float4 mvNorm;\n"
" float4 mvBinorm;\n"
" float4 mvTangent;\n"
" float4 color;\n"
" float2 uv0;\n"
" float2 uv1;\n"
" float2 uv2;\n"
" float2 uv3;\n"
" float2 uv4;\n"
" float2 uv5;\n"
" float2 uv6;\n"
"};\n"
"\n"
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
" sampler samp [[ sampler(0) ]],\n"
" constant LightingUniform& lu [[ buffer(4) ]]%s)\n" // Textures here
"{\n"
" float4 colorOut;\n"
"%s" // Combiner expression here
" return colorOut;\n"
"}\n";
CFluidPlaneShader::ShaderPair
CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info)
{
if (!s_vtxFmt)
{
boo::VertexElementDescriptor elements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 0},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 1},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 2},
{nullptr, nullptr, boo::VertexSemantic::Color}
};
s_vtxFmt = ctx.newVertexFormat(5, elements);
}
std::string additionalTCGs;
std::string textures;
std::string combiner;
int nextTex = 0;
int nextTCG = 3;
int nextMtx = 4;
int bumpMapUv, envBumpMapUv, envMapUv, lightmapUv;
if (info.m_hasPatternTex1)
textures += hecl::Format(",\ntexture2d<float> patternTex1 [[ texture(%d) ]]", nextTex++);
if (info.m_hasPatternTex2)
textures += hecl::Format(",\ntexture2d<float> patternTex2 [[ texture(%d) ]]", nextTex++);
if (info.m_hasColorTex)
textures += hecl::Format(",\ntexture2d<float> colorTex [[ texture(%d) ]]", nextTex++);
if (info.m_hasBumpMap)
textures += hecl::Format(",\ntexture2d<float> bumpMap [[ texture(%d) ]]", nextTex++);
if (info.m_hasEnvMap)
textures += hecl::Format(",\ntexture2d<float> envMap [[ texture(%d) ]]", nextTex++);
if (info.m_hasEnvBumpMap)
textures += hecl::Format(",\ntexture2d<float> envBumpMap [[ texture(%d) ]]", nextTex++);
if (info.m_hasLightmap)
textures += hecl::Format(",\ntexture2d<float> lightMap [[ texture(%d) ]]", nextTex++);
if (info.m_hasBumpMap)
{
bumpMapUv = nextTCG;
additionalTCGs += hecl::Format(" vtf.uv%d = (fu.texMtxs[0] * pos).xy;\n", nextTCG++);
}
if (info.m_hasEnvBumpMap)
{
envBumpMapUv = nextTCG;
additionalTCGs += hecl::Format(" vtf.uv%d = (fu.texMtxs[3] * float4(normalIn.xyz, 1.0)).xy;\n", nextTCG++);
}
if (info.m_hasEnvMap)
{
envMapUv = nextTCG;
additionalTCGs += hecl::Format(" vtf.uv%d = (fu.texMtxs[%d] * pos).xy;\n", nextTCG++, nextMtx++);
}
if (info.m_hasLightmap)
{
lightmapUv = nextTCG;
additionalTCGs += hecl::Format(" vtf.uv%d = (fu.texMtxs[%d] * pos).xy;\n", nextTCG++, nextMtx++);
}
switch (info.m_type)
{
case EFluidType::NormalWater:
case EFluidType::PhazonFluid:
case EFluidType::Four:
if (info.m_hasLightmap)
{
combiner += hecl::Format(" float4 lightMapTexel = lightMap.sample(samp, vtf.uv%d);\n", lightmapUv);
// 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1
// ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS
// Output reg 2
// KColor 2
if (info.m_doubleLightmapBlend)
{
// 1: Tex4TCG2, Tex4, GX_COLOR1A1
// C2, TEX, KONST, RAS
// Output reg 2
// KColor 3
// Tex * K2 + Lighting
combiner += " lighting += mix(lightMapTexel * lu.kColor2, lightMapTexel, lu.kColor3);\n";
}
else
{
// mix(Tex * K2, Tex, K3) + Lighting
combiner += " lighting += lightMapTexel * lu.kColor2;\n";
}
}
// Next: Tex0TCG, Tex0, GX_COLOR1A1
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// Next: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// Next: Tex2TCG, Tex2, GX_COLOR1A1
// ZERO, TEX, hasTex4 ? C2 : RAS, PREV
// Output reg prev
// (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (patternTex1.sample(samp, vtf.uv0) * lu.kColor0 + lighting) *\n"
" patternTex2.sample(samp, vtf.uv1) + vtf.color;\n";
else
combiner += " colorOut = lighting * patternTex2.sample(samp, vtf.uv1) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex && !info.m_hasEnvMap && info.m_hasEnvBumpMap)
{
// Make previous stage indirect, mtx0
combiner += hecl::Format(" float2 indUvs = (envBumpMap.sample(samp, vtf.uv%d).ra - float2(0.5, 0.5)) *\n"
" float2(lu.fog.indScale, -lu.fog.indScale);\n", envBumpMapUv);
combiner += " colorOut += colorTex.sample(samp, indUvs + vtf.uv2) * lighting;\n";
}
else if (info.m_hasEnvMap)
{
// Next: envTCG, envTex, NULL
// PREV, TEX, KONST, ZERO
// Output reg prev
// KColor 1
// Make previous stage indirect, mtx0
if (info.m_hasColorTex)
combiner += " colorOut += colorTex.sample(samp, vtf.uv2) * lighting;\n";
combiner += hecl::Format(" float2 indUvs = (envBumpMap.sample(samp, vtf.uv%d).ra - float2(0.5, 0.5)) *\n"
" float2(lu.fog.indScale, -lu.fog.indScale);\n", envBumpMapUv);
combiner += hecl::Format(" colorOut = mix(colorOut, envMap.sample(samp, indUvs + vtf.uv%d), lu.kColor1);\n",
envMapUv);
}
else if (info.m_hasColorTex)
{
combiner += " colorOut += colorTex.sample(samp, vtf.uv2) * lighting;\n";
}
break;
case EFluidType::PoisonWater:
if (info.m_hasLightmap)
{
combiner += hecl::Format(" float4 lightMapTexel = lightMap.sample(samp, vtf.uv%d);\n", lightmapUv);
// 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1
// ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS
// Output reg 2
// KColor 2
if (info.m_doubleLightmapBlend)
{
// 1: Tex4TCG2, Tex4, GX_COLOR1A1
// C2, TEX, KONST, RAS
// Output reg 2
// KColor 3
// Tex * K2 + Lighting
combiner += " lighting += mix(lightMapTexel * lu.kColor2, lightMapTexel, lu.kColor3);\n";
}
else
{
// mix(Tex * K2, Tex, K3) + Lighting
combiner += " lighting += lightMapTexel * lu.kColor2;\n";
}
}
// Next: Tex0TCG, Tex0, GX_COLOR1A1
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// Next: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// Next: Tex2TCG, Tex2, GX_COLOR1A1
// ZERO, TEX, hasTex4 ? C2 : RAS, PREV
// Output reg prev
// (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (patternTex1.sample(samp, vtf.uv0) * lu.kColor0 + lighting) *\n"
" patternTex2.sample(samp, vtf.uv1) + vtf.color;\n";
else
combiner += " colorOut = lighting * patternTex2.sample(samp, vtf.uv1) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
{
if (info.m_hasEnvBumpMap)
{
// Make previous stage indirect, mtx0
combiner += hecl::Format(" float2 indUvs = (envBumpMap.sample(samp, vtf.uv%d).ra - float2(0.5, 0.5)) *\n"
" float2(lu.fog.indScale, -lu.fog.indScale);\n", envBumpMapUv);
combiner += " colorOut += colorTex.sample(samp, indUvs + vtf.uv2) * lighting;\n";
}
else
{
combiner += " colorOut += colorTex.sample(samp, vtf.uv2) * lighting;\n";
}
}
break;
case EFluidType::Lava:
// 0: Tex0TCG, Tex0, GX_COLOR0A0
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// 1: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// 2: Tex2TCG, Tex2, NULL
// ZERO, TEX, ONE, PREV
// Output reg prev
// (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (patternTex1.sample(samp, vtf.uv0) * lu.kColor0 + vtf.color) *\n"
" patternTex2.sample(samp, vtf.uv1) + vtf.color;\n";
else
combiner += " colorOut = vtf.color * patternTex2.sample(samp, vtf.uv1) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
combiner += " colorOut += colorTex.sample(samp, vtf.uv2);\n";
if (info.m_hasBumpMap)
{
// 3: bumpMapTCG, bumpMap, NULL
// ZERO, TEX, ONE, HALF
// Output reg 0, no clamp, no bias
// 4: bumpMapTCG2, bumpMap, NULL
// ZERO, TEX, ONE, C0
// Output reg 0, subtract, clamp, no bias
combiner += " float3 lightVec = lights[3].pos.xyz - vtf.mvPos.xyz;\n"
" float lx = dot(vtf.mvTangent.xyz, lightVec);\n"
" float ly = dot(vtf.mvBinorm.xyz, lightVec);\n";
combiner += hecl::Format(" float4 emboss1 = bumpMap.sample(samp, vtf.uv%d) + float4(0.5);\n"
" float4 emboss2 = bumpMap.sample(samp, vtf.uv%d + float2(lx, ly));\n",
bumpMapUv, bumpMapUv);
// 5: NULL, NULL, NULL
// ZERO, PREV, C0, ZERO
// Output reg prev, scale 2, clamp
// colorOut * clamp(emboss1 + 0.5 - emboss2, 0.0, 1.0) * 2.0
combiner += "colorOut *= clamp((emboss1 + float4(0.5) - emboss2) * float4(2.0), float4(0.0), float4(1.0));\n";
}
break;
case EFluidType::ThickLava:
// 0: Tex0TCG, Tex0, GX_COLOR0A0
// ZERO, TEX, KONST, RAS
// Output reg prev
// KColor 0
// 1: Tex1TCG, Tex1, GX_COLOR0A0
// ZERO, TEX, PREV, RAS
// Output reg prev
// 2: Tex2TCG, Tex2, NULL
// ZERO, TEX, ONE, PREV
// Output reg prev
// (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2
if (info.m_hasPatternTex2)
{
if (info.m_hasPatternTex1)
combiner += " colorOut = (patternTex1.sample(samp, vtf.uv0) * lu.kColor0 + vtf.color) *\n"
" patternTex2.sample(samp, vtf.uv1) + vtf.color;\n";
else
combiner += " colorOut = vtf.color * patternTex2.sample(samp, vtf.uv1) + vtf.color;\n";
}
else
{
combiner += " colorOut = vtf.color;\n";
}
if (info.m_hasColorTex)
combiner += " colorOut += colorTex.sample(samp, vtf.uv2);\n";
if (info.m_hasBumpMap)
{
// 3: bumpMapTCG, bumpMap, NULL
// ZERO, TEX, PREV, ZERO
// Output reg prev, scale 2
combiner += hecl::Format(" float4 emboss1 = bumpMap.sample(samp, vtf.uv%d) + float4(0.5);\n", bumpMapUv);
combiner += "colorOut *= emboss1 * float4(2.0);\n";
}
break;
}
combiner += " colorOut.a = lu.kColor0.a;\n";
char *finalVS, *finalFS;
asprintf(&finalVS, VS, additionalTCGs.c_str());
asprintf(&finalFS, FS, textures.c_str(), combiner.c_str());
auto regular = ctx.newShaderPipeline(finalVS, finalFS, nullptr, nullptr, s_vtxFmt,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None);
boo::ObjToken<boo::IShaderPipeline> tessellation;
if (info.m_tessellation)
{
if (!s_tessVtxFmt)
{
boo::VertexElementDescriptor tessElements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::UV4, 0},
{nullptr, nullptr, boo::VertexSemantic::UV4, 1},
};
s_tessVtxFmt = ctx.newVertexFormat(3, tessElements);
}
char *finalES;
asprintf(&finalES, TessES, nextTex, additionalTCGs.c_str());
tessellation = ctx.newTessellationShaderPipeline(TessCS, finalFS, finalES, nullptr, nullptr, nullptr, s_tessVtxFmt,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha,
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
1, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None);
free(finalES);
}
free(finalVS);
free(finalFS);
return {regular, tessellation};
}
CFluidPlaneShader::ShaderPair
CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info)
{
if (!s_vtxFmt)
{
boo::VertexElementDescriptor elements[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 0},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 1},
{nullptr, nullptr, boo::VertexSemantic::Normal4, 2},
{nullptr, nullptr, boo::VertexSemantic::Color}
};
s_vtxFmt = ctx.newVertexFormat(5, elements);
}
std::string additionalTCGs;
std::string textures;
std::string combiner;
int nextTex = 0;
if (info.m_hasPatternTex1)
textures += hecl::Format(",\ntexture2d<float> patternTex1 [[ texture(%d) ]]", nextTex++);
if (info.m_hasPatternTex2)
textures += hecl::Format(",\ntexture2d<float> patternTex2 [[ texture(%d) ]]", nextTex++);
if (info.m_hasColorTex)
textures += hecl::Format(",\ntexture2d<float> colorTex [[ texture(%d) ]]", nextTex++);
// Tex0 * kColor0 * Tex1 + Tex2
if (info.m_hasPatternTex1 && info.m_hasPatternTex2)
{
combiner += " colorOut = patternTex1.sample(samp, vtf.uv0) * lu.kColor0 *\n"
" patternTex2.sample(samp, vtf.uv1);\n";
}
else
{
combiner += " colorOut = float4(0.0);\n";
}
if (info.m_hasColorTex)
{
combiner += " colorOut += colorTex.sample(samp, vtf.uv2);\n";
}
combiner += " colorOut.a = lu.kColor0.a;\n";
char *finalVS, *finalFS;
asprintf(&finalVS, VS, additionalTCGs.c_str());
asprintf(&finalFS, FSDoor, textures.c_str(), combiner.c_str());
auto ret = ctx.newShaderPipeline(finalVS, finalFS, nullptr, nullptr, s_vtxFmt,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
boo::CullMode::None);
free(finalVS);
free(finalFS);
return {ret, {}};
}
template <>
void CFluidPlaneShader::_Shutdown<boo::MetalDataFactory>()
{
s_vtxFmt.reset();
s_tessVtxFmt.reset();
}
CFluidPlaneShader::BindingPair
CFluidPlaneShader::BuildBinding(boo::MetalDataFactory::Context& ctx, const ShaderPair& pipeline)
{
boo::ObjToken<boo::IGraphicsBuffer> ubufs[] = { m_uniBuf.get(), m_uniBuf.get(), m_uniBuf.get() };
boo::PipelineStage ubufStages[] = { boo::PipelineStage::Vertex, boo::PipelineStage::Vertex,
boo::PipelineStage::Fragment };
size_t ubufOffs[] = {0, 0, 1280};
size_t ubufSizes[] = {1280, 1280, sizeof(CModelShaders::LightingUniform)};
size_t texCount = 0;
boo::ObjToken<boo::ITexture> texs[8];
if (m_patternTex1)
texs[texCount++] = m_patternTex1->GetBooTexture();
if (m_patternTex2)
texs[texCount++] = m_patternTex2->GetBooTexture();
if (m_colorTex)
texs[texCount++] = m_colorTex->GetBooTexture();
if (m_bumpMap)
texs[texCount++] = m_bumpMap->GetBooTexture();
if (m_envMap)
texs[texCount++] = m_envMap->GetBooTexture();
if (m_envBumpMap)
texs[texCount++] = m_envBumpMap->GetBooTexture();
if (m_lightmap)
texs[texCount++] = m_lightmap->GetBooTexture();
auto regular = ctx.newShaderDataBinding(pipeline.m_regular, s_vtxFmt, m_vbo.get(), nullptr, nullptr, 3,
ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
boo::ObjToken<boo::IShaderDataBinding> tessellation;
if (pipeline.m_tessellation)
{
texs[texCount++] = m_rippleMap.get();
tessellation = ctx.newShaderDataBinding(pipeline.m_tessellation, s_tessVtxFmt, m_pvbo.get(), nullptr, nullptr, 3,
ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
}
return {regular, tessellation};
}
}

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CFOGVOLUMEFILTER_HPP__
#define __URDE_CFOGVOLUMEFILTER_HPP__
#pragma once
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
@@ -26,4 +25,3 @@ public:
}
#endif // __URDE_CFOGVOLUMEFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CFOGVOLUMEPLANESHADER_HPP__
#define __URDE_CFOGVOLUMEPLANESHADER_HPP__
#pragma once
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "zeus/CMatrix4f.hpp"
@@ -30,4 +29,3 @@ public:
}
#endif // __URDE_CFOGVOLUMEPLANESHADER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CLINERENDERERSHADERS_HPP__
#define __URDE_CLINERENDERERSHADERS_HPP__
#pragma once
#include "Graphics/CGraphics.hpp"
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
@@ -34,4 +33,3 @@ public:
}
#endif // __URDE_CLINERENDERERSHADERS_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CMAPSURFACESHADER_HPP__
#define __URDE_CMAPSURFACESHADER_HPP__
#pragma once
#include "RetroTypes.hpp"
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
@@ -32,4 +31,3 @@ public:
}
#endif // __URDE_CMAPSURFACESHADER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CMODELSHADERS_HPP__
#define __URDE_CMODELSHADERS_HPP__
#pragma once
#include "hecl/Runtime.hpp"
#include "hecl/Backend/Backend.hpp"
@@ -94,4 +93,3 @@ private:
}
#endif // __URDE_CMODELSHADERS_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CPARTICLESWOOSHSHADERS_HPP__
#define __URDE_CPARTICLESWOOSHSHADERS_HPP__
#pragma once
#include "Graphics/CGraphics.hpp"
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
@@ -44,4 +43,3 @@ public:
}
#endif // __URDE_CPARTICLESWOOSHSHADERS_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CPHAZONSUITFILTER_HPP__
#define __URDE_CPHAZONSUITFILTER_HPP__
#pragma once
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "zeus/CColor.hpp"
@@ -30,4 +29,3 @@ public:
}
#endif // __URDE_CPHAZONSUITFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CRADARPAINTSHADER_HPP__
#define __URDE_CRADARPAINTSHADER_HPP__
#pragma once
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
@@ -34,4 +33,3 @@ public:
}
#endif // __URDE_CRADARPAINTSHADER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CRANDOMSTATICFILTER_HPP__
#define __URDE_CRANDOMSTATICFILTER_HPP__
#pragma once
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
@@ -44,4 +43,3 @@ public:
}
#endif // __URDE_CRANDOMSTATICFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CSCANLINESFILTER_HPP__
#define __URDE_CSCANLINESFILTER_HPP__
#pragma once
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
@@ -48,4 +47,3 @@ public:
}
#endif // __URDE_CSCANLINESFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CSPACEWARPFILTER_HPP__
#define __URDE_CSPACEWARPFILTER_HPP__
#pragma once
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "RetroTypes.hpp"
@@ -37,4 +36,3 @@ public:
}
#endif // __URDE_CSPACEWARPFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CTEXTSUPPORTSHADER_HPP__
#define __URDE_CTEXTSUPPORTSHADER_HPP__
#pragma once
#include "GuiSys/CGuiWidget.hpp"
#include "hecl/VertexBufferPool.hpp"
@@ -109,4 +108,3 @@ public:
}
#endif // __URDE_CTEXTSUPPORTSHADER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CTEXTUREDQUADFILTER_HPP__
#define __URDE_CTEXTUREDQUADFILTER_HPP__
#pragma once
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
@@ -72,4 +71,3 @@ public:
}
#endif // __URDE_CTEXTUREDQUADFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CTHERMALCOLDFILTER_HPP__
#define __URDE_CTHERMALCOLDFILTER_HPP__
#pragma once
#include "RetroTypes.hpp"
#include "zeus/CMatrix4f.hpp"
@@ -44,4 +43,3 @@ public:
}
#endif // __URDE_CTHERMALCOLDFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CTHERMALHOTFILTER_HPP__
#define __URDE_CTHERMALHOTFILTER_HPP__
#pragma once
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
@@ -31,4 +30,3 @@ public:
}
#endif // __URDE_CTHERMALHOTFILTER_HPP__

View File

@@ -1,5 +1,4 @@
#ifndef URDE_CWORLDSHADOWSHADER_HPP
#define URDE_CWORLDSHADOWSHADER_HPP
#pragma once
#include "CColoredQuadFilter.hpp"
#include "CTexturedQuadFilter.hpp"
@@ -42,4 +41,3 @@ public:
}
#endif // URDE_CWORLDSHADOWSHADER_HPP

View File

@@ -1,5 +1,4 @@
#ifndef __URDE_CXRAYBLURFILTER_HPP__
#define __URDE_CXRAYBLURFILTER_HPP__
#pragma once
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "zeus/CMatrix4f.hpp"
@@ -32,4 +31,3 @@ public:
}
#endif // __URDE_CXRAYBLURFILTER_HPP__