mirror of https://github.com/aap/librw.git
add modulate flag check for material rendering
This commit is contained in:
parent
207c2ee244
commit
71d132839e
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue