diff --git a/engine/art/shaderlib/light.glsl b/engine/art/shaderlib/light.glsl index dcdecc0..cf9f66a 100644 --- a/engine/art/shaderlib/light.glsl +++ b/engine/art/shaderlib/light.glsl @@ -72,26 +72,6 @@ vec3 shading_light(light_t l, material_t m) { return vec3(0,0,0); } -#ifdef SHADING_PHONG - vec3 n = normalize(v_normal_ws); - - float diffuse = max(dot(n, lightDir), 0.0); - - vec3 halfVec = normalize(lightDir + u_cam_dir); - float specular = pow(max(dot(n, halfVec), 0.0), l.power); - - return (attenuation*l.ambient + diffuse*attenuation*l.diffuse + specular*attenuation*l.specular); -#endif -#ifdef SHADING_VERTEXLIT - vec3 n = normalize(v_normal_ws); - - float diffuse = max(dot(n, lightDir), 0.0); - - vec3 halfVec = normalize(lightDir + u_cam_dir); - float specular = pow(max(dot(n, halfVec), 0.0), l.power); - - return (attenuation*l.ambient + diffuse*attenuation*l.diffuse + specular*attenuation*l.specular); -#endif #ifdef SHADING_PBR vec3 radiance = l.diffuse * BOOST_LIGHTING; vec3 V = normalize( v_to_camera ); @@ -118,6 +98,15 @@ vec3 shading_light(light_t l, material_t m) { float NdotL = max( 0., dot( N, L ) ); return ( kD * ( m.albedo / PI ) + specular ) * radiance * NdotL * attenuation; +#else + vec3 n = normalize(v_normal_ws); + + float diffuse = max(dot(n, lightDir), 0.0); + + vec3 halfVec = normalize(lightDir + u_cam_dir); + float specular = pow(max(dot(n, halfVec), 0.0), l.power); + + return (attenuation*l.ambient + diffuse*attenuation*l.diffuse + specular*attenuation*l.specular); #endif } diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 6a7ee79..886c86a 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -386336,6 +386336,16 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f fs = vfs_read("shaders/fs_32_4_model.glsl"); } + /* needs to match SHADING_MODE */ + const char *shading_defines[] = { + "SHADING_NONE", + "SHADING_PHONG", + "SHADING_VERTEXLIT", + "SHADING_PBR", + }; + + const char *shading_define = shading_defines[shading]; + // rebind shader // @fixme: app crashes rn // glUseProgram(0); @@ -386343,7 +386353,7 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs, "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", - va("%s,%s,%s", defines ? defines : "NO_CUSTOM_DEFINES", shading == SHADING_PBR ? "SHADING_PBR" : shading == SHADING_VERTEXLIT ? "SHADING_VERTEXLIT" : "SHADING_PHONG", (flags&MODEL_RIMLIGHT)?"RIM":"")); + va("%s,%s,%s", defines ? defines : "NO_CUSTOM_DEFINES", shading_define, (flags&MODEL_RIMLIGHT)?"RIM":"")); m->program = shaderprog; model_init_uniforms(m); } diff --git a/engine/split/v4k_render.c b/engine/split/v4k_render.c index e7e2f4b..2a6c2e3 100644 --- a/engine/split/v4k_render.c +++ b/engine/split/v4k_render.c @@ -4679,6 +4679,16 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f fs = vfs_read("shaders/fs_32_4_model.glsl"); } + /* needs to match SHADING_MODE */ + const char *shading_defines[] = { + "SHADING_NONE", + "SHADING_PHONG", + "SHADING_VERTEXLIT", + "SHADING_PBR", + }; + + const char *shading_define = shading_defines[shading]; + // rebind shader // @fixme: app crashes rn // glUseProgram(0); @@ -4686,7 +4696,7 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs, "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", - va("%s,%s,%s", defines ? defines : "NO_CUSTOM_DEFINES", shading == SHADING_PBR ? "SHADING_PBR" : shading == SHADING_VERTEXLIT ? "SHADING_VERTEXLIT" : "SHADING_PHONG", (flags&MODEL_RIMLIGHT)?"RIM":"")); + va("%s,%s,%s", defines ? defines : "NO_CUSTOM_DEFINES", shading_define, (flags&MODEL_RIMLIGHT)?"RIM":"")); m->program = shaderprog; model_init_uniforms(m); } diff --git a/engine/v4k.c b/engine/v4k.c index 235916a..bb062aa 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -21478,6 +21478,16 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f fs = vfs_read("shaders/fs_32_4_model.glsl"); } + /* needs to match SHADING_MODE */ + const char *shading_defines[] = { + "SHADING_NONE", + "SHADING_PHONG", + "SHADING_VERTEXLIT", + "SHADING_PBR", + }; + + const char *shading_define = shading_defines[shading]; + // rebind shader // @fixme: app crashes rn // glUseProgram(0); @@ -21485,7 +21495,7 @@ void model_shading_custom(model_t *m, int shading, const char *vs, const char *f const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM int shaderprog = shader(strlerp(1,symbols,vs), strlerp(1,symbols,fs), //fs, "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", - va("%s,%s,%s", defines ? defines : "NO_CUSTOM_DEFINES", shading == SHADING_PBR ? "SHADING_PBR" : shading == SHADING_VERTEXLIT ? "SHADING_VERTEXLIT" : "SHADING_PHONG", (flags&MODEL_RIMLIGHT)?"RIM":"")); + va("%s,%s,%s", defines ? defines : "NO_CUSTOM_DEFINES", shading_define, (flags&MODEL_RIMLIGHT)?"RIM":"")); m->program = shaderprog; model_init_uniforms(m); }