From ecb3ff09772ab58e43a1e2ebb97bbf48eb14d691 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 24 Mar 2020 14:05:39 -0400 Subject: [PATCH] - add warp2 shader to softpoly2 --- .../drawers/screen_scanline_setup.cpp | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp b/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp index ba95a06f4c..8a076f3777 100644 --- a/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp +++ b/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp @@ -434,6 +434,33 @@ static void WriteVaryingWarp1(float posU, float posV, float stepU, float stepV, } } +static void WriteVaryingWarp2(float posU, float posV, float stepU, float stepV, int x0, int x1, PolyTriangleThreadData* thread) +{ + float pi2 = 3.14159265358979323846f * 2.0f; + float timer = thread->mainVertexShader.Data.timer; + + const float* w = thread->scanline.W; + uint16_t* scanlineU = thread->scanline.U; + uint16_t* scanlineV = thread->scanline.V; + + for (int x = x0; x < x1; x++) + { + float u = posU * w[x]; + float v = posV * w[x]; + + v += (0.5f + sin(pi2 * (v + timer * 0.61f + 900.f/8192.f)) + sin(pi2 * (u * 2.0f + timer * 0.36f + 300.0f/8192.0f))) * 0.025f; + u += (0.5f + sin(pi2 * (v + timer * 0.49f + 700.f/8192.f)) + sin(pi2 * (u * 2.0f + timer * 0.49f + 1200.0f/8192.0f))) * 0.025f; + + u = u - std::floor(u); + v = v - std::floor(v); + scanlineU[x] = static_cast(static_cast(u * static_cast(0x1000'0000)) << 4) >> 16; + scanlineV[x] = static_cast(static_cast(v * static_cast(0x1000'0000)) << 4) >> 16; + + posU += stepU; + posV += stepV; + } +} + #ifdef NO_SSE static void WriteVaryingColor(float pos, float step, int x0, int x1, const float* w, uint8_t* varying) { @@ -475,9 +502,16 @@ void WriteVaryings(int y, int x0, int x1, const TriDrawTriangleArgs* args, PolyT float startX = x0 + (0.5f - args->v1->x); float startY = y + (0.5f - args->v1->y); - if (thread->EffectState == SHADER_Warp1 || thread->EffectState == SHADER_Warp2) + void (*useShader)(float posU, float posV, float stepU, float stepV, int x0, int x1, PolyTriangleThreadData* thread) = nullptr; + + if (thread->EffectState == SHADER_Warp1) + useShader = &WriteVaryingWarp1; + else if (thread->EffectState == SHADER_Warp2) + useShader = &WriteVaryingWarp2; + + if (useShader) { - WriteVaryingWarp1( + useShader( args->v1->u * args->v1->w + args->gradientX.U * startX + args->gradientY.U * startY, args->v1->v * args->v1->w + args->gradientX.V * startX + args->gradientY.V * startY, args->gradientX.U,