CParticleSwooshShaders HLSL implementation

This commit is contained in:
Jack Andersen 2017-06-09 20:13:16 -10:00
parent f3acc97d63
commit 6701ac264d
7 changed files with 167 additions and 35 deletions

View File

@ -5,15 +5,15 @@
#include "CParticleGenInfo.hpp" #include "CParticleGenInfo.hpp"
#include "zeus/CFrustum.hpp" #include "zeus/CFrustum.hpp"
#include "CToken.hpp" #include "CToken.hpp"
#include "Particle/CGenDescription.hpp"
#include "Particle/CSwooshDescription.hpp"
#include "Particle/CElectricDescription.hpp"
#include <map> #include <map>
namespace urde namespace urde
{ {
class CPoseAsTransforms; class CPoseAsTransforms;
class CCharLayoutInfo; class CCharLayoutInfo;
class CGenDescription;
class CSwooshDescription;
class CElectricDescription;
class CParticleDatabase class CParticleDatabase
{ {

View File

@ -370,13 +370,12 @@ TShader<CElementGenShaders>::IDataBindingFactory* CElementGenShaders::Initialize
} }
#if BOO_HAS_VULKAN #if BOO_HAS_VULKAN
struct VulkanElementDataBindingFactory : CElementGenShaders::IDataBindingFactory struct VulkanElementDataBindingFactory : TShader<CElementGenShaders>::IDataBindingFactory
{ {
void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
CElementGen& gen, CElementGenShaders& shaders)
boo::IShaderPipeline* regPipeline,
boo::IShaderPipeline* redToAlphaPipeline)
{ {
CElementGen& gen = shaders.m_gen;
CGenDescription* desc = gen.GetDesc(); CGenDescription* desc = gen.GetDesc();
CUVElement* texr = desc->x54_x40_TEXR.get(); CUVElement* texr = desc->x54_x40_TEXR.get();
@ -398,18 +397,20 @@ struct VulkanElementDataBindingFactory : CElementGenShaders::IDataBindingFactory
boo::IGraphicsBuffer* uniforms[] = {gen.m_uniformBuf}; boo::IGraphicsBuffer* uniforms[] = {gen.m_uniformBuf};
if (regPipeline) if (shaders.m_regPipeline)
gen.m_normalDataBind = ctx.newShaderDataBinding(regPipeline, nullptr, nullptr, gen.m_normalDataBind = ctx.newShaderDataBinding(shaders.m_regPipeline, nullptr, nullptr,
gen.m_instBuf, nullptr, 1, uniforms, gen.m_instBuf, nullptr, 1, uniforms,
nullptr, texCount, textures, nullptr, nullptr); nullptr, texCount, textures, nullptr, nullptr);
if (redToAlphaPipeline) if (shaders.m_redToAlphaPipeline)
gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, nullptr, gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipeline, nullptr, nullptr,
gen.m_instBuf, nullptr, 1, uniforms, gen.m_instBuf, nullptr, 1, uniforms,
nullptr, texCount, textures, nullptr, nullptr); nullptr, texCount, textures, nullptr, nullptr);
return nullptr;
} }
}; };
CElementGenShaders::IDataBindingFactory* CElementGenShaders::Initialize(boo::VulkanDataFactory::Context& ctx) TShader<CElementGenShaders>::IDataBindingFactory* CElementGenShaders::Initialize(boo::VulkanDataFactory::Context& ctx)
{ {
static const boo::VertexElementDescriptor TexFmtTex[] = static const boo::VertexElementDescriptor TexFmtTex[] =
{ {

View File

@ -109,9 +109,9 @@ TShader<CParticleSwooshShaders>::IDataBindingFactory* CParticleSwooshShaders::In
boo::Primitive::TriStrips, boo::ZTest::LEqual, true, boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, 1, TexNames, 1, UniNames, m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, 1, TexNames, 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames, m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
@ -126,9 +126,9 @@ TShader<CParticleSwooshShaders>::IDataBindingFactory* CParticleSwooshShaders::In
boo::Primitive::TriStrips, boo::ZTest::LEqual, true, boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames, m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
return new struct OGLParticleSwooshDataBindingFactory; return new struct OGLParticleSwooshDataBindingFactory;
} }
@ -176,9 +176,9 @@ TShader<CParticleSwooshShaders>::IDataBindingFactory* CParticleSwooshShaders::In
boo::Primitive::TriStrips, boo::ZTest::LEqual, true, boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
@ -193,9 +193,9 @@ TShader<CParticleSwooshShaders>::IDataBindingFactory* CParticleSwooshShaders::In
boo::Primitive::TriStrips, boo::ZTest::LEqual, true, boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
return new struct VulkanParticleSwooshDataBindingFactory; return new struct VulkanParticleSwooshDataBindingFactory;
} }

View File

@ -0,0 +1,131 @@
#include "CParticleSwooshShaders.hpp"
#include "Particle/CParticleSwoosh.hpp"
#include "Particle/CSwooshDescription.hpp"
namespace urde
{
static const char* VS =
"struct VertData\n"
"{\n"
" float4 posIn : POSITION;\n"
" float4 uvIn : UV;\n"
" float4 colorIn : COLOR;\n"
"};\n"
"\n"
"cbuffer SwooshUniform : register(b0)\n"
"{\n"
" float4x4 mvp;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" float4 pos : SV_Position;\n"
" float4 color : COLOR;\n"
" float2 uv : UV;\n"
"};\n"
"\n"
"VertToFrag main(in VertData v)\n"
"{\n"
" VertToFrag vtf;\n"
" vtf.color = v.colorIn;\n"
" vtf.uv = v.uvIn;\n"
" vtf.pos = mul(mvp, float4(v.posIn.xyz, 1.0));\n"
" return vtf;\n"
"}\n";
static const char* FS_TEX =
"struct VertToFrag\n"
"{\n"
" float4 pos : SV_Position;\n"
" float4 color : COLOR;\n"
" float2 uv : UV;\n"
"};\n"
"\n"
"SamplerState samp : register(s0);\n"
"Texture2D tex : register(t0);\n"
"float4 main(in VertToFrag vtf) : SV_Target0\n"
"{\n"
" return vtf.color * tex.Sample(samp, vtf.uv);\n"
"}\n";
static const char* FS_NOTEX =
"struct VertToFrag\n"
"{\n"
" float4 pos : SV_Position;\n"
" float4 color : COLOR;\n"
" float2 uv : UV;\n"
"};\n"
"\n"
"float4 main(in VertToFrag vtf) : SV_Target0\n"
"{\n"
" return vtf.color;\n"
"}\n";
struct D3DParticleSwooshDataBindingFactory : TShader<CParticleSwooshShaders>::IDataBindingFactory
{
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
CParticleSwooshShaders& shaders)
{
CParticleSwoosh& gen = shaders.m_gen;
CSwooshDescription* desc = gen.GetDesc();
CUVElement* texr = desc->x3c_TEXR.get();
boo::ITexture* textures[] = {texr->GetValueTexture(0).GetObj()->GetBooTexture()};
boo::IGraphicsBuffer* uniforms[] = {gen.m_uniformBuf};
gen.m_dataBind = ctx.newShaderDataBinding(shaders.m_pipeline, CParticleSwooshShaders::m_vtxFormat,
gen.m_vertBuf, nullptr, nullptr, 1, uniforms,
nullptr, texr ? 1 : 0, textures, nullptr, nullptr);
return nullptr;
}
};
TShader<CParticleSwooshShaders>::IDataBindingFactory* CParticleSwooshShaders::Initialize(boo::ID3DDataFactory::Context& ctx)
{
static const boo::VertexElementDescriptor VtxFmt[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::UV4},
{nullptr, nullptr, boo::VertexSemantic::Color},
};
m_vtxFormat = ctx.newVertexFormat(3, VtxFmt);
m_texZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, nullptr, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None);
m_texNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, nullptr, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None);
m_texAdditiveZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, nullptr, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None);
m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, nullptr, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None);
m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, nullptr, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None);
m_noTexNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, nullptr, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None);
m_noTexAdditiveZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, nullptr, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None);
m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, nullptr, m_vtxFormat,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None);
return new struct D3DParticleSwooshDataBindingFactory;
}
}

View File

@ -27,7 +27,6 @@ static const char* VS =
" float2 uv;\n" " float2 uv;\n"
"};\n" "};\n"
"\n" "\n"
"SBINDING(0) out VertToFrag vtf;\n"
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SwooshUniform& su [[ buffer(2) ]])\n" "vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SwooshUniform& su [[ buffer(2) ]])\n"
"{\n" "{\n"
" VertToFrag vtf;\n" " VertToFrag vtf;\n"
@ -111,9 +110,9 @@ TShader<CParticleSwooshShaders>::IDataBindingFactory* CParticleSwooshShaders::In
boo::Primitive::TriStrips, boo::ZTest::LEqual, true, boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, CGraphics::g_ViewportSamples, m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, CGraphics::g_ViewportSamples,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, CGraphics::g_ViewportSamples, m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, CGraphics::g_ViewportSamples,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
@ -128,9 +127,9 @@ TShader<CParticleSwooshShaders>::IDataBindingFactory* CParticleSwooshShaders::In
boo::Primitive::TriStrips, boo::ZTest::LEqual, true, boo::Primitive::TriStrips, boo::ZTest::LEqual, true,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, CGraphics::g_ViewportSamples, m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, CGraphics::g_ViewportSamples,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
boo::Primitive::TriStrips, boo::ZTest::LEqual, false, boo::Primitive::TriStrips, boo::ZTest::LEqual, false,
true, false, boo::CullMode::None); true, false, boo::CullMode::None);
return new struct MetalParticleSwooshDataBindingFactory; return new struct MetalParticleSwooshDataBindingFactory;
} }

View File

@ -1,5 +1,4 @@
#include "CProjectileWeapon.hpp" #include "CProjectileWeapon.hpp"
#include "Particle/CWeaponDescription.hpp"
namespace urde namespace urde
{ {

View File

@ -5,13 +5,15 @@
#include "CRandom16.hpp" #include "CRandom16.hpp"
#include "CToken.hpp" #include "CToken.hpp"
#include "zeus/CVector3f.hpp" #include "zeus/CVector3f.hpp"
#include "Particle/CParticleSwoosh.hpp"
#include "Particle/CElementGen.hpp" #include "Particle/CElementGen.hpp"
#include "Particle/CParticleSwoosh.hpp"
#include "Particle/CGenDescription.hpp"
#include "Particle/CSwooshDescription.hpp"
#include "Particle/CWeaponDescription.hpp"
namespace urde namespace urde
{ {
class CModel; class CModel;
class CWeaponDescription;
class CProjectileWeapon class CProjectileWeapon
{ {
static CRandom16 g_GlobalSeed; static CRandom16 g_GlobalSeed;