[Bf-blender-cvs] [d0af56fe3b6] master: Cycles: antialias normal baking if the mesh has a bump map.

Brecht Van Lommel noreply at git.blender.org
Wed Nov 8 00:02:42 CET 2017


Commit: d0af56fe3b6490445ba3e501b0fb98cfec622aa3
Author: Brecht Van Lommel
Date:   Mon Oct 30 17:19:37 2017 +0100
Branches: master
https://developer.blender.org/rBd0af56fe3b6490445ba3e501b0fb98cfec622aa3

Cycles: antialias normal baking if the mesh has a bump map.

===================================================================

M	intern/cycles/kernel/kernel_bake.h
M	intern/cycles/render/bake.cpp
M	intern/cycles/render/bake.h

===================================================================

diff --git a/intern/cycles/kernel/kernel_bake.h b/intern/cycles/kernel/kernel_bake.h
index 9ce10358b81..5cb32545c6e 100644
--- a/intern/cycles/kernel/kernel_bake.h
+++ b/intern/cycles/kernel/kernel_bake.h
@@ -172,17 +172,6 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg,
 	path_radiance_accum_sample(L, &L_sample);
 }
 
-ccl_device bool is_aa_pass(ShaderEvalType type)
-{
-	switch(type) {
-		case SHADER_EVAL_UV:
-		case SHADER_EVAL_NORMAL:
-			return false;
-		default:
-			return true;
-	}
-}
-
 /* this helps with AA but it's not the real solution as it does not AA the geometry
  *  but it's better than nothing, thus committed */
 ccl_device_inline float bake_clamp_mirror_repeat(float u, float max)
@@ -485,10 +474,10 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
 	}
 
 	/* write output */
-	const float output_fac = is_aa_pass(type)? 1.0f/num_samples: 1.0f;
+	const float output_fac = 1.0f/num_samples;
 	const float4 scaled_result = make_float4(out.x, out.y, out.z, 1.0f) * output_fac;
 
-	output[i] = (sample == 0)?  scaled_result: output[i] + scaled_result;
+	output[i] = (sample == 0)? scaled_result: output[i] + scaled_result;
 }
 
 #endif  /* __BAKING__ */
diff --git a/intern/cycles/render/bake.cpp b/intern/cycles/render/bake.cpp
index bae72e67410..aeb5d1c1316 100644
--- a/intern/cycles/render/bake.cpp
+++ b/intern/cycles/render/bake.cpp
@@ -15,8 +15,13 @@
  */
 
 #include "render/bake.h"
+#include "render/mesh.h"
+#include "render/object.h"
+#include "render/shader.h"
 #include "render/integrator.h"
 
+#include "util/util_foreach.h"
+
 CCL_NAMESPACE_BEGIN
 
 BakeData::BakeData(const int object, const size_t tri_offset, const size_t num_pixels):
@@ -135,7 +140,7 @@ bool BakeManager::bake(Device *device, DeviceScene *dscene, Scene *scene, Progre
 {
 	size_t num_pixels = bake_data->size();
 
-	int num_samples = is_aa_pass(shader_type)? scene->integrator->aa_samples : 1;
+	int num_samples = aa_samples(scene, bake_data, shader_type);
 
 	/* calculate the total pixel samples for the progress bar */
 	total_pixel_samples = 0;
@@ -239,14 +244,27 @@ void BakeManager::device_free(Device * /*device*/, DeviceScene * /*dscene*/)
 {
 }
 
-bool BakeManager::is_aa_pass(ShaderEvalType type)
+int BakeManager::aa_samples(Scene *scene, BakeData *bake_data, ShaderEvalType type)
 {
-	switch(type) {
-		case SHADER_EVAL_UV:
-		case SHADER_EVAL_NORMAL:
-			return false;
-		default:
-			return true;
+	if(type == SHADER_EVAL_UV) {
+		return 1;
+	}
+	else if(type == SHADER_EVAL_NORMAL) {
+		/* Only antialias normal if mesh has bump mapping. */
+		Object *object = scene->objects[bake_data->object()];
+
+		if(object->mesh) {
+			foreach(Shader *shader, object->mesh->used_shaders) {
+				if(shader->has_bump) {
+					return scene->integrator->aa_samples;
+				}
+			}
+		}
+
+		return 1;
+	}
+	else {
+		return scene->integrator->aa_samples;
 	}
 }
 
diff --git a/intern/cycles/render/bake.h b/intern/cycles/render/bake.h
index ceb94cfb682..fbb8686b8f6 100644
--- a/intern/cycles/render/bake.h
+++ b/intern/cycles/render/bake.h
@@ -69,7 +69,7 @@ public:
 	void device_free(Device *device, DeviceScene *dscene);
 
 	static int shader_type_to_pass_filter(ShaderEvalType type, const int pass_filter);
-	static bool is_aa_pass(ShaderEvalType type);
+	static int aa_samples(Scene *scene, BakeData *bake_data, ShaderEvalType type);
 
 	bool need_update;



More information about the Bf-blender-cvs mailing list