diff options
author | aap <aap@papnet.eu> | 2019-06-01 12:02:31 +0200 |
---|---|---|
committer | aap <aap@papnet.eu> | 2019-06-01 12:02:31 +0200 |
commit | 92434f01f1631d54207fb4395e3d5ab7e20941c5 (patch) | |
tree | 256adb4226cec31c683d10f9cfcdc4d0b03ee3db | |
parent | added CCoronas (diff) | |
download | re3-92434f01f1631d54207fb4395e3d5ab7e20941c5.tar re3-92434f01f1631d54207fb4395e3d5ab7e20941c5.tar.gz re3-92434f01f1631d54207fb4395e3d5ab7e20941c5.tar.bz2 re3-92434f01f1631d54207fb4395e3d5ab7e20941c5.tar.lz re3-92434f01f1631d54207fb4395e3d5ab7e20941c5.tar.xz re3-92434f01f1631d54207fb4395e3d5ab7e20941c5.tar.zst re3-92434f01f1631d54207fb4395e3d5ab7e20941c5.zip |
-rw-r--r-- | src/config.h | 1 | ||||
-rw-r--r-- | src/render/Lights.cpp | 164 | ||||
-rw-r--r-- | src/render/Lights.h | 11 |
3 files changed, 174 insertions, 2 deletions
diff --git a/src/config.h b/src/config.h index 61eb6d64..f366b76e 100644 --- a/src/config.h +++ b/src/config.h @@ -51,6 +51,7 @@ enum Config { NUMWEATHERS = 4, NUMHOURS = 24, + NUMEXTRADIRECTIONALS = 4, NUMANTENNAS = 8, NUMCORONAS = 56 }; diff --git a/src/render/Lights.cpp b/src/render/Lights.cpp index 7954a07d..1e27ec48 100644 --- a/src/render/Lights.cpp +++ b/src/render/Lights.cpp @@ -11,6 +11,9 @@ RpLight *&pAmbient = *(RpLight**)0x885B6C; RpLight *&pDirect = *(RpLight**)0x880F7C; +RpLight **pExtraDirectionals = (RpLight**)0x60009C; +int *LightStrengths = (int*)0x87BEF0; +int &NumExtraDirLightsInWorld = *(int*)0x64C608; RwRGBAReal &AmbientLightColourForFrame = *(RwRGBAReal*)0x6F46F8; RwRGBAReal &AmbientLightColourForFrame_PedsCarsAndObjects = *(RwRGBAReal*)0x6F1D10; @@ -85,6 +88,151 @@ SetLightsWithTimeOfDayColour(RpWorld *) } } +RpWorld* +LightsCreate(RpWorld *world) +{ + int i; + RwRGBAReal color; + RwFrame *frame; + + if(world == nil) + return nil; + + pAmbient = RpLightCreate(rpLIGHTAMBIENT); + RpLightSetFlags(pAmbient, rpLIGHTLIGHTATOMICS); + color.red = 0.25f; + color.green = 0.25f; + color.blue = 0.2f; + RpLightSetColor(pAmbient, &color); + + pDirect = RpLightCreate(rpLIGHTDIRECTIONAL); + RpLightSetFlags(pDirect, rpLIGHTLIGHTATOMICS); + color.red = 1.0f; + color.green = 0.84f; + color.blue = 0.45f; + RpLightSetColor(pDirect, &color); + RpLightSetRadius(pDirect, 2.0f); + frame = RwFrameCreate(); + RpLightSetFrame(pDirect, frame); + RwV3d axis = { 1.0f, 1.0f, 0.0f }; + RwFrameRotate(frame, &axis, 160.0f, rwCOMBINEPRECONCAT); + + RpWorldAddLight(world, pAmbient); + RpWorldAddLight(world, pDirect); + + for(i = 0; i < NUMEXTRADIRECTIONALS; i++){ + pExtraDirectionals[i] = RpLightCreate(rpLIGHTDIRECTIONAL); + RpLightSetFlags(pExtraDirectionals[i], 0); + color.red = 1.0f; + color.green = 0.5f; + color.blue = 0.0f; + RpLightSetColor(pExtraDirectionals[i], &color); + RpLightSetRadius(pExtraDirectionals[i], 2.0f); + frame = RwFrameCreate(); + RpLightSetFrame(pExtraDirectionals[i], frame); + RpWorldAddLight(world, pExtraDirectionals[i]); + } + + return world; +} + +void +LightsDestroy(RpWorld *world) +{ + int i; + + if(world == nil) + return; + + if(pAmbient){ + RpWorldRemoveLight(world, pAmbient); + RpLightDestroy(pAmbient); + pAmbient = nil; + } + + if(pDirect){ + RpWorldRemoveLight(world, pDirect); + RwFrameDestroy(RpLightGetFrame(pDirect)); + RpLightDestroy(pDirect); + pDirect = nil; + } + + for(i = 0; i < NUMEXTRADIRECTIONALS; i++) + if(pExtraDirectionals[i]){ + RpWorldRemoveLight(world, pExtraDirectionals[i]); + RwFrameDestroy(RpLightGetFrame(pExtraDirectionals[i])); + RpLightDestroy(pExtraDirectionals[i]); + pExtraDirectionals[i] = nil; + } +} + +void +WorldReplaceNormalLightsWithScorched(RpWorld *world, float l) +{ + RwRGBAReal color; + color.red = l; + color.green = l; + color.blue = l; + RpLightSetColor(pAmbient, &color); + RpLightSetFlags(pDirect, 0); +} + +void +WorldReplaceScorchedLightsWithNormal(RpWorld *world) +{ + RpLightSetColor(pAmbient, &AmbientLightColourForFrame); + RpLightSetFlags(pDirect, rpLIGHTLIGHTATOMICS); +} + +void +AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, float red, float green, float blue) +{ + float strength; + int weakest; + int i, n; + RwRGBAReal color; + RwV3d *dir; + + strength = max(max(red, green), blue); + n = -1; + if(NumExtraDirLightsInWorld < NUMEXTRADIRECTIONALS) + n = NumExtraDirLightsInWorld; + else{ + weakest = strength; + for(i = 0; i < NUMEXTRADIRECTIONALS; i++) + if(LightStrengths[i] < weakest){ + weakest = LightStrengths[i]; + n = i; + } + } + + if(n < 0) + return; + + color.red = red; + color.green = green; + color.blue = blue; + RpLightSetColor(pExtraDirectionals[n], &color); + dir = RwMatrixGetAt(RwFrameGetMatrix(RpLightGetFrame(pExtraDirectionals[n]))); + dir->x = -dirx; + dir->y = -diry; + dir->z = -dirz; + RwMatrixUpdate(RwFrameGetMatrix(RpLightGetFrame(pExtraDirectionals[n]))); + RwFrameUpdateObjects(RpLightGetFrame(pExtraDirectionals[n])); + RpLightSetFlags(pExtraDirectionals[n], rpLIGHTLIGHTATOMICS); + LightStrengths[n] = strength; + NumExtraDirLightsInWorld = min(NumExtraDirLightsInWorld+1, NUMEXTRADIRECTIONALS); +} + +void +RemoveExtraDirectionalLights(RpWorld *world) +{ + int i; + for(i = 0; i < NumExtraDirLightsInWorld; i++) + RpLightSetFlags(pExtraDirectionals[i], 0); + NumExtraDirLightsInWorld = 0; +} + void SetAmbientAndDirectionalColours(float f) { @@ -159,13 +307,27 @@ SetAmbientColoursToIndicateRoadGroup(int i) RpLightSetColor(pAmbient, &AmbientLightColour); } +void +SetAmbientColours(RwRGBAReal *color) +{ + RpLightSetColor(pAmbient, color); +} + + STARTPATCHES InjectHook(0x526510, SetLightsWithTimeOfDayColour, PATCH_JUMP); + InjectHook(0x5269A0, LightsCreate, PATCH_JUMP); + InjectHook(0x526B40, LightsDestroy, PATCH_JUMP); + InjectHook(0x526C10, WorldReplaceNormalLightsWithScorched, PATCH_JUMP); + InjectHook(0x526C50, WorldReplaceScorchedLightsWithNormal, PATCH_JUMP); + InjectHook(0x526C70, AddAnExtraDirectionalLight, PATCH_JUMP); + InjectHook(0x526DB0, RemoveExtraDirectionalLights, PATCH_JUMP); InjectHook(0x526DE0, SetAmbientAndDirectionalColours, PATCH_JUMP); InjectHook(0x526E60, SetBrightMarkerColours, PATCH_JUMP); InjectHook(0x526F10, ReSetAmbientAndDirectionalColours, PATCH_JUMP); InjectHook(0x526F40, DeActivateDirectional, PATCH_JUMP); InjectHook(0x526F50, ActivateDirectional, PATCH_JUMP); - InjectHook(0x526F60, SetAmbientColours, PATCH_JUMP); + InjectHook(0x526F60, (void (*)(void))SetAmbientColours, PATCH_JUMP); InjectHook(0x526F80, SetAmbientColoursForPedsCarsAndObjects, PATCH_JUMP); + InjectHook(0x526FA0, (void (*)(RwRGBAReal*))SetAmbientColours, PATCH_JUMP); ENDPATCHES diff --git a/src/render/Lights.h b/src/render/Lights.h index ca926eb8..6fdd51de 100644 --- a/src/render/Lights.h +++ b/src/render/Lights.h @@ -1,4 +1,12 @@ +#pragma once + void SetLightsWithTimeOfDayColour(RpWorld *); +RpWorld *LightsCreate(RpWorld *world); +void LightsDestroy(RpWorld *world); +void WorldReplaceNormalLightsWithScorched(RpWorld *world, float l); +void WorldReplaceScorchedLightsWithNormal(RpWorld *world); +void AddAnExtraDirectionalLight(RpWorld *world, float dirx, float diry, float dirz, float red, float green, float blue); +void RemoveExtraDirectionalLights(RpWorld *world); void SetAmbientAndDirectionalColours(float f); void SetBrightMarkerColours(float f); void ReSetAmbientAndDirectionalColours(void); @@ -6,4 +14,5 @@ void DeActivateDirectional(void); void ActivateDirectional(void); void SetAmbientColours(void); void SetAmbientColoursForPedsCarsAndObjects(void); -void SetAmbientColoursToIndicateRoadGroup(int i);
\ No newline at end of file +void SetAmbientColoursToIndicateRoadGroup(int i); +void SetAmbientColours(RwRGBAReal *color); |