summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2021-01-09 19:20:32 +0100
committeraap <aap@papnet.eu>2021-01-09 19:20:32 +0100
commit03c5fdef4391b403955120aeb74e687c0a2c9578 (patch)
treed6b589e2690aaaa038656957ad65d30954e7abed /src
parentscript (diff)
downloadre3-03c5fdef4391b403955120aeb74e687c0a2c9578.tar
re3-03c5fdef4391b403955120aeb74e687c0a2c9578.tar.gz
re3-03c5fdef4391b403955120aeb74e687c0a2c9578.tar.bz2
re3-03c5fdef4391b403955120aeb74e687c0a2c9578.tar.lz
re3-03c5fdef4391b403955120aeb74e687c0a2c9578.tar.xz
re3-03c5fdef4391b403955120aeb74e687c0a2c9578.tar.zst
re3-03c5fdef4391b403955120aeb74e687c0a2c9578.zip
Diffstat (limited to '')
-rw-r--r--src/core/main.cpp2
-rw-r--r--src/extras/custompipes.h7
-rw-r--r--src/extras/custompipes_d3d9.cpp187
-rw-r--r--src/extras/custompipes_gl.cpp187
-rw-r--r--src/extras/shaders/leedsBuilding.vert4
-rw-r--r--src/extras/shaders/leedsBuilding_VS.csobin628 -> 676 bytes
-rw-r--r--src/extras/shaders/leedsBuilding_VS.hlsl5
-rw-r--r--src/extras/shaders/leedsBuilding_VS.inc68
-rw-r--r--src/extras/shaders/leedsBuilding_vs_gl.inc4
-rw-r--r--src/render/Renderer.cpp328
10 files changed, 435 insertions, 357 deletions
diff --git a/src/core/main.cpp b/src/core/main.cpp
index d9579fee..ea6f25ec 100644
--- a/src/core/main.cpp
+++ b/src/core/main.cpp
@@ -124,7 +124,7 @@ bool gbPrintMemoryUsage;
#endif
#ifdef NEW_RENDERER
-bool gbNewRenderer;
+bool gbNewRenderer = true;
#endif
#ifdef FIX_BUGS
// need to clear stencil for mblur fx. no idea why it works in the original game
diff --git a/src/extras/custompipes.h b/src/extras/custompipes.h
index ca3f0fb4..f9181fe9 100644
--- a/src/extras/custompipes.h
+++ b/src/extras/custompipes.h
@@ -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
diff --git a/src/extras/custompipes_d3d9.cpp b/src/extras/custompipes_d3d9.cpp
index 57f364a3..d2d50bca 100644
--- a/src/extras/custompipes_d3d9.cpp
+++ b/src/extras/custompipes_d3d9.cpp
@@ -201,7 +201,6 @@ worldRenderCB(rw::Atomic *atomic, rw::d3d9::InstanceDataHeader *header)
using namespace rw::d3d;
using namespace rw::d3d9;
- int vsBits;
setStreamSource(0, header->vertexStream[0].vertexBuffer, 0, header->vertexStream[0].stride);
setIndices(header->indexBuffer);
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
diff --git a/src/extras/custompipes_gl.cpp b/src/extras/custompipes_gl.cpp
index a222f5e9..193a4ac6 100644
--- a/src/extras/custompipes_gl.cpp
+++ b/src/extras/custompipes_gl.cpp
@@ -245,7 +245,7 @@ worldRenderCB(rw::Atomic *atomic, rw::gl3::InstanceDataHeader *header)
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);
@@ -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
diff --git a/src/extras/shaders/leedsBuilding.vert b/src/extras/shaders/leedsBuilding.vert
index 67dd7938..766cd081 100644
--- a/src/extras/shaders/leedsBuilding.vert
+++ b/src/extras/shaders/leedsBuilding.vert
@@ -1,6 +1,8 @@
uniform vec4 u_amb;
uniform vec4 u_emiss;
+#define surfEmissive (u_surfProps.w)
+
VSIN(ATTRIB_POS) vec3 in_pos;
VSOUT vec4 v_color;
@@ -18,7 +20,7 @@ main(void)
v_color = in_color;
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.a *= u_matColor.a;
diff --git a/src/extras/shaders/leedsBuilding_VS.cso b/src/extras/shaders/leedsBuilding_VS.cso
index 1ec92fb1..b4b94afa 100644
--- a/src/extras/shaders/leedsBuilding_VS.cso
+++ b/src/extras/shaders/leedsBuilding_VS.cso
Binary files differ
diff --git a/src/extras/shaders/leedsBuilding_VS.hlsl b/src/extras/shaders/leedsBuilding_VS.hlsl
index dd3592e9..361d5058 100644
--- a/src/extras/shaders/leedsBuilding_VS.hlsl
+++ b/src/extras/shaders/leedsBuilding_VS.hlsl
@@ -1,5 +1,8 @@
#include "standardConstants.h"
+#define surfEmissive (surfProps.w)
+
+
float4 emissive : register(c41);
float4 ambient : register(c42);
@@ -33,7 +36,7 @@ VS_out main(in VS_in input)
output.Color = input.Prelight;
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.a *= matCol.a;
diff --git a/src/extras/shaders/leedsBuilding_VS.inc b/src/extras/shaders/leedsBuilding_VS.inc
index d24f45b0..8b17983f 100644
--- a/src/extras/shaders/leedsBuilding_VS.inc
+++ b/src/extras/shaders/leedsBuilding_VS.inc
@@ -1,36 +1,40 @@
static unsigned char leedsBuilding_VS_cso[] = {
- 0x00, 0x02, 0xfe, 0xff, 0xfe, 0xff, 0x42, 0x00, 0x43, 0x54, 0x41, 0x42,
- 0x1c, 0x00, 0x00, 0x00, 0xd3, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff,
- 0x05, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0xcc, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x2a, 0x00,
- 0x01, 0x00, 0xaa, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x98, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00,
- 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00,
- 0x02, 0x00, 0x29, 0x00, 0x01, 0x00, 0xa6, 0x00, 0x88, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0e, 0x00,
- 0x01, 0x00, 0x3a, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xc5, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x32, 0x00,
- 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x6d, 0x62, 0x69,
- 0x65, 0x6e, 0x74, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6d, 0x62,
- 0x69, 0x6e, 0x65, 0x64, 0x4d, 0x61, 0x74, 0x00, 0x03, 0x00, 0x03, 0x00,
- 0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x65, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x76, 0x65, 0x00, 0x66, 0x6f, 0x67,
- 0x44, 0x61, 0x74, 0x61, 0x00, 0x6d, 0x61, 0x74, 0x43, 0x6f, 0x6c, 0x00,
- 0x76, 0x73, 0x5f, 0x32, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f,
- 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53,
- 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d,
- 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x39, 0x2e, 0x32, 0x39, 0x2e, 0x39,
- 0x35, 0x32, 0x2e, 0x33, 0x31, 0x31, 0x31, 0x00, 0x51, 0x00, 0x00, 0x05,
- 0x04, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02,
- 0x05, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02,
- 0x05, 0x00, 0x01, 0x80, 0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02,
- 0x0a, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0f, 0x90, 0x01, 0x00, 0x00, 0x02,
- 0x00, 0x00, 0x07, 0x80, 0x2a, 0x00, 0xe4, 0xa0, 0x04, 0x00, 0x00, 0x04,
- 0x00, 0x00, 0x07, 0x80, 0x03, 0x00, 0xe4, 0x90, 0x00, 0x00, 0xe4, 0x80,
- 0x29, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x08, 0x80,
+ 0x00, 0x02, 0xfe, 0xff, 0xfe, 0xff, 0x4a, 0x00, 0x43, 0x54, 0x41, 0x42,
+ 0x1c, 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff,
+ 0x06, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
+ 0xea, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x02, 0x00, 0x2a, 0x00,
+ 0x01, 0x00, 0xaa, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xac, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00,
+ 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00,
+ 0x02, 0x00, 0x29, 0x00, 0x01, 0x00, 0xa6, 0x00, 0x9c, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xd1, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0e, 0x00,
+ 0x01, 0x00, 0x3a, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xd9, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x32, 0x00,
+ 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00,
+ 0x02, 0x00, 0x0d, 0x00, 0x01, 0x00, 0x36, 0x00, 0x9c, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x61, 0x6d, 0x62, 0x69, 0x65, 0x6e, 0x74, 0x00,
+ 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x65, 0x64,
+ 0x4d, 0x61, 0x74, 0x00, 0x03, 0x00, 0x03, 0x00, 0x04, 0x00, 0x04, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x6d, 0x69, 0x73,
+ 0x73, 0x69, 0x76, 0x65, 0x00, 0x66, 0x6f, 0x67, 0x44, 0x61, 0x74, 0x61,
+ 0x00, 0x6d, 0x61, 0x74, 0x43, 0x6f, 0x6c, 0x00, 0x73, 0x75, 0x72, 0x66,
+ 0x50, 0x72, 0x6f, 0x70, 0x73, 0x00, 0x76, 0x73, 0x5f, 0x32, 0x5f, 0x30,
+ 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28,
+ 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64,
+ 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20,
+ 0x39, 0x2e, 0x32, 0x39, 0x2e, 0x39, 0x35, 0x32, 0x2e, 0x33, 0x31, 0x31,
+ 0x31, 0x00, 0xab, 0xab, 0x51, 0x00, 0x00, 0x05, 0x04, 0x00, 0x0f, 0xa0,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80,
+ 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80,
+ 0x01, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x01, 0x80,
+ 0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 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,
0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0xa0, 0x0a, 0x00, 0x00, 0x03,
0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x55, 0xa0,
diff --git a/src/extras/shaders/leedsBuilding_vs_gl.inc b/src/extras/shaders/leedsBuilding_vs_gl.inc
index 4e2db0d0..33c5eccc 100644
--- a/src/extras/shaders/leedsBuilding_vs_gl.inc
+++ b/src/extras/shaders/leedsBuilding_vs_gl.inc
@@ -2,6 +2,8 @@ const char *leedsBuilding_vert_src =
"uniform vec4 u_amb;\n"
"uniform vec4 u_emiss;\n"
+"#define surfEmissive (u_surfProps.w)\n"
+
"VSIN(ATTRIB_POS) vec3 in_pos;\n"
"VSOUT vec4 v_color;\n"
@@ -19,7 +21,7 @@ const char *leedsBuilding_vert_src =
" v_color = in_color;\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.a *= u_matColor.a;\n"
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 660b05fe..91a34592 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -347,8 +347,6 @@ enum {
PASS_BLEND // normal blend
};
-static RwRGBAReal black;
-
static void
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
CRenderer::RenderOneBuilding(CEntity *ent, float camdist)
{
@@ -715,16 +405,16 @@ CRenderer::RenderOneBuilding(CEntity *ent, float camdist)
alpha = mi->m_alpha * fadefactor;
if(alpha == 255)
- AtomicFirstPass(atomic, pass);
+ WorldRender::AtomicFirstPass(atomic, pass);
else{
// not quite sure what this is about, do we have to do that?
RpGeometry *geo = RpAtomicGetGeometry(lodatm);
if(geo != RpAtomicGetGeometry(atomic))
RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE);
- AtomicFullyTransparent(atomic, pass, alpha);
+ WorldRender::AtomicFullyTransparent(atomic, pass, alpha);
}
}else
- AtomicFirstPass(atomic, pass);
+ WorldRender::AtomicFirstPass(atomic, pass);
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(rwRENDERSTATEZWRITEENABLE, FALSE);
- RenderBlendPass(PASS_NOZ);
+ WorldRender::RenderBlendPass(PASS_NOZ);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
break;
case 2:
// Transparent
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
- RenderBlendPass(PASS_ADD);
+ WorldRender::RenderBlendPass(PASS_ADD);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
- RenderBlendPass(PASS_BLEND);
+ WorldRender::RenderBlendPass(PASS_BLEND);
break;
}
}
@@ -872,9 +562,9 @@ CRenderer::ClearForFrame(void)
ms_nNoOfInVisibleEntities = 0;
gSortedVehiclesAndPeds.Clear();
- numBlendInsts[PASS_NOZ] = 0;
- numBlendInsts[PASS_ADD] = 0;
- numBlendInsts[PASS_BLEND] = 0;
+ WorldRender::numBlendInsts[PASS_NOZ] = 0;
+ WorldRender::numBlendInsts[PASS_ADD] = 0;
+ WorldRender::numBlendInsts[PASS_BLEND] = 0;
}
#endif