add modulate flag check for material rendering

This commit is contained in:
aap 2021-02-06 10:59:38 +01:00
parent 207c2ee244
commit 71d132839e
9 changed files with 39 additions and 18 deletions

View File

@ -29,8 +29,8 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
d3d::lightingCB_Fix(atomic); d3d::lightingCB_Fix(atomic);
Geometry *geo = atomic->geometry; uint32 flags = atomic->geometry->flags;
d3d::setRenderState(D3DRS_LIGHTING, !!(geo->flags & rw::Geometry::LIGHT)); d3d::setRenderState(D3DRS_LIGHTING, !!(flags & rw::Geometry::LIGHT));
Frame *f = atomic->getFrame(); Frame *f = atomic->getFrame();
convMatrix(&world, f->getLTM()); convMatrix(&world, f->getLTM());
@ -39,12 +39,12 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
InstanceData *inst = header->inst; InstanceData *inst = header->inst;
for(uint32 i = 0; i < header->numMeshes; i++){ for(uint32 i = 0; i < header->numMeshes; i++){
d3d::setTexture(0, inst->material->texture); 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_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
if(geo->flags & Geometry::PRELIT) if(flags & Geometry::PRELIT)
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1);
else else
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL); d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);

View File

@ -150,6 +150,7 @@ void
matfxRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header) matfxRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
{ {
int vsBits; int vsBits;
uint32 flags = atomic->geometry->flags;
setStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer, setStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer,
0, header->vertexStream[0].stride); 0, header->vertexStream[0].stride);
setIndices((IDirect3DIndexBuffer9*)header->indexBuffer); setIndices((IDirect3DIndexBuffer9*)header->indexBuffer);
@ -166,7 +167,7 @@ matfxRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
for(uint32 i = 0; i < header->numMeshes; i++){ for(uint32 i = 0; i < header->numMeshes; i++){
Material *m = inst->material; Material *m = inst->material;
setMaterial(m->color, m->surfaceProps); setMaterial(flags, m->color, m->surfaceProps);
MatFX *matfx = MatFX::get(m); MatFX *matfx = MatFX::get(m);
if(matfx == nil) if(matfx == nil)

View File

@ -145,6 +145,7 @@ void
defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header) defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
{ {
int vsBits; int vsBits;
uint32 flags = atomic->geometry->flags;
setStreamSource(0, header->vertexStream[0].vertexBuffer, 0, header->vertexStream[0].stride); setStreamSource(0, header->vertexStream[0].vertexBuffer, 0, header->vertexStream[0].stride);
setIndices(header->indexBuffer); setIndices(header->indexBuffer);
setVertexDeclaration(header->vertexDeclaration); setVertexDeclaration(header->vertexDeclaration);
@ -166,7 +167,7 @@ defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255); SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255);
setMaterial(m->color, m->surfaceProps); setMaterial(flags, m->color, m->surfaceProps);
if(m->texture){ if(m->texture){
d3d::setTexture(0, m->texture); d3d::setTexture(0, m->texture);

View File

@ -289,7 +289,7 @@ void
skinRenderCB(Atomic *atomic, InstanceDataHeader *header) skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
{ {
int vsBits; int vsBits;
uint32 flags = atomic->geometry->flags;
setStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer, setStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer,
0, header->vertexStream[0].stride); 0, header->vertexStream[0].stride);
setIndices((IDirect3DIndexBuffer9*)header->indexBuffer); setIndices((IDirect3DIndexBuffer9*)header->indexBuffer);
@ -314,7 +314,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255); SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255);
setMaterial(m->color, m->surfaceProps); setMaterial(flags, m->color, m->surfaceProps);
if(inst->material->texture){ if(inst->material->texture){
d3d::setTexture(0, m->texture); d3d::setTexture(0, m->texture);

View File

@ -292,6 +292,14 @@ void flushCache(void);
void setTexture(uint32 stage, Texture *tex); void setTexture(uint32 stage, Texture *tex);
void setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f); 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 setVertexShader(void *vs);
void setPixelShader(void *ps); void setPixelShader(void *ps);

View File

@ -34,14 +34,14 @@ static int32 u_fxparams;
static int32 u_colorClamp; static int32 u_colorClamp;
void void
matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst) matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst, uint32 flags)
{ {
Material *m; Material *m;
m = inst->material; m = inst->material;
defaultShader->use(); defaultShader->use();
setMaterial(m->color, m->surfaceProps); setMaterial(flags, m->color, m->surfaceProps);
setTexture(0, m->texture); setTexture(0, m->texture);
@ -83,13 +83,13 @@ uploadEnvMatrix(Frame *frame)
} }
void void
matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env) matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, uint32 flags, MatFX::Env *env)
{ {
Material *m; Material *m;
m = inst->material; m = inst->material;
if(env->tex == nil || env->coefficient == 0.0f){ if(env->tex == nil || env->coefficient == 0.0f){
matfxDefaultRender(header, inst); matfxDefaultRender(header, inst, flags);
return; return;
} }
@ -99,7 +99,7 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env)
setTexture(1, env->tex); setTexture(1, env->tex);
uploadEnvMatrix(env->frame); uploadEnvMatrix(env->frame);
setMaterial(m->color, m->surfaceProps); setMaterial(flags, m->color, m->surfaceProps);
float fxparams[2]; float fxparams[2];
fxparams[0] = env->coefficient; fxparams[0] = env->coefficient;
@ -125,6 +125,7 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env)
void void
matfxRenderCB(Atomic *atomic, InstanceDataHeader *header) matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
{ {
uint32 flags = atomic->geometry->flags;
setWorldMatrix(atomic->getFrame()->getLTM()); setWorldMatrix(atomic->getFrame()->getLTM());
lightingCB(atomic); lightingCB(atomic);
@ -145,13 +146,13 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
MatFX *matfx = MatFX::get(inst->material); MatFX *matfx = MatFX::get(inst->material);
if(matfx == nil) if(matfx == nil)
matfxDefaultRender(header, inst); matfxDefaultRender(header, inst, flags);
else switch(matfx->type){ else switch(matfx->type){
case MatFX::ENVMAP: case MatFX::ENVMAP:
matfxEnvRender(header, inst, &matfx->fx[0].env); matfxEnvRender(header, inst, flags, &matfx->fx[0].env);
break; break;
default: default:
matfxDefaultRender(header, inst); matfxDefaultRender(header, inst, flags);
break; break;
} }
inst++; inst++;

View File

@ -123,6 +123,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
{ {
Material *m; Material *m;
uint32 flags = atomic->geometry->flags;
setWorldMatrix(atomic->getFrame()->getLTM()); setWorldMatrix(atomic->getFrame()->getLTM());
lightingCB(atomic); lightingCB(atomic);
@ -142,7 +143,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
while(n--){ while(n--){
m = inst->material; m = inst->material;
setMaterial(m->color, m->surfaceProps); setMaterial(flags, m->color, m->surfaceProps);
setTexture(0, m->texture); setTexture(0, m->texture);

View File

@ -257,6 +257,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
{ {
Material *m; Material *m;
uint32 flags = atomic->geometry->flags;
setWorldMatrix(atomic->getFrame()->getLTM()); setWorldMatrix(atomic->getFrame()->getLTM());
lightingCB(atomic); lightingCB(atomic);
@ -278,7 +279,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
while(n--){ while(n--){
m = inst->material; m = inst->material;
setMaterial(m->color, m->surfaceProps); setMaterial(flags, m->color, m->surfaceProps);
setTexture(0, m->texture); setTexture(0, m->texture);

View File

@ -181,6 +181,14 @@ int32 setLights(WorldLights *lightData);
// per Mesh // per Mesh
void setTexture(int32 n, Texture *tex); void setTexture(int32 n, Texture *tex);
void setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f); 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); void setAlphaBlend(bool32 enable);
bool32 getAlphaBlend(void); bool32 getAlphaBlend(void);