Skip to content

Commit

Permalink
Add cvar r_studio_viewmodel_lightdir_adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Dec 30, 2023
1 parent 1379514 commit 6218d8e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
66 changes: 64 additions & 2 deletions Plugins/Renderer/gl_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,8 @@ bool LoadImageGenericRGBA8(const char *filename, byte* buf, size_t bufSize, FIBI
return true;
}

#if 0

bool LoadImageGenericRGB8(const char* filename, byte* buf, size_t bufSize, FIBITMAP* fiB, gl_loadtexture_state_t* state)
{
size_t pos = 0;
Expand Down Expand Up @@ -2158,6 +2160,8 @@ bool LoadImageGenericRGB8(const char* filename, byte* buf, size_t bufSize, FIBIT
return true;
}

#endif

bool LoadImagePaletteRGBA8(const char* filename, byte* buf, size_t bufSize, FIBITMAP* fiB, gl_loadtexture_state_t* state)
{
size_t pos = 0;
Expand Down Expand Up @@ -2197,6 +2201,8 @@ bool LoadImagePaletteRGBA8(const char* filename, byte* buf, size_t bufSize, FIBI
return true;
}

#if 0

bool LoadImagePaletteRGB8(const char* filename, byte* buf, size_t bufSize, FIBITMAP* fiB, gl_loadtexture_state_t* state)
{
size_t pos = 0;
Expand Down Expand Up @@ -2236,6 +2242,8 @@ bool LoadImagePaletteRGB8(const char* filename, byte* buf, size_t bufSize, FIBIT
return true;
}

#endif

bool LoadImageGeneric(const char *filename, const char* pathId, byte *buf, size_t bufSize, gl_loadtexture_state_t *state, bool throw_warning_on_missing)
{
FileHandle_t fileHandle = FILESYSTEM_ANY_OPEN(filename, "rb", pathId);
Expand Down Expand Up @@ -2328,14 +2336,34 @@ bool LoadImageGeneric(const char *filename, const char* pathId, byte *buf, size_

if (colorType == FIC_RGBALPHA)
{
if (!LoadImageGenericRGBA8(filename, buf, bufSize, scopedBitmap.get(), state))
FIBITMAP* fiB32 = FreeImage_ConvertTo32Bits(scopedBitmap.get());

if (!fiB32)
{
gEngfuncs.Con_Printf("LoadImageGeneric: Could not load %s, FreeImage_ConvertTo32Bits failed.\n", filename);
return false;
}

CScopedFIBitmap scopedBitmap32(fiB32);

if (!LoadImageGenericRGBA8(filename, buf, bufSize, scopedBitmap32.get(), state))
{
return false;
}
}
else if (colorType == FIC_RGB)
{
if (!LoadImageGenericRGBA8(filename, buf, bufSize, scopedBitmap.get(), state))
FIBITMAP* fiB24 = FreeImage_ConvertTo24Bits(scopedBitmap.get());

if (!fiB24)
{
gEngfuncs.Con_Printf("LoadImageGeneric: Could not load %s, FreeImage_ConvertTo24Bits failed.\n", filename);
return false;
}

CScopedFIBitmap scopedBitmap24(fiB24);

if (!LoadImageGenericRGBA8(filename, buf, bufSize, scopedBitmap24.get(), state))
{
return false;
}
Expand Down Expand Up @@ -2518,6 +2546,8 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
(const char*)texloader_buffer, state.width, state.height,
hardwareFilter, true);

(*currenttexture) = -1;
GL_Bind(textureId);
GL_UploadCompressedTexture(&state);

bLoaded = true;
Expand All @@ -2528,6 +2558,8 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
(const char *)texloader_buffer, state.width, state.height,
hardwareFilter, true);

(*currenttexture) = -1;
GL_Bind(textureId);
GL_UploadCompressedTexture(&state);

bLoaded = true;
Expand All @@ -2546,13 +2578,23 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);

//(*currenttexture) = -1;
//GL_Bind(textureId);
//GL_UploadUncompressedTexture(&state);

bLoaded = true;
}
if (!bLoaded && LoadImageGeneric(filepath, NULL, texloader_buffer, sizeof(texloader_buffer), &state, false) && state.mipmaps.size() > 0)
{
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);

//(*currenttexture) = -1;
//GL_Bind(textureId);
//GL_UploadUncompressedTexture(&state);

bLoaded = true;
}
}
Expand All @@ -2569,13 +2611,23 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);

//(*currenttexture) = -1;
//GL_Bind(textureId);
//GL_UploadUncompressedTexture(&state);

bLoaded = true;
}
if (!bLoaded && LoadImageGeneric(filepath, NULL, texloader_buffer, sizeof(texloader_buffer), &state, false) && state.mipmaps.size() > 0)
{
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);

//(*currenttexture) = -1;
//GL_Bind(textureId);
//GL_UploadUncompressedTexture(&state);

bLoaded = true;
}
}
Expand All @@ -2592,13 +2644,23 @@ void __fastcall enginesurface_drawSetTextureFile(void* pthis, int dummy, int tex
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);

//(*currenttexture) = -1;
//GL_Bind(textureId);
//GL_UploadUncompressedTexture(&state);

bLoaded = true;
}
if (!bLoaded && LoadImageGeneric(filepath, NULL, texloader_buffer, sizeof(texloader_buffer), &state, false) && state.mipmaps.size() > 0)
{
gPrivateFuncs.enginesurface_drawSetTextureRGBA(pthis, dummy, textureId,
(const char*)state.mipmaps[0].data, state.mipmaps[0].width, state.mipmaps[0].height,
hardwareFilter, true);

//(*currenttexture) = -1;
//GL_Bind(textureId);
//GL_UploadUncompressedTexture(&state);

bLoaded = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ void R_FillAddress(void)
{
auto pString = (PCHAR)pinst->detail->x86.operands[0].imm;
if (!memcmp(pString, "Failed to query GL vendor", sizeof("Failed to query GL vendor") - 1) ||
!memcmp(pString, "Failed to query gl vendor", sizeof("Failed to query gl vendor") - 1) ||
!memcmp(pString, "GL_VENDOR: %s", sizeof("GL_VENDOR: %s") - 1))
{
ctx->bFoundPushString = true;
Expand Down
17 changes: 11 additions & 6 deletions Plugins/Renderer/gl_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ cvar_t* r_studio_debug = NULL;
MapConVar* r_studio_base_specular = NULL;
MapConVar* r_studio_celshade_specular = NULL;

cvar_t* r_studio_viewmodel_lightdir_adjust = NULL;

cvar_t* r_studio_celshade = NULL;
cvar_t* r_studio_celshade_midpoint = NULL;
cvar_t* r_studio_celshade_softness = NULL;
Expand Down Expand Up @@ -656,7 +658,6 @@ void R_UseStudioProgram(program_state_t state, studio_program_t* progOutput)
SHADER_UNIFORM(prog, r_hair_shadow_offset, "r_hair_shadow_offset");
SHADER_UNIFORM(prog, r_outline_dark, "r_outline_dark");
SHADER_UNIFORM(prog, r_uvscale, "r_uvscale");
SHADER_UNIFORM(prog, entityPos, "entityPos");
}

g_StudioProgramTable[state] = prog;
Expand All @@ -670,11 +671,6 @@ void R_UseStudioProgram(program_state_t state, studio_program_t* progOutput)
{
GL_UseProgram(prog.program);

if (prog.entityPos != -1)
{
glUniform3f(prog.entityPos, (*rotationmatrix)[0][3], (*rotationmatrix)[1][3], (*rotationmatrix)[2][3]);
}

if (prog.r_base_specular != -1)
{
vec4_t values = { 0 };
Expand Down Expand Up @@ -1097,6 +1093,8 @@ void R_InitStudio(void)
{
r_studio_debug = gEngfuncs.pfnRegisterVariable("r_studio_debug", "0", FCVAR_CLIENTDLL);

r_studio_viewmodel_lightdir_adjust = gEngfuncs.pfnRegisterVariable("r_studio_viewmodel_lightdir_adjust", "0", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);

r_studio_celshade = gEngfuncs.pfnRegisterVariable("r_studio_celshade", "1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_studio_celshade_midpoint = gEngfuncs.pfnRegisterVariable("r_studio_celshade_midpoint", "-0.1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_studio_celshade_softness = gEngfuncs.pfnRegisterVariable("r_studio_celshade_softness", "0.05", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
Expand Down Expand Up @@ -1657,6 +1655,13 @@ void R_StudioDrawVBOBegin(studio_vbo_t* VBOData)

memcpy(StudioUBO.r_plightvec, r_plightvec, sizeof(vec3_t));

if (r_draw_drawviewmodel && r_studio_viewmodel_lightdir_adjust->value > 0)
{
StudioUBO.r_plightvec[2] = StudioUBO.r_plightvec[2] * clamp(r_studio_viewmodel_lightdir_adjust->value, 0, 1);

VectorNormalize(StudioUBO.r_plightvec);
}

vec3_t entity_origin = { (*rotationmatrix)[0][3], (*rotationmatrix)[1][3], (*rotationmatrix)[2][3] };
memcpy(StudioUBO.entity_origin, entity_origin, sizeof(vec3_t));

Expand Down
1 change: 0 additions & 1 deletion Plugins/Renderer/gl_studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ typedef struct
int r_hair_specular_smooth;
int r_hair_shadow_offset;
int r_uvscale;
int entityPos;
}studio_program_t;

typedef struct studio_vbo_vertex_s
Expand Down
3 changes: 2 additions & 1 deletion scripts/build-MetaHook-blob.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
"%InstallDir%\Common7\Tools\vsdevcmd.bat"

MSBuild.exe MetaHook.sln "/target:MetaHook" /p:Configuration="Release_blob" /p:Platform="Win32"
)
)

1 change: 0 additions & 1 deletion src/MetaHook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
<LargeAddressAware>true</LargeAddressAware>
<AdditionalLibraryDirectories>$(CapstoneLibrariesDirectory)</AdditionalLibraryDirectories>
<AdditionalDependencies>$(CapstoneLibraryFiles);ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
<PostBuildEvent>
<Command>$(ExePostBuildCommand)</Command>
Expand Down

0 comments on commit 6218d8e

Please sign in to comment.