improve shading mode define picker

main
Dominik Madarász 2024-08-24 19:40:02 +02:00
parent 33eecb039b
commit fff2db7ea5
4 changed files with 42 additions and 23 deletions

View File

@ -72,26 +72,6 @@ vec3 shading_light(light_t l, material_t m) {
return vec3(0,0,0); 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 #ifdef SHADING_PBR
vec3 radiance = l.diffuse * BOOST_LIGHTING; vec3 radiance = l.diffuse * BOOST_LIGHTING;
vec3 V = normalize( v_to_camera ); 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 ) ); float NdotL = max( 0., dot( N, L ) );
return ( kD * ( m.albedo / PI ) + specular ) * radiance * NdotL * attenuation; 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 #endif
} }

View File

@ -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"); 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 // rebind shader
// @fixme: app crashes rn // @fixme: app crashes rn
// glUseProgram(0); // 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 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, 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", "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; m->program = shaderprog;
model_init_uniforms(m); model_init_uniforms(m);
} }

View File

@ -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"); 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 // rebind shader
// @fixme: app crashes rn // @fixme: app crashes rn
// glUseProgram(0); // 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 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, 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", "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; m->program = shaderprog;
model_init_uniforms(m); model_init_uniforms(m);
} }

View File

@ -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"); 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 // rebind shader
// @fixme: app crashes rn // @fixme: app crashes rn
// glUseProgram(0); // 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 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, 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", "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; m->program = shaderprog;
model_init_uniforms(m); model_init_uniforms(m);
} }