- implement more shaders

This commit is contained in:
Magnus Norddahl 2019-08-06 04:51:37 +02:00
parent 4e24fdacf0
commit eb127d0dac
2 changed files with 156 additions and 105 deletions

View file

@ -599,6 +599,8 @@ void PolyTriangleThreadData::Draw(int index, int vcount, PolyDrawMode drawmode)
ShadedTriVertex PolyTriangleThreadData::ShadeVertex(int index)
{
inputAssembly->Load(this, vertices, index);
mainVertexShader.SIMPLE = (SpecialEffect == EFF_BURN) || (SpecialEffect == EFF_STENCIL);
mainVertexShader.SPHEREMAP = (SpecialEffect == EFF_SPHEREMAP);
mainVertexShader.main();
return mainVertexShader;
}

View file

@ -234,15 +234,66 @@ static uint32_t sampleTexture(float u, float v, const uint32_t* texPixels, int t
static void RunShader(int x0, int x1, PolyTriangleThreadData* thread)
{
int texWidth = thread->drawargs.TextureWidth();
int texHeight = thread->drawargs.TextureHeight();
const uint32_t* texPixels = (const uint32_t*)thread->drawargs.TexturePixels();
auto constants = thread->PushConstants;
auto& streamdata = thread->mainVertexShader.Data;
uint32_t* fragcolor = thread->scanline.FragColor;
float* u = thread->scanline.U;
float* v = thread->scanline.V;
if (thread->SpecialEffect == EFF_FOGBOUNDARY) // fogboundary.fp
{
/*float fogdist = pixelpos.w;
float fogfactor = exp2(uFogDensity * fogdist);
FragColor = vec4(uFogColor.rgb, 1.0 - fogfactor);*/
return;
}
else if (thread->SpecialEffect == EFF_BURN) // burn.fp
{
/*vec4 frag = vColor;
vec4 t1 = texture(tex, vTexCoord.xy);
vec4 t2 = texture(texture2, vec2(vTexCoord.x, 1.0-vTexCoord.y));
FragColor = frag * vec4(t1.rgb, t2.a);*/
return;
}
else if (thread->SpecialEffect == EFF_STENCIL) // stencil.fp
{
for (int x = x0; x < x1; x++)
{
fragcolor[x] = 0x00ffffff;
}
return;
}
else if (thread->EffectState == SHADER_NoTexture) // func_notexture
{
uint32_t a = (int)(streamdata.uObjectColor.a * 255.0f);
uint32_t r = (int)(streamdata.uObjectColor.r * 255.0f);
uint32_t g = (int)(streamdata.uObjectColor.g * 255.0f);
uint32_t b = (int)(streamdata.uObjectColor.b * 255.0f);
uint32_t texel = MAKEARGB(a, r, g, b);
if (streamdata.uDesaturationFactor > 0.0f)
{
uint32_t t = (int)(streamdata.uDesaturationFactor * 256.0f);
uint32_t inv_t = 256 - t;
uint32_t gray = (RPART(texel) * 77 + GPART(texel) * 143 + BPART(texel) * 37) >> 8;
texel = MAKEARGB(
APART(texel),
(RPART(texel) * inv_t + gray * t + 127) >> 8,
(GPART(texel) * inv_t + gray * t + 127) >> 8,
(BPART(texel) * inv_t + gray * t + 127) >> 8);
}
for (int x = x0; x < x1; x++)
{
fragcolor[x] = texel;
}
}
else // func_normal
{
int texWidth = thread->drawargs.TextureWidth();
int texHeight = thread->drawargs.TextureHeight();
const uint32_t* texPixels = (const uint32_t*)thread->drawargs.TexturePixels();
switch (constants->uTextureMode)
{
default:
@ -374,6 +425,7 @@ static void RunShader(int x0, int x1, PolyTriangleThreadData* thread)
}
}
}
}
if (thread->mainVertexShader.vColor != 0xffffffff)
{
@ -404,9 +456,6 @@ static void RunShader(int x0, int x1, PolyTriangleThreadData* thread)
static void DrawSpan(int y, int x0, int x1, const TriDrawTriangleArgs* args, PolyTriangleThreadData* thread)
{
if (thread->SpecialEffect != EFF_NONE || !(thread->EffectState == SHADER_Default || thread->EffectState == SHADER_Brightmap))
return;
WriteVaryings(y, x0, x1, args, thread);
RunShader(x0, x1, thread);