mirror of
https://git.rip/DMCA_FUCKER/re3.git
synced 2025-01-11 09:54:09 +00:00
moved new renderer; implemented leeds building rendering
This commit is contained in:
parent
203dff9165
commit
03c5fdef43
|
@ -124,7 +124,7 @@ bool gbPrintMemoryUsage;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NEW_RENDERER
|
#ifdef NEW_RENDERER
|
||||||
bool gbNewRenderer;
|
bool gbNewRenderer = true;
|
||||||
#endif
|
#endif
|
||||||
#ifdef FIX_BUGS
|
#ifdef FIX_BUGS
|
||||||
// need to clear stencil for mblur fx. no idea why it works in the original game
|
// need to clear stencil for mblur fx. no idea why it works in the original game
|
||||||
|
|
|
@ -133,5 +133,12 @@ void AttachRimPipe(rw::Clump *clump);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace WorldRender{
|
||||||
|
extern int numBlendInsts[3];
|
||||||
|
void AtomicFirstPass(RpAtomic *atomic, int pass);
|
||||||
|
void AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha);
|
||||||
|
void RenderBlendPass(int pass);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -201,7 +201,6 @@ worldRenderCB(rw::Atomic *atomic, rw::d3d9::InstanceDataHeader *header)
|
||||||
using namespace rw::d3d;
|
using namespace rw::d3d;
|
||||||
using namespace rw::d3d9;
|
using namespace rw::d3d9;
|
||||||
|
|
||||||
int vsBits;
|
|
||||||
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);
|
||||||
|
@ -547,5 +546,191 @@ DestroyRimLightPipes(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NEW_RENDERER
|
||||||
|
|
||||||
|
namespace WorldRender
|
||||||
|
{
|
||||||
|
|
||||||
|
struct BuildingInst
|
||||||
|
{
|
||||||
|
rw::RawMatrix combinedMat;
|
||||||
|
rw::d3d9::InstanceDataHeader *instHeader;
|
||||||
|
uint8 fadeAlpha;
|
||||||
|
bool lighting;
|
||||||
|
};
|
||||||
|
BuildingInst blendInsts[3][2000];
|
||||||
|
int numBlendInsts[3];
|
||||||
|
|
||||||
|
static RwRGBAReal black;
|
||||||
|
|
||||||
|
static void
|
||||||
|
SetMatrix(BuildingInst *building, rw::Matrix *worldMat)
|
||||||
|
{
|
||||||
|
using namespace rw;
|
||||||
|
RawMatrix world, worldview;
|
||||||
|
Camera *cam = engine->currentCamera;
|
||||||
|
convMatrix(&world, worldMat);
|
||||||
|
RawMatrix::mult(&worldview, &world, &cam->devView);
|
||||||
|
RawMatrix::mult(&building->combinedMat, &worldview, &cam->devProj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
IsTextureTransparent(RwTexture *tex)
|
||||||
|
{
|
||||||
|
if(tex == nil || tex->raster == nil)
|
||||||
|
return false;
|
||||||
|
return PLUGINOFFSET(rw::d3d::D3dRaster, tex->raster, rw::d3d::nativeRasterOffset)->hasAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render all opaque meshes and put atomics that needs blending
|
||||||
|
// into the deferred list.
|
||||||
|
void
|
||||||
|
AtomicFirstPass(RpAtomic *atomic, int pass)
|
||||||
|
{
|
||||||
|
using namespace rw;
|
||||||
|
using namespace rw::d3d;
|
||||||
|
using namespace rw::d3d9;
|
||||||
|
|
||||||
|
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
|
||||||
|
|
||||||
|
atomic->getPipeline()->instance(atomic);
|
||||||
|
building->instHeader = (d3d9::InstanceDataHeader*)atomic->geometry->instData;
|
||||||
|
assert(building->instHeader != nil);
|
||||||
|
assert(building->instHeader->platform == PLATFORM_D3D9);
|
||||||
|
building->fadeAlpha = 255;
|
||||||
|
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
|
||||||
|
|
||||||
|
bool setupDone = false;
|
||||||
|
bool defer = false;
|
||||||
|
SetMatrix(building, atomic->getFrame()->getLTM());
|
||||||
|
|
||||||
|
float colorscale[4];
|
||||||
|
|
||||||
|
InstanceData *inst = building->instHeader->inst;
|
||||||
|
for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){
|
||||||
|
Material *m = inst->material;
|
||||||
|
|
||||||
|
if(inst->vertexAlpha || m->color.alpha != 255 ||
|
||||||
|
IsTextureTransparent(m->texture)){
|
||||||
|
defer = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// alright we're rendering this atomic
|
||||||
|
if(!setupDone){
|
||||||
|
setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride);
|
||||||
|
setIndices(building->instHeader->indexBuffer);
|
||||||
|
setVertexDeclaration(building->instHeader->vertexDeclaration);
|
||||||
|
setVertexShader(CustomPipes::leedsBuilding_VS);
|
||||||
|
setPixelShader(CustomPipes::scale_PS);
|
||||||
|
d3ddevice->SetVertexShaderConstantF(VSLOC_combined, (float*)&building->combinedMat, 4);
|
||||||
|
|
||||||
|
RGBAf amb, emiss;
|
||||||
|
amb.red = CTimeCycle::GetAmbientRed();
|
||||||
|
amb.green = CTimeCycle::GetAmbientGreen();
|
||||||
|
amb.blue = CTimeCycle::GetAmbientBlue();
|
||||||
|
amb.alpha = 1.0f;
|
||||||
|
emiss = pAmbient->color;
|
||||||
|
|
||||||
|
d3ddevice->SetVertexShaderConstantF(CustomPipes::VSLOC_ambient, (float*)&amb, 1);
|
||||||
|
d3ddevice->SetVertexShaderConstantF(CustomPipes::VSLOC_emissive, (float*)&emiss, 1);
|
||||||
|
|
||||||
|
colorscale[3] = 1.0f;
|
||||||
|
|
||||||
|
setupDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float cs = 1.0f;
|
||||||
|
if(m->texture)
|
||||||
|
cs = 255/128.0f;
|
||||||
|
colorscale[0] = colorscale[1] = colorscale[2] = cs;
|
||||||
|
d3ddevice->SetPixelShaderConstantF(CustomPipes::PSLOC_colorscale, colorscale, 1);
|
||||||
|
|
||||||
|
if(m->texture)
|
||||||
|
d3d::setTexture(0, m->texture);
|
||||||
|
else
|
||||||
|
d3d::setTexture(0, gpWhiteTexture); // actually we don't even render this
|
||||||
|
|
||||||
|
setMaterial(m->color, m->surfaceProps, 0.5f);
|
||||||
|
|
||||||
|
drawInst(building->instHeader, inst);
|
||||||
|
}
|
||||||
|
if(defer)
|
||||||
|
numBlendInsts[pass]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha)
|
||||||
|
{
|
||||||
|
using namespace rw;
|
||||||
|
using namespace rw::d3d;
|
||||||
|
using namespace rw::d3d9;
|
||||||
|
|
||||||
|
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
|
||||||
|
|
||||||
|
atomic->getPipeline()->instance(atomic);
|
||||||
|
building->instHeader = (d3d9::InstanceDataHeader*)atomic->geometry->instData;
|
||||||
|
assert(building->instHeader != nil);
|
||||||
|
assert(building->instHeader->platform == PLATFORM_D3D9);
|
||||||
|
building->fadeAlpha = fadeAlpha;
|
||||||
|
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
|
||||||
|
SetMatrix(building, atomic->getFrame()->getLTM());
|
||||||
|
numBlendInsts[pass]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RenderBlendPass(int pass)
|
||||||
|
{
|
||||||
|
using namespace rw;
|
||||||
|
using namespace rw::d3d;
|
||||||
|
using namespace rw::d3d9;
|
||||||
|
|
||||||
|
setVertexShader(CustomPipes::leedsBuilding_VS);
|
||||||
|
setPixelShader(CustomPipes::scale_PS);
|
||||||
|
|
||||||
|
float colorscale[4];
|
||||||
|
colorscale[3] = 1.0f;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < numBlendInsts[pass]; i++){
|
||||||
|
BuildingInst *building = &blendInsts[pass][i];
|
||||||
|
|
||||||
|
setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride);
|
||||||
|
setIndices(building->instHeader->indexBuffer);
|
||||||
|
setVertexDeclaration(building->instHeader->vertexDeclaration);
|
||||||
|
d3ddevice->SetVertexShaderConstantF(VSLOC_combined, (float*)&building->combinedMat, 4);
|
||||||
|
if(building->lighting)
|
||||||
|
setAmbient(pAmbient->color);
|
||||||
|
else
|
||||||
|
setAmbient(black);
|
||||||
|
|
||||||
|
InstanceData *inst = building->instHeader->inst;
|
||||||
|
for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){
|
||||||
|
Material *m = inst->material;
|
||||||
|
if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255)
|
||||||
|
continue; // already done this one
|
||||||
|
|
||||||
|
float cs = 1.0f;
|
||||||
|
if(m->texture)
|
||||||
|
cs = 255/128.0f;
|
||||||
|
colorscale[0] = colorscale[1] = colorscale[2] = cs;
|
||||||
|
d3ddevice->SetPixelShaderConstantF(CustomPipes::PSLOC_colorscale, colorscale, 1);
|
||||||
|
|
||||||
|
if(m->texture)
|
||||||
|
d3d::setTexture(0, m->texture);
|
||||||
|
else
|
||||||
|
d3d::setTexture(0, gpWhiteTexture); // actually we don't even render this
|
||||||
|
|
||||||
|
rw::RGBA color = m->color;
|
||||||
|
color.alpha = (color.alpha * building->fadeAlpha)/255;
|
||||||
|
setMaterial(m->color, m->surfaceProps, 0.5f);
|
||||||
|
|
||||||
|
drawInst(building->instHeader, inst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -245,7 +245,7 @@ worldRenderCB(rw::Atomic *atomic, rw::gl3::InstanceDataHeader *header)
|
||||||
|
|
||||||
setTexture(0, m->texture);
|
setTexture(0, m->texture);
|
||||||
|
|
||||||
setMaterial(m->color, m->surfaceProps);
|
setMaterial(m->color, m->surfaceProps, 0.5f);
|
||||||
|
|
||||||
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
||||||
|
|
||||||
|
@ -616,5 +616,190 @@ CustomPipeRegisterGL(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NEW_RENDERER
|
||||||
|
|
||||||
|
namespace WorldRender
|
||||||
|
{
|
||||||
|
|
||||||
|
struct BuildingInst
|
||||||
|
{
|
||||||
|
rw::Matrix matrix;
|
||||||
|
rw::gl3::InstanceDataHeader *instHeader;
|
||||||
|
uint8 fadeAlpha;
|
||||||
|
bool lighting;
|
||||||
|
};
|
||||||
|
BuildingInst blendInsts[3][2000];
|
||||||
|
int numBlendInsts[3];
|
||||||
|
|
||||||
|
static RwRGBAReal black;
|
||||||
|
|
||||||
|
static bool
|
||||||
|
IsTextureTransparent(RwTexture *tex)
|
||||||
|
{
|
||||||
|
if(tex == nil || tex->raster == nil)
|
||||||
|
return false;
|
||||||
|
return PLUGINOFFSET(rw::gl3::Gl3Raster, tex->raster, rw::gl3::nativeRasterOffset)->hasAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render all opaque meshes and put atomics that needs blending
|
||||||
|
// into the deferred list.
|
||||||
|
void
|
||||||
|
AtomicFirstPass(RpAtomic *atomic, int pass)
|
||||||
|
{
|
||||||
|
using namespace rw;
|
||||||
|
using namespace rw::gl3;
|
||||||
|
|
||||||
|
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
|
||||||
|
|
||||||
|
atomic->getPipeline()->instance(atomic);
|
||||||
|
building->instHeader = (gl3::InstanceDataHeader*)atomic->geometry->instData;
|
||||||
|
assert(building->instHeader != nil);
|
||||||
|
assert(building->instHeader->platform == PLATFORM_GL3);
|
||||||
|
building->fadeAlpha = 255;
|
||||||
|
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
|
||||||
|
|
||||||
|
bool setupDone = false;
|
||||||
|
bool defer = false;
|
||||||
|
building->matrix = *atomic->getFrame()->getLTM();
|
||||||
|
|
||||||
|
float colorscale[4];
|
||||||
|
|
||||||
|
InstanceData *inst = building->instHeader->inst;
|
||||||
|
for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){
|
||||||
|
Material *m = inst->material;
|
||||||
|
|
||||||
|
if(inst->vertexAlpha || m->color.alpha != 255 ||
|
||||||
|
IsTextureTransparent(m->texture)){
|
||||||
|
defer = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// alright we're rendering this atomic
|
||||||
|
if(!setupDone){
|
||||||
|
CustomPipes::leedsWorldShader->use();
|
||||||
|
// defaultShader->use();
|
||||||
|
setWorldMatrix(&building->matrix);
|
||||||
|
#ifdef RW_GL_USE_VAOS
|
||||||
|
glBindVertexArray(building->instHeader->vao);
|
||||||
|
#else
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, building->instHeader->ibo);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, building->instHeader->vbo);
|
||||||
|
setAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RGBAf amb, emiss;
|
||||||
|
amb.red = CTimeCycle::GetAmbientRed();
|
||||||
|
amb.green = CTimeCycle::GetAmbientGreen();
|
||||||
|
amb.blue = CTimeCycle::GetAmbientBlue();
|
||||||
|
amb.alpha = 1.0f;
|
||||||
|
emiss = pAmbient->color;
|
||||||
|
|
||||||
|
glUniform4fv(U(CustomPipes::u_amb), 1, (float*)&amb);
|
||||||
|
glUniform4fv(U(CustomPipes::u_emiss), 1, (float*)&emiss);
|
||||||
|
|
||||||
|
colorscale[3] = 1.0f;
|
||||||
|
|
||||||
|
setupDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
setMaterial(m->color, m->surfaceProps, 0.5f);
|
||||||
|
|
||||||
|
float cs = 1.0f;
|
||||||
|
if(m->texture)
|
||||||
|
cs = 255/128.0f;
|
||||||
|
colorscale[0] = colorscale[1] = colorscale[2] = cs;
|
||||||
|
glUniform4fv(U(CustomPipes::u_colorscale), 1, colorscale);
|
||||||
|
|
||||||
|
setTexture(0, m->texture);
|
||||||
|
|
||||||
|
drawInst(building->instHeader, inst);
|
||||||
|
}
|
||||||
|
#ifndef RW_GL_USE_VAOS
|
||||||
|
disableAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
|
||||||
|
#endif
|
||||||
|
if(defer)
|
||||||
|
numBlendInsts[pass]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha)
|
||||||
|
{
|
||||||
|
using namespace rw;
|
||||||
|
using namespace rw::gl3;
|
||||||
|
|
||||||
|
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
|
||||||
|
|
||||||
|
atomic->getPipeline()->instance(atomic);
|
||||||
|
building->instHeader = (gl3::InstanceDataHeader*)atomic->geometry->instData;
|
||||||
|
assert(building->instHeader != nil);
|
||||||
|
assert(building->instHeader->platform == PLATFORM_GL3);
|
||||||
|
building->fadeAlpha = fadeAlpha;
|
||||||
|
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
|
||||||
|
building->matrix = *atomic->getFrame()->getLTM();
|
||||||
|
numBlendInsts[pass]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RenderBlendPass(int pass)
|
||||||
|
{
|
||||||
|
using namespace rw;
|
||||||
|
using namespace rw::gl3;
|
||||||
|
|
||||||
|
CustomPipes::leedsWorldShader->use();
|
||||||
|
|
||||||
|
RGBAf amb, emiss;
|
||||||
|
amb.red = CTimeCycle::GetAmbientRed();
|
||||||
|
amb.green = CTimeCycle::GetAmbientGreen();
|
||||||
|
amb.blue = CTimeCycle::GetAmbientBlue();
|
||||||
|
amb.alpha = 1.0f;
|
||||||
|
emiss = pAmbient->color;
|
||||||
|
|
||||||
|
glUniform4fv(U(CustomPipes::u_amb), 1, (float*)&amb);
|
||||||
|
glUniform4fv(U(CustomPipes::u_emiss), 1, (float*)&emiss);
|
||||||
|
|
||||||
|
float colorscale[4];
|
||||||
|
colorscale[3] = 1.0f;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < numBlendInsts[pass]; i++){
|
||||||
|
BuildingInst *building = &blendInsts[pass][i];
|
||||||
|
|
||||||
|
#ifdef RW_GL_USE_VAOS
|
||||||
|
glBindVertexArray(building->instHeader->vao);
|
||||||
|
#else
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, building->instHeader->ibo);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, building->instHeader->vbo);
|
||||||
|
setAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
|
||||||
|
#endif
|
||||||
|
setWorldMatrix(&building->matrix);
|
||||||
|
|
||||||
|
InstanceData *inst = building->instHeader->inst;
|
||||||
|
for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){
|
||||||
|
Material *m = inst->material;
|
||||||
|
if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255)
|
||||||
|
continue; // already done this one
|
||||||
|
|
||||||
|
rw::RGBA color = m->color;
|
||||||
|
color.alpha = (color.alpha * building->fadeAlpha)/255;
|
||||||
|
setMaterial(color, m->surfaceProps, 0.5f);
|
||||||
|
|
||||||
|
float cs = 1.0f;
|
||||||
|
if(m->texture)
|
||||||
|
cs = 255/128.0f;
|
||||||
|
colorscale[0] = colorscale[1] = colorscale[2] = cs;
|
||||||
|
glUniform4fv(U(CustomPipes::u_colorscale), 1, colorscale);
|
||||||
|
|
||||||
|
setTexture(0, m->texture);
|
||||||
|
|
||||||
|
drawInst(building->instHeader, inst);
|
||||||
|
}
|
||||||
|
#ifndef RW_GL_USE_VAOS
|
||||||
|
disableAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
uniform vec4 u_amb;
|
uniform vec4 u_amb;
|
||||||
uniform vec4 u_emiss;
|
uniform vec4 u_emiss;
|
||||||
|
|
||||||
|
#define surfEmissive (u_surfProps.w)
|
||||||
|
|
||||||
VSIN(ATTRIB_POS) vec3 in_pos;
|
VSIN(ATTRIB_POS) vec3 in_pos;
|
||||||
|
|
||||||
VSOUT vec4 v_color;
|
VSOUT vec4 v_color;
|
||||||
|
@ -18,7 +20,7 @@ main(void)
|
||||||
|
|
||||||
v_color = in_color;
|
v_color = in_color;
|
||||||
v_color.rgb *= u_amb.rgb;
|
v_color.rgb *= u_amb.rgb;
|
||||||
v_color.rgb += u_emiss.rgb;
|
v_color.rgb += u_emiss.rgb*surfEmissive;
|
||||||
v_color = clamp(v_color, 0.0, 1.0);
|
v_color = clamp(v_color, 0.0, 1.0);
|
||||||
v_color.a *= u_matColor.a;
|
v_color.a *= u_matColor.a;
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -1,5 +1,8 @@
|
||||||
#include "standardConstants.h"
|
#include "standardConstants.h"
|
||||||
|
|
||||||
|
#define surfEmissive (surfProps.w)
|
||||||
|
|
||||||
|
|
||||||
float4 emissive : register(c41);
|
float4 emissive : register(c41);
|
||||||
float4 ambient : register(c42);
|
float4 ambient : register(c42);
|
||||||
|
|
||||||
|
@ -33,7 +36,7 @@ VS_out main(in VS_in input)
|
||||||
|
|
||||||
output.Color = input.Prelight;
|
output.Color = input.Prelight;
|
||||||
output.Color.rgb *= ambient.rgb;
|
output.Color.rgb *= ambient.rgb;
|
||||||
output.Color.rgb += emissive.rgb;
|
output.Color.rgb += emissive.rgb*surfEmissive;
|
||||||
|
|
||||||
output.Color = clamp(output.Color, 0.0, 1.0);
|
output.Color = clamp(output.Color, 0.0, 1.0);
|
||||||
output.Color.a *= matCol.a;
|
output.Color.a *= matCol.a;
|
||||||
|
|
|
@ -1,36 +1,40 @@
|
||||||
static unsigned char leedsBuilding_VS_cso[] = {
|
static unsigned char leedsBuilding_VS_cso[] = {
|
||||||
0x00, 0x02, 0xfe, 0xff, 0xfe, 0xff, 0x42, 0x00, 0x43, 0x54, 0x41, 0x42,
|
0x00, 0x02, 0xfe, 0xff, 0xfe, 0xff, 0x4a, 0x00, 0x43, 0x54, 0x41, 0x42,
|
||||||
0x1c, 0x00, 0x00, 0x00, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff,
|
0x1c, 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff,
|
||||||
0x05, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
|
0x06, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
|
||||||
0xcc, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x2a, 0x00,
|
0xea, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x02, 0x00, 0x2a, 0x00,
|
||||||
0x01, 0x00, 0xaa, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x01, 0x00, 0xaa, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x98, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00,
|
0xac, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00,
|
||||||
0xa4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00,
|
0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00,
|
||||||
0x02, 0x00, 0x29, 0x00, 0x01, 0x00, 0xa6, 0x00, 0x88, 0x00, 0x00, 0x00,
|
0x02, 0x00, 0x29, 0x00, 0x01, 0x00, 0xa6, 0x00, 0x9c, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0e, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0xd1, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0e, 0x00,
|
||||||
0x01, 0x00, 0x3a, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x01, 0x00, 0x3a, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0xc5, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x32, 0x00,
|
0xd9, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x32, 0x00,
|
||||||
0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x6d, 0x62, 0x69,
|
0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00,
|
||||||
0x65, 0x6e, 0x74, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00,
|
0x02, 0x00, 0x0d, 0x00, 0x01, 0x00, 0x36, 0x00, 0x9c, 0x00, 0x00, 0x00,
|
||||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6d, 0x62,
|
0x00, 0x00, 0x00, 0x00, 0x61, 0x6d, 0x62, 0x69, 0x65, 0x6e, 0x74, 0x00,
|
||||||
0x69, 0x6e, 0x65, 0x64, 0x4d, 0x61, 0x74, 0x00, 0x03, 0x00, 0x03, 0x00,
|
0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x65, 0x64,
|
||||||
0x65, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x76, 0x65, 0x00, 0x66, 0x6f, 0x67,
|
0x4d, 0x61, 0x74, 0x00, 0x03, 0x00, 0x03, 0x00, 0x04, 0x00, 0x04, 0x00,
|
||||||
0x44, 0x61, 0x74, 0x61, 0x00, 0x6d, 0x61, 0x74, 0x43, 0x6f, 0x6c, 0x00,
|
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x6d, 0x69, 0x73,
|
||||||
0x76, 0x73, 0x5f, 0x32, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f,
|
0x73, 0x69, 0x76, 0x65, 0x00, 0x66, 0x6f, 0x67, 0x44, 0x61, 0x74, 0x61,
|
||||||
0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53,
|
0x00, 0x6d, 0x61, 0x74, 0x43, 0x6f, 0x6c, 0x00, 0x73, 0x75, 0x72, 0x66,
|
||||||
0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d,
|
0x50, 0x72, 0x6f, 0x70, 0x73, 0x00, 0x76, 0x73, 0x5f, 0x32, 0x5f, 0x30,
|
||||||
0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, 0x32, 0x39, 0x2e, 0x39,
|
0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28,
|
||||||
0x35, 0x32, 0x2e, 0x33, 0x31, 0x31, 0x31, 0x00, 0x51, 0x00, 0x00, 0x05,
|
0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64,
|
||||||
0x04, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f,
|
0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02,
|
0x39, 0x2e, 0x32, 0x39, 0x2e, 0x39, 0x35, 0x32, 0x2e, 0x33, 0x31, 0x31,
|
||||||
0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02,
|
0x31, 0x00, 0xab, 0xab, 0x51, 0x00, 0x00, 0x05, 0x04, 0x00, 0x0f, 0xa0,
|
||||||
0x05, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x05, 0x00, 0x01, 0x80, 0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02,
|
0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80,
|
||||||
0x0a, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0f, 0x90, 0x01, 0x00, 0x00, 0x02,
|
0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80,
|
||||||
0x00, 0x00, 0x07, 0x80, 0x2a, 0x00, 0xe4, 0xa0, 0x04, 0x00, 0x00, 0x04,
|
0x01, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x01, 0x80,
|
||||||
0x00, 0x00, 0x07, 0x80, 0x03, 0x00, 0xe4, 0x90, 0x00, 0x00, 0xe4, 0x80,
|
0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80,
|
||||||
0x29, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x08, 0x80,
|
0x03, 0x00, 0x0f, 0x90, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x07, 0x80,
|
||||||
|
0x29, 0x00, 0xe4, 0xa0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x07, 0x80,
|
||||||
|
0x00, 0x00, 0xe4, 0x80, 0x0d, 0x00, 0xff, 0xa0, 0x04, 0x00, 0x00, 0x04,
|
||||||
|
0x00, 0x00, 0x07, 0x80, 0x03, 0x00, 0xe4, 0x90, 0x2a, 0x00, 0xe4, 0xa0,
|
||||||
|
0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x08, 0x80,
|
||||||
0x03, 0x00, 0xff, 0x90, 0x0b, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80,
|
0x03, 0x00, 0xff, 0x90, 0x0b, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80,
|
||||||
0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0xa0, 0x0a, 0x00, 0x00, 0x03,
|
0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0xa0, 0x0a, 0x00, 0x00, 0x03,
|
||||||
0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x55, 0xa0,
|
0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x55, 0xa0,
|
||||||
|
|
|
@ -2,6 +2,8 @@ const char *leedsBuilding_vert_src =
|
||||||
"uniform vec4 u_amb;\n"
|
"uniform vec4 u_amb;\n"
|
||||||
"uniform vec4 u_emiss;\n"
|
"uniform vec4 u_emiss;\n"
|
||||||
|
|
||||||
|
"#define surfEmissive (u_surfProps.w)\n"
|
||||||
|
|
||||||
"VSIN(ATTRIB_POS) vec3 in_pos;\n"
|
"VSIN(ATTRIB_POS) vec3 in_pos;\n"
|
||||||
|
|
||||||
"VSOUT vec4 v_color;\n"
|
"VSOUT vec4 v_color;\n"
|
||||||
|
@ -19,7 +21,7 @@ const char *leedsBuilding_vert_src =
|
||||||
|
|
||||||
" v_color = in_color;\n"
|
" v_color = in_color;\n"
|
||||||
" v_color.rgb *= u_amb.rgb;\n"
|
" v_color.rgb *= u_amb.rgb;\n"
|
||||||
" v_color.rgb += u_emiss.rgb;\n"
|
" v_color.rgb += u_emiss.rgb*surfEmissive;\n"
|
||||||
" v_color = clamp(v_color, 0.0, 1.0);\n"
|
" v_color = clamp(v_color, 0.0, 1.0);\n"
|
||||||
" v_color.a *= u_matColor.a;\n"
|
" v_color.a *= u_matColor.a;\n"
|
||||||
|
|
||||||
|
|
|
@ -347,8 +347,6 @@ enum {
|
||||||
PASS_BLEND // normal blend
|
PASS_BLEND // normal blend
|
||||||
};
|
};
|
||||||
|
|
||||||
static RwRGBAReal black;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
SetStencilState(int state)
|
SetStencilState(int state)
|
||||||
{
|
{
|
||||||
|
@ -377,314 +375,6 @@ SetStencilState(int state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RW_D3D9
|
|
||||||
struct BuildingInst
|
|
||||||
{
|
|
||||||
rw::RawMatrix combinedMat;
|
|
||||||
rw::d3d9::InstanceDataHeader *instHeader;
|
|
||||||
uint8 fadeAlpha;
|
|
||||||
bool lighting;
|
|
||||||
};
|
|
||||||
static BuildingInst blendInsts[3][2000];
|
|
||||||
static int numBlendInsts[3];
|
|
||||||
|
|
||||||
static void
|
|
||||||
SetMatrix(BuildingInst *building, rw::Matrix *worldMat)
|
|
||||||
{
|
|
||||||
using namespace rw;
|
|
||||||
RawMatrix world, worldview;
|
|
||||||
Camera *cam = engine->currentCamera;
|
|
||||||
convMatrix(&world, worldMat);
|
|
||||||
RawMatrix::mult(&worldview, &world, &cam->devView);
|
|
||||||
RawMatrix::mult(&building->combinedMat, &worldview, &cam->devProj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
IsTextureTransparent(RwTexture *tex)
|
|
||||||
{
|
|
||||||
if(tex == nil || tex->raster == nil)
|
|
||||||
return false;
|
|
||||||
return PLUGINOFFSET(rw::d3d::D3dRaster, tex->raster, rw::d3d::nativeRasterOffset)->hasAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render all opaque meshes and put atomics that needs blending
|
|
||||||
// into the deferred list.
|
|
||||||
static void
|
|
||||||
AtomicFirstPass(RpAtomic *atomic, int pass)
|
|
||||||
{
|
|
||||||
using namespace rw;
|
|
||||||
using namespace rw::d3d;
|
|
||||||
using namespace rw::d3d9;
|
|
||||||
|
|
||||||
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
|
|
||||||
|
|
||||||
atomic->getPipeline()->instance(atomic);
|
|
||||||
building->instHeader = (d3d9::InstanceDataHeader*)atomic->geometry->instData;
|
|
||||||
assert(building->instHeader != nil);
|
|
||||||
assert(building->instHeader->platform == PLATFORM_D3D9);
|
|
||||||
building->fadeAlpha = 255;
|
|
||||||
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
|
|
||||||
|
|
||||||
bool setupDone = false;
|
|
||||||
bool defer = false;
|
|
||||||
SetMatrix(building, atomic->getFrame()->getLTM());
|
|
||||||
|
|
||||||
InstanceData *inst = building->instHeader->inst;
|
|
||||||
for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){
|
|
||||||
Material *m = inst->material;
|
|
||||||
|
|
||||||
if(inst->vertexAlpha || m->color.alpha != 255 ||
|
|
||||||
IsTextureTransparent(m->texture)){
|
|
||||||
defer = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// alright we're rendering this atomic
|
|
||||||
if(!setupDone){
|
|
||||||
setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride);
|
|
||||||
setIndices(building->instHeader->indexBuffer);
|
|
||||||
setVertexDeclaration(building->instHeader->vertexDeclaration);
|
|
||||||
setVertexShader(default_amb_VS);
|
|
||||||
d3ddevice->SetVertexShaderConstantF(VSLOC_combined, (float*)&building->combinedMat, 4);
|
|
||||||
if(building->lighting)
|
|
||||||
setAmbient(pAmbient->color);
|
|
||||||
else
|
|
||||||
setAmbient(black);
|
|
||||||
setupDone = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
setMaterial(m->color, m->surfaceProps);
|
|
||||||
|
|
||||||
if(m->texture){
|
|
||||||
d3d::setTexture(0, m->texture);
|
|
||||||
setPixelShader(default_tex_PS);
|
|
||||||
}else
|
|
||||||
setPixelShader(default_PS);
|
|
||||||
|
|
||||||
drawInst(building->instHeader, inst);
|
|
||||||
}
|
|
||||||
if(defer)
|
|
||||||
numBlendInsts[pass]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha)
|
|
||||||
{
|
|
||||||
using namespace rw;
|
|
||||||
using namespace rw::d3d;
|
|
||||||
using namespace rw::d3d9;
|
|
||||||
|
|
||||||
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
|
|
||||||
|
|
||||||
atomic->getPipeline()->instance(atomic);
|
|
||||||
building->instHeader = (d3d9::InstanceDataHeader*)atomic->geometry->instData;
|
|
||||||
assert(building->instHeader != nil);
|
|
||||||
assert(building->instHeader->platform == PLATFORM_D3D9);
|
|
||||||
building->fadeAlpha = fadeAlpha;
|
|
||||||
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
|
|
||||||
SetMatrix(building, atomic->getFrame()->getLTM());
|
|
||||||
numBlendInsts[pass]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
RenderBlendPass(int pass)
|
|
||||||
{
|
|
||||||
using namespace rw;
|
|
||||||
using namespace rw::d3d;
|
|
||||||
using namespace rw::d3d9;
|
|
||||||
|
|
||||||
setVertexShader(default_amb_VS);
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < numBlendInsts[pass]; i++){
|
|
||||||
BuildingInst *building = &blendInsts[pass][i];
|
|
||||||
|
|
||||||
setStreamSource(0, building->instHeader->vertexStream[0].vertexBuffer, 0, building->instHeader->vertexStream[0].stride);
|
|
||||||
setIndices(building->instHeader->indexBuffer);
|
|
||||||
setVertexDeclaration(building->instHeader->vertexDeclaration);
|
|
||||||
d3ddevice->SetVertexShaderConstantF(VSLOC_combined, (float*)&building->combinedMat, 4);
|
|
||||||
if(building->lighting)
|
|
||||||
setAmbient(pAmbient->color);
|
|
||||||
else
|
|
||||||
setAmbient(black);
|
|
||||||
|
|
||||||
InstanceData *inst = building->instHeader->inst;
|
|
||||||
for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){
|
|
||||||
Material *m = inst->material;
|
|
||||||
if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255)
|
|
||||||
continue; // already done this one
|
|
||||||
|
|
||||||
rw::RGBA color = m->color;
|
|
||||||
color.alpha = (color.alpha * building->fadeAlpha)/255;
|
|
||||||
setMaterial(color, m->surfaceProps);
|
|
||||||
|
|
||||||
if(m->texture){
|
|
||||||
d3d::setTexture(0, m->texture);
|
|
||||||
setPixelShader(default_tex_PS);
|
|
||||||
}else
|
|
||||||
setPixelShader(default_PS);
|
|
||||||
|
|
||||||
drawInst(building->instHeader, inst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef RW_GL3
|
|
||||||
struct BuildingInst
|
|
||||||
{
|
|
||||||
rw::Matrix matrix;
|
|
||||||
rw::gl3::InstanceDataHeader *instHeader;
|
|
||||||
uint8 fadeAlpha;
|
|
||||||
bool lighting;
|
|
||||||
};
|
|
||||||
static BuildingInst blendInsts[3][2000];
|
|
||||||
static int numBlendInsts[3];
|
|
||||||
|
|
||||||
static bool
|
|
||||||
IsTextureTransparent(RwTexture *tex)
|
|
||||||
{
|
|
||||||
if(tex == nil || tex->raster == nil)
|
|
||||||
return false;
|
|
||||||
return PLUGINOFFSET(rw::gl3::Gl3Raster, tex->raster, rw::gl3::nativeRasterOffset)->hasAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render all opaque meshes and put atomics that needs blending
|
|
||||||
// into the deferred list.
|
|
||||||
static void
|
|
||||||
AtomicFirstPass(RpAtomic *atomic, int pass)
|
|
||||||
{
|
|
||||||
using namespace rw;
|
|
||||||
using namespace rw::gl3;
|
|
||||||
|
|
||||||
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
|
|
||||||
|
|
||||||
atomic->getPipeline()->instance(atomic);
|
|
||||||
building->instHeader = (gl3::InstanceDataHeader*)atomic->geometry->instData;
|
|
||||||
assert(building->instHeader != nil);
|
|
||||||
assert(building->instHeader->platform == PLATFORM_GL3);
|
|
||||||
building->fadeAlpha = 255;
|
|
||||||
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
|
|
||||||
|
|
||||||
WorldLights lights;
|
|
||||||
lights.numAmbients = 1;
|
|
||||||
lights.numDirectionals = 0;
|
|
||||||
lights.numLocals = 0;
|
|
||||||
if(building->lighting)
|
|
||||||
lights.ambient = pAmbient->color;
|
|
||||||
else
|
|
||||||
lights.ambient = black;
|
|
||||||
|
|
||||||
bool setupDone = false;
|
|
||||||
bool defer = false;
|
|
||||||
building->matrix = *atomic->getFrame()->getLTM();
|
|
||||||
|
|
||||||
InstanceData *inst = building->instHeader->inst;
|
|
||||||
for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){
|
|
||||||
Material *m = inst->material;
|
|
||||||
|
|
||||||
if(inst->vertexAlpha || m->color.alpha != 255 ||
|
|
||||||
IsTextureTransparent(m->texture)){
|
|
||||||
defer = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// alright we're rendering this atomic
|
|
||||||
if(!setupDone){
|
|
||||||
defaultShader->use();
|
|
||||||
setWorldMatrix(&building->matrix);
|
|
||||||
#ifdef RW_GL_USE_VAOS
|
|
||||||
glBindVertexArray(building->instHeader->vao);
|
|
||||||
#else
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, building->instHeader->ibo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, building->instHeader->vbo);
|
|
||||||
setAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
|
|
||||||
#endif
|
|
||||||
setLights(&lights);
|
|
||||||
setupDone = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
setMaterial(m->color, m->surfaceProps);
|
|
||||||
|
|
||||||
setTexture(0, m->texture);
|
|
||||||
|
|
||||||
drawInst(building->instHeader, inst);
|
|
||||||
}
|
|
||||||
#ifndef RW_GL_USE_VAOS
|
|
||||||
disableAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
|
|
||||||
#endif
|
|
||||||
if(defer)
|
|
||||||
numBlendInsts[pass]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
AtomicFullyTransparent(RpAtomic *atomic, int pass, int fadeAlpha)
|
|
||||||
{
|
|
||||||
using namespace rw;
|
|
||||||
using namespace rw::gl3;
|
|
||||||
|
|
||||||
BuildingInst *building = &blendInsts[pass][numBlendInsts[pass]];
|
|
||||||
|
|
||||||
atomic->getPipeline()->instance(atomic);
|
|
||||||
building->instHeader = (gl3::InstanceDataHeader*)atomic->geometry->instData;
|
|
||||||
assert(building->instHeader != nil);
|
|
||||||
assert(building->instHeader->platform == PLATFORM_GL3);
|
|
||||||
building->fadeAlpha = fadeAlpha;
|
|
||||||
building->lighting = !!(atomic->geometry->flags & rw::Geometry::LIGHT);
|
|
||||||
building->matrix = *atomic->getFrame()->getLTM();
|
|
||||||
numBlendInsts[pass]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
RenderBlendPass(int pass)
|
|
||||||
{
|
|
||||||
using namespace rw;
|
|
||||||
using namespace rw::gl3;
|
|
||||||
|
|
||||||
defaultShader->use();
|
|
||||||
WorldLights lights;
|
|
||||||
lights.numAmbients = 1;
|
|
||||||
lights.numDirectionals = 0;
|
|
||||||
lights.numLocals = 0;
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < numBlendInsts[pass]; i++){
|
|
||||||
BuildingInst *building = &blendInsts[pass][i];
|
|
||||||
|
|
||||||
#ifdef RW_GL_USE_VAOS
|
|
||||||
glBindVertexArray(building->instHeader->vao);
|
|
||||||
#else
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, building->instHeader->ibo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, building->instHeader->vbo);
|
|
||||||
setAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
|
|
||||||
#endif
|
|
||||||
setWorldMatrix(&building->matrix);
|
|
||||||
if(building->lighting)
|
|
||||||
lights.ambient = pAmbient->color;
|
|
||||||
else
|
|
||||||
lights.ambient = black;
|
|
||||||
setLights(&lights);
|
|
||||||
|
|
||||||
InstanceData *inst = building->instHeader->inst;
|
|
||||||
for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){
|
|
||||||
Material *m = inst->material;
|
|
||||||
if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255)
|
|
||||||
continue; // already done this one
|
|
||||||
|
|
||||||
rw::RGBA color = m->color;
|
|
||||||
color.alpha = (color.alpha * building->fadeAlpha)/255;
|
|
||||||
setMaterial(color, m->surfaceProps);
|
|
||||||
|
|
||||||
setTexture(0, m->texture);
|
|
||||||
|
|
||||||
drawInst(building->instHeader, inst);
|
|
||||||
}
|
|
||||||
#ifndef RW_GL_USE_VAOS
|
|
||||||
disableAttribPointers(building->instHeader->attribDesc, building->instHeader->numAttribs);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CRenderer::RenderOneBuilding(CEntity *ent, float camdist)
|
CRenderer::RenderOneBuilding(CEntity *ent, float camdist)
|
||||||
{
|
{
|
||||||
|
@ -715,16 +405,16 @@ CRenderer::RenderOneBuilding(CEntity *ent, float camdist)
|
||||||
alpha = mi->m_alpha * fadefactor;
|
alpha = mi->m_alpha * fadefactor;
|
||||||
|
|
||||||
if(alpha == 255)
|
if(alpha == 255)
|
||||||
AtomicFirstPass(atomic, pass);
|
WorldRender::AtomicFirstPass(atomic, pass);
|
||||||
else{
|
else{
|
||||||
// not quite sure what this is about, do we have to do that?
|
// not quite sure what this is about, do we have to do that?
|
||||||
RpGeometry *geo = RpAtomicGetGeometry(lodatm);
|
RpGeometry *geo = RpAtomicGetGeometry(lodatm);
|
||||||
if(geo != RpAtomicGetGeometry(atomic))
|
if(geo != RpAtomicGetGeometry(atomic))
|
||||||
RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE);
|
RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE);
|
||||||
AtomicFullyTransparent(atomic, pass, alpha);
|
WorldRender::AtomicFullyTransparent(atomic, pass, alpha);
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
AtomicFirstPass(atomic, pass);
|
WorldRender::AtomicFirstPass(atomic, pass);
|
||||||
|
|
||||||
ent->bImBeingRendered = false; // TODO: this seems wrong, but do we even need it?
|
ent->bImBeingRendered = false; // TODO: this seems wrong, but do we even need it?
|
||||||
}
|
}
|
||||||
|
@ -779,16 +469,16 @@ CRenderer::RenderWorld(int pass)
|
||||||
|
|
||||||
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
|
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
|
||||||
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
|
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
|
||||||
RenderBlendPass(PASS_NOZ);
|
WorldRender::RenderBlendPass(PASS_NOZ);
|
||||||
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
|
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Transparent
|
// Transparent
|
||||||
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
|
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
|
||||||
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
|
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
|
||||||
RenderBlendPass(PASS_ADD);
|
WorldRender::RenderBlendPass(PASS_ADD);
|
||||||
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
|
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
|
||||||
RenderBlendPass(PASS_BLEND);
|
WorldRender::RenderBlendPass(PASS_BLEND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -872,9 +562,9 @@ CRenderer::ClearForFrame(void)
|
||||||
ms_nNoOfInVisibleEntities = 0;
|
ms_nNoOfInVisibleEntities = 0;
|
||||||
gSortedVehiclesAndPeds.Clear();
|
gSortedVehiclesAndPeds.Clear();
|
||||||
|
|
||||||
numBlendInsts[PASS_NOZ] = 0;
|
WorldRender::numBlendInsts[PASS_NOZ] = 0;
|
||||||
numBlendInsts[PASS_ADD] = 0;
|
WorldRender::numBlendInsts[PASS_ADD] = 0;
|
||||||
numBlendInsts[PASS_BLEND] = 0;
|
WorldRender::numBlendInsts[PASS_BLEND] = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue