From ad7855f99599c1128f03e14044cf1ea17f0bac76 Mon Sep 17 00:00:00 2001 From: Seemann Date: Sat, 9 Jan 2021 23:59:47 -0500 Subject: [PATCH 1/3] Update command definitions --- src/control/Script.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 543221c6..4102946b 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -298,10 +298,10 @@ const tScriptCommandData commands[] = { REGISTER_COMMAND(COMMAND_CSET_VAR_FLOAT_TO_LVAR_INT, INPUT_ARGUMENTS(ARGTYPE_FLOAT, ARGTYPE_INT,), OUTPUT_ARGUMENTS(), false, 0, " =#"), REGISTER_COMMAND(COMMAND_CSET_LVAR_INT_TO_VAR_FLOAT, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(), false, 0, " =#"), REGISTER_COMMAND(COMMAND_CSET_LVAR_FLOAT_TO_VAR_INT, INPUT_ARGUMENTS(ARGTYPE_FLOAT, ARGTYPE_INT,), OUTPUT_ARGUMENTS(), false, 0, " =#"), - REGISTER_COMMAND(COMMAND_ABS_VAR_INT, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT,), OUTPUT_ARGUMENTS(), false, 0, " ABS"), - REGISTER_COMMAND(COMMAND_ABS_LVAR_INT, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT,), OUTPUT_ARGUMENTS(), false, 0, " ABS"), - REGISTER_COMMAND(COMMAND_ABS_VAR_FLOAT, INPUT_ARGUMENTS(ARGTYPE_FLOAT, ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(), false, 0, " ABS"), - REGISTER_COMMAND(COMMAND_ABS_VAR_FLOAT, INPUT_ARGUMENTS(ARGTYPE_FLOAT, ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(), false, 0, " ABS"), + REGISTER_COMMAND(COMMAND_ABS_VAR_INT, INPUT_ARGUMENTS(ARGTYPE_INT,), OUTPUT_ARGUMENTS(), false, 0, " ABS"), + REGISTER_COMMAND(COMMAND_ABS_LVAR_INT, INPUT_ARGUMENTS(ARGTYPE_INT,), OUTPUT_ARGUMENTS(), false, 0, " ABS"), + REGISTER_COMMAND(COMMAND_ABS_VAR_FLOAT, INPUT_ARGUMENTS(ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(), false, 0, " ABS"), + REGISTER_COMMAND(COMMAND_ABS_LVAR_FLOAT, INPUT_ARGUMENTS(ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(), false, 0, " ABS"), REGISTER_COMMAND(COMMAND_GENERATE_RANDOM_FLOAT, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(ARGTYPE_FLOAT,), false, -1, ""), REGISTER_COMMAND(COMMAND_GENERATE_RANDOM_INT, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(ARGTYPE_INT,), false, -1, ""), REGISTER_COMMAND(COMMAND_CREATE_CHAR, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(ARGTYPE_PED_HANDLE,), false, -1, ""), @@ -935,8 +935,8 @@ const tScriptCommandData commands[] = { REGISTER_COMMAND(COMMAND_PRINT_WITH_6_NUMBERS_NOW, INPUT_ARGUMENTS(ARGTYPE_STRING, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_PRINT_WITH_6_NUMBERS_SOON, INPUT_ARGUMENTS(ARGTYPE_STRING, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_SET_CHAR_OBJ_FOLLOW_CHAR_IN_FORMATION, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), - REGISTER_COMMAND(COMMAND_PLAYER_MADE_PROGRESS, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""), - REGISTER_COMMAND(COMMAND_SET_PROGRESS_TOTAL, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""), + REGISTER_COMMAND(COMMAND_PLAYER_MADE_PROGRESS, INPUT_ARGUMENTS(ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), + REGISTER_COMMAND(COMMAND_SET_PROGRESS_TOTAL, INPUT_ARGUMENTS(ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_REGISTER_JUMP_DISTANCE, INPUT_ARGUMENTS(ARGTYPE_FLOAT, ), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_REGISTER_JUMP_HEIGHT, INPUT_ARGUMENTS(ARGTYPE_FLOAT, ), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_REGISTER_JUMP_FLIPS, INPUT_ARGUMENTS(ARGTYPE_INT, ), OUTPUT_ARGUMENTS(), false, -1, ""), From 0ee87d7b46c4e340554f25d38d01bc1accb8c826 Mon Sep 17 00:00:00 2001 From: aap Date: Sun, 10 Jan 2021 11:59:51 +0100 Subject: [PATCH 2/3] env map rendering --- src/core/main.cpp | 5 +- src/core/re3.cpp | 16 +- src/extras/custompipes.cpp | 5 +- src/extras/custompipes.h | 3 + src/extras/custompipes_d3d9.cpp | 139 ++++++++++++- src/extras/custompipes_gl.cpp | 141 ++++++++++++- src/extras/shaders/Makefile | 18 +- src/extras/shaders/leedsVehicle.vert | 27 +++ src/extras/shaders/leedsVehicle_VS.cso | Bin 0 -> 1204 bytes src/extras/shaders/leedsVehicle_VS.hlsl | 45 +++++ src/extras/shaders/leedsVehicle_VS.inc | 103 ++++++++++ src/extras/shaders/leedsVehicle_add.frag | 32 +++ src/extras/shaders/leedsVehicle_add_PS.cso | Bin 0 -> 496 bytes src/extras/shaders/leedsVehicle_add_PS.hlsl | 34 ++++ src/extras/shaders/leedsVehicle_add_PS.inc | 44 +++++ src/extras/shaders/leedsVehicle_add_gl.inc | 34 ++++ src/extras/shaders/leedsVehicle_blend.frag | 32 +++ src/extras/shaders/leedsVehicle_blend_PS.cso | Bin 0 -> 572 bytes src/extras/shaders/leedsVehicle_blend_PS.hlsl | 33 ++++ src/extras/shaders/leedsVehicle_blend_PS.inc | 50 +++++ src/extras/shaders/leedsVehicle_blend_gl.inc | 34 ++++ src/extras/shaders/leedsVehicle_vs_gl.inc | 29 +++ src/render/Renderer.cpp | 185 ++++++++++++++++++ src/render/Renderer.h | 2 + 24 files changed, 991 insertions(+), 20 deletions(-) create mode 100644 src/extras/shaders/leedsVehicle.vert create mode 100644 src/extras/shaders/leedsVehicle_VS.cso create mode 100644 src/extras/shaders/leedsVehicle_VS.hlsl create mode 100644 src/extras/shaders/leedsVehicle_VS.inc create mode 100644 src/extras/shaders/leedsVehicle_add.frag create mode 100644 src/extras/shaders/leedsVehicle_add_PS.cso create mode 100644 src/extras/shaders/leedsVehicle_add_PS.hlsl create mode 100644 src/extras/shaders/leedsVehicle_add_PS.inc create mode 100644 src/extras/shaders/leedsVehicle_add_gl.inc create mode 100644 src/extras/shaders/leedsVehicle_blend.frag create mode 100644 src/extras/shaders/leedsVehicle_blend_PS.cso create mode 100644 src/extras/shaders/leedsVehicle_blend_PS.hlsl create mode 100644 src/extras/shaders/leedsVehicle_blend_PS.inc create mode 100644 src/extras/shaders/leedsVehicle_blend_gl.inc create mode 100644 src/extras/shaders/leedsVehicle_vs_gl.inc diff --git a/src/core/main.cpp b/src/core/main.cpp index ea6f25ec..03a7fcc2 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -1159,6 +1159,8 @@ if(gbRenderWorld1) if(gbRenderRoads) CRenderer::RenderRoads(); + CRenderer::GenerateEnvironmentMap(); // should be after static shadows, but that's weird + CRenderer::RenderPeds(); // not sure where to put these since LCS has no underwater entities @@ -1172,7 +1174,7 @@ if(gbRenderWater) if(gbRenderEverythingBarRoads) CRenderer::RenderEverythingBarRoads(); - // get env map here? + // seam fixer // moved this: // CRenderer::RenderFadingInEntities(); } @@ -1195,7 +1197,6 @@ void RenderEffects_new(void) { CShadows::RenderStaticShadows(); - // CRenderer::GenerateEnvironmentMap CShadows::RenderStoredShadows(); CSkidmarks::Render(); CRubbish::Render(); diff --git a/src/core/re3.cpp b/src/core/re3.cpp index 3a5488d1..65bb61b4 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -578,22 +578,19 @@ DebugMenuPopulate(void) DebugMenuAddCmd("Spawn", "Spawn Stinger", [](){ SpawnCar(MI_STINGER); }); DebugMenuAddCmd("Spawn", "Spawn Infernus", [](){ SpawnCar(MI_INFERNUS); }); DebugMenuAddCmd("Spawn", "Spawn Cheetah", [](){ SpawnCar(MI_CHEETAH); }); - DebugMenuAddCmd("Spawn", "Spawn Phoenix", [](){ SpawnCar(MI_PHEONIX); }); + DebugMenuAddCmd("Spawn", "Spawn Esprit", [](){ SpawnCar(MI_ESPRIT); }); DebugMenuAddCmd("Spawn", "Spawn Banshee", [](){ SpawnCar(MI_BANSHEE); }); DebugMenuAddCmd("Spawn", "Spawn Esperanto", [](){ SpawnCar(MI_ESPERANT); }); DebugMenuAddCmd("Spawn", "Spawn Stallion", [](){ SpawnCar(MI_STALLION); }); - DebugMenuAddCmd("Spawn", "Spawn Admiral", [](){ SpawnCar(MI_ADMIRAL); }); - DebugMenuAddCmd("Spawn", "Spawn Washington", [](){ SpawnCar(MI_WASHING); }); + DebugMenuAddCmd("Spawn", "Spawn Mafia", [](){ SpawnCar(MI_MAFIA); }); + DebugMenuAddCmd("Spawn", "Spawn Kuruma", [](){ SpawnCar(MI_KURUMA); }); DebugMenuAddCmd("Spawn", "Spawn Taxi", [](){ SpawnCar(MI_TAXI); }); DebugMenuAddCmd("Spawn", "Spawn Police", [](){ SpawnCar(MI_POLICE); }); DebugMenuAddCmd("Spawn", "Spawn Enforcer", [](){ SpawnCar(MI_ENFORCER); }); - DebugMenuAddCmd("Spawn", "Spawn Cuban", [](){ SpawnCar(MI_CUBAN); }); - DebugMenuAddCmd("Spawn", "Spawn Voodoo", [](){ SpawnCar(MI_VOODOO); }); + DebugMenuAddCmd("Spawn", "Spawn Diablo", [](){ SpawnCar(MI_DIABLOS); }); + DebugMenuAddCmd("Spawn", "Spawn Yardie", [](){ SpawnCar(MI_YARDIE); }); DebugMenuAddCmd("Spawn", "Spawn BF injection", [](){ SpawnCar(MI_BFINJECT); }); DebugMenuAddCmd("Spawn", "Spawn Maverick", [](){ SpawnCar(MI_MAVERICK); }); - DebugMenuAddCmd("Spawn", "Spawn VCN Maverick", [](){ SpawnCar(MI_VCNMAV); }); - DebugMenuAddCmd("Spawn", "Spawn Sparrow", [](){ SpawnCar(MI_SPARROW); }); - DebugMenuAddCmd("Spawn", "Spawn Sea Sparrow", [](){ SpawnCar(MI_SEASPAR); }); DebugMenuAddCmd("Spawn", "Spawn Hunter", [](){ SpawnCar(MI_HUNTER); }); DebugMenuAddCmd("Spawn", "Spawn Rhino", [](){ SpawnCar(MI_RHINO); }); DebugMenuAddCmd("Spawn", "Spawn Firetruck", [](){ SpawnCar(MI_FIRETRUCK); }); @@ -601,8 +598,6 @@ DebugMenuPopulate(void) DebugMenuAddCmd("Spawn", "Spawn PCJ 600", [](){ SpawnCar(MI_PCJ600); }); DebugMenuAddCmd("Spawn", "Spawn Faggio", [](){ SpawnCar(MI_FAGGIO); }); DebugMenuAddCmd("Spawn", "Spawn Freeway", [](){ SpawnCar(MI_FREEWAY); }); - DebugMenuAddCmd("Spawn", "Spawn Squalo", [](){ SpawnCar(MI_SQUALO); }); - DebugMenuAddCmd("Spawn", "Spawn Skimmer", [](){ SpawnCar(MI_SKIMMER); }); DebugMenuAddVarBool8("Render", "Draw hud", &CHud::m_Wants_To_Draw_Hud, nil); DebugMenuAddVarBool8("Render", "Backface Culling", &gBackfaceCulling, nil); @@ -651,6 +646,7 @@ extern bool gbRenderWorld2; e = DebugMenuAddVar("Render", "Vehicle Pipeline", &CustomPipes::VehiclePipeSwitch, nil, 1, CustomPipes::VEHICLEPIPE_MATFX, CustomPipes::VEHICLEPIPE_NEO, vehpipenames); DebugMenuEntrySetWrap(e, true); + DebugMenuAddVarBool8("Render", "Chrome cheat", &CustomPipes::bChromeCheat, nil); DebugMenuAddVar("Render", "Neo Vehicle Shininess", &CustomPipes::VehicleShininess, nil, 0.1f, 0, 1.0f); DebugMenuAddVar("Render", "Neo Vehicle Specularity", &CustomPipes::VehicleSpecularity, nil, 0.1f, 0, 1.0f); DebugMenuAddVarBool8("Render", "Neo Ped Rim light enable", &CustomPipes::RimlightEnable, nil); diff --git a/src/extras/custompipes.cpp b/src/extras/custompipes.cpp index 2cecf1c0..f7f8bbe5 100644 --- a/src/extras/custompipes.cpp +++ b/src/extras/custompipes.cpp @@ -46,13 +46,14 @@ CustomMatCopy(void *dst, void *src, int32, int32) rw::TexDictionary *neoTxd; +bool bChromeCheat; bool bRenderingEnvMap; int32 EnvMapSize = 128; rw::Camera *EnvMapCam; rw::Texture *EnvMapTex; rw::Texture *EnvMaskTex; -static rw::RWDEVICE::Im2DVertex EnvScreenQuad[4]; -static int16 QuadIndices[6] = { 0, 1, 2, 0, 2, 3 }; +rw::RWDEVICE::Im2DVertex EnvScreenQuad[4]; +int16 QuadIndices[6] = { 0, 1, 2, 0, 2, 3 }; static rw::Camera* CreateEnvMapCam(rw::World *world) diff --git a/src/extras/custompipes.h b/src/extras/custompipes.h index f9181fe9..aed34520 100644 --- a/src/extras/custompipes.h +++ b/src/extras/custompipes.h @@ -75,11 +75,14 @@ void CustomPipeInit(void); void CustomPipeShutdown(void); void SetTxdFindCallback(void); +extern bool bChromeCheat; extern bool bRenderingEnvMap; extern int32 EnvMapSize; extern rw::Camera *EnvMapCam; extern rw::Texture *EnvMapTex; extern rw::Texture *EnvMaskTex; +extern rw::RWDEVICE::Im2DVertex EnvScreenQuad[4]; +extern int16 QuadIndices[6]; void EnvMapRender(void); enum { diff --git a/src/extras/custompipes_d3d9.cpp b/src/extras/custompipes_d3d9.cpp index 993a64ce..2483bb30 100644 --- a/src/extras/custompipes_d3d9.cpp +++ b/src/extras/custompipes_d3d9.cpp @@ -4,6 +4,8 @@ #ifdef RW_D3D9 #ifdef EXTENDED_PIPELINES +#include "rpmatfx.h" + #include "main.h" #include "RwHelper.h" #include "Lights.h" @@ -42,13 +44,112 @@ enum { VSLOC_emissive = rw::d3d::VSLOC_afterLights, VSLOC_ambient, - PSLOC_colorscale = 1 + PSLOC_colorscale = 1, + + // Leed vehicle + VSLOC_texMat = rw::d3d::VSLOC_afterLights, + + PSLOC_shininess = 1, + }; /* - * Neo Vehicle pipe + * Leeds & Neo Vehicle pipe */ +static void *leedsVehicle_VS; +static void *leedsVehicle_blend_PS; +static void *leedsVehicle_add_PS; + +static rw::RawMatrix normal2texcoord_flipU = { + { -0.5f, 0.0f, 0.0f }, 0.0f, + { 0.0f, -0.5f, 0.0f }, 0.0f, + { 0.0f, 0.0f, 1.0f }, 0.0f, + { 0.5f, 0.5f, 0.0f }, 1.0f +}; + +void +uploadEnvMatrix(rw::Frame *frame) +{ + using namespace rw; + Matrix invMat; + if(frame == nil) + frame = engine->currentCamera->getFrame(); + + RawMatrix envMtx, invMtx; + Matrix tmp = *frame->getLTM(); + // Now the weird part: we remove the camera pitch + tmp.at.z = 0.0f; + tmp.at = normalize(tmp.at); + tmp.right.x = -tmp.at.y; + tmp.right.y = tmp.at.x; + tmp.right.z = 0.0f;; + tmp.up.set(0.0f, 0.0f, 1.0f); + tmp.pos.set(0.0f, 0.0f, 0.0f); + tmp.flags = Matrix::TYPEORTHONORMAL; + + Matrix::invert(&invMat, &tmp); + convMatrix(&invMtx, &invMat); + RawMatrix::mult(&envMtx, &invMtx, &normal2texcoord_flipU); + d3d::d3ddevice->SetVertexShaderConstantF(VSLOC_texMat, (float*)&envMtx, 4); +} + +void +leedsVehicleRenderCB(rw::Atomic *atomic, rw::d3d9::InstanceDataHeader *header) +{ + using namespace rw; + 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); + + vsBits = lightingCB_Shader(atomic); + uploadMatrices(atomic->getFrame()->getLTM()); + + setVertexShader(leedsVehicle_VS); + if(bChromeCheat) + setPixelShader(leedsVehicle_blend_PS); + else + setPixelShader(leedsVehicle_add_PS); + + d3d::setTexture(1, EnvMapTex); + uploadEnvMatrix(nil); + + SetRenderState(SRCBLEND, BLENDONE); + + InstanceData *inst = header->inst; + for(rw::uint32 i = 0; i < header->numMeshes; i++){ + Material *m = inst->material; + + SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 255); + + float coef = 0.0f; + if(RpMatFXMaterialGetEffects(m) == rpMATFXEFFECTENVMAP) + coef = RpMatFXMaterialGetEnvMapCoefficient(m); + coef *= 0.5f; + if(bChromeCheat && coef > 0.0f) + coef = 1.0f; + d3ddevice->SetPixelShaderConstantF(PSLOC_shininess, (float*)&coef, 1); + + setMaterial(m->color, m->surfaceProps); + + if(m->texture) + d3d::setTexture(0, m->texture); + else + d3d::setTexture(0, gpWhiteTexture); + + drawInst(header, inst); + inst++; + } + + d3d::setTexture(1, nil); + + SetRenderState(SRCBLEND, BLENDSRCALPHA); +} + static void *neoVehicle_VS; static void *neoVehicle_PS; @@ -90,7 +191,8 @@ vehicleRenderCB(rw::Atomic *atomic, rw::d3d9::InstanceDataHeader *header) // TODO: make this less of a kludge if(VehiclePipeSwitch == VEHICLEPIPE_MATFX){ - matFXGlobals.pipelines[rw::platform]->render(atomic); + leedsVehicleRenderCB(atomic, header); + // matFXGlobals.pipelines[rw::platform]->render(atomic); return; } @@ -164,6 +266,18 @@ CreateVehiclePipe(void) neoVehicle_PS = rw::d3d::createPixelShader(neoVehicle_PS_cso); assert(neoVehicle_PS); +#include "shaders/leedsVehicle_VS.inc" + leedsVehicle_VS = rw::d3d::createVertexShader(leedsVehicle_VS_cso); + assert(leedsVehicle_VS); + +#include "shaders/leedsVehicle_blend_PS.inc" + leedsVehicle_blend_PS = rw::d3d::createPixelShader(leedsVehicle_blend_PS_cso); + assert(leedsVehicle_blend_PS); + +#include "shaders/leedsVehicle_add_PS.inc" + leedsVehicle_add_PS = rw::d3d::createPixelShader(leedsVehicle_add_PS_cso); + assert(leedsVehicle_add_PS); + rw::d3d9::ObjPipeline *pipe = rw::d3d9::ObjPipeline::create(); pipe->instanceCB = rw::d3d9::defaultInstanceCB; @@ -181,6 +295,15 @@ DestroyVehiclePipe(void) rw::d3d::destroyPixelShader(neoVehicle_PS); neoVehicle_PS = nil; + rw::d3d::destroyVertexShader(leedsVehicle_VS); + leedsVehicle_VS = nil; + + rw::d3d::destroyPixelShader(leedsVehicle_blend_PS); + leedsVehicle_blend_PS = nil; + + rw::d3d::destroyPixelShader(leedsVehicle_add_PS); + leedsVehicle_add_PS = nil; + ((rw::d3d9::ObjPipeline*)vehiclePipe)->destroy(); vehiclePipe = nil; } @@ -688,6 +811,16 @@ RenderBlendPass(int pass) setVertexShader(CustomPipes::leedsBuilding_VS); setPixelShader(CustomPipes::scale_PS); + 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); + float colorscale[4]; colorscale[3] = 1.0f; diff --git a/src/extras/custompipes_gl.cpp b/src/extras/custompipes_gl.cpp index 193a4ac6..e9350802 100644 --- a/src/extras/custompipes_gl.cpp +++ b/src/extras/custompipes_gl.cpp @@ -3,6 +3,8 @@ #ifdef RW_OPENGL #ifdef EXTENDED_PIPELINES +#include "rpmatfx.h" + #include "main.h" #include "RwHelper.h" #include "Lights.h" @@ -37,14 +39,126 @@ static int32 u_amb; static int32 u_emiss; static int32 u_colorscale; +static int32 u_texMatrix; +static int32 u_fxparams; + #define U(i) currentShader->uniformLocations[i] /* - * Neo Vehicle pipe + * Leeds & Neo Vehicle pipe */ +rw::gl3::Shader *leedsVehicleShader_add; +rw::gl3::Shader *leedsVehicleShader_blend; + rw::gl3::Shader *neoVehicleShader; +static rw::RawMatrix normal2texcoord_flipU = { + { -0.5f, 0.0f, 0.0f }, 0.0f, + { 0.0f, -0.5f, 0.0f }, 0.0f, + { 0.0f, 0.0f, 1.0f }, 0.0f, + { 0.5f, 0.5f, 0.0f }, 1.0f +}; + +static void +uploadEnvMatrix(rw::Frame *frame) +{ + using namespace rw; + using namespace rw::gl3; + + Matrix invMat; + if(frame == nil) + frame = engine->currentCamera->getFrame(); + + // cache the matrix across multiple meshes + static RawMatrix envMtx; +// can't do it, frame matrix may change +// if(frame != lastEnvFrame){ +// lastEnvFrame = frame; + { + + Matrix tmp = *frame->getLTM(); + // Now the weird part: we remove the camera pitch + tmp.at.z = 0.0f; + tmp.at = normalize(tmp.at); + tmp.right.x = -tmp.at.y; + tmp.right.y = tmp.at.x; + tmp.right.z = 0.0f;; + tmp.up.set(0.0f, 0.0f, 1.0f); + tmp.pos.set(0.0f, 0.0f, 0.0f); + tmp.flags = Matrix::TYPEORTHONORMAL; + + RawMatrix invMtx; + Matrix::invert(&invMat, &tmp); + convMatrix(&invMtx, &invMat); + RawMatrix::mult(&envMtx, &invMtx, &normal2texcoord_flipU); + } + glUniformMatrix4fv(U(u_texMatrix), 1, GL_FALSE, (float*)&envMtx); +} + +static void +leedsVehicleRenderCB(rw::Atomic *atomic, rw::gl3::InstanceDataHeader *header) +{ + using namespace rw; + using namespace rw::gl3; + + Material *m; + + setWorldMatrix(atomic->getFrame()->getLTM()); + lightingCB(atomic); + +#ifdef RW_GL_USE_VAOS + glBindVertexArray(header->vao); +#else + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); + glBindBuffer(GL_ARRAY_BUFFER, header->vbo); + setAttribPointers(header->attribDesc, header->numAttribs); +#endif + + InstanceData *inst = header->inst; + rw::int32 n = header->numMeshes; + + if(bChromeCheat) + leedsVehicleShader_blend->use(); + else + leedsVehicleShader_add->use(); + + setTexture(1, EnvMapTex); + uploadEnvMatrix(nil); + + SetRenderState(SRCBLEND, BLENDONE); + + while(n--){ + m = inst->material; + + rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); + + float coef = 0.0f; + if(RpMatFXMaterialGetEffects(m) == rpMATFXEFFECTENVMAP) + coef = RpMatFXMaterialGetEnvMapCoefficient(m); + coef *= 0.5f; + if(bChromeCheat && coef > 0.0f) + coef = 1.0f; + glUniform1f(U(u_fxparams), coef); + + setMaterial(m->color, m->surfaceProps); + + setTexture(0, m->texture); + + drawInst(header, inst); + inst++; + } + + setTexture(1, nil); + + SetRenderState(SRCBLEND, BLENDSRCALPHA); + +#ifndef RW_GL_USE_VAOS + disableAttribPointers(header->attribDesc, header->numAttribs); +#endif +} + + static void uploadSpecLights(void) { @@ -85,7 +199,8 @@ vehicleRenderCB(rw::Atomic *atomic, rw::gl3::InstanceDataHeader *header) // TODO: make this less of a kludge if(VehiclePipeSwitch == VEHICLEPIPE_MATFX){ - matFXGlobals.pipelines[rw::platform]->render(atomic); + leedsVehicleRenderCB(atomic, header); +// matFXGlobals.pipelines[rw::platform]->render(atomic); return; } @@ -172,6 +287,19 @@ CreateVehiclePipe(void) assert(neoVehicleShader); } + { +#include "shaders/leedsVehicle_add_gl.inc" +#include "shaders/leedsVehicle_blend_gl.inc" +#include "shaders/leedsVehicle_vs_gl.inc" + const char *vs[] = { shaderDecl, header_vert_src, leedsVehicle_vert_src, nil }; + const char *fs_add[] = { shaderDecl, header_frag_src, leedsVehicle_add_frag_src, nil }; + const char *fs_blend[] = { shaderDecl, header_frag_src, leedsVehicle_blend_frag_src, nil }; + leedsVehicleShader_add = Shader::create(vs, fs_add); + assert(leedsVehicleShader_add); + leedsVehicleShader_blend = Shader::create(vs, fs_blend); + assert(leedsVehicleShader_blend); + } + rw::gl3::ObjPipeline *pipe = rw::gl3::ObjPipeline::create(); pipe->instanceCB = rw::gl3::defaultInstanceCB; @@ -186,6 +314,12 @@ DestroyVehiclePipe(void) neoVehicleShader->destroy(); neoVehicleShader = nil; + leedsVehicleShader_add->destroy(); + leedsVehicleShader_add = nil; + + leedsVehicleShader_blend->destroy(); + leedsVehicleShader_blend = nil; + ((rw::gl3::ObjPipeline*)vehiclePipe)->destroy(); vehiclePipe = nil; } @@ -611,6 +745,9 @@ CustomPipeRegisterGL(void) u_amb = rw::gl3::registerUniform("u_amb"); u_emiss = rw::gl3::registerUniform("u_emiss"); u_colorscale = rw::gl3::registerUniform("u_colorscale"); + + u_texMatrix = rw::gl3::registerUniform("u_texMatrix"); + u_fxparams = rw::gl3::registerUniform("u_fxparams"); } diff --git a/src/extras/shaders/Makefile b/src/extras/shaders/Makefile index 355d71af..7fa0f125 100644 --- a/src/extras/shaders/Makefile +++ b/src/extras/shaders/Makefile @@ -4,7 +4,8 @@ all: im2d_gl.inc simple_fs_gl.inc default_UV2_gl.inc \ neoWorldVC_fs_gl.inc neoGloss_vs_gl.inc neoGloss_fs_gl.inc \ neoVehicle_vs_gl.inc neoVehicle_fs_gl.inc \ im2d_UV2_gl.inc screenDroplet_fs_gl.inc \ - leedsBuilding_vs_gl.inc scale_fs_gl.inc + leedsBuilding_vs_gl.inc scale_fs_gl.inc \ + leedsVehicle_vs_gl.inc leedsVehicle_add_gl.inc leedsVehicle_blend_gl.inc im2d_gl.inc: im2d.vert (echo 'const char *im2d_vert_src =';\ @@ -87,3 +88,18 @@ scale_fs_gl.inc: scale.frag (echo 'const char *scale_frag_src =';\ sed 's/..*/"&\\n"/' scale.frag;\ echo ';') >scale_fs_gl.inc + +leedsVehicle_vs_gl.inc: leedsVehicle.vert + (echo 'const char *leedsVehicle_vert_src =';\ + sed 's/..*/"&\\n"/' leedsVehicle.vert;\ + echo ';') >leedsVehicle_vs_gl.inc + +leedsVehicle_add_gl.inc: leedsVehicle_add.frag + (echo 'const char *leedsVehicle_add_frag_src =';\ + sed 's/..*/"&\\n"/' leedsVehicle_add.frag;\ + echo ';') >leedsVehicle_add_gl.inc + +leedsVehicle_blend_gl.inc: leedsVehicle_blend.frag + (echo 'const char *leedsVehicle_blend_frag_src =';\ + sed 's/..*/"&\\n"/' leedsVehicle_blend.frag;\ + echo ';') >leedsVehicle_blend_gl.inc diff --git a/src/extras/shaders/leedsVehicle.vert b/src/extras/shaders/leedsVehicle.vert new file mode 100644 index 00000000..b93c7ea0 --- /dev/null +++ b/src/extras/shaders/leedsVehicle.vert @@ -0,0 +1,27 @@ +uniform mat4 u_texMatrix; + +VSIN(ATTRIB_POS) vec3 in_pos; + +VSOUT vec4 v_color; +VSOUT vec2 v_tex0; +VSOUT vec2 v_tex1; +VSOUT float v_fog; + +void +main(void) +{ + vec4 Vertex = u_world * vec4(in_pos, 1.0); + gl_Position = u_proj * u_view * Vertex; + vec3 Normal = mat3(u_world) * in_normal; + + v_tex0 = in_tex0; + v_tex1 = (u_texMatrix * vec4(Normal, 1.0)).xy; + + v_color = in_color; + v_color.rgb += u_ambLight.rgb*surfAmbient; + v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse; + v_color = clamp(v_color, 0.0, 1.0); + v_color *= u_matColor; + + v_fog = DoFog(gl_Position.w); +} diff --git a/src/extras/shaders/leedsVehicle_VS.cso b/src/extras/shaders/leedsVehicle_VS.cso new file mode 100644 index 0000000000000000000000000000000000000000..57db3798aa1d793f5cc695510cc96d436519aad8 GIT binary patch literal 1204 zcmZuw%Wl(95FOj85=vU9V#5Lniv^pPj%-l0`Z%98+&(jao+JC-tgNXiU z_yAkQ!al+OjW=PKOt??!7vp#ez;#~nt#BS5ORx%fJG7Z&PXt>B_IR1w7HosA(+i4n zUMyG{yvCCENw5+bbc;Ucysuc<)UfaO980k3vRuQED-uxBmWSVXMF6o9beiD zIL=eiNmdz(l-WBX=yEfkR%v27rrjU3rY}6)jD-gvwhen_|uqmWpVaX(S`Pq&-0qb+yf|Q&>f{I(O>i8 B*Y^Mb literal 0 HcmV?d00001 diff --git a/src/extras/shaders/leedsVehicle_VS.hlsl b/src/extras/shaders/leedsVehicle_VS.hlsl new file mode 100644 index 00000000..eb53313a --- /dev/null +++ b/src/extras/shaders/leedsVehicle_VS.hlsl @@ -0,0 +1,45 @@ +#include "standardConstants.h" + +float4x4 texMat : register(c41); + +struct VS_in +{ + float4 Position : POSITION; + float3 Normal : NORMAL; + float2 TexCoord : TEXCOORD0; + float4 Prelight : COLOR0; +}; + +struct VS_out { + float4 Position : POSITION; + float3 TexCoord0 : TEXCOORD0; // also fog + float2 TexCoord1 : TEXCOORD1; + float4 Color : COLOR0; +}; + + +VS_out main(in VS_in input) +{ + VS_out output; + + output.Position = mul(combinedMat, input.Position); + float3 V = mul(worldMat, input.Position).xyz; + float3 N = mul(normalMat, input.Normal); + + output.TexCoord0.xy = input.TexCoord; + output.TexCoord1 = mul(texMat, float4(N, 1.0)).xy; + + output.Color = input.Prelight; + output.Color.rgb += ambientLight.rgb * surfAmbient; + + int i; + for(i = 0; i < numDirLights; i++) + output.Color.xyz += DoDirLight(lights[i+firstDirLight], N)*surfDiffuse; + // PS2 clamps before material color + output.Color = clamp(output.Color, 0.0, 1.0); + output.Color *= matCol; + + output.TexCoord0.z = clamp((output.Position.w - fogEnd)*fogRange, fogDisable, 1.0); + + return output; +} diff --git a/src/extras/shaders/leedsVehicle_VS.inc b/src/extras/shaders/leedsVehicle_VS.inc new file mode 100644 index 00000000..89527d72 --- /dev/null +++ b/src/extras/shaders/leedsVehicle_VS.inc @@ -0,0 +1,103 @@ +static unsigned char leedsVehicle_VS_cso[] = { + 0x00, 0x02, 0xfe, 0xff, 0xfe, 0xff, 0x8d, 0x00, 0x43, 0x54, 0x41, 0x42, + 0x1c, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, + 0x0a, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0xf5, 0x01, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0f, 0x00, + 0x01, 0x00, 0x3e, 0x00, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, + 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, + 0x02, 0x00, 0x10, 0x00, 0x01, 0x00, 0x42, 0x00, 0x2c, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3c, 0x01, 0x00, 0x00, 0x02, 0x00, 0x0e, 0x00, + 0x01, 0x00, 0x3a, 0x00, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x44, 0x01, 0x00, 0x00, 0x02, 0x00, 0x11, 0x00, 0x18, 0x00, 0x46, 0x00, + 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x01, 0x00, 0x00, + 0x02, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x32, 0x00, 0xf4, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa7, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, + 0x03, 0x00, 0x22, 0x00, 0xb4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc4, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, + 0xd4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x01, 0x00, 0x00, + 0x02, 0x00, 0x0d, 0x00, 0x01, 0x00, 0x36, 0x00, 0xf4, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xee, 0x01, 0x00, 0x00, 0x02, 0x00, 0x29, 0x00, + 0x04, 0x00, 0xa6, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x61, 0x6d, 0x62, 0x69, 0x65, 0x6e, 0x74, 0x4c, 0x69, 0x67, 0x68, 0x74, + 0x00, 0xab, 0xab, 0xab, 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, + 0x66, 0x69, 0x72, 0x73, 0x74, 0x4c, 0x69, 0x67, 0x68, 0x74, 0x00, 0xab, + 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x66, 0x6f, 0x67, 0x44, 0x61, 0x74, 0x61, 0x00, + 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73, 0x00, 0x63, 0x6f, 0x6c, 0x6f, 0x72, + 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x00, 0xab, 0x4b, 0x01, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, + 0x64, 0x01, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x6d, 0x01, 0x00, 0x00, + 0x54, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x03, 0x00, 0x78, 0x01, 0x00, 0x00, 0x6d, 0x61, 0x74, 0x43, + 0x6f, 0x6c, 0x00, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x4d, 0x61, 0x74, + 0x00, 0xab, 0xab, 0xab, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x75, 0x6d, 0x44, + 0x69, 0x72, 0x4c, 0x69, 0x67, 0x68, 0x74, 0x73, 0x00, 0xab, 0xab, 0xab, + 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x73, 0x75, 0x72, 0x66, 0x50, 0x72, 0x6f, 0x70, + 0x73, 0x00, 0x74, 0x65, 0x78, 0x4d, 0x61, 0x74, 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, 0xab, 0x51, 0x00, 0x00, 0x05, + 0x04, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, + 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, + 0x03, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, + 0x05, 0x00, 0x00, 0x80, 0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, + 0x0a, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0f, 0x90, 0x05, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x55, 0x90, 0x01, 0x00, 0xe4, 0xa0, + 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, + 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, 0x00, 0x00, 0xaa, 0x90, + 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, + 0x03, 0x00, 0xe4, 0xa0, 0x00, 0x00, 0xff, 0x90, 0x00, 0x00, 0xe4, 0x80, + 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0xe4, 0x80, + 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x07, 0x80, 0x01, 0x00, 0x55, 0x90, + 0x09, 0x00, 0xe4, 0xa0, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x07, 0x80, + 0x08, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x90, 0x00, 0x00, 0xe4, 0x80, + 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x07, 0x80, 0x0a, 0x00, 0xe4, 0xa0, + 0x01, 0x00, 0xaa, 0x90, 0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x02, + 0x01, 0x00, 0x01, 0x80, 0x0d, 0x00, 0x00, 0xa0, 0x04, 0x00, 0x00, 0x04, + 0x01, 0x00, 0x07, 0x80, 0x0f, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x80, + 0x03, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x02, 0x02, 0x00, 0x07, 0x80, + 0x01, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x08, 0x80, + 0x04, 0x00, 0x00, 0xa0, 0x26, 0x00, 0x00, 0x01, 0x00, 0x00, 0xe4, 0xf0, + 0x02, 0x00, 0x00, 0x03, 0x03, 0x00, 0x01, 0x80, 0x01, 0x00, 0xff, 0x80, + 0x10, 0x00, 0x00, 0xa0, 0x05, 0x00, 0x00, 0x03, 0x03, 0x00, 0x01, 0x80, + 0x03, 0x00, 0x00, 0x80, 0x04, 0x00, 0x55, 0xa0, 0x2e, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x01, 0xb0, 0x03, 0x00, 0x00, 0x80, 0x08, 0x00, 0x00, 0x04, + 0x03, 0x00, 0x01, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x13, 0x20, 0xe4, 0xa1, + 0x00, 0x00, 0x00, 0xb0, 0x0b, 0x00, 0x00, 0x03, 0x03, 0x00, 0x01, 0x80, + 0x03, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0xa0, 0x05, 0x00, 0x00, 0x04, + 0x03, 0x00, 0x07, 0x80, 0x03, 0x00, 0x00, 0x80, 0x11, 0x20, 0xe4, 0xa0, + 0x00, 0x00, 0x00, 0xb0, 0x04, 0x00, 0x00, 0x04, 0x02, 0x00, 0x07, 0x80, + 0x03, 0x00, 0xe4, 0x80, 0x0d, 0x00, 0xaa, 0xa0, 0x02, 0x00, 0xe4, 0x80, + 0x02, 0x00, 0x00, 0x03, 0x01, 0x00, 0x08, 0x80, 0x01, 0x00, 0xff, 0x80, + 0x04, 0x00, 0xaa, 0xa0, 0x27, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, + 0x02, 0x00, 0x08, 0x80, 0x03, 0x00, 0xff, 0x90, 0x0b, 0x00, 0x00, 0x03, + 0x01, 0x00, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0xa0, + 0x0a, 0x00, 0x00, 0x03, 0x01, 0x00, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0x80, + 0x04, 0x00, 0xaa, 0xa0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0xd0, + 0x01, 0x00, 0xe4, 0x80, 0x0c, 0x00, 0xe4, 0xa0, 0x05, 0x00, 0x00, 0x03, + 0x01, 0x00, 0x03, 0x80, 0x00, 0x00, 0x55, 0x80, 0x2a, 0x00, 0xe4, 0xa0, + 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x80, 0x29, 0x00, 0xe4, 0xa0, + 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x03, 0x80, 0x2b, 0x00, 0xe4, 0xa0, 0x00, 0x00, 0xaa, 0x80, + 0x00, 0x00, 0xe4, 0x80, 0x02, 0x00, 0x00, 0x03, 0x01, 0x00, 0x03, 0xe0, + 0x00, 0x00, 0xe4, 0x80, 0x2c, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xff, 0x80, 0x0e, 0x00, 0x55, 0xa1, + 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, + 0x0e, 0x00, 0xaa, 0xa0, 0x0b, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x80, + 0x00, 0x00, 0x00, 0x80, 0x0e, 0x00, 0xff, 0xa0, 0x0a, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x04, 0xe0, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0xaa, 0xa0, + 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x03, 0xe0, 0x02, 0x00, 0xe4, 0x90, + 0xff, 0xff, 0x00, 0x00 +}; diff --git a/src/extras/shaders/leedsVehicle_add.frag b/src/extras/shaders/leedsVehicle_add.frag new file mode 100644 index 00000000..e9bcef74 --- /dev/null +++ b/src/extras/shaders/leedsVehicle_add.frag @@ -0,0 +1,32 @@ +uniform sampler2D tex0; +uniform sampler2D tex1; + +uniform float u_fxparams; + +#define shininess (u_fxparams) + +FSIN vec4 v_color; +FSIN vec2 v_tex0; +FSIN vec2 v_tex1; +FSIN float v_fog; + +void +main(void) +{ + vec4 pass1 = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y)); + vec4 pass2 = texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y)); + pass2.a *= shininess; + + pass1.rgb = mix(u_fogColor.rgb, pass1.rgb, v_fog); + pass2.rgb = mix(vec3(0.0, 0.0, 0.0), pass2.rgb, v_fog); + + // We simulate drawing this in two passes. + // We premultiply alpha so render state should be one. + vec4 color; + color.rgb = pass1.rgb*pass1.a + pass2.rgb*pass2.a; + color.a = pass1.a; + + DoAlphaTest(color.a); + + FRAGCOLOR(color); +} diff --git a/src/extras/shaders/leedsVehicle_add_PS.cso b/src/extras/shaders/leedsVehicle_add_PS.cso new file mode 100644 index 0000000000000000000000000000000000000000..11db8b0eadbbe198b3a07144e5263766db701ae5 GIT binary patch literal 496 zcmZ8dF;2rk5S+Uh;sVJZK*A+77B-?t2T4N_8j?PWNDPq@E^;E2(gh`jA3za06gMu@ z((w?#gJbS&gTzYf-I<-8wGLA2Z+(T{@Va{p;EM@z4vWDMz$eR`*|Jb#&1&L>*`h$; z5U-X2-dH75@cU77d&^b2hMUadcsSj_!I5>~85`55XG7=z`B**l)LbRV^IX`g4)>~v zH_LG{UaYWOjiS*xZfEz2TB&&LpWdDMH~m51A3TmH)5Pzo#d0=h(+Q$Z(7B9)i!cn0 z=SlV3DbOyOo_BtGz{_ergX?XZUa;@lr}0vOvJh@*v4BUfvHLImT$q{8BWgThW4p-KXl6k-@_;^@#1aHyN1OGj5X zKcwGbJ@>U};!98OIj8rY*SjkqQM4G0`>{{bo zx%~CQ3%&Ugi{+?2I>y!XHVl@5zj6<6j@--spzjXuz40V;d%=7$oso2!?M}0E+HRh- zS}n=E2I?A40z_w3tSJZO=R`mw+j8#z%K;~@{1~>AY`G%unj>>Kn`f|dqZOP;Q7dYm zF|UR^j|r)7bu(j=7lQb&XOmSuN!cTF(vwG`6?2$Ny~#vt*wh7qgwPtwaLH5EGybP1 f!n}t?Px53&6MO8lm?^x>&1IgkPGoVPq5ysXwX0}+ literal 0 HcmV?d00001 diff --git a/src/extras/shaders/leedsVehicle_blend_PS.hlsl b/src/extras/shaders/leedsVehicle_blend_PS.hlsl new file mode 100644 index 00000000..e32970b2 --- /dev/null +++ b/src/extras/shaders/leedsVehicle_blend_PS.hlsl @@ -0,0 +1,33 @@ +struct VS_out { + float4 Position : POSITION; + float3 TexCoord0 : TEXCOORD0; + float2 TexCoord1 : TEXCOORD1; + float4 Color : COLOR0; +}; + +sampler2D diffTex : register(s0); +sampler2D envTex : register(s1); + +float4 fogColor : register(c0); + +float4 fxparams : register(c1); + +#define shininess (fxparams.x) + +float4 main(VS_out input) : COLOR +{ + float4 pass1 = input.Color*tex2D(diffTex, input.TexCoord0.xy); + float4 pass2 = tex2D(envTex, input.TexCoord1.xy); + pass2.a *= shininess; + + pass1.rgb = lerp(fogColor.rgb, pass1.rgb, input.TexCoord0.z); + pass2.rgb = lerp(float3(0.0, 0.0, 0.0), pass2.rgb, input.TexCoord0.z); + + // We simulate drawing this in two passes. + // We premultiply alpha so render state should be one. + float4 color; + color.rgb = pass1.rgb*pass1.a*(1.0-pass2.a) + pass2.rgb*pass2.a; + color.a = pass1.a*(1.0-pass2.a) + pass2.a; + + return color; +} diff --git a/src/extras/shaders/leedsVehicle_blend_PS.inc b/src/extras/shaders/leedsVehicle_blend_PS.inc new file mode 100644 index 00000000..94fb000c --- /dev/null +++ b/src/extras/shaders/leedsVehicle_blend_PS.inc @@ -0,0 +1,50 @@ +static unsigned char leedsVehicle_blend_PS_cso[] = { + 0x00, 0x02, 0xff, 0xff, 0xfe, 0xff, 0x40, 0x00, 0x43, 0x54, 0x41, 0x42, + 0x1c, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0xc1, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x02, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x84, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x06, 0x00, + 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0xa8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x06, 0x00, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x64, 0x69, 0x66, 0x66, 0x54, 0x65, 0x78, 0x00, 0x04, 0x00, 0x0c, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x65, 0x6e, 0x76, 0x54, 0x65, 0x78, 0x00, 0xab, 0x04, 0x00, 0x0c, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x66, 0x6f, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, + 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x66, 0x78, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, + 0x00, 0x70, 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, 0xab, + 0x51, 0x00, 0x00, 0x05, 0x02, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x80, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x07, 0xb0, + 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x03, 0xb0, + 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, + 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x00, 0x08, 0x0f, 0xa0, + 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x01, 0x08, 0x0f, 0xa0, + 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xb0, + 0x00, 0x08, 0xe4, 0xa0, 0x42, 0x00, 0x00, 0x03, 0x01, 0x00, 0x0f, 0x80, + 0x01, 0x00, 0xe4, 0xb0, 0x01, 0x08, 0xe4, 0xa0, 0x04, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0xe4, 0x90, 0x00, 0x00, 0xe4, 0x80, + 0x00, 0x00, 0xe4, 0xa1, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08, 0x80, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xff, 0x90, 0x04, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0xaa, 0xb0, 0x00, 0x00, 0xe4, 0x80, + 0x00, 0x00, 0xe4, 0xa0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x07, 0x80, + 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x05, 0x00, 0x00, 0x03, + 0x01, 0x00, 0x07, 0x80, 0x01, 0x00, 0xe4, 0x80, 0x00, 0x00, 0xaa, 0xb0, + 0x05, 0x00, 0x00, 0x03, 0x02, 0x00, 0x08, 0x80, 0x01, 0x00, 0xff, 0x80, + 0x01, 0x00, 0x00, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x00, 0x01, 0x80, + 0x01, 0x00, 0x00, 0xa0, 0x04, 0x00, 0x00, 0x04, 0x01, 0x00, 0x08, 0x80, + 0x01, 0x00, 0xff, 0x80, 0x02, 0x00, 0x00, 0x81, 0x02, 0x00, 0x00, 0xa0, + 0x04, 0x00, 0x00, 0x04, 0x03, 0x00, 0x08, 0x80, 0x00, 0x00, 0xff, 0x80, + 0x01, 0x00, 0xff, 0x80, 0x02, 0x00, 0xff, 0x80, 0x12, 0x00, 0x00, 0x04, + 0x03, 0x00, 0x07, 0x80, 0x02, 0x00, 0xff, 0x80, 0x01, 0x00, 0xe4, 0x80, + 0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, + 0x03, 0x00, 0xe4, 0x80, 0xff, 0xff, 0x00, 0x00 +}; diff --git a/src/extras/shaders/leedsVehicle_blend_gl.inc b/src/extras/shaders/leedsVehicle_blend_gl.inc new file mode 100644 index 00000000..707afb10 --- /dev/null +++ b/src/extras/shaders/leedsVehicle_blend_gl.inc @@ -0,0 +1,34 @@ +const char *leedsVehicle_blend_frag_src = +"uniform sampler2D tex0;\n" +"uniform sampler2D tex1;\n" + +"uniform float u_fxparams;\n" + +"#define shininess (u_fxparams)\n" + +"FSIN vec4 v_color;\n" +"FSIN vec2 v_tex0;\n" +"FSIN vec2 v_tex1;\n" +"FSIN float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 pass1 = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n" +" vec4 pass2 = texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y));\n" +" pass2.a *= shininess;\n" + +" pass1.rgb = mix(u_fogColor.rgb, pass1.rgb, v_fog);\n" +" pass2.rgb = mix(vec3(0.0, 0.0, 0.0), pass2.rgb, v_fog);\n" + +" // We simulate drawing this in two passes.\n" +" // We premultiply alpha so render state should be one.\n" +" vec4 color;\n" +" color.rgb = pass1.rgb*pass1.a*(1.0-pass2.a) + pass2.rgb*pass2.a;\n" +" color.a = pass1.a*(1.0-pass2.a) + pass2.a;\n" + +" DoAlphaTest(color.a);\n" + +" FRAGCOLOR(color);\n" +"}\n" +; diff --git a/src/extras/shaders/leedsVehicle_vs_gl.inc b/src/extras/shaders/leedsVehicle_vs_gl.inc new file mode 100644 index 00000000..eb36b6e9 --- /dev/null +++ b/src/extras/shaders/leedsVehicle_vs_gl.inc @@ -0,0 +1,29 @@ +const char *leedsVehicle_vert_src = +"uniform mat4 u_texMatrix;\n" + +"VSIN(ATTRIB_POS) vec3 in_pos;\n" + +"VSOUT vec4 v_color;\n" +"VSOUT vec2 v_tex0;\n" +"VSOUT vec2 v_tex1;\n" +"VSOUT float v_fog;\n" + +"void\n" +"main(void)\n" +"{\n" +" vec4 Vertex = u_world * vec4(in_pos, 1.0);\n" +" gl_Position = u_proj * u_view * Vertex;\n" +" vec3 Normal = mat3(u_world) * in_normal;\n" + +" v_tex0 = in_tex0;\n" +" v_tex1 = (u_texMatrix * vec4(Normal, 1.0)).xy;\n" + +" v_color = in_color;\n" +" v_color.rgb += u_ambLight.rgb*surfAmbient;\n" +" v_color.rgb += DoDynamicLight(Vertex.xyz, Normal)*surfDiffuse;\n" +" v_color = clamp(v_color, 0.0, 1.0);\n" +" v_color *= u_matColor;\n" + +" v_fog = DoFog(gl_Position.w);\n" +"}\n" +; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 91a34592..3065027b 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -2,6 +2,7 @@ #include "common.h" #include "main.h" +#include "General.h" #include "Lights.h" #include "ModelInfo.h" #include "Treadable.h" @@ -20,6 +21,7 @@ #include "ModelIndices.h" #include "Streaming.h" #include "Shadows.h" +#include "Coronas.h" #include "PointLights.h" #include "Occlusion.h" #include "Renderer.h" @@ -40,6 +42,8 @@ bool gbDontRenderPeds; bool gbDontRenderObjects; bool gbDontRenderVehicles; +bool gbRenderDebugEnvMap; + // unused int16 TestCloseThings; int16 TestBigThings; @@ -1642,3 +1646,184 @@ CRenderer::RemoveVehiclePedLights(CEntity *ent, bool reset) SetAmbientColours(); DeActivateDirectional(); } + + +#include "postfx.h" + +static RwIm2DVertex Screen2EnvQuad[4]; +static RwImVertexIndex EnvQuadIndices[6] = { 0, 1, 2, 0, 2, 3 }; + +static void +SetQuadVertices(RwRaster *env, RwRaster *screen, float z) +{ + uint32 width = RwRasterGetWidth(env); + uint32 height = RwRasterGetHeight(env); + + float zero, xmax, ymax; + + zero = -HALFPX; + xmax = width - HALFPX; + ymax = height - HALFPX; + + float recipz = 1.0f/z; + float umax = (float)SCREEN_WIDTH/RwRasterGetWidth(screen); + float vmax = (float)SCREEN_HEIGHT/RwRasterGetHeight(screen); + + RwIm2DVertexSetScreenX(&Screen2EnvQuad[0], zero); + RwIm2DVertexSetScreenY(&Screen2EnvQuad[0], zero); + RwIm2DVertexSetScreenZ(&Screen2EnvQuad[0], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Screen2EnvQuad[0], z); + RwIm2DVertexSetRecipCameraZ(&Screen2EnvQuad[0], recipz); + RwIm2DVertexSetU(&Screen2EnvQuad[0], 0.0f, recipz); + RwIm2DVertexSetV(&Screen2EnvQuad[0], 0.0f, recipz); + RwIm2DVertexSetIntRGBA(&Screen2EnvQuad[0], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Screen2EnvQuad[1], zero); + RwIm2DVertexSetScreenY(&Screen2EnvQuad[1], ymax); + RwIm2DVertexSetScreenZ(&Screen2EnvQuad[1], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Screen2EnvQuad[1], z); + RwIm2DVertexSetRecipCameraZ(&Screen2EnvQuad[1], recipz); + RwIm2DVertexSetU(&Screen2EnvQuad[1], 0.0f, recipz); + RwIm2DVertexSetV(&Screen2EnvQuad[1], vmax, recipz); + RwIm2DVertexSetIntRGBA(&Screen2EnvQuad[1], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Screen2EnvQuad[2], xmax); + RwIm2DVertexSetScreenY(&Screen2EnvQuad[2], ymax); + RwIm2DVertexSetScreenZ(&Screen2EnvQuad[2], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Screen2EnvQuad[2], z); + RwIm2DVertexSetRecipCameraZ(&Screen2EnvQuad[2], recipz); + RwIm2DVertexSetU(&Screen2EnvQuad[2], umax, recipz); + RwIm2DVertexSetV(&Screen2EnvQuad[2], vmax, recipz); + RwIm2DVertexSetIntRGBA(&Screen2EnvQuad[2], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Screen2EnvQuad[3], xmax); + RwIm2DVertexSetScreenY(&Screen2EnvQuad[3], zero); + RwIm2DVertexSetScreenZ(&Screen2EnvQuad[3], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Screen2EnvQuad[3], z); + RwIm2DVertexSetRecipCameraZ(&Screen2EnvQuad[3], recipz); + RwIm2DVertexSetU(&Screen2EnvQuad[3], umax, recipz); + RwIm2DVertexSetV(&Screen2EnvQuad[3], 0.0f, recipz); + RwIm2DVertexSetIntRGBA(&Screen2EnvQuad[3], 255, 255, 255, 255); +} + +static RwIm2DVertex coronaVerts[4*4]; +static RwImVertexIndex coronaIndices[6*4]; +static int numCoronaVerts, numCoronaIndices; + +static void +AddCorona(float x, float y, float sz) +{ + float nearz, recipz; + RwIm2DVertex *v; + nearz = RwIm2DGetNearScreenZ(); + float z = RwCameraGetNearClipPlane(RwCameraGetCurrentCamera()); + recipz = 1.0f/z; + + v = &coronaVerts[numCoronaVerts]; + RwIm2DVertexSetScreenX(&v[0], x); + RwIm2DVertexSetScreenY(&v[0], y); + RwIm2DVertexSetScreenZ(&v[0], z); + RwIm2DVertexSetScreenZ(&v[0], nearz); + RwIm2DVertexSetRecipCameraZ(&v[0], recipz); + RwIm2DVertexSetU(&v[0], 0.0f, recipz); + RwIm2DVertexSetV(&v[0], 0.0f, recipz); + RwIm2DVertexSetIntRGBA(&v[0], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&v[1], x); + RwIm2DVertexSetScreenY(&v[1], y + sz); + RwIm2DVertexSetScreenZ(&v[1], z); + RwIm2DVertexSetScreenZ(&v[1], nearz); + RwIm2DVertexSetRecipCameraZ(&v[1], recipz); + RwIm2DVertexSetU(&v[1], 0.0f, recipz); + RwIm2DVertexSetV(&v[1], 1.0f, recipz); + RwIm2DVertexSetIntRGBA(&v[1], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&v[2], x + sz); + RwIm2DVertexSetScreenY(&v[2], y + sz); + RwIm2DVertexSetScreenZ(&v[2], z); + RwIm2DVertexSetScreenZ(&v[2], nearz); + RwIm2DVertexSetRecipCameraZ(&v[2], recipz); + RwIm2DVertexSetU(&v[2], 1.0f, recipz); + RwIm2DVertexSetV(&v[2], 1.0f, recipz); + RwIm2DVertexSetIntRGBA(&v[2], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&v[3], x + sz); + RwIm2DVertexSetScreenY(&v[3], y); + RwIm2DVertexSetScreenZ(&v[3], z); + RwIm2DVertexSetScreenZ(&v[3], nearz); + RwIm2DVertexSetRecipCameraZ(&v[3], recipz); + RwIm2DVertexSetU(&v[3], 1.0f, recipz); + RwIm2DVertexSetV(&v[3], 0.0f, recipz); + RwIm2DVertexSetIntRGBA(&v[3], 255, 255, 255, 255); + + + coronaIndices[numCoronaIndices++] = numCoronaVerts; + coronaIndices[numCoronaIndices++] = numCoronaVerts + 1; + coronaIndices[numCoronaIndices++] = numCoronaVerts + 2; + coronaIndices[numCoronaIndices++] = numCoronaVerts; + coronaIndices[numCoronaIndices++] = numCoronaVerts + 2; + coronaIndices[numCoronaIndices++] = numCoronaVerts + 3; + numCoronaVerts += 4; +} +#include "Debug.h" + +static void +DrawEnvMapCoronas(float heading) +{ + RwRaster *rt = RwTextureGetRaster(CustomPipes::EnvMapTex); + const float BIG = 89.0f * RwRasterGetWidth(rt)/128.0f; + const float SMALL = 38.0f * RwRasterGetHeight(rt)/128.0f; + + float x; + numCoronaVerts = 0; + numCoronaIndices = 0; + x = (heading - PI)/TWOPI;// - 1.0f; + x *= BIG+SMALL; + AddCorona(x, 0.0f, BIG); x += BIG; + AddCorona(x, 12.0f, SMALL); x += SMALL; + AddCorona(x, 0.0f, BIG); x += BIG; + AddCorona(x, 12.0f, SMALL); x += SMALL; + + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[CCoronas::TYPE_STAR])); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, coronaVerts, numCoronaVerts, coronaIndices, numCoronaIndices); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); +} + +void +CRenderer::GenerateEnvironmentMap(void) +{ + // We'll probably do this differently eventually + // re-using all sorts of stuff here... + + CPostFX::GetBackBuffer(Scene.camera); + + RwCameraBeginUpdate(CustomPipes::EnvMapCam); + + // get current scene + SetQuadVertices(RwTextureGetRaster(CustomPipes::EnvMapTex), CPostFX::pBackBuffer, RwCameraGetNearClipPlane(RwCameraGetCurrentCamera())); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, CPostFX::pBackBuffer); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Screen2EnvQuad, 4, EnvQuadIndices, 6); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + + // Draw coronas + DrawEnvMapCoronas(TheCamera.GetForward().Heading()); + + RwCameraEndUpdate(CustomPipes::EnvMapCam); + + + RwCameraBeginUpdate(Scene.camera); + + if(gbRenderDebugEnvMap){ + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(CustomPipes::EnvMapTex)); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, CustomPipes::EnvScreenQuad, 4, (RwImVertexIndex*)CustomPipes::QuadIndices, 6); + } +} diff --git a/src/render/Renderer.h b/src/render/Renderer.h index 9b202098..a4b6b0b8 100644 --- a/src/render/Renderer.h +++ b/src/render/Renderer.h @@ -102,4 +102,6 @@ public: static void RenderTransparentWater(void); // keep-out polys and transparent water #endif static void InsertEntityIntoList(CEntity *ent); + + static void GenerateEnvironmentMap(void); }; From 453405f131f91e601f0300a3c4fbe0b689880431 Mon Sep 17 00:00:00 2001 From: aap Date: Sun, 10 Jan 2021 13:05:34 +0100 Subject: [PATCH 3/3] dont render untextured world --- src/extras/custompipes_d3d9.cpp | 17 ++++++++--------- src/extras/custompipes_gl.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/extras/custompipes_d3d9.cpp b/src/extras/custompipes_d3d9.cpp index 2483bb30..c4505b75 100644 --- a/src/extras/custompipes_d3d9.cpp +++ b/src/extras/custompipes_d3d9.cpp @@ -733,6 +733,9 @@ AtomicFirstPass(RpAtomic *atomic, int pass) for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){ Material *m = inst->material; + if(m->texture == nil) + continue; + if(inst->vertexAlpha || m->color.alpha != 255 || IsTextureTransparent(m->texture)){ defer = true; @@ -769,10 +772,7 @@ AtomicFirstPass(RpAtomic *atomic, int pass) 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 + d3d::setTexture(0, m->texture); setMaterial(m->color, m->surfaceProps, 0.5f); @@ -836,19 +836,18 @@ RenderBlendPass(int pass) InstanceData *inst = building->instHeader->inst; for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){ Material *m = inst->material; + if(m->texture == nil) + continue; 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) + if(m->texture) // always true 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 + d3d::setTexture(0, m->texture); rw::RGBA color = m->color; color.alpha = (color.alpha * building->fadeAlpha)/255; diff --git a/src/extras/custompipes_gl.cpp b/src/extras/custompipes_gl.cpp index e9350802..54e212d6 100644 --- a/src/extras/custompipes_gl.cpp +++ b/src/extras/custompipes_gl.cpp @@ -805,6 +805,9 @@ AtomicFirstPass(RpAtomic *atomic, int pass) for(rw::uint32 i = 0; i < building->instHeader->numMeshes; i++, inst++){ Material *m = inst->material; + if(m->texture == nil) + continue; + if(inst->vertexAlpha || m->color.alpha != 255 || IsTextureTransparent(m->texture)){ defer = true; @@ -913,6 +916,8 @@ RenderBlendPass(int pass) InstanceData *inst = building->instHeader->inst; for(rw::uint32 j = 0; j < building->instHeader->numMeshes; j++, inst++){ Material *m = inst->material; + if(m->texture == nil) + continue; if(!inst->vertexAlpha && m->color.alpha == 255 && !IsTextureTransparent(m->texture) && building->fadeAlpha == 255) continue; // already done this one @@ -921,7 +926,7 @@ RenderBlendPass(int pass) setMaterial(color, m->surfaceProps, 0.5f); float cs = 1.0f; - if(m->texture) + if(m->texture) // always true cs = 255/128.0f; colorscale[0] = colorscale[1] = colorscale[2] = cs; glUniform4fv(U(CustomPipes::u_colorscale), 1, colorscale);