mirror of https://github.com/AxioDL/metaforce.git
Implement Metal fluid plane tessellation shader
This commit is contained in:
parent
8f9d7da3ee
commit
1e36329ed4
|
@ -120,12 +120,11 @@ void ViewManager::TestGameView::think()
|
||||||
}
|
}
|
||||||
overlayText += hecl::Format("Area AssetId: 0x%08X, Total Objects: %i, Total Layers: %i, Total Active Layers: %i\n"
|
overlayText += hecl::Format("Area AssetId: 0x%08X, Total Objects: %i, Total Layers: %i, Total Active Layers: %i\n"
|
||||||
"Active Layer bits: %s\n",
|
"Active Layer bits: %s\n",
|
||||||
g_StateManager->WorldNC()->GetArea(aId)->GetAreaAssetId().Value(),
|
(unsigned int)g_StateManager->WorldNC()->GetArea(aId)->GetAreaAssetId().Value(),
|
||||||
g_StateManager->GetAllObjectList().size(), layerStates->GetAreaLayerCount(aId),
|
g_StateManager->GetAllObjectList().size(), layerStates->GetAreaLayerCount(aId),
|
||||||
totalActive, layerBits.c_str());
|
totalActive, layerBits.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!overlayText.empty())
|
if (!overlayText.empty())
|
||||||
m_debugText->typesetGlyphs(overlayText);
|
m_debugText->typesetGlyphs(overlayText);
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ static const char* FS_METAL =
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler clampSamp [[ sampler(3) ]],\n"
|
" sampler clampSamp [[ sampler(4) ]],\n"
|
||||||
" texture2d<float> tex [[ texture(0) ]])\n"
|
" texture2d<float> tex [[ texture(0) ]])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return vtf.color * float4(tex.sample(clampSamp, vtf.uv).bgr, 1.0);\n"
|
" return vtf.color * float4(tex.sample(clampSamp, vtf.uv).bgr, 1.0);\n"
|
||||||
|
|
|
@ -940,7 +940,7 @@ CAutoMapper::FindClosestVisibleWorld(const zeus::CVector3f& point,
|
||||||
const CStateManager& mgr) const
|
const CStateManager& mgr) const
|
||||||
{
|
{
|
||||||
float minDist = 29999.f;
|
float minDist = 29999.f;
|
||||||
std::pair<int, int> closestWorld = {xa0_curAreaId, xa0_curAreaId};
|
std::pair<int, int> closestWorld = {x9c_worldIdx, xa0_curAreaId};
|
||||||
for (u32 w=0 ; w<x8_mapu->GetNumMapWorldDatas() ; ++w)
|
for (u32 w=0 ; w<x8_mapu->GetNumMapWorldDatas() ; ++w)
|
||||||
{
|
{
|
||||||
const CMapUniverse::CMapWorldData& mwData = x8_mapu->GetMapWorldData(w);
|
const CMapUniverse::CMapWorldData& mwData = x8_mapu->GetMapWorldData(w);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "IOStreams.hpp"
|
#include "IOStreams.hpp"
|
||||||
#include "rstl.hpp"
|
#include "rstl.hpp"
|
||||||
#include "World/CHealthInfo.hpp"
|
#include "World/CHealthInfo.hpp"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace urde
|
namespace urde
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace urde
|
||||||
{
|
{
|
||||||
|
|
||||||
static boo::ObjToken<boo::IVertexFormat> s_vtxFmt;
|
static boo::ObjToken<boo::IVertexFormat> s_vtxFmt;
|
||||||
|
static boo::ObjToken<boo::IVertexFormat> s_tessVtxFmt;
|
||||||
|
|
||||||
static const char* VS =
|
static const char* VS =
|
||||||
"#include <metal_stdlib>\n"
|
"#include <metal_stdlib>\n"
|
||||||
|
@ -47,6 +48,7 @@ static const char* VS =
|
||||||
"{\n"
|
"{\n"
|
||||||
" VertToFrag vtf;\n"
|
" VertToFrag vtf;\n"
|
||||||
" float4 pos = float4(v.posIn.xyz, 1.0);\n"
|
" float4 pos = float4(v.posIn.xyz, 1.0);\n"
|
||||||
|
" float4 normalIn = v.normalIn;\n"
|
||||||
" vtf.mvPos = fu.mv * pos;\n"
|
" vtf.mvPos = fu.mv * pos;\n"
|
||||||
" vtf.pos = fu.proj * vtf.mvPos;\n"
|
" vtf.pos = fu.proj * vtf.mvPos;\n"
|
||||||
" vtf.mvNorm = fu.mvNorm * v.normalIn;\n"
|
" vtf.mvNorm = fu.mvNorm * v.normalIn;\n"
|
||||||
|
@ -60,6 +62,142 @@ static const char* VS =
|
||||||
" return vtf;\n"
|
" return vtf;\n"
|
||||||
"}\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 =
|
static const char* FS =
|
||||||
"#include <metal_stdlib>\n"
|
"#include <metal_stdlib>\n"
|
||||||
"using namespace metal;\n"
|
"using namespace metal;\n"
|
||||||
|
@ -91,22 +229,22 @@ static const char* FS =
|
||||||
" Fog fog;\n"
|
" Fog fog;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"static float4 LightingFunc(float3 mvPosIn, float3 mvNormIn)\n"
|
"static float4 LightingFunc(constant LightingUniform& lu, float3 mvPosIn, float3 mvNormIn)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4 ret = ambient;\n"
|
" float4 ret = lu.ambient;\n"
|
||||||
" \n"
|
" \n"
|
||||||
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
|
" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" float3 delta = mvPosIn - lights[i].pos.xyz;\n"
|
" float3 delta = mvPosIn - lu.lights[i].pos.xyz;\n"
|
||||||
" float dist = length(delta);\n"
|
" float dist = length(delta);\n"
|
||||||
" float angDot = clamp(dot(normalize(delta), lights[i].dir.xyz), 0.0, 1.0);\n"
|
" float angDot = clamp(dot(normalize(delta), lu.lights[i].dir.xyz), 0.0, 1.0);\n"
|
||||||
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
|
" float att = 1.0 / (lu.lights[i].linAtt[2] * dist * dist +\n"
|
||||||
" lights[i].linAtt[1] * dist +\n"
|
" lu.lights[i].linAtt[1] * dist +\n"
|
||||||
" lights[i].linAtt[0]);\n"
|
" lu.lights[i].linAtt[0]);\n"
|
||||||
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
|
" float angAtt = lu.lights[i].angAtt[2] * angDot * angDot +\n"
|
||||||
" lights[i].angAtt[1] * angDot +\n"
|
" lu.lights[i].angAtt[1] * angDot +\n"
|
||||||
" lights[i].angAtt[0];\n"
|
" lu.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"
|
" ret += lu.lights[i].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn), 0.0, 1.0);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" \n"
|
" \n"
|
||||||
" return ret;\n"
|
" return ret;\n"
|
||||||
|
@ -133,7 +271,7 @@ static const char* FS =
|
||||||
" sampler samp [[ sampler(0) ]],\n"
|
" sampler samp [[ sampler(0) ]],\n"
|
||||||
" constant LightingUniform& lu [[ buffer(4) ]]%s)\n" // Textures here
|
" constant LightingUniform& lu [[ buffer(4) ]]%s)\n" // Textures here
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n"
|
" float4 lighting = LightingFunc(lu, vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n"
|
||||||
" float4 colorOut;\n"
|
" float4 colorOut;\n"
|
||||||
"%s" // Combiner expression here
|
"%s" // Combiner expression here
|
||||||
" return colorOut;\n"
|
" return colorOut;\n"
|
||||||
|
@ -196,7 +334,7 @@ static const char* FSDoor =
|
||||||
" return colorOut;\n"
|
" return colorOut;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
boo::ObjToken<boo::IShaderPipeline>
|
CFluidPlaneShader::ShaderPair
|
||||||
CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info)
|
CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info)
|
||||||
{
|
{
|
||||||
if (!s_vtxFmt)
|
if (!s_vtxFmt)
|
||||||
|
@ -243,7 +381,7 @@ CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluid
|
||||||
if (info.m_hasEnvBumpMap)
|
if (info.m_hasEnvBumpMap)
|
||||||
{
|
{
|
||||||
envBumpMapUv = nextTCG;
|
envBumpMapUv = nextTCG;
|
||||||
additionalTCGs += hecl::Format(" vtf.uv%d = (fu.texMtxs[3] * float4(v.normalIn.xyz, 1.0)).xy;\n", nextTCG++);
|
additionalTCGs += hecl::Format(" vtf.uv%d = (fu.texMtxs[3] * float4(normalIn.xyz, 1.0)).xy;\n", nextTCG++);
|
||||||
}
|
}
|
||||||
if (info.m_hasEnvMap)
|
if (info.m_hasEnvMap)
|
||||||
{
|
{
|
||||||
|
@ -258,9 +396,9 @@ CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluid
|
||||||
|
|
||||||
switch (info.m_type)
|
switch (info.m_type)
|
||||||
{
|
{
|
||||||
case CFluidPlane::EFluidType::NormalWater:
|
case EFluidType::NormalWater:
|
||||||
case CFluidPlane::EFluidType::PhazonFluid:
|
case EFluidType::PhazonFluid:
|
||||||
case CFluidPlane::EFluidType::Four:
|
case EFluidType::Four:
|
||||||
if (info.m_hasLightmap)
|
if (info.m_hasLightmap)
|
||||||
{
|
{
|
||||||
combiner += hecl::Format(" float4 lightMapTexel = lightMap.sample(samp, vtf.uv%d);\n", lightmapUv);
|
combiner += hecl::Format(" float4 lightMapTexel = lightMap.sample(samp, vtf.uv%d);\n", lightmapUv);
|
||||||
|
@ -341,7 +479,7 @@ CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluid
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFluidPlane::EFluidType::PoisonWater:
|
case EFluidType::PoisonWater:
|
||||||
if (info.m_hasLightmap)
|
if (info.m_hasLightmap)
|
||||||
{
|
{
|
||||||
combiner += hecl::Format(" float4 lightMapTexel = lightMap.sample(samp, vtf.uv%d);\n", lightmapUv);
|
combiner += hecl::Format(" float4 lightMapTexel = lightMap.sample(samp, vtf.uv%d);\n", lightmapUv);
|
||||||
|
@ -409,7 +547,7 @@ CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluid
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFluidPlane::EFluidType::Lava:
|
case EFluidType::Lava:
|
||||||
// 0: Tex0TCG, Tex0, GX_COLOR0A0
|
// 0: Tex0TCG, Tex0, GX_COLOR0A0
|
||||||
// ZERO, TEX, KONST, RAS
|
// ZERO, TEX, KONST, RAS
|
||||||
// Output reg prev
|
// Output reg prev
|
||||||
|
@ -467,7 +605,7 @@ CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluid
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFluidPlane::EFluidType::ThickLava:
|
case EFluidType::ThickLava:
|
||||||
// 0: Tex0TCG, Tex0, GX_COLOR0A0
|
// 0: Tex0TCG, Tex0, GX_COLOR0A0
|
||||||
// ZERO, TEX, KONST, RAS
|
// ZERO, TEX, KONST, RAS
|
||||||
// Output reg prev
|
// Output reg prev
|
||||||
|
@ -516,19 +654,45 @@ CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluid
|
||||||
asprintf(&finalVS, VS, additionalTCGs.c_str());
|
asprintf(&finalVS, VS, additionalTCGs.c_str());
|
||||||
asprintf(&finalFS, FS, textures.c_str(), combiner.c_str());
|
asprintf(&finalFS, FS, textures.c_str(), combiner.c_str());
|
||||||
|
|
||||||
auto ret = ctx.newShaderPipeline(finalVS, finalFS, nullptr, nullptr, s_vtxFmt,
|
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::SrcAlpha,
|
||||||
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
|
info.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha,
|
||||||
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
|
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false,
|
||||||
boo::CullMode::None);
|
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(finalVS);
|
||||||
free(finalFS);
|
free(finalFS);
|
||||||
|
|
||||||
return ret;
|
return {regular, tessellation};
|
||||||
}
|
}
|
||||||
|
|
||||||
boo::ObjToken<boo::IShaderPipeline>
|
CFluidPlaneShader::ShaderPair
|
||||||
CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info)
|
CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info)
|
||||||
{
|
{
|
||||||
if (!s_vtxFmt)
|
if (!s_vtxFmt)
|
||||||
|
@ -586,41 +750,50 @@ CFluidPlaneShader::BuildShader(boo::MetalDataFactory::Context& ctx, const SFluid
|
||||||
free(finalVS);
|
free(finalVS);
|
||||||
free(finalFS);
|
free(finalFS);
|
||||||
|
|
||||||
return ret;
|
return {ret, {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void CFluidPlaneShader::_Shutdown<boo::MetalDataFactory>()
|
void CFluidPlaneShader::_Shutdown<boo::MetalDataFactory>()
|
||||||
{
|
{
|
||||||
s_vtxFmt.reset();
|
s_vtxFmt.reset();
|
||||||
|
s_tessVtxFmt.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
boo::ObjToken<boo::IShaderDataBinding> CFluidPlaneShader::BuildBinding(boo::MetalDataFactory::Context& ctx,
|
CFluidPlaneShader::BindingPair
|
||||||
const boo::ObjToken<boo::IShaderPipeline>& pipeline, bool door)
|
CFluidPlaneShader::BuildBinding(boo::MetalDataFactory::Context& ctx, const ShaderPair& pipeline)
|
||||||
{
|
{
|
||||||
boo::ObjToken<boo::IGraphicsBuffer> ubufs[] = { m_uniBuf.get(), m_uniBuf.get(), m_uniBuf.get() };
|
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 ubufStages[] = { boo::PipelineStage::Vertex, boo::PipelineStage::Vertex,
|
||||||
boo::PipelineStage::Fragment };
|
boo::PipelineStage::Fragment };
|
||||||
size_t ubufOffs[] = {0, 0, 768};
|
size_t ubufOffs[] = {0, 0, 1280};
|
||||||
size_t ubufSizes[] = {768, 768, sizeof(CModelShaders::LightingUniform)};
|
size_t ubufSizes[] = {1280, 1280, sizeof(CModelShaders::LightingUniform)};
|
||||||
size_t texCount = 0;
|
size_t texCount = 0;
|
||||||
boo::ObjToken<boo::ITexture> texs[7];
|
boo::ObjToken<boo::ITexture> texs[8];
|
||||||
if (m_patternTex1)
|
if (m_patternTex1)
|
||||||
texs[texCount++] = (*m_patternTex1)->GetBooTexture();
|
texs[texCount++] = m_patternTex1->GetBooTexture();
|
||||||
if (m_patternTex2)
|
if (m_patternTex2)
|
||||||
texs[texCount++] = (*m_patternTex2)->GetBooTexture();
|
texs[texCount++] = m_patternTex2->GetBooTexture();
|
||||||
if (m_colorTex)
|
if (m_colorTex)
|
||||||
texs[texCount++] = (*m_colorTex)->GetBooTexture();
|
texs[texCount++] = m_colorTex->GetBooTexture();
|
||||||
if (m_bumpMap)
|
if (m_bumpMap)
|
||||||
texs[texCount++] = (*m_bumpMap)->GetBooTexture();
|
texs[texCount++] = m_bumpMap->GetBooTexture();
|
||||||
if (m_envMap)
|
if (m_envMap)
|
||||||
texs[texCount++] = (*m_envMap)->GetBooTexture();
|
texs[texCount++] = m_envMap->GetBooTexture();
|
||||||
if (m_envBumpMap)
|
if (m_envBumpMap)
|
||||||
texs[texCount++] = (*m_envBumpMap)->GetBooTexture();
|
texs[texCount++] = m_envBumpMap->GetBooTexture();
|
||||||
if (m_lightmap)
|
if (m_lightmap)
|
||||||
texs[texCount++] = (*m_lightmap)->GetBooTexture();
|
texs[texCount++] = m_lightmap->GetBooTexture();
|
||||||
return ctx.newShaderDataBinding(pipeline, s_vtxFmt, m_vbo.get(), nullptr, nullptr, 3,
|
auto regular = ctx.newShaderDataBinding(pipeline.m_regular, s_vtxFmt, m_vbo.get(), nullptr, nullptr, 3,
|
||||||
ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr);
|
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};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ static const char* FS =
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler clampSamp [[ sampler(2) ]],\n"
|
" sampler clampSamp [[ sampler(3) ]],\n"
|
||||||
" texture2d<float> screenTex [[ texture(0) ]],\n"
|
" texture2d<float> screenTex [[ texture(0) ]],\n"
|
||||||
" texture2d<float> maskTex [[ texture(1) ]],\n"
|
" texture2d<float> maskTex [[ texture(1) ]],\n"
|
||||||
" texture2d<float> maskTexBlur [[ texture(2) ]])\n"
|
" texture2d<float> maskTexBlur [[ texture(2) ]])\n"
|
||||||
|
@ -136,7 +136,7 @@ static const char* BlurFS =
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler clampSamp [[ sampler(2) ]],\n"
|
" sampler clampSamp [[ sampler(3) ]],\n"
|
||||||
" texture2d<float> maskTex [[ texture(0) ]])\n"
|
" texture2d<float> maskTex [[ texture(0) ]])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" //this will be our alpha sum\n"
|
" //this will be our alpha sum\n"
|
||||||
|
|
|
@ -60,7 +60,7 @@ static const char* TextFS =
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler clampSamp [[ sampler(2) ]],\n"
|
" sampler clampSamp [[ sampler(3) ]],\n"
|
||||||
" texture2d_array<float> tex [[ texture(0) ]])\n"
|
" texture2d_array<float> tex [[ texture(0) ]])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4 texel = tex.sample(clampSamp, vtf.uv.xy, vtf.uv.z);\n"
|
" float4 texel = tex.sample(clampSamp, vtf.uv.xy, vtf.uv.z);\n"
|
||||||
|
@ -113,7 +113,7 @@ static const char* ImgFS =
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler clampSamp [[ sampler(2) ]],\n"
|
" sampler clampSamp [[ sampler(3) ]],\n"
|
||||||
" texture2d<float> tex [[ texture(0) ]])\n"
|
" texture2d<float> tex [[ texture(0) ]])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4 texel = tex.sample(clampSamp, vtf.uv);\n"
|
" float4 texel = tex.sample(clampSamp, vtf.uv);\n"
|
||||||
|
|
|
@ -86,7 +86,7 @@ static const char* FS =
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler clampSamp [[ sampler(2) ]],\n"
|
" sampler clampSamp [[ sampler(3) ]],\n"
|
||||||
" texture2d<float> tex [[ texture(0) ]])\n"
|
" texture2d<float> tex [[ texture(0) ]])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return vtf.color * float4(tex.sample(clampSamp, vtf.uv, bias(vtf.lod)).rgb, 1.0);\n"
|
" return vtf.color * float4(tex.sample(clampSamp, vtf.uv, bias(vtf.lod)).rgb, 1.0);\n"
|
||||||
|
@ -104,7 +104,7 @@ static const char* FSAlpha =
|
||||||
"};\n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler clampSamp [[ sampler(2) ]],\n"
|
" sampler clampSamp [[ sampler(3) ]],\n"
|
||||||
" texture2d<float> tex [[ texture(0) ]])\n"
|
" texture2d<float> tex [[ texture(0) ]])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return vtf.color * tex.sample(clampSamp, vtf.uv, bias(vtf.lod));\n"
|
" return vtf.color * tex.sample(clampSamp, vtf.uv, bias(vtf.lod));\n"
|
||||||
|
|
|
@ -72,7 +72,7 @@ static const char* FS =
|
||||||
"\n"
|
"\n"
|
||||||
"constant float4 kRGBToYPrime = {0.299, 0.587, 0.114, 0.0};\n"
|
"constant float4 kRGBToYPrime = {0.299, 0.587, 0.114, 0.0};\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler samp [[ sampler(2) ]],\n"
|
" sampler samp [[ sampler(3) ]],\n"
|
||||||
" texture2d<float> sceneTex [[ texture(0) ]],\n"
|
" texture2d<float> sceneTex [[ texture(0) ]],\n"
|
||||||
" texture2d<float> shiftTex [[ texture(1) ]])\n"
|
" texture2d<float> shiftTex [[ texture(1) ]])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
|
@ -80,7 +80,7 @@ static const char* FS =
|
||||||
"\n"
|
"\n"
|
||||||
"constant float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0);\n"
|
"constant float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0);\n"
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||||
" sampler samp [[ sampler(2) ]],\n"
|
" sampler samp [[ sampler(3) ]],\n"
|
||||||
" texture2d<float> sceneTex [[ texture(0) ]],\n"
|
" texture2d<float> sceneTex [[ texture(0) ]],\n"
|
||||||
" texture2d<float> paletteTex [[ texture(1) ]])\n"
|
" texture2d<float> paletteTex [[ texture(1) ]])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
|
@ -1810,7 +1810,7 @@ CEntity* ScriptLoader::LoadRipple(CStateManager& mgr, CInputStream& in, int prop
|
||||||
{
|
{
|
||||||
if (!EnsurePropertyCount(propCount, 4, "Ripple"))
|
if (!EnsurePropertyCount(propCount, 4, "Ripple"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
std::string_view name = mgr.HashInstanceName(in);
|
std::string name = mgr.HashInstanceName(in);
|
||||||
zeus::CVector3f center = zeus::CVector3f::ReadBig(in);
|
zeus::CVector3f center = zeus::CVector3f::ReadBig(in);
|
||||||
bool active = in.readBool();
|
bool active = in.readBool();
|
||||||
float mag = in.readFloatBig();
|
float mag = in.readFloatBig();
|
||||||
|
@ -1822,7 +1822,7 @@ CEntity* ScriptLoader::LoadBallTrigger(CStateManager& mgr, CInputStream& in, int
|
||||||
if (!EnsurePropertyCount(propCount, 9, "BallTrigger"))
|
if (!EnsurePropertyCount(propCount, 9, "BallTrigger"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
std::string_view name = in.readString();
|
std::string name = in.readString();
|
||||||
zeus::CVector3f pos = zeus::CVector3f::ReadBig(in);
|
zeus::CVector3f pos = zeus::CVector3f::ReadBig(in);
|
||||||
zeus::CVector3f scale = zeus::CVector3f::ReadBig(in);
|
zeus::CVector3f scale = zeus::CVector3f::ReadBig(in);
|
||||||
|
|
||||||
|
@ -2342,7 +2342,7 @@ CEntity* ScriptLoader::LoadGunTurret(CStateManager& mgr, CInputStream& in, int p
|
||||||
if (!EnsurePropertyCount(propCount, CScriptGunTurretData::GetMinProperties(), "GunTurret"))
|
if (!EnsurePropertyCount(propCount, CScriptGunTurretData::GetMinProperties(), "GunTurret"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
std::string_view name = mgr.HashInstanceName(in);
|
std::string name = mgr.HashInstanceName(in);
|
||||||
CScriptGunTurret::ETurretComponent component = CScriptGunTurret::ETurretComponent(in.readUint32Big());
|
CScriptGunTurret::ETurretComponent component = CScriptGunTurret::ETurretComponent(in.readUint32Big());
|
||||||
zeus::CTransform xf = LoadEditorTransform(in);
|
zeus::CTransform xf = LoadEditorTransform(in);
|
||||||
zeus::CVector3f scale = zeus::CVector3f::ReadBig(in);
|
zeus::CVector3f scale = zeus::CVector3f::ReadBig(in);
|
||||||
|
@ -2461,7 +2461,7 @@ CEntity* ScriptLoader::LoadTeamAIMgr(CStateManager& mgr, CInputStream& in, int p
|
||||||
if (!EnsurePropertyCount(propCount, 8, "TeamAiMgr"))
|
if (!EnsurePropertyCount(propCount, 8, "TeamAiMgr"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
std::string_view name = mgr.HashInstanceName(in);
|
std::string name = mgr.HashInstanceName(in);
|
||||||
CTeamAiData data(in, propCount);
|
CTeamAiData data(in, propCount);
|
||||||
return new CTeamAiMgr(mgr.AllocateUniqueId(), name, info, data);
|
return new CTeamAiMgr(mgr.AllocateUniqueId(), name, info, data);
|
||||||
}
|
}
|
||||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
||||||
Subproject commit 439a90dbb4fda47b7f71b740a0f709c3b2dc7ca4
|
Subproject commit 667d4113b5475de7d25abc3807ee126749f90aa9
|
Loading…
Reference in New Issue