diff --git a/demos/03-anims.c b/demos/03-anims.c index 103113e..b07dab6 100644 --- a/demos/03-anims.c +++ b/demos/03-anims.c @@ -25,6 +25,10 @@ int main() { model_t mdl = model("Stan.fbx", MODEL_RIMLIGHT); anims_t a = animations("Stan.fbx", 0); + // shader_bind(mdl.program); + // shader_vec3("u_rimcolor", vec3(0.12,0.23,0.34)); + // shader_vec3("u_rimrange", vec3(0.06,0.74,0.5)); + // load all postfx files in all subdirs fx_load("fx**.fs"); @@ -133,6 +137,19 @@ int main() { } ui_panel_end(); } + if ( ui_panel("Rim lighting", 0) ) { + static vec3 rimcolor = {0.2,0.2,0.2}; + static vec3 rimrange = {0.11,0.98,0.5}; + ui_color3f("Color", &rimcolor.x); + ui_clampf("Low", &rimrange.x, 0, 1); + ui_clampf("High", &rimrange.y, 0, 1); + ui_clampf("Mix", &rimrange.z, 0, 1); + // ui_vec + shader_bind(mdl.program); + shader_vec3("u_rimcolor", rimcolor); + shader_vec3("u_rimrange", rimrange); + ui_panel_end(); + } if( ui_panel("FX", 0) ) { for( int i = 0; i < 64; ++i ) { char *name = fx_name(i); if( !name ) break; diff --git a/engine/art/shaders/fs_32_4_model.glsl b/engine/art/shaders/fs_32_4_model.glsl index c877a59..1cb5843 100644 --- a/engine/art/shaders/fs_32_4_model.glsl +++ b/engine/art/shaders/fs_32_4_model.glsl @@ -11,6 +11,8 @@ in vec3 v_position; uniform mat4 M; // RIM uniform vec3 u_rimcolor = vec3(0.2,0.2,0.2); uniform vec3 u_rimrange = vec3(0.11,0.98,0.5); +uniform vec3 u_rimpivot = vec3(0,0,0); +uniform bool u_rimambient = true; #endif in vec3 v_normal, v_normal_ws; in vec2 v_texcoord; @@ -68,7 +70,10 @@ if(u_matcaps) { #ifdef RIM {vec3 n = normalize(mat3(M) * v_normal); // convert normal to view space vec3 p = (M * vec4(v_position,1.0)).xyz; // convert position to view space - vec3 v = normalize(vpeye.xyz-p); // eye vector + vec3 v = vec3(0,-1,0); + if (!u_rimambient) { + v = normalize(u_rimpivot-p); + } float rim = 1.0 - max(dot(v,n), 0.0); vec3 col = u_rimcolor*(pow(smoothstep(1.0-u_rimrange.x,u_rimrange.y,rim), u_rimrange.z)); fragcolor += vec4(col, 1.0);} diff --git a/engine/art/shaders/vs_323444143_16_332_model.glsl b/engine/art/shaders/vs_323444143_16_332_model.glsl index 9dcebfd..88284a9 100644 --- a/engine/art/shaders/vs_323444143_16_332_model.glsl +++ b/engine/art/shaders/vs_323444143_16_332_model.glsl @@ -96,19 +96,19 @@ void main() { if(!SKINNED) { objPos = att_position; v_normal = att_normal; - } else { - mat3x4 m = vsBoneMatrix[int(att_indexes.x)] * att_weights.x; - m += vsBoneMatrix[int(att_indexes.y)] * att_weights.y; - m += vsBoneMatrix[int(att_indexes.z)] * att_weights.z; - m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w; - objPos = vec4(att_position, 1.0) * m; - - // blendshapes - // objPos += evaluate_blend_shape(int(att_vertexindex)); - - v_normal = vec4(att_normal, 0.0) * m; - //@todo: tangents - } + } else { + mat3x4 m = vsBoneMatrix[int(att_indexes.x)] * att_weights.x; + m += vsBoneMatrix[int(att_indexes.y)] * att_weights.y; + m += vsBoneMatrix[int(att_indexes.z)] * att_weights.z; + m += vsBoneMatrix[int(att_indexes.w)] * att_weights.w; + objPos = vec4(att_position, 1.0) * m; + + // blendshapes + // objPos += evaluate_blend_shape(int(att_vertexindex)); + + v_normal = vec4(att_normal, 0.0) * m; + //@todo: tangents + } // vec3 tangent = att_tangent.xyz; // vec3 bitangent = cross(att_normal, att_tangent.xyz) * att_tangent.w; diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index b3bf388..b346172 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -344064,6 +344064,7 @@ void model_destroy(model_t m) { anims_t animations(const char *pathfile, int flags) { anims_t a = {0}; char *anim_file = vfs_read(va("%s@animlist.txt", pathfile)); + if (!anim_file) return a; for each_substring(anim_file, "\r\n", anim) { int from, to; char anim_name[128] = {0}; diff --git a/engine/split/v4k_render.c b/engine/split/v4k_render.c index 0379055..de5a11e 100644 --- a/engine/split/v4k_render.c +++ b/engine/split/v4k_render.c @@ -4498,6 +4498,7 @@ void model_destroy(model_t m) { anims_t animations(const char *pathfile, int flags) { anims_t a = {0}; char *anim_file = vfs_read(va("%s@animlist.txt", pathfile)); + if (!anim_file) return a; for each_substring(anim_file, "\r\n", anim) { int from, to; char anim_name[128] = {0}; diff --git a/engine/v4k.c b/engine/v4k.c index 724d5e1..98840a1 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -14762,6 +14762,7 @@ void model_destroy(model_t m) { anims_t animations(const char *pathfile, int flags) { anims_t a = {0}; char *anim_file = vfs_read(va("%s@animlist.txt", pathfile)); + if (!anim_file) return a; for each_substring(anim_file, "\r\n", anim) { int from, to; char anim_name[128] = {0};