- add support for using FModelVertex as input to the softpoly vertex shader
This commit is contained in:
parent
c9fd52340e
commit
9ba26a5ece
8 changed files with 104 additions and 116 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include "g_game.h"
|
||||
#include "g_level.h"
|
||||
#include "r_data/r_translate.h"
|
||||
#include "r_data/models/models.h"
|
||||
#include "v_palette.h"
|
||||
#include "r_data/colormaps.h"
|
||||
#include "poly_triangle.h"
|
||||
|
|
@ -102,6 +103,11 @@ void PolyTriangleDrawer::SetWeaponScene(const DrawerCommandQueuePtr &queue, bool
|
|||
queue->Push<PolySetWeaponSceneCommand>(enable);
|
||||
}
|
||||
|
||||
void PolyTriangleDrawer::SetModelVertexShader(const DrawerCommandQueuePtr &queue, int frame1, int frame2, float interpolationFactor)
|
||||
{
|
||||
queue->Push<PolySetModelVertexShaderCommand>(frame1, frame2, interpolationFactor);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void PolyTriangleThreadData::ClearStencil(uint8_t value)
|
||||
|
|
@ -156,7 +162,6 @@ void PolyTriangleThreadData::DrawElements(const PolyDrawArgs &drawargs)
|
|||
args.zbuffer = PolyZBuffer::Instance()->Values();
|
||||
args.depthOffset = weaponScene ? 1.0f : 0.0f;
|
||||
|
||||
const TriVertex *vinput = drawargs.Vertices();
|
||||
const unsigned int *elements = drawargs.Elements();
|
||||
int vcount = drawargs.VertexCount();
|
||||
|
||||
|
|
@ -166,17 +171,17 @@ void PolyTriangleThreadData::DrawElements(const PolyDrawArgs &drawargs)
|
|||
for (int i = 0; i < vcount / 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
vert[j] = ShadeVertex(drawargs, vinput[*(elements++)]);
|
||||
vert[j] = ShadeVertex(drawargs, *(elements++));
|
||||
DrawShadedTriangle(vert, ccw, &args);
|
||||
}
|
||||
}
|
||||
else if (drawargs.DrawMode() == PolyDrawMode::TriangleFan)
|
||||
{
|
||||
vert[0] = ShadeVertex(drawargs, vinput[*(elements++)]);
|
||||
vert[1] = ShadeVertex(drawargs, vinput[*(elements++)]);
|
||||
vert[0] = ShadeVertex(drawargs, *(elements++));
|
||||
vert[1] = ShadeVertex(drawargs, *(elements++));
|
||||
for (int i = 2; i < vcount; i++)
|
||||
{
|
||||
vert[2] = ShadeVertex(drawargs, vinput[*(elements++)]);
|
||||
vert[2] = ShadeVertex(drawargs, *(elements++));
|
||||
DrawShadedTriangle(vert, ccw, &args);
|
||||
vert[1] = vert[2];
|
||||
}
|
||||
|
|
@ -184,11 +189,11 @@ void PolyTriangleThreadData::DrawElements(const PolyDrawArgs &drawargs)
|
|||
else // TriangleDrawMode::TriangleStrip
|
||||
{
|
||||
bool toggleccw = ccw;
|
||||
vert[0] = ShadeVertex(drawargs, vinput[*(elements++)]);
|
||||
vert[1] = ShadeVertex(drawargs, vinput[*(elements++)]);
|
||||
vert[0] = ShadeVertex(drawargs, *(elements++));
|
||||
vert[1] = ShadeVertex(drawargs, *(elements++));
|
||||
for (int i = 2; i < vcount; i++)
|
||||
{
|
||||
vert[2] = ShadeVertex(drawargs, vinput[*(elements++)]);
|
||||
vert[2] = ShadeVertex(drawargs, *(elements++));
|
||||
DrawShadedTriangle(vert, toggleccw, &args);
|
||||
vert[0] = vert[1];
|
||||
vert[1] = vert[2];
|
||||
|
|
@ -213,7 +218,7 @@ void PolyTriangleThreadData::DrawArrays(const PolyDrawArgs &drawargs)
|
|||
args.zbuffer = PolyZBuffer::Instance()->Values();
|
||||
args.depthOffset = weaponScene ? 1.0f : 0.0f;
|
||||
|
||||
const TriVertex *vinput = drawargs.Vertices();
|
||||
int vinput = 0;
|
||||
int vcount = drawargs.VertexCount();
|
||||
|
||||
ShadedTriVertex vert[3];
|
||||
|
|
@ -222,17 +227,17 @@ void PolyTriangleThreadData::DrawArrays(const PolyDrawArgs &drawargs)
|
|||
for (int i = 0; i < vcount / 3; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
vert[j] = ShadeVertex(drawargs, *(vinput++));
|
||||
vert[j] = ShadeVertex(drawargs, vinput++);
|
||||
DrawShadedTriangle(vert, ccw, &args);
|
||||
}
|
||||
}
|
||||
else if (drawargs.DrawMode() == PolyDrawMode::TriangleFan)
|
||||
{
|
||||
vert[0] = ShadeVertex(drawargs, *(vinput++));
|
||||
vert[1] = ShadeVertex(drawargs, *(vinput++));
|
||||
vert[0] = ShadeVertex(drawargs, vinput++);
|
||||
vert[1] = ShadeVertex(drawargs, vinput++);
|
||||
for (int i = 2; i < vcount; i++)
|
||||
{
|
||||
vert[2] = ShadeVertex(drawargs, *(vinput++));
|
||||
vert[2] = ShadeVertex(drawargs, vinput++);
|
||||
DrawShadedTriangle(vert, ccw, &args);
|
||||
vert[1] = vert[2];
|
||||
}
|
||||
|
|
@ -240,11 +245,11 @@ void PolyTriangleThreadData::DrawArrays(const PolyDrawArgs &drawargs)
|
|||
else // TriangleDrawMode::TriangleStrip
|
||||
{
|
||||
bool toggleccw = ccw;
|
||||
vert[0] = ShadeVertex(drawargs, *(vinput++));
|
||||
vert[1] = ShadeVertex(drawargs, *(vinput++));
|
||||
vert[0] = ShadeVertex(drawargs, vinput++);
|
||||
vert[1] = ShadeVertex(drawargs, vinput++);
|
||||
for (int i = 2; i < vcount; i++)
|
||||
{
|
||||
vert[2] = ShadeVertex(drawargs, *(vinput++));
|
||||
vert[2] = ShadeVertex(drawargs, vinput++);
|
||||
DrawShadedTriangle(vert, toggleccw, &args);
|
||||
vert[0] = vert[1];
|
||||
vert[1] = vert[2];
|
||||
|
|
@ -253,25 +258,51 @@ void PolyTriangleThreadData::DrawArrays(const PolyDrawArgs &drawargs)
|
|||
}
|
||||
}
|
||||
|
||||
ShadedTriVertex PolyTriangleThreadData::ShadeVertex(const PolyDrawArgs &drawargs, const TriVertex &v)
|
||||
ShadedTriVertex PolyTriangleThreadData::ShadeVertex(const PolyDrawArgs &drawargs, int index)
|
||||
{
|
||||
ShadedTriVertex sv;
|
||||
Vec4f objpos;
|
||||
|
||||
if (modelFrame1 == -1)
|
||||
{
|
||||
const TriVertex &v = ((TriVertex*)drawargs.Vertices())[index];
|
||||
objpos = Vec4f(v.x, v.y, v.z, v.w);
|
||||
sv.u = v.u;
|
||||
sv.v = v.v;
|
||||
}
|
||||
else if (modelFrame1 == modelFrame2 || modelInterpolationFactor == 0.f)
|
||||
{
|
||||
const FModelVertex &v = ((FModelVertex*)drawargs.Vertices())[modelFrame1 + index];
|
||||
objpos = Vec4f(v.x, v.y, v.z, 1.0f);
|
||||
sv.u = v.u;
|
||||
sv.v = v.v;
|
||||
}
|
||||
else
|
||||
{
|
||||
const FModelVertex &v1 = ((FModelVertex*)drawargs.Vertices())[modelFrame1 + index];
|
||||
const FModelVertex &v2 = ((FModelVertex*)drawargs.Vertices())[modelFrame2 + index];
|
||||
|
||||
float frac = modelInterpolationFactor;
|
||||
float inv_frac = 1.0f - frac;
|
||||
|
||||
objpos = Vec4f(v1.x * inv_frac + v2.x * frac, v1.y * inv_frac + v2.y * frac, v1.z * inv_frac + v2.z * frac, 1.0f);
|
||||
sv.u = v1.u;
|
||||
sv.v = v1.v;
|
||||
}
|
||||
|
||||
// Apply transform to get clip coordinates:
|
||||
Vec4f objpos = Vec4f(v.x, v.y, v.z, v.w);
|
||||
Vec4f clippos = (*objectToClip) * objpos;
|
||||
|
||||
ShadedTriVertex sv;
|
||||
sv.x = clippos.X;
|
||||
sv.y = clippos.Y;
|
||||
sv.z = clippos.Z;
|
||||
sv.w = clippos.W;
|
||||
sv.u = v.u;
|
||||
sv.v = v.v;
|
||||
|
||||
if (!objectToWorld) // Identity matrix
|
||||
{
|
||||
sv.worldX = v.x;
|
||||
sv.worldY = v.y;
|
||||
sv.worldZ = v.z;
|
||||
sv.worldX = objpos.X;
|
||||
sv.worldY = objpos.Y;
|
||||
sv.worldZ = objpos.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -285,7 +316,7 @@ ShadedTriVertex PolyTriangleThreadData::ShadeVertex(const PolyDrawArgs &drawargs
|
|||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
const auto &clipPlane = drawargs.ClipPlane(i);
|
||||
sv.clipDistance[i] = v.x * clipPlane.A + v.y * clipPlane.B + v.z * clipPlane.C + v.w * clipPlane.D;
|
||||
sv.clipDistance[i] = objpos.X * clipPlane.A + objpos.Y * clipPlane.B + objpos.Z * clipPlane.C + objpos.W * clipPlane.D;
|
||||
}
|
||||
|
||||
return sv;
|
||||
|
|
@ -653,6 +684,17 @@ void PolySetWeaponSceneCommand::Execute(DrawerThread *thread)
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PolySetModelVertexShaderCommand::PolySetModelVertexShaderCommand(int frame1, int frame2, float interpolationFactor) : frame1(frame1), frame2(frame2), interpolationFactor(interpolationFactor)
|
||||
{
|
||||
}
|
||||
|
||||
void PolySetModelVertexShaderCommand::Execute(DrawerThread *thread)
|
||||
{
|
||||
PolyTriangleThreadData::Get(thread)->SetModelVertexShader(frame1, frame2, interpolationFactor);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PolyClearStencilCommand::PolyClearStencilCommand(uint8_t value) : value(value)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue