Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2013-06-24 17:46:34 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2013-06-24 17:46:34 +0400
commit553dd71efbd69e15157d1b69cc5d4deb628ba7b0 (patch)
treec603dd12ef8a7c9173b782579500a4165a46d722 /source
parent1a55b53375cf45481e3916d9d3a96c7ce4204e73 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c19
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl6
2 files changed, 18 insertions, 7 deletions
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);
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index c095d803f48..2aee5b4846a 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -147,7 +147,7 @@ void geom(vec3 co, vec3 nor, mat4 viewinvmat, vec3 attorco, vec2 attuv, vec4 att
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_add_shader(vec4 shader1, vec4 shader2, out vec4 shader)
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 @@ void node_geometry(vec3 I, vec3 N, mat4 toworld,
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,