From 7ae7b7507a98081114748feef5374e1fcae750ee Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Wed, 8 Apr 2026 17:09:25 +0900 Subject: [PATCH] several fixes after ages --- client/main.c | 2 +- engine/data/shader/shadow.fs | 7 ++++++- engine/include/GearSrc/GL.h | 1 + engine/include/GearSrc/TypeDefs.h | 1 + engine/src/client.c | 6 ++++++ engine/src/gl/gl_shadow.c | 15 +++++++++++++++ engine/src/model.c | 6 +++--- 7 files changed, 33 insertions(+), 5 deletions(-) diff --git a/client/main.c b/client/main.c index 2f717db..2bc1d4e 100644 --- a/client/main.c +++ b/client/main.c @@ -104,7 +104,7 @@ int main(int argc, char** argv){ GSVector3 pos = {0, 1, 0}; GSVector3 sz = {1, 1, 1}; - mdl = GSModelOpen(engine, "game:/mdl/tetopear.gsm"); + mdl = GSModelOpen(engine, "game:/mdl/crate.gsm"); for(i = 0; i < sizeof(obj) / sizeof(obj[0]); i++){ obj[i] = GSPhysicsCreateSphere(GSServerGetPhysics(GSEngineGetServer(engine)), 1, 0.5); diff --git a/engine/data/shader/shadow.fs b/engine/data/shader/shadow.fs index 2acc948..5d1894c 100644 --- a/engine/data/shader/shadow.fs +++ b/engine/data/shader/shadow.fs @@ -13,6 +13,7 @@ uniform sampler2D shadow_map2; uniform sampler2D current_texture; uniform float enable_lighting; uniform float enable_texture; +uniform float enable_shadow; uniform vec3 camera; vec4 PhongShading(void) @@ -83,7 +84,11 @@ float ShadowCoef(void){ void main(void){ vec4 c = PhongShading(); vec4 ambient = gl_LightSource[0].ambient; - float shadow_coef = ShadowCoef(); + float shadow_coef = 1.0; + + if(enable_shadow >= 0.5){ + shadow_coef = ShadowCoef(); + } if(enable_texture >= 0.5){ c = c * texture2D(current_texture, gl_TexCoord[0].st); diff --git a/engine/include/GearSrc/GL.h b/engine/include/GearSrc/GL.h index 360eab4..7c9cb4c 100644 --- a/engine/include/GearSrc/GL.h +++ b/engine/include/GearSrc/GL.h @@ -46,6 +46,7 @@ GSDECL void GSGLShadowDeinit(GSGL gl); GSDECL void GSGLShadowDisable(GSGL gl); GSDECL void GSGLShadowEnable(GSGL gl); GSDECL int GSGLShadowCascadeSteps(GSGL gl); +GSDECL void GSGLShadowRender(GSGL gl, int toggle); /* gl.c */ GSDECL GSGL GSGLCreate(GSClient client); diff --git a/engine/include/GearSrc/TypeDefs.h b/engine/include/GearSrc/TypeDefs.h index 1a29497..090f842 100644 --- a/engine/include/GearSrc/TypeDefs.h +++ b/engine/include/GearSrc/TypeDefs.h @@ -212,6 +212,7 @@ struct _GSGL { GSNumber frustum_clip[16]; GSBool bold; + GSBool shadow; }; struct _GSSkyBox { diff --git a/engine/src/client.c b/engine/src/client.c index 959a3d9..8d8088f 100644 --- a/engine/src/client.c +++ b/engine/src/client.c @@ -132,6 +132,7 @@ void GSClientStep(GSClient client) { GSGLTextBold(client->gl, 0); +#ifdef SHADOW if(GSGLShadowBegin(client->gl)) { int c; for(c = 0; c < GSGLShadowCascadeSteps(client->gl); c++) { @@ -141,12 +142,17 @@ void GSClientStep(GSClient client) { } GSGLShadowApply(client->gl); } +#else + GSGLShadowRender(client->gl, 0); +#endif if(client->skybox_enabled) { if(client->skybox != NULL) GSSkyBoxDraw(client->skybox); } scene(client); +#ifdef SHADOW GSGLShadowEnd(client->gl); +#endif GSVersionGet(&ver); diff --git a/engine/src/gl/gl_shadow.c b/engine/src/gl/gl_shadow.c index e4549b9..e11076d 100644 --- a/engine/src/gl/gl_shadow.c +++ b/engine/src/gl/gl_shadow.c @@ -40,6 +40,7 @@ void GSGLShadowInit(GSGL gl) { glUniform1i(glGetUniformLocation(gl->shadow_shader, "current_texture"), 0); glUniform1f(glGetUniformLocation(gl->shadow_shader, "enable_lighting"), 1); glUniform1f(glGetUniformLocation(gl->shadow_shader, "enable_texture"), 0); + glUniform1f(glGetUniformLocation(gl->shadow_shader, "enable_shadow"), 1); glUseProgram(0); gl->shadow_use_shader = 1; @@ -48,6 +49,8 @@ void GSGLShadowInit(GSGL gl) { gl->shadow_use_shader = 0; } + + gl->shadow = GSFalse; } GSBool GSGLShadowBegin(GSGL gl) { @@ -207,6 +210,8 @@ void GSGLShadowDisable(GSGL gl) { } glActiveTexture(GL_TEXTURE0); } + + gl->shadow = GSFalse; } void GSGLShadowEnable(GSGL gl) { @@ -222,6 +227,16 @@ void GSGLShadowEnable(GSGL gl) { } glActiveTexture(GL_TEXTURE0); } + + gl->shadow = GSTrue; +} + +void GSGLShadowRender(GSGL gl, int toggle){ + if(gl->shadow_use_shader){ + if(!gl->shadow) glUseProgram(gl->shadow_shader); + glUniform1f(glGetUniformLocation(gl->shadow_shader, "enable_shadow"), toggle); + if(!gl->shadow) glUseProgram(0); + } } void GSGLShadowEnd(GSGL gl) { diff --git a/engine/src/model.c b/engine/src/model.c index 4f2e787..ed7f2d6 100644 --- a/engine/src/model.c +++ b/engine/src/model.c @@ -171,9 +171,9 @@ static void parse_obj(GSModel model, char* txt) { if(l < bud) l = bud; if(l < bbf) l = bbf; - model->bbox[0][0] = l; - model->bbox[0][1] = l; - model->bbox[0][2] = l; + model->bbox[0][0] = -l * 2; + model->bbox[0][1] = -l * 2; + model->bbox[0][2] = -l * 2; model->bbox[1][0] = -model->bbox[0][0]; model->bbox[1][1] = -model->bbox[0][1];