Initial space warp filter

This commit is contained in:
Jack Andersen 2016-07-29 07:38:44 -10:00
parent 2eaa87b7e7
commit 67801e993a
15 changed files with 350 additions and 81 deletions

View File

@ -92,26 +92,7 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
m_vm.m_modelTest->GetInstance().ActivateLights(lights); m_vm.m_modelTest->GetInstance().ActivateLights(lights);
m_vm.m_modelTest->Draw(flags); m_vm.m_modelTest->Draw(flags);
zeus::CColor ctrlCol{0.7f, 0.f, 0.3f, 1.f}; m_spaceWarpFilter.draw(zeus::CVector2f{0.f, 0.f});
float fac = 0.0f;
zeus::CColor a = zeus::CColor::lerp(ctrlCol, zeus::CColor::skWhite, fac);
m_thermColdFilter.setColorA(a);
float bFac = 0.f;
float bAlpha = 1.f;
if (fac < 0.5f)
{
bAlpha = fac * 2.f;
bFac = (1.f - bAlpha) / 8.f;
}
zeus::CColor b{bFac, bFac, bFac, bAlpha};
m_thermColdFilter.setColorB(b);
zeus::CColor c = zeus::CColor::lerp(zeus::CColor::skBlack, zeus::CColor::skWhite, fac * 0.75f + 0.25f);
m_thermColdFilter.setColorC(zeus::CColor::skBlack);
m_thermColdFilter.setScale(std::sin(m_theta) * 0.5f + 0.5f);
m_thermColdFilter.setShift(m_random.Next() % 32);
//m_thermColdFilter.draw();
} }
if (m_vm.m_partGen) if (m_vm.m_partGen)
{ {
@ -380,6 +361,7 @@ void ViewManager::stop()
m_videoVoice.reset(); m_videoVoice.reset();
m_projManager.shutdown(); m_projManager.shutdown();
TShader<CThermalColdFilter>::Shutdown(); TShader<CThermalColdFilter>::Shutdown();
TShader<CThermalColdFilter>::Shutdown();
CElementGen::Shutdown(); CElementGen::Shutdown();
CMoviePlayer::Shutdown(); CMoviePlayer::Shutdown();
CLineRenderer::Shutdown(); CLineRenderer::Shutdown();

View File

@ -46,7 +46,7 @@ class ViewManager : public specter::IViewManager
class ParticleView : public specter::View class ParticleView : public specter::View
{ {
ViewManager& m_vm; ViewManager& m_vm;
CThermalColdFilter m_thermColdFilter; CSpaceWarpFilter m_spaceWarpFilter;
CRandom16 m_random; CRandom16 m_random;
float m_theta = 0.f; float m_theta = 0.f;
public: public:

View File

@ -9,7 +9,6 @@
#include "CMetroidModelInstance.hpp" #include "CMetroidModelInstance.hpp"
#include "World/CAreaOctTree.hpp" #include "World/CAreaOctTree.hpp"
#define MIRROR_RAMP_RES 32
#define FOGVOL_RAMP_RES 256 #define FOGVOL_RAMP_RES 256
#define SPHERE_RAMP_RES 32 #define SPHERE_RAMP_RES 32
@ -245,26 +244,6 @@ void CBooRenderer::HandleUnsortedModel(CAreaListItem* item, CBooModel& model)
} }
} }
void CBooRenderer::GenerateMirrorRampTex(boo::IGraphicsDataFactory::Context& ctx)
{
u8 data[MIRROR_RAMP_RES][MIRROR_RAMP_RES][4] = {};
float halfRes = MIRROR_RAMP_RES / 2.f;
for (int y=0 ; y<MIRROR_RAMP_RES ; ++y)
{
for (int x=0 ; x<MIRROR_RAMP_RES ; ++x)
{
zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes);
if (vec.magnitude() <= halfRes && vec.canBeNormalized())
vec.normalize();
data[y][x][0] = zeus::clamp(0.f, vec.x, 1.f) * 255;
data[y][x][1] = zeus::clamp(0.f, vec.y, 1.f) * 255;
}
}
x150_mirrorRamp = ctx.newStaticTexture(MIRROR_RAMP_RES, MIRROR_RAMP_RES, 1,
boo::TextureFormat::RGBA8, data[0],
MIRROR_RAMP_RES * MIRROR_RAMP_RES * 4);
}
void CBooRenderer::GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx) void CBooRenderer::GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx)
{ {
u8 data[FOGVOL_RAMP_RES][FOGVOL_RAMP_RES] = {}; u8 data[FOGVOL_RAMP_RES][FOGVOL_RAMP_RES] = {};
@ -314,7 +293,6 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{ {
GenerateMirrorRampTex(ctx);
GenerateFogVolumeRampTex(ctx); GenerateFogVolumeRampTex(ctx);
GenerateSphereRampTex(ctx); GenerateSphereRampTex(ctx);
return true; return true;
@ -534,10 +512,6 @@ void CBooRenderer::SetWorldViewpoint(const zeus::CTransform& xf)
xb0_viewPlane.d = xf.basis[1].dot(xf.origin); xb0_viewPlane.d = xf.basis[1].dot(xf.origin);
} }
void CBooRenderer::SetPerspectiveFovScalar(float)
{
}
void CBooRenderer::SetPerspective(float fovy, float width, float height, float znear, float zfar) void CBooRenderer::SetPerspective(float fovy, float width, float height, float znear, float zfar)
{ {
CGraphics::SetPerspective(fovy, width / height, znear, zfar); CGraphics::SetPerspective(fovy, width / height, znear, zfar);
@ -548,8 +522,16 @@ void CBooRenderer::SetPerspective(float fovy, float aspect, float znear, float z
CGraphics::SetPerspective(fovy, aspect, znear, zfar); CGraphics::SetPerspective(fovy, aspect, znear, zfar);
} }
void CBooRenderer::SetViewportOrtho(bool, float, float) void CBooRenderer::SetViewportOrtho(bool centered, float znear, float zfar)
{ {
float left = centered ? CGraphics::g_ViewportResolutionHalf.x : 0;
float bottom = centered ? CGraphics::g_ViewportResolutionHalf.y : 0;
float top = centered ? CGraphics::g_ViewportResolutionHalf.y : CGraphics::g_ViewportResolution.y;
float right = centered ? CGraphics::g_ViewportResolutionHalf.x : CGraphics::g_ViewportResolution.x;
CGraphics::SetOrtho(left, right, top, bottom, znear, zfar);
CGraphics::SetViewPointMatrix(zeus::CTransform::Identity());
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
} }
void CBooRenderer::SetClippingPlanes(const zeus::CFrustum& frustum) void CBooRenderer::SetClippingPlanes(const zeus::CFrustum& frustum)
@ -557,8 +539,10 @@ void CBooRenderer::SetClippingPlanes(const zeus::CFrustum& frustum)
x44_frustumPlanes = frustum; x44_frustumPlanes = frustum;
} }
void CBooRenderer::SetViewport(int, int, int, int) void CBooRenderer::SetViewport(int l, int b, int w, int h)
{ {
CGraphics::SetViewport(l, b, w, h);
CGraphics::SetScissor(l, b, w, h);
} }
void CBooRenderer::SetDepthReadWrite(bool, bool) void CBooRenderer::SetDepthReadWrite(bool, bool)
@ -603,10 +587,15 @@ void CBooRenderer::SetDebugOption(EDebugOption, int)
void CBooRenderer::BeginScene() void CBooRenderer::BeginScene()
{ {
CGraphics::SetViewport(0, 0, CGraphics::g_ViewportResolution.x, CGraphics::g_ViewportResolution.y);
CGraphics::SetPerspective(75.f, CGraphics::g_ProjAspect, 1.f, 4096.f);
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
CGraphics::BeginScene();
} }
void CBooRenderer::EndScene() void CBooRenderer::EndScene()
{ {
CGraphics::EndScene();
} }
void CBooRenderer::BeginPrimitive(EPrimitiveType, int) void CBooRenderer::BeginPrimitive(EPrimitiveType, int)
@ -653,12 +642,9 @@ void CBooRenderer::EndPrimitive()
{ {
} }
void CBooRenderer::SetAmbientColor(const zeus::CColor&) void CBooRenderer::SetAmbientColor(const zeus::CColor& color)
{
}
void CBooRenderer::SetStaticWorldAmbientColor(const zeus::CColor&)
{ {
CGraphics::SetAmbientColor(color);
} }
void CBooRenderer::DrawString(const char*, int, int) void CBooRenderer::DrawString(const char*, int, int)
@ -670,12 +656,9 @@ u32 CBooRenderer::GetFPS()
return 0; return 0;
} }
void CBooRenderer::CacheReflection(TReflectionCallback, void*, bool) void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float)
{ {
}
void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f&, float)
{
} }
void CBooRenderer::DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*) void CBooRenderer::DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*)

View File

@ -6,8 +6,10 @@
#include "CDrawable.hpp" #include "CDrawable.hpp"
#include "CDrawablePlaneObject.hpp" #include "CDrawablePlaneObject.hpp"
#include "Shaders/CThermalColdFilter.hpp" #include "Shaders/CThermalColdFilter.hpp"
#include "Shaders/CSpaceWarpFilter.hpp"
#include "CRandom16.hpp" #include "CRandom16.hpp"
#include "CPVSVisSet.hpp" #include "CPVSVisSet.hpp"
#include "zeus/CRectangle.hpp"
namespace urde namespace urde
{ {
@ -85,7 +87,7 @@ class CBooRenderer : public IRenderer
bool xee_24_ : 1; bool xee_24_ : 1;
boo::ITextureR* x14c_reflectionTex = nullptr; boo::ITextureR* x14c_reflectionTex = nullptr;
boo::ITextureS* x150_mirrorRamp = nullptr; //boo::ITextureS* x150_mirrorRamp = nullptr;
boo::ITextureS* x1b8_fogVolumeRamp = nullptr; boo::ITextureS* x1b8_fogVolumeRamp = nullptr;
boo::ITextureS* x220_sphereRamp = nullptr; boo::ITextureS* x220_sphereRamp = nullptr;
TLockedToken<CTexture> m_thermoPaletteTex; TLockedToken<CTexture> m_thermoPaletteTex;
@ -119,7 +121,6 @@ class CBooRenderer : public IRenderer
u16 dummy = 0; u16 dummy = 0;
}; };
void GenerateMirrorRampTex(boo::IGraphicsDataFactory::Context& ctx);
void GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx); void GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx);
void GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx); void GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx);
void LoadThermoPalette(); void LoadThermoPalette();
@ -147,7 +148,6 @@ public:
void AddDrawable(void const *, const zeus::CVector3f&, const zeus::CAABox&, int, EDrawableSorting); void AddDrawable(void const *, const zeus::CVector3f&, const zeus::CAABox&, int, EDrawableSorting);
void SetDrawableCallback(TDrawableCallback&&, const void*); void SetDrawableCallback(TDrawableCallback&&, const void*);
void SetWorldViewpoint(const zeus::CTransform&); void SetWorldViewpoint(const zeus::CTransform&);
void SetPerspectiveFovScalar(float);
void SetPerspective(float, float, float, float, float); void SetPerspective(float, float, float, float, float);
void SetPerspective(float, float, float, float); void SetPerspective(float, float, float, float);
void SetViewportOrtho(bool, float, float); void SetViewportOrtho(bool, float, float);
@ -177,10 +177,9 @@ public:
void PrimColor(const zeus::CColor&); void PrimColor(const zeus::CColor&);
void EndPrimitive(); void EndPrimitive();
void SetAmbientColor(const zeus::CColor&); void SetAmbientColor(const zeus::CColor&);
void SetStaticWorldAmbientColor(const zeus::CColor&);
void DrawString(const char*, int, int); void DrawString(const char*, int, int);
u32 GetFPS(); u32 GetFPS();
void CacheReflection(TReflectionCallback, void*, bool); //void CacheReflection(TReflectionCallback, void*, bool);
void DrawSpaceWarp(const zeus::CVector3f&, float); void DrawSpaceWarp(const zeus::CVector3f&, float);
void DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*); void DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*);
void DrawXRayOutline(const CModel&, const float*, const float*); void DrawXRayOutline(const CModel&, const float*, const float*);

View File

@ -79,6 +79,10 @@ void CGraphics::SetCullMode(ERglCullMode)
{ {
} }
void CGraphics::BeginScene()
{
}
void CGraphics::EndScene() void CGraphics::EndScene()
{ {
/* Spinwait until g_NumBreakpointsWaiting is 0 */ /* Spinwait until g_NumBreakpointsWaiting is 0 */

View File

@ -31,6 +31,7 @@ set(GRAPHICS_SOURCES
Shaders/CXrayOutlineFilter.hpp Shaders/CXrayOutlineFilter.cpp Shaders/CXrayOutlineFilterGLSL.cpp Shaders/CXrayOutlineFilter.hpp Shaders/CXrayOutlineFilter.cpp Shaders/CXrayOutlineFilterGLSL.cpp
Shaders/CThermalColdFilter.hpp Shaders/CThermalColdFilter.cpp Shaders/CThermalColdFilterGLSL.cpp Shaders/CThermalColdFilter.hpp Shaders/CThermalColdFilter.cpp Shaders/CThermalColdFilterGLSL.cpp
Shaders/CThermalHotFilter.hpp Shaders/CThermalHotFilter.cpp Shaders/CThermalHotFilterGLSL.cpp Shaders/CThermalHotFilter.hpp Shaders/CThermalHotFilter.cpp Shaders/CThermalHotFilterGLSL.cpp
Shaders/CSpaceWarpFilter.hpp Shaders/CSpaceWarpFilter.cpp Shaders/CSpaceWarpFilterGLSL.cpp
${PLAT_SRCS}) ${PLAT_SRCS})
runtime_add_list(Graphics GRAPHICS_SOURCES) runtime_add_list(Graphics GRAPHICS_SOURCES)

View File

@ -54,7 +54,6 @@ public:
virtual void AddDrawable(void const *, const zeus::CVector3f&, const zeus::CAABox&, int, EDrawableSorting)=0; virtual void AddDrawable(void const *, const zeus::CVector3f&, const zeus::CAABox&, int, EDrawableSorting)=0;
virtual void SetDrawableCallback(TDrawableCallback&&, const void*)=0; virtual void SetDrawableCallback(TDrawableCallback&&, const void*)=0;
virtual void SetWorldViewpoint(const zeus::CTransform&)=0; virtual void SetWorldViewpoint(const zeus::CTransform&)=0;
virtual void SetPerspectiveFovScalar(float)=0;
virtual void SetPerspective(float, float, float, float, float)=0; virtual void SetPerspective(float, float, float, float, float)=0;
virtual void SetPerspective(float, float, float, float)=0; virtual void SetPerspective(float, float, float, float)=0;
virtual void SetViewportOrtho(bool, float, float)=0; virtual void SetViewportOrtho(bool, float, float)=0;
@ -84,10 +83,9 @@ public:
virtual void PrimColor(const zeus::CColor&)=0; virtual void PrimColor(const zeus::CColor&)=0;
virtual void EndPrimitive()=0; virtual void EndPrimitive()=0;
virtual void SetAmbientColor(const zeus::CColor&)=0; virtual void SetAmbientColor(const zeus::CColor&)=0;
virtual void SetStaticWorldAmbientColor(const zeus::CColor&)=0;
virtual void DrawString(const char*, int, int)=0; virtual void DrawString(const char*, int, int)=0;
virtual u32 GetFPS()=0; virtual u32 GetFPS()=0;
virtual void CacheReflection(TReflectionCallback, void*, bool)=0; //virtual void CacheReflection(TReflectionCallback, void*, bool)=0;
virtual void DrawSpaceWarp(const zeus::CVector3f&, float)=0; virtual void DrawSpaceWarp(const zeus::CVector3f&, float)=0;
virtual void DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*)=0; virtual void DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&, const float*, const float*)=0;
virtual void DrawXRayOutline(const CModel&, const float*, const float*)=0; virtual void DrawXRayOutline(const CModel&, const float*, const float*)=0;

View File

@ -0,0 +1,133 @@
#include "CSpaceWarpFilter.hpp"
#include "Graphics/CGraphics.hpp"
#include "Graphics/CBooRenderer.hpp"
#define WARP_RAMP_RES 32
namespace urde
{
void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx)
{
u8 data[WARP_RAMP_RES][WARP_RAMP_RES][4] = {};
float halfRes = WARP_RAMP_RES / 2.f;
for (int y=0 ; y<WARP_RAMP_RES ; ++y)
{
for (int x=0 ; x<WARP_RAMP_RES ; ++x)
{
zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes);
if (vec.magnitude() <= halfRes && vec.canBeNormalized())
vec.normalize();
data[y][x][0] = zeus::clamp(0.f, vec.x / 2.f + 1.f, 1.f) * 255;
data[y][x][1] = zeus::clamp(0.f, vec.y / 2.f + 1.f, 1.f) * 255;
}
}
m_warpTex = ctx.newStaticTexture(WARP_RAMP_RES, WARP_RAMP_RES, 1,
boo::TextureFormat::RGBA8, data[0],
WARP_RAMP_RES * WARP_RAMP_RES * 4);
}
CSpaceWarpFilter::CSpaceWarpFilter()
{
m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{
GenerateWarpRampTex(ctx);
struct Vert
{
zeus::CVector2f m_pos;
zeus::CVector2f m_uv;
} verts[4] =
{
{{-1.0, -1.0}, {0.0, 0.0}},
{{-1.0, 1.0}, {0.0, 1.0}},
{{ 1.0, -1.0}, {1.0, 0.0}},
{{ 1.0, 1.0}, {1.0, 1.0}},
};
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4);
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
m_dataBind = TShader<CSpaceWarpFilter>::BuildShaderDataBinding(ctx, *this);
return true;
});
setStrength(1.f);
}
void CSpaceWarpFilter::draw(const zeus::CVector2f& pt)
{
/* Indirect coords are full-texture sampling when warp is completely in viewport */
m_uniform.m_indXf[1][1] = 1.f;
m_uniform.m_indXf[0][0] = 1.f;
m_uniform.m_indXf[3][0] = 0.f;
m_uniform.m_indXf[3][1] = 0.f;
/* Warp effect is fixed at 192x192 rectangle in original (1/2.5 viewport height) */
m_uniform.m_matrix[1][1] = 1.f / 2.5f;
m_uniform.m_matrix[0][0] = m_uniform.m_matrix[1][1] / CGraphics::g_ProjAspect;
SClipScreenRect clipRect = {};
clipRect.x4_left = ((pt[0] - m_uniform.m_matrix[0][0] / 2.f) / 2.f + 0.5f) * CGraphics::g_ViewportResolution.x;
if (clipRect.x4_left >= CGraphics::g_ViewportResolution.x)
return;
clipRect.x8_top = ((pt[1] - m_uniform.m_matrix[1][1] / 2.f) / 2.f + 0.5f) * CGraphics::g_ViewportResolution.y;
if (clipRect.x8_top >= CGraphics::g_ViewportResolution.y)
return;
clipRect.xc_width = CGraphics::g_ViewportResolution.x * m_uniform.m_matrix[1][1];
if (clipRect.x4_left + clipRect.xc_width <= 0)
return;
clipRect.x10_height = CGraphics::g_ViewportResolution.y * m_uniform.m_matrix[0][0];
if (clipRect.x8_top + clipRect.x10_height <= 0)
return;
if (clipRect.x4_left < 0)
{
float old = clipRect.xc_width;
clipRect.xc_width += clipRect.x4_left;
m_uniform.m_indXf[0][0] = clipRect.xc_width / old;
m_uniform.m_indXf[3][0] = -clipRect.x4_left * m_uniform.m_matrix[0][0];
clipRect.x4_left = 0;
}
if (clipRect.x8_top < 0)
{
float old = clipRect.x10_height;
clipRect.x10_height += clipRect.x8_top;
m_uniform.m_indXf[1][1] = clipRect.x10_height / old;
m_uniform.m_indXf[3][1] = -clipRect.x8_top * m_uniform.m_matrix[1][1];
clipRect.x8_top = 0;
}
float tmp = clipRect.x4_left + clipRect.xc_width;
if (tmp >= CGraphics::g_ViewportResolution.x)
{
float old = clipRect.xc_width;
clipRect.xc_width = CGraphics::g_ViewportResolution.x - clipRect.x4_left;
m_uniform.m_indXf[0][0] *= clipRect.xc_width / old;
}
tmp = clipRect.x8_top + clipRect.x10_height;
if (tmp >= CGraphics::g_ViewportResolution.y)
{
float old = clipRect.x10_height;
clipRect.x10_height = CGraphics::g_ViewportResolution.y - clipRect.x8_top;
m_uniform.m_indXf[1][1] *= clipRect.x10_height / old;
}
CGraphics::ResolveSpareTexture(clipRect);
/* Transform UV coordinates of rectangle within viewport and sampled scene texels (clamped to viewport bounds) */
zeus::CVector2f vp{CGraphics::g_ViewportResolution.x, CGraphics::g_ViewportResolution.y};
zeus::CVector2f center(clipRect.x4_left + clipRect.xc_width / 2.f, clipRect.x8_top + clipRect.x10_height / 2.f);
center /= vp;
center *= zeus::CVector2f{2.f, 2.f};
center -= zeus::CVector2f{1.f, 1.f};
m_uniform.m_matrix[0][0] = clipRect.xc_width / vp.x;
m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y;
m_uniform.m_matrix[3][0] = center.x;
m_uniform.m_matrix[3][1] = center.y;
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind);
CGraphics::g_BooMainCommandQueue->draw(0, 4);
}
URDE_SPECIALIZE_SHADER(CSpaceWarpFilter)
}

View File

@ -0,0 +1,47 @@
#ifndef __URDE_CSPACEWARPFILTER_HPP__
#define __URDE_CSPACEWARPFILTER_HPP__
#include "TShader.hpp"
#include "zeus/CMatrix4f.hpp"
#include "zeus/CColor.hpp"
namespace urde
{
class CSpaceWarpFilter
{
friend struct CSpaceWarpFilterGLDataBindingFactory;
friend struct CSpaceWarpFilterVulkanDataBindingFactory;
struct Uniform
{
zeus::CMatrix4f m_matrix;
zeus::CMatrix4f m_indXf;
zeus::CVector3f m_strength;
};
u8 m_shiftTexture[4][8][4] = {};
boo::GraphicsDataToken m_token;
boo::ITexture* m_warpTex;
boo::IGraphicsBufferS* m_vbo;
boo::IGraphicsBufferD* m_uniBuf;
boo::IShaderDataBinding* m_dataBind = nullptr;
Uniform m_uniform;
void GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx);
public:
CSpaceWarpFilter();
void setStrength(float scale)
{
m_uniform.m_strength[0] = scale;
m_uniform.m_strength[1] = scale;
}
void draw(const zeus::CVector2f& pt);
using _CLS = CSpaceWarpFilter;
#include "TShaderDecl.hpp"
};
}
#endif // __URDE_CSPACEWARPFILTER_HPP__

View File

@ -0,0 +1,120 @@
#include "CSpaceWarpFilter.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 uvIn;\n"
"\n"
"UBINDING0 uniform SpaceWarpUniform\n"
"{\n"
" mat4 mainMtx;\n"
" mat4 indMtx;\n"
" vec4 strength;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" vec4 strength;\n"
" vec2 sceneUv;\n"
" vec2 indUv;\n"
"};\n"
"\n"
"SBINDING(0) out VertToFrag vtf;\n"
"void main()\n"
"{\n"
" vtf.strength = strength;\n"
" vtf.sceneUv = (mainMtx * uvIn).xy;\n"
" vtf.indUv = (indMtx * uvIn).xy;\n"
" gl_Position = mainMtx * vec4(posIn.xyz, 1.0);\n"
"}\n";
static const char* FS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"struct VertToFrag\n"
"{\n"
" vec4 strength;\n"
" vec2 sceneUv;\n"
" vec2 indUv;\n"
"};\n"
"\n"
"SBINDING(0) in VertToFrag vtf;\n"
"layout(location=0) out vec4 colorOut;\n"
"TBINDING0 uniform sampler2D sceneTex;\n"
"TBINDING1 uniform sampler2D indTex;\n"
"void main()\n"
"{\n"
" colorOut = texture(sceneTex, vtf.sceneUv + mix(vtf.indUv, texture(indTex, vtf.indUv).xy, vtf.strength.xy) * vec2(2.0) - vec2(1.0));\n"
"}\n";
URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
struct CSpaceWarpFilterGLDataBindingFactory : TShader<CSpaceWarpFilter>::IDataBindingFactory
{
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CSpaceWarpFilter& filter)
{
boo::GLDataFactory::Context& cctx = static_cast<boo::GLDataFactory::Context&>(ctx);
const boo::VertexElementDescriptor VtxVmt[] =
{
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4},
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4}
};
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_warpTex};
return cctx.newShaderDataBinding(TShader<CSpaceWarpFilter>::m_pipeline,
ctx.newVertexFormat(2, VtxVmt), filter.m_vbo, nullptr, nullptr,
1, bufs, stages, nullptr, nullptr, 2, texs);
}
};
#if BOO_HAS_VULKAN
struct CSpaceWarpFilterVulkanDataBindingFactory : TShader<CSpaceWarpFilter>::IDataBindingFactory
{
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CSpaceWarpFilter& filter)
{
boo::VulkanDataFactory::Context& cctx = static_cast<boo::VulkanDataFactory::Context&>(ctx);
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_warpTex};
return cctx.newShaderDataBinding(TShader<CSpaceWarpFilter>::m_pipeline,
TShader<CSpaceWarpFilter>::m_vtxFmt,
filter.m_vbo, nullptr, nullptr, 1, bufs,
nullptr, nullptr, nullptr, 2, texs);
}
};
#endif
TShader<CSpaceWarpFilter>::IDataBindingFactory* CSpaceWarpFilter::Initialize(boo::GLDataFactory::Context& ctx,
boo::IShaderPipeline*& pipeOut)
{
const char* texNames[] = {"sceneTex", "indTex"};
const char* uniNames[] = {"SpaceWarpUniform"};
pipeOut = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::One,
boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false);
return new CSpaceWarpFilterGLDataBindingFactory;
}
#if BOO_HAS_VULKAN
TShader<CSpaceWarpFilter>::IDataBindingFactory* CSpaceWarpFilter::Initialize(boo::VulkanDataFactory::Context& ctx,
boo::IShaderPipeline*& pipeOut,
boo::IVertexFormat*& vtxFmtOut)
{
const boo::VertexElementDescriptor VtxVmt[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4},
{nullptr, nullptr, boo::VertexSemantic::UV4}
};
vtxFmtOut = ctx.newVertexFormat(2, VtxVmt);
pipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, boo::BlendFactor::One,
boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false);
return new CSpaceWarpFilterVulkanDataBindingFactory;
}
#endif
}

View File

@ -9,11 +9,6 @@ CThermalColdFilter::CThermalColdFilter()
m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{ {
m_shiftTex = ctx.newDynamicTexture(8, 4, boo::TextureFormat::RGBA8); m_shiftTex = ctx.newDynamicTexture(8, 4, boo::TextureFormat::RGBA8);
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4);
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
m_dataBind = TShader<CThermalColdFilter>::BuildShaderDataBinding(ctx, *this);
return true;
});
struct Vert struct Vert
{ {
@ -26,7 +21,11 @@ CThermalColdFilter::CThermalColdFilter()
{{ 1.0, -1.0}, {1.0, 0.0}}, {{ 1.0, -1.0}, {1.0, 0.0}},
{{ 1.0, 1.0}, {1.0, 1.0}}, {{ 1.0, 1.0}, {1.0, 1.0}},
}; };
m_vbo->load(verts, sizeof(verts)); m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4);
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
m_dataBind = TShader<CThermalColdFilter>::BuildShaderDataBinding(ctx, *this);
return true;
});
setShift(0); setShift(0);
setScale(0.f); setScale(0.f);

View File

@ -23,7 +23,7 @@ class CThermalColdFilter
u8 m_shiftTexture[4][8][4] = {}; u8 m_shiftTexture[4][8][4] = {};
boo::GraphicsDataToken m_token; boo::GraphicsDataToken m_token;
boo::ITextureD* m_shiftTex = nullptr; boo::ITextureD* m_shiftTex = nullptr;
boo::IGraphicsBufferD* m_vbo; boo::IGraphicsBufferS* m_vbo;
boo::IGraphicsBufferD* m_uniBuf; boo::IGraphicsBufferD* m_uniBuf;
boo::IShaderDataBinding* m_dataBind = nullptr; boo::IShaderDataBinding* m_dataBind = nullptr;
Uniform m_uniform; Uniform m_uniform;

View File

@ -1,10 +1,12 @@
#include "MP1.hpp" #include "MP1.hpp"
#include "Graphics/Shaders/CModelShaders.hpp" #include "Graphics/Shaders/CModelShaders.hpp"
#include "Graphics/Shaders/CThermalColdFilter.hpp" #include "Graphics/Shaders/CThermalColdFilter.hpp"
#include "Graphics/Shaders/CSpaceWarpFilter.hpp"
namespace urde namespace urde
{ {
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter) URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
namespace MP1 namespace MP1
{ {
@ -33,6 +35,7 @@ void CMain::InitializeSubsystems(boo::IGraphicsDataFactory* factory,
CGraphics::InitializeBoo(factory, cc, renderTex); CGraphics::InitializeBoo(factory, cc, renderTex);
CModelShaders::Initialize(storeMgr, factory); CModelShaders::Initialize(storeMgr, factory);
TShader<CThermalColdFilter>::Initialize(); TShader<CThermalColdFilter>::Initialize();
TShader<CSpaceWarpFilter>::Initialize();
CMoviePlayer::Initialize(); CMoviePlayer::Initialize();
CLineRenderer::Initialize(); CLineRenderer::Initialize();
CElementGen::Initialize(); CElementGen::Initialize();