From 6701ac264d352c248b7577c1dd3ae5166bbadfb1 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 9 Jun 2017 20:13:16 -1000 Subject: [PATCH] CParticleSwooshShaders HLSL implementation --- Runtime/Character/CParticleDatabase.hpp | 6 +- .../Shaders/CElementGenShadersGLSL.cpp | 21 +-- .../Shaders/CParticleSwooshShadersGLSL.cpp | 24 ++-- .../Shaders/CParticleSwooshShadersHLSL.cpp | 131 ++++++++++++++++++ .../Shaders/CParticleSwooshShadersMetal.cpp | 13 +- Runtime/Weapon/CProjectileWeapon.cpp | 1 - Runtime/Weapon/CProjectileWeapon.hpp | 6 +- 7 files changed, 167 insertions(+), 35 deletions(-) diff --git a/Runtime/Character/CParticleDatabase.hpp b/Runtime/Character/CParticleDatabase.hpp index 01ba19f15..9fe2355da 100644 --- a/Runtime/Character/CParticleDatabase.hpp +++ b/Runtime/Character/CParticleDatabase.hpp @@ -5,15 +5,15 @@ #include "CParticleGenInfo.hpp" #include "zeus/CFrustum.hpp" #include "CToken.hpp" +#include "Particle/CGenDescription.hpp" +#include "Particle/CSwooshDescription.hpp" +#include "Particle/CElectricDescription.hpp" #include namespace urde { class CPoseAsTransforms; class CCharLayoutInfo; -class CGenDescription; -class CSwooshDescription; -class CElectricDescription; class CParticleDatabase { diff --git a/Runtime/Graphics/Shaders/CElementGenShadersGLSL.cpp b/Runtime/Graphics/Shaders/CElementGenShadersGLSL.cpp index cbf390b28..eb61f4225 100644 --- a/Runtime/Graphics/Shaders/CElementGenShadersGLSL.cpp +++ b/Runtime/Graphics/Shaders/CElementGenShadersGLSL.cpp @@ -370,13 +370,12 @@ TShader::IDataBindingFactory* CElementGenShaders::Initialize } #if BOO_HAS_VULKAN -struct VulkanElementDataBindingFactory : CElementGenShaders::IDataBindingFactory +struct VulkanElementDataBindingFactory : TShader::IDataBindingFactory { - void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CElementGen& gen, - boo::IShaderPipeline* regPipeline, - boo::IShaderPipeline* redToAlphaPipeline) + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + CElementGenShaders& shaders) { + CElementGen& gen = shaders.m_gen; CGenDescription* desc = gen.GetDesc(); CUVElement* texr = desc->x54_x40_TEXR.get(); @@ -398,18 +397,20 @@ struct VulkanElementDataBindingFactory : CElementGenShaders::IDataBindingFactory boo::IGraphicsBuffer* uniforms[] = {gen.m_uniformBuf}; - if (regPipeline) - gen.m_normalDataBind = ctx.newShaderDataBinding(regPipeline, nullptr, nullptr, + if (shaders.m_regPipeline) + gen.m_normalDataBind = ctx.newShaderDataBinding(shaders.m_regPipeline, nullptr, nullptr, gen.m_instBuf, nullptr, 1, uniforms, nullptr, texCount, textures, nullptr, nullptr); - if (redToAlphaPipeline) - gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, nullptr, + if (shaders.m_redToAlphaPipeline) + gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipeline, nullptr, nullptr, gen.m_instBuf, nullptr, 1, uniforms, nullptr, texCount, textures, nullptr, nullptr); + + return nullptr; } }; -CElementGenShaders::IDataBindingFactory* CElementGenShaders::Initialize(boo::VulkanDataFactory::Context& ctx) +TShader::IDataBindingFactory* CElementGenShaders::Initialize(boo::VulkanDataFactory::Context& ctx) { static const boo::VertexElementDescriptor TexFmtTex[] = { diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShadersGLSL.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShadersGLSL.cpp index 347b27b89..e9f59e739 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShadersGLSL.cpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShadersGLSL.cpp @@ -109,9 +109,9 @@ TShader::IDataBindingFactory* CParticleSwooshShaders::In boo::Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, boo::CullMode::None); m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); + 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, 0, nullptr, 1, UniNames, boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, @@ -126,9 +126,9 @@ TShader::IDataBindingFactory* CParticleSwooshShaders::In boo::Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, boo::CullMode::None); m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); + boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, + boo::Primitive::TriStrips, boo::ZTest::LEqual, false, + true, false, boo::CullMode::None); return new struct OGLParticleSwooshDataBindingFactory; } @@ -176,9 +176,9 @@ TShader::IDataBindingFactory* CParticleSwooshShaders::In boo::Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, boo::CullMode::None); m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); + 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, m_vtxFormat, boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, @@ -193,9 +193,9 @@ TShader::IDataBindingFactory* CParticleSwooshShaders::In boo::Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, boo::CullMode::None); m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); + boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, + boo::Primitive::TriStrips, boo::ZTest::LEqual, false, + true, false, boo::CullMode::None); return new struct VulkanParticleSwooshDataBindingFactory; } diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShadersHLSL.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShadersHLSL.cpp index e69de29bb..3d7f1e985 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShadersHLSL.cpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShadersHLSL.cpp @@ -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::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::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; +} + +} diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShadersMetal.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShadersMetal.cpp index 8c6d698f6..0d1ef934c 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShadersMetal.cpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShadersMetal.cpp @@ -27,7 +27,6 @@ static const char* VS = " float2 uv;\n" "};\n" "\n" -"SBINDING(0) out VertToFrag vtf;\n" "vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SwooshUniform& su [[ buffer(2) ]])\n" "{\n" " VertToFrag vtf;\n" @@ -111,9 +110,9 @@ TShader::IDataBindingFactory* CParticleSwooshShaders::In boo::Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, boo::CullMode::None); m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, CGraphics::g_ViewportSamples, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); + 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, m_vtxFormat, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, @@ -128,9 +127,9 @@ TShader::IDataBindingFactory* CParticleSwooshShaders::In boo::Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, boo::CullMode::None); m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, CGraphics::g_ViewportSamples, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); + boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, + boo::Primitive::TriStrips, boo::ZTest::LEqual, false, + true, false, boo::CullMode::None); return new struct MetalParticleSwooshDataBindingFactory; } diff --git a/Runtime/Weapon/CProjectileWeapon.cpp b/Runtime/Weapon/CProjectileWeapon.cpp index ecfef7033..0b8f8b5ae 100644 --- a/Runtime/Weapon/CProjectileWeapon.cpp +++ b/Runtime/Weapon/CProjectileWeapon.cpp @@ -1,5 +1,4 @@ #include "CProjectileWeapon.hpp" -#include "Particle/CWeaponDescription.hpp" namespace urde { diff --git a/Runtime/Weapon/CProjectileWeapon.hpp b/Runtime/Weapon/CProjectileWeapon.hpp index e58a125fe..1e359009a 100644 --- a/Runtime/Weapon/CProjectileWeapon.hpp +++ b/Runtime/Weapon/CProjectileWeapon.hpp @@ -5,13 +5,15 @@ #include "CRandom16.hpp" #include "CToken.hpp" #include "zeus/CVector3f.hpp" -#include "Particle/CParticleSwoosh.hpp" #include "Particle/CElementGen.hpp" +#include "Particle/CParticleSwoosh.hpp" +#include "Particle/CGenDescription.hpp" +#include "Particle/CSwooshDescription.hpp" +#include "Particle/CWeaponDescription.hpp" namespace urde { class CModel; -class CWeaponDescription; class CProjectileWeapon { static CRandom16 g_GlobalSeed;