Skip to content

Commit

Permalink
xrRender_R1: Ported LightShadows to FFP
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Apr 22, 2023
1 parent 78a54e6 commit b16cd99
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
41 changes: 40 additions & 1 deletion src/Layers/xrRenderPC_R1/FStaticRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,46 @@ void CRender::Render()
BasicStats.Primitives.End();
}

void CRender::ApplyBlur4(FVF::TL4uv* pv, u32 w, u32 h, float k)
void CRender::ApplyBlur2(FVF::TL2uv* pv, u32 size) const
{
const float dim = float(size);
Fvector2 shift, p0, p1, a0, a1, b0, b1, c0, c1, d0, d1;
p0.set(.5f / dim, .5f / dim);
p1.set((dim + .5f) / dim, (dim + .5f) / dim);
shift.set(.5f / dim, .5f / dim);
a0.add(p0, shift);
a1.add(p1, shift);
b0.sub(p0, shift);
b1.sub(p1, shift);
shift.set(.5f / dim, -.5f / dim);
c0.add(p0, shift);
c1.add(p1, shift);
d0.sub(p0, shift);
d1.sub(p1, shift);

constexpr u32 C = 0xffffffff;

// Fill VB
pv->set(0.f, dim, C, a0.x, a1.y, b0.x, b1.y);
pv++;
pv->set(0.f, 0.f, C, a0.x, a0.y, b0.x, b0.y);
pv++;
pv->set(dim, dim, C, a1.x, a1.y, b1.x, b1.y);
pv++;
pv->set(dim, 0.f, C, a1.x, a0.y, b1.x, b0.y);
pv++;

pv->set(0.f, dim, C, c0.x, c1.y, d0.x, d1.y);
pv++;
pv->set(0.f, 0.f, C, c0.x, c0.y, d0.x, d0.y);
pv++;
pv->set(dim, dim, C, c1.x, c1.y, d1.x, d1.y);
pv++;
pv->set(dim, 0.f, C, c1.x, c0.y, d1.x, d0.y);
pv++;
}

void CRender::ApplyBlur4(FVF::TL4uv* pv, u32 w, u32 h, float k) const
{
float _w = float(w);
float _h = float(h);
Expand Down
3 changes: 2 additions & 1 deletion src/Layers/xrRenderPC_R1/FStaticRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class CRender : public D3DXRenderBase
IRender_Portal* getPortal(int id);
IRender_Sector* getSectorActive();
IRenderVisual* model_CreatePE(LPCSTR name);
void ApplyBlur4(FVF::TL4uv* dest, u32 w, u32 h, float k);
void ApplyBlur2(FVF::TL2uv* dest, u32 size) const;
void ApplyBlur4(FVF::TL4uv* dest, u32 w, u32 h, float k) const;
void apply_object(IRenderable* O);
void apply_lmaterial(){};

Expand Down
6 changes: 6 additions & 0 deletions src/Layers/xrRenderPC_R1/LightProjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,15 @@ void CLightProjector::calculate()
{
// Fill vertex buffer
u32 Offset;
if (RImplementation.o.ffp) {
FVF::TL2uv* pv = (FVF::TL2uv*) RCache.Vertex.Lock (8,geom_Blur.stride(),Offset);
RImplementation.ApplyBlur2 (pv, rt_size);
RCache.Vertex.Unlock (8,geom_Blur.stride());
} else {
FVF::TL4uv* pv = (FVF::TL4uv*) RCache.Vertex.Lock (4,geom_Blur.stride(),Offset);
RImplementation.ApplyBlur4 (pv,P_rt_size,P_rt_size,P_blur_kernel);
RCache.Vertex.Unlock (4,geom_Blur.stride());
}
// Actual rendering (pass0, temp2real)
RCache.set_RT (RT->pRT);
Expand Down
39 changes: 33 additions & 6 deletions src/Layers/xrRenderPC_R1/LightShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Layers/xrRender/LightTrack.h"
#include "xrEngine/xr_object.h"
#include "Layers/xrRender/FBasicVisual.h"
#include "Layers/xrRender/blenders/Blender_Blur.h"
#include "xrEngine/CustomHUD.h"

const float S_distance = 144;
Expand Down Expand Up @@ -50,9 +51,26 @@ CLightShadows::CLightShadows() : xrc("LightShadows")
sh_World.create("effects" DELIMITER "shadow_world", r1_RT_shadow);
geom_World.create(FVF::F_LIT, RCache.Vertex.Buffer(), nullptr);

sh_BlurTR.create("blur4", TWO_TEMP_TEXTURES);
sh_BlurRT.create("blur4", TWO_SHADOW_TEXTURES);
geom_Blur.create(FVF::F_TL4uv, RCache.Vertex.Buffer(), RCache.QuadIB);
if (RImplementation.o.ffp)
{
CBlender_Blur blender;

sh_BlurTR.create("effects\\blur", TWO_TEMP_TEXTURES);
if (!sh_BlurTR)
sh_BlurTR.create(&blender, "effects\\blur", TWO_TEMP_TEXTURES);

sh_BlurRT.create("effects\\blur", TWO_SHADOW_TEXTURES);
if (!sh_BlurRT)
sh_BlurRT.create(&blender, "effects\\blur", TWO_SHADOW_TEXTURES);

geom_Blur.create(FVF::F_TL2uv, RCache.Vertex.Buffer(), RCache.QuadIB);
}
else
{
sh_BlurTR.create("blur4", TWO_TEMP_TEXTURES);
sh_BlurRT.create("blur4", TWO_SHADOW_TEXTURES);
geom_Blur.create(FVF::F_TL4uv, RCache.Vertex.Buffer(), RCache.QuadIB);
}

// Debug
sh_Screen.create("effects" DELIMITER "screen_set", r1_RT_shadow);
Expand Down Expand Up @@ -327,9 +345,18 @@ void CLightShadows::calculate()
{
// Fill VB
u32 Offset;
FVF::TL4uv* pv = (FVF::TL4uv*)RCache.Vertex.Lock(4, geom_Blur.stride(), Offset);
RImplementation.ApplyBlur4(pv, rt_size, rt_size, S_blur_kernel);
RCache.Vertex.Unlock(4, geom_Blur.stride());
if (RImplementation.o.ffp)
{
FVF::TL2uv* pv = (FVF::TL2uv*)RCache.Vertex.Lock(8, geom_Blur.stride(), Offset);
RImplementation.ApplyBlur2(pv, rt_size);
RCache.Vertex.Unlock(8, geom_Blur.stride());
}
else
{
FVF::TL4uv* pv = (FVF::TL4uv*)RCache.Vertex.Lock(4, geom_Blur.stride(), Offset);
RImplementation.ApplyBlur4(pv, rt_size, rt_size, S_blur_kernel);
RCache.Vertex.Unlock(4, geom_Blur.stride());
}

// Actual rendering (pass0, temp2real)
RCache.set_RT(rt_shadow->pRT);
Expand Down

1 comment on commit b16cd99

@Xottab-DUTY
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.