Change the behavior of AO pass in Blender internal's shader/render node tree so that...
authorIrie Shinsuke <irieshinsuke@yahoo.co.jp>
Tue, 12 Nov 2013 10:59:40 +0000 (10:59 +0000)
committerIrie Shinsuke <irieshinsuke@yahoo.co.jp>
Tue, 12 Nov 2013 10:59:40 +0000 (10:59 +0000)
For materials using AO pass, this makes the material preview and the GLSL
preview more accurate, but shouldn't affect final rendering in most cases
because we usually enable AO when using the AO pass in node tree.

Thanks to Brecht for code review.

source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/nodes/shader/nodes/node_shader_material.c
source/blender/render/intern/source/shadeoutput.c

index 78664f3b539a45330a8dde0bd4101e3febc9f8fb..5e5fac3049c31df5a83c4551bedde1b4d95f54c4 100644 (file)
@@ -393,11 +393,21 @@ void set_rgb_zero(out vec3 outval)
        outval = vec3(0.0);
 }
 
+void set_rgb_one(out vec3 outval)
+{
+       outval = vec3(1.0);
+}
+
 void set_rgba_zero(out vec4 outval)
 {
        outval = vec4(0.0);
 }
 
+void set_rgba_one(out vec4 outval)
+{
+       outval = vec4(1.0);
+}
+
 void brightness_contrast(vec4 col, float brightness, float contrast, out vec4 outcol)
 {
        float a = 1.0 + contrast;
index 4200f515a80c095923c9f190c1e05f14ef02041c..820e0f479be348bbf164c1990bf2f3e5720bb308 100644 (file)
@@ -299,6 +299,7 @@ static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNU
                if (node->type == SH_NODE_MATERIAL_EXT) {
                        out[MAT_OUT_DIFFUSE].link = shr.diff;
                        out[MAT_OUT_SPEC].link = shr.spec;
+                       GPU_link(mat, "set_rgb_one", &out[MAT_OUT_AO].link);
                }
 
                return 1;
index 114961394c41d7afabfd42775c930e7f6c639aa5..dbc9c47446f257e6196c0ee0d2815e392a7fdb43 100644 (file)
@@ -1789,18 +1789,20 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
        }
        
        /* AO pass */
-       if (R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) {
-               if (((passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) ||
-                   (passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))
-               {
-                       if (R.r.mode & R_SHADOW) {
-                               /* AO was calculated for scanline already */
-                               if (shi->depth || shi->volume_depth)
-                                       ambient_occlusion(shi);
-                               copy_v3_v3(shr->ao, shi->ao);
-                               copy_v3_v3(shr->env, shi->env); /* XXX multiply */
-                               copy_v3_v3(shr->indirect, shi->indirect); /* XXX multiply */
-                       }
+       if (((passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) ||
+           (passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) {
+               if ((R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && (R.r.mode & R_SHADOW)) {
+                       /* AO was calculated for scanline already */
+                       if (shi->depth || shi->volume_depth)
+                               ambient_occlusion(shi);
+                       copy_v3_v3(shr->ao, shi->ao);
+                       copy_v3_v3(shr->env, shi->env); /* XXX multiply */
+                       copy_v3_v3(shr->indirect, shi->indirect); /* XXX multiply */
+               }
+               else {
+                       shr->ao[0]= shr->ao[1]= shr->ao[2]= 1.0f;
+                       zero_v3(shr->env);
+                       zero_v3(shr->indirect);
                }
        }