[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57702] trunk/blender/source/blender/gpu: Fix GLSL not showing shading properly on the backside of faces.
Daniel Stokes
kupomail at gmail.com
Fri Aug 2 02:27:55 CEST 2013
The BGE tracker has a bug report referencing this commit. It appears to
cause problems if users set custom normals:
[#36255] Inverted custom vertex
normal's<https://projects.blender.org/tracker/index.php?func=detail&aid=36255&group_id=9&atid=306>
I am not sure if there is a way we can detect if the user is already
controlling normals and not bother flipping them, or possibly adding a UI
option to toggle this flipping.
Regards,
Daniel Stokes
On Mon, Jun 24, 2013 at 6:46 AM, Brecht Van Lommel <
brechtvanlommel at pandora.be> wrote:
> Revision: 57702
>
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57702
> Author: blendix
> Date: 2013-06-24 13:46:34 +0000 (Mon, 24 Jun 2013)
> Log Message:
> -----------
> 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.
>
> Modified Paths:
> --------------
> trunk/blender/source/blender/gpu/intern/gpu_codegen.c
> trunk/blender/source/blender/gpu/shaders/gpu_shader_material.glsl
>
> Modified: trunk/blender/source/blender/gpu/intern/gpu_codegen.c
> ===================================================================
> --- trunk/blender/source/blender/gpu/intern/gpu_codegen.c 2013-06-24
> 13:45:35 UTC (rev 57701)
> +++ trunk/blender/source/blender/gpu/intern/gpu_codegen.c 2013-06-24
> 13:46:34 UTC (rev 57702)
> @@ -461,7 +461,7 @@
> 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 @@
> }
>
> BLI_dynstr_append(ds, "\n");
> +
> + return builtins;
> }
>
> static void codegen_declare_tmps(DynStr *ds, ListBase *nodes)
> @@ -564,8 +566,12 @@
> 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 @@
> {
> 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 @@
> 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);
>
>
> Modified: trunk/blender/source/blender/gpu/shaders/gpu_shader_material.glsl
> ===================================================================
> --- trunk/blender/source/blender/gpu/shaders/gpu_shader_material.glsl
> 2013-06-24 13:45:35 UTC (rev 57701)
> +++ trunk/blender/source/blender/gpu/shaders/gpu_shader_material.glsl
> 2013-06-24 13:46:34 UTC (rev 57702)
> @@ -147,7 +147,7 @@
> normal = -normalize(nor); /* blender render normal is
> negated */
> vcol_attribute(attvcol, vcol);
> vcol_alpha = attvcol.a;
> - frontback = 1.0;
> + frontback = (gl_FrontFacing)? 1.0: 0.0;
> }
>
> void mapping(vec3 vec, mat4 mat, vec3 minvec, vec3 maxvec, float domin,
> float domax, out vec3 outvec)
> @@ -2116,7 +2116,7 @@
> void node_fresnel(float ior, vec3 N, vec3 I, out float result)
> {
> float eta = max(ior, 0.00001);
> - result = fresnel_dielectric(I, N, eta); //backfacing() ? 1.0/eta:
> eta);
> + result = fresnel_dielectric(I, N, (gl_FrontFacing)? eta: 1.0/eta);
> }
>
> /* geometry */
> @@ -2139,7 +2139,7 @@
> true_normal = N;
> incoming = I;
> parametric = vec3(0.0);
> - backfacing = 0.0;
> + backfacing = (gl_FrontFacing)? 0.0: 1.0;
> }
>
> void node_tex_coord(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat,
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>
More information about the Bf-committers
mailing list