From 553dd71efbd69e15157d1b69cc5d4deb628ba7b0 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 24 Jun 2013 13:46:34 +0000 Subject: Fix GLSL not showing shading properly on the backside of faces. Now it flips the normal towards the viewer, seems to give consistent results with blender internal, cycles, normal maps, etc. Started from patch #32761 by Vitor Balbio, but changed it to do normal flipping earlier so it solves all cases. --- source/blender/gpu/intern/gpu_codegen.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'source/blender/gpu/intern/gpu_codegen.c') diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 39cae4f01ce..f9e1babcb56 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -461,7 +461,7 @@ static void codegen_set_unique_ids(ListBase *nodes) BLI_ghash_free(definehash, NULL, NULL); } -static void codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes) +static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes) { GPUNode *node; GPUInput *input; @@ -516,6 +516,8 @@ static void codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes) } BLI_dynstr_append(ds, "\n"); + + return builtins; } static void codegen_declare_tmps(DynStr *ds, ListBase *nodes) @@ -564,8 +566,12 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final codegen_convert_datatype(ds, input->link->output->type, input->type, "tmp", input->link->output->id); } - else if (input->source == GPU_SOURCE_BUILTIN) - BLI_dynstr_appendf(ds, "%s", GPU_builtin_name(input->builtin)); + else if (input->source == GPU_SOURCE_BUILTIN) { + if(input->builtin == GPU_VIEW_NORMAL) + BLI_dynstr_append(ds, "facingnormal"); + else + BLI_dynstr_append(ds, GPU_builtin_name(input->builtin)); + } else if (input->source == GPU_SOURCE_VEC_UNIFORM) { if (input->dynamicvec) BLI_dynstr_appendf(ds, "unf%d", input->id); @@ -596,11 +602,12 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, const ch { DynStr *ds = BLI_dynstr_new(); char *code; + int builtins; /*BLI_dynstr_append(ds, FUNCTION_PROTOTYPES);*/ codegen_set_unique_ids(nodes); - codegen_print_uniforms_functions(ds, nodes); + builtins = codegen_print_uniforms_functions(ds, nodes); //if (G.debug & G_DEBUG) // BLI_dynstr_appendf(ds, "/* %s */\n", name); @@ -608,6 +615,10 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, const ch BLI_dynstr_append(ds, "void main(void)\n"); BLI_dynstr_append(ds, "{\n"); + if(builtins & GPU_VIEW_NORMAL) + BLI_dynstr_append(ds, "\tvec3 facingnormal = (gl_FrontFacing)? varnormal: -varnormal;\n"); + + codegen_declare_tmps(ds, nodes); codegen_call_functions(ds, nodes, output); -- cgit v1.2.3