Space warp pixel-accuracy fixes

This commit is contained in:
Jack Andersen 2016-07-29 12:57:48 -10:00
parent 4d018ade12
commit 0a7e36a1fb
3 changed files with 12 additions and 21 deletions

View File

@ -21,6 +21,7 @@ namespace urde
{ {
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter) URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
void ViewManager::BuildTestPART(urde::IObjectStore& objStore) void ViewManager::BuildTestPART(urde::IObjectStore& objStore)
{ {

View File

@ -9,26 +9,26 @@ namespace urde
void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx) void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx)
{ {
u8 data[WARP_RAMP_RES][WARP_RAMP_RES][4] = {}; u8 data[WARP_RAMP_RES+1][WARP_RAMP_RES+1][4] = {};
float halfRes = WARP_RAMP_RES / 2.f; float halfRes = WARP_RAMP_RES / 2.f;
for (int y=0 ; y<WARP_RAMP_RES ; ++y) for (int y=0 ; y<WARP_RAMP_RES+1 ; ++y)
{ {
for (int x=0 ; x<WARP_RAMP_RES ; ++x) for (int x=0 ; x<WARP_RAMP_RES+1 ; ++x)
{ {
zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes); zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes);
float mag = vec.magnitude(); float mag = vec.magnitude();
if (mag <= 1.f && vec.canBeNormalized()) if (mag < 1.f && vec.canBeNormalized())
{ {
vec.normalize(); vec.normalize();
vec *= std::sqrt(mag); vec *= std::sqrt(mag);
} }
data[y][x][0] = zeus::clamp(0.f, ((vec.x / 2.f + 0.5f) - x / float(WARP_RAMP_RES)) + 0.5f, 1.f) * 255; data[y][x][0] = zeus::clamp(0, int((((vec.x / 2.f + 0.5f) - x / float(WARP_RAMP_RES)) + 0.5f) * 255), 255);
data[y][x][1] = zeus::clamp(0.f, ((vec.y / 2.f + 0.5f) - y / float(WARP_RAMP_RES)) + 0.5f, 1.f) * 255; data[y][x][1] = zeus::clamp(0, int((((vec.y / 2.f + 0.5f) - y / float(WARP_RAMP_RES)) + 0.5f) * 255), 255);
} }
} }
m_warpTex = ctx.newStaticTexture(WARP_RAMP_RES, WARP_RAMP_RES, 1, m_warpTex = ctx.newStaticTexture(WARP_RAMP_RES+1, WARP_RAMP_RES+1, 1,
boo::TextureFormat::RGBA8, data[0], boo::TextureFormat::RGBA8, data[0],
WARP_RAMP_RES * WARP_RAMP_RES * 4); (WARP_RAMP_RES+1) * (WARP_RAMP_RES+1) * 4);
} }
CSpaceWarpFilter::CSpaceWarpFilter() CSpaceWarpFilter::CSpaceWarpFilter()
@ -111,18 +111,11 @@ void CSpaceWarpFilter::draw(const zeus::CVector2f& pt)
clipRect.x10_height = CGraphics::g_ViewportResolution.y - clipRect.x8_top; clipRect.x10_height = CGraphics::g_ViewportResolution.y - clipRect.x8_top;
m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH; m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH;
} }
SClipScreenRect clipRectDummy = {}; CGraphics::ResolveSpareTexture(clipRect);
clipRectDummy.xc_width = CGraphics::g_ViewportResolution.x;
clipRectDummy.x10_height = CGraphics::g_ViewportResolution.y;
CGraphics::ResolveSpareTexture(clipRectDummy);
/* Transform UV coordinates of rectangle within viewport and sampled scene texels (clamped to viewport bounds) */ /* 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 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[0][0] = clipRect.xc_width / vp.x;
m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y; m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y;
m_uniform.m_matrix[2][0] = pt.x; m_uniform.m_matrix[2][0] = pt.x;

View File

@ -48,10 +48,7 @@ BOO_GLSL_BINDING_HEAD
"TBINDING1 uniform sampler2D indTex;\n" "TBINDING1 uniform sampler2D indTex;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" colorOut = texture(sceneTex, vtf.sceneUv + (texture(indTex, vtf.indUv).xy * vec2(2.0) - vec2(1.0)) * vtf.strength.xy);\n" " colorOut = texture(sceneTex, vtf.sceneUv + (texture(indTex, vtf.indUv).xy * vec2(2.0) - vec2(1.0 - 1.0 / 256.0)) * vtf.strength.xy);\n"
" //colorOut *= vec4(0.00001);\n"
" //colorOut.rg = texture(indTex, vtf.indUv).xy;\n"
" //colorOut.a = 1.0;\n"
"}\n"; "}\n";
URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter) URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)