From 71d132839ed40d19ae124e4be2f3bbe1725fb3d3 Mon Sep 17 00:00:00 2001 From: aap Date: Sat, 6 Feb 2021 10:59:38 +0100 Subject: [PATCH] add modulate flag check for material rendering --- src/d3d/d3d8render.cpp | 8 ++++---- src/d3d/d3d9matfx.cpp | 3 ++- src/d3d/d3d9render.cpp | 3 ++- src/d3d/d3d9skin.cpp | 4 ++-- src/d3d/rwd3d.h | 8 ++++++++ src/gl/gl3matfx.cpp | 17 +++++++++-------- src/gl/gl3render.cpp | 3 ++- src/gl/gl3skin.cpp | 3 ++- src/gl/rwgl3.h | 8 ++++++++ 9 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/d3d/d3d8render.cpp b/src/d3d/d3d8render.cpp index b6eef0e..c5375cb 100644 --- a/src/d3d/d3d8render.cpp +++ b/src/d3d/d3d8render.cpp @@ -29,8 +29,8 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) d3d::lightingCB_Fix(atomic); - Geometry *geo = atomic->geometry; - d3d::setRenderState(D3DRS_LIGHTING, !!(geo->flags & rw::Geometry::LIGHT)); + uint32 flags = atomic->geometry->flags; + d3d::setRenderState(D3DRS_LIGHTING, !!(flags & rw::Geometry::LIGHT)); Frame *f = atomic->getFrame(); convMatrix(&world, f->getLTM()); @@ -39,12 +39,12 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) InstanceData *inst = header->inst; for(uint32 i = 0; i < header->numMeshes; i++){ d3d::setTexture(0, inst->material->texture); - d3d::setMaterial(inst->material->color, inst->material->surfaceProps); + d3d::setMaterial(flags, inst->material->color, inst->material->surfaceProps); d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); - if(geo->flags & Geometry::PRELIT) + if(flags & Geometry::PRELIT) d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); else d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL); diff --git a/src/d3d/d3d9matfx.cpp b/src/d3d/d3d9matfx.cpp index 80a3703..f4fcfe2 100644 --- a/src/d3d/d3d9matfx.cpp +++ b/src/d3d/d3d9matfx.cpp @@ -150,6 +150,7 @@ void matfxRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header) { int vsBits; + uint32 flags = atomic->geometry->flags; setStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer, 0, header->vertexStream[0].stride); setIndices((IDirect3DIndexBuffer9*)header->indexBuffer); @@ -166,7 +167,7 @@ matfxRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header) for(uint32 i = 0; i < header->numMeshes; i++){ Material *m = inst->material; - setMaterial(m->color, m->surfaceProps); + setMaterial(flags, m->color, m->surfaceProps); MatFX *matfx = MatFX::get(m); if(matfx == nil) diff --git a/src/d3d/d3d9render.cpp b/src/d3d/d3d9render.cpp index 0460922..89d937f 100644 --- a/src/d3d/d3d9render.cpp +++ b/src/d3d/d3d9render.cpp @@ -145,6 +145,7 @@ void defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header) { int vsBits; + uint32 flags = atomic->geometry->flags; setStreamSource(0, header->vertexStream[0].vertexBuffer, 0, header->vertexStream[0].stride); setIndices(header->indexBuffer); setVertexDeclaration(header->vertexDeclaration); @@ -166,7 +167,7 @@ defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header) SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255); - setMaterial(m->color, m->surfaceProps); + setMaterial(flags, m->color, m->surfaceProps); if(m->texture){ d3d::setTexture(0, m->texture); diff --git a/src/d3d/d3d9skin.cpp b/src/d3d/d3d9skin.cpp index 23c234d..86c79ab 100644 --- a/src/d3d/d3d9skin.cpp +++ b/src/d3d/d3d9skin.cpp @@ -289,7 +289,7 @@ void skinRenderCB(Atomic *atomic, InstanceDataHeader *header) { int vsBits; - + uint32 flags = atomic->geometry->flags; setStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer, 0, header->vertexStream[0].stride); setIndices((IDirect3DIndexBuffer9*)header->indexBuffer); @@ -314,7 +314,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header) SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255); - setMaterial(m->color, m->surfaceProps); + setMaterial(flags, m->color, m->surfaceProps); if(inst->material->texture){ d3d::setTexture(0, m->texture); diff --git a/src/d3d/rwd3d.h b/src/d3d/rwd3d.h index 34593b6..adc7cfd 100644 --- a/src/d3d/rwd3d.h +++ b/src/d3d/rwd3d.h @@ -292,6 +292,14 @@ void flushCache(void); void setTexture(uint32 stage, Texture *tex); void setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f); +inline void setMaterial(uint32 flags, const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f) +{ + static RGBA white = { 255, 255, 255, 255 }; + if(flags & Geometry::MODULATE) + setMaterial(color, surfaceprops, extraSurfProp); + else + setMaterial(white, surfaceprops, extraSurfProp); +} void setVertexShader(void *vs); void setPixelShader(void *ps); diff --git a/src/gl/gl3matfx.cpp b/src/gl/gl3matfx.cpp index 657489c..30b82c5 100644 --- a/src/gl/gl3matfx.cpp +++ b/src/gl/gl3matfx.cpp @@ -34,14 +34,14 @@ static int32 u_fxparams; static int32 u_colorClamp; void -matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst) +matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst, uint32 flags) { Material *m; m = inst->material; defaultShader->use(); - setMaterial(m->color, m->surfaceProps); + setMaterial(flags, m->color, m->surfaceProps); setTexture(0, m->texture); @@ -83,13 +83,13 @@ uploadEnvMatrix(Frame *frame) } void -matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env) +matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, uint32 flags, MatFX::Env *env) { Material *m; m = inst->material; if(env->tex == nil || env->coefficient == 0.0f){ - matfxDefaultRender(header, inst); + matfxDefaultRender(header, inst, flags); return; } @@ -99,7 +99,7 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env) setTexture(1, env->tex); uploadEnvMatrix(env->frame); - setMaterial(m->color, m->surfaceProps); + setMaterial(flags, m->color, m->surfaceProps); float fxparams[2]; fxparams[0] = env->coefficient; @@ -125,6 +125,7 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env) void matfxRenderCB(Atomic *atomic, InstanceDataHeader *header) { + uint32 flags = atomic->geometry->flags; setWorldMatrix(atomic->getFrame()->getLTM()); lightingCB(atomic); @@ -145,13 +146,13 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header) MatFX *matfx = MatFX::get(inst->material); if(matfx == nil) - matfxDefaultRender(header, inst); + matfxDefaultRender(header, inst, flags); else switch(matfx->type){ case MatFX::ENVMAP: - matfxEnvRender(header, inst, &matfx->fx[0].env); + matfxEnvRender(header, inst, flags, &matfx->fx[0].env); break; default: - matfxDefaultRender(header, inst); + matfxDefaultRender(header, inst, flags); break; } inst++; diff --git a/src/gl/gl3render.cpp b/src/gl/gl3render.cpp index 467d8b1..d189dd6 100644 --- a/src/gl/gl3render.cpp +++ b/src/gl/gl3render.cpp @@ -123,6 +123,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) { Material *m; + uint32 flags = atomic->geometry->flags; setWorldMatrix(atomic->getFrame()->getLTM()); lightingCB(atomic); @@ -142,7 +143,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) while(n--){ m = inst->material; - setMaterial(m->color, m->surfaceProps); + setMaterial(flags, m->color, m->surfaceProps); setTexture(0, m->texture); diff --git a/src/gl/gl3skin.cpp b/src/gl/gl3skin.cpp index aa5d527..c973980 100644 --- a/src/gl/gl3skin.cpp +++ b/src/gl/gl3skin.cpp @@ -257,6 +257,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header) { Material *m; + uint32 flags = atomic->geometry->flags; setWorldMatrix(atomic->getFrame()->getLTM()); lightingCB(atomic); @@ -278,7 +279,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header) while(n--){ m = inst->material; - setMaterial(m->color, m->surfaceProps); + setMaterial(flags, m->color, m->surfaceProps); setTexture(0, m->texture); diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index 93c1718..4f1e501 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -181,6 +181,14 @@ int32 setLights(WorldLights *lightData); // per Mesh void setTexture(int32 n, Texture *tex); void setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f); +inline void setMaterial(uint32 flags, const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f) +{ + static RGBA white = { 255, 255, 255, 255 }; + if(flags & Geometry::MODULATE) + setMaterial(color, surfaceprops, extraSurfProp); + else + setMaterial(white, surfaceprops, extraSurfProp); +} void setAlphaBlend(bool32 enable); bool32 getAlphaBlend(void);