[Bf-blender-cvs] [e5462421c00] blender2.8: Eevee: Add support for common BSDFs.

Clément Foucault noreply at git.blender.org
Thu Jul 6 13:32:23 CEST 2017


Commit: e5462421c006929f4e88b27d38b3391d05163262
Author: Clément Foucault
Date:   Thu Jul 6 13:31:36 2017 +0200
Branches: blender2.8
https://developer.blender.org/rBe5462421c006929f4e88b27d38b3391d05163262

Eevee: Add support for common BSDFs.

Add Diffuse BSDF, and Glossy.

Also Use World normal instead of view normal as input.

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

M	source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c
M	source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c
M	source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c

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

diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
index 8bbdc57678c..c8fd57412ef 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -299,4 +299,179 @@ vec3 eevee_surface_clearcoat_lit(
 	out_light += diff_accum.rgb * albedo * gtao_multibounce(final_ao, albedo);
 
 	return out_light;
-}
\ No newline at end of file
+}
+
+/* ----------- Diffuse -----------  */
+
+vec3 eevee_surface_diffuse_lit(vec3 N, vec3 albedo, float ao)
+{
+	vec3 V = cameraVec;
+	N = normalize(N);
+
+	vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
+
+	/* ---------------- SCENE LAMPS LIGHTING ----------------- */
+
+#ifdef HAIR_SHADER
+	vec3 norm_view = cross(V, N);
+	norm_view = normalize(cross(norm_view, N)); /* Normal facing view */
+#endif
+
+	vec3 diff = vec3(0.0);
+	for (int i = 0; i < MAX_LIGHT && i < light_count; ++i) {
+		LightData ld = lights_data[i];
+
+		vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */
+		l_vector.xyz = ld.l_position - worldPosition;
+		l_vector.w = length(l_vector.xyz);
+
+		vec3 l_color_vis = ld.l_color * light_visibility(ld, worldPosition, l_vector);
+
+#ifdef HAIR_SHADER
+		vec3 norm_lamp, view_vec;
+		float occlu_trans, occlu;
+		light_hair_common(ld, N, V, l_vector, norm_view, occlu_trans, occlu, norm_lamp, view_vec);
+
+		diff += l_color_vis * light_diffuse(ld, -norm_lamp, V, l_vector) * occlu_trans;
+#else
+		diff += l_color_vis * light_diffuse(ld, N, V, l_vector);
+#endif
+	}
+
+	/* Accumulate outgoing radiance */
+	vec3 out_light = diff * albedo;
+
+#ifdef HAIR_SHADER
+	N = -norm_view;
+#endif
+
+	/* ---------------- DIFFUSE ENVIRONMENT LIGHTING ----------------- */
+
+	/* Ambient Occlusion */
+	vec3 bent_normal;
+	float final_ao = occlusion_compute(N, viewPosition, ao, rand.rg, bent_normal);
+
+	/* Accumulate light from all sources until accumulator is full. Then apply Occlusion and BRDF. */
+	vec4 diff_accum = vec4(0.0);
+
+	/* Start at 1 because 0 is world irradiance */
+	for (int i = 1; i < MAX_GRID && i < grid_count && diff_accum.a < 0.999; ++i) {
+		GridData gd = grids_data[i];
+
+		vec3 localpos;
+		float fade = probe_attenuation_grid(gd, worldPosition, localpos);
+
+		if (fade > 0.0) {
+			vec3 diff = probe_evaluate_grid(gd, worldPosition, bent_normal, localpos);
+			accumulate_light(diff, fade, diff_accum);
+		}
+	}
+
+	/* World Diffuse */
+	if (diff_accum.a < 0.999 && grid_count > 0) {
+		vec3 diff = probe_evaluate_world_diff(bent_normal);
+		accumulate_light(diff, 1.0, diff_accum);
+	}
+
+	out_light += diff_accum.rgb * albedo * gtao_multibounce(final_ao, albedo);
+
+	return out_light;
+}
+
+/* ----------- Glossy -----------  */
+
+vec3 eevee_surface_glossy_lit(vec3 N, vec3 f0, float roughness, float ao)
+{
+	roughness = clamp(roughness, 1e-8, 0.9999);
+	float roughnessSquared = roughness * roughness;
+
+	vec3 V = cameraVec;
+	N = normalize(N);
+
+	vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
+
+	/* ---------------- SCENE LAMPS LIGHTING ----------------- */
+
+#ifdef HAIR_SHADER
+	vec3 norm_view = cross(V, N);
+	norm_view = normalize(cross(norm_view, N)); /* Normal facing view */
+#endif
+
+	vec3 spec = vec3(0.0);
+	for (int i = 0; i < MAX_LIGHT && i < light_count; ++i) {
+		LightData ld = lights_data[i];
+
+		vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */
+		l_vector.xyz = ld.l_position - worldPosition;
+		l_vector.w = length(l_vector.xyz);
+
+		vec3 l_color_vis = ld.l_color * light_visibility(ld, worldPosition, l_vector);
+
+#ifdef HAIR_SHADER
+		vec3 norm_lamp, view_vec;
+		float occlu_trans, occlu;
+		light_hair_common(ld, N, V, l_vector, norm_view, occlu_trans, occlu, norm_lamp, view_vec);
+
+		spec += l_color_vis * light_specular(ld, N, view_vec, l_vector, roughnessSquared, f0) * occlu;
+#else
+		spec += l_color_vis * light_specular(ld, N, V, l_vector, roughnessSquared, f0);
+#endif
+	}
+
+	/* Accumulate outgoing radiance */
+	vec3 out_light = spec * float(specToggle);
+
+#ifdef HAIR_SHADER
+	N = -norm_view;
+#endif
+
+	/* ---------------- SPECULAR ENVIRONMENT LIGHTING ----------------- */
+
+	/* Accumulate light from all sources until accumulator is full. Then apply Occlusion and BRDF. */
+	vec4 spec_accum = vec4(0.0);
+
+	/* Planar Reflections */
+	for (int i = 0; i < MAX_PLANAR && i < planar_count && spec_accum.a < 0.999; ++i) {
+		PlanarData pd = planars_data[i];
+
+		float fade = probe_attenuation_planar(pd, worldPosition, N);
+
+		if (fade > 0.0) {
+			vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, rand.r, cameraPos, roughness, fade);
+			accumulate_light(spec, fade, spec_accum);
+		}
+	}
+
+	/* Specular probes */
+	vec3 spec_dir = get_specular_dominant_dir(N, V, roughnessSquared);
+
+	/* Starts at 1 because 0 is world probe */
+	for (int i = 1; i < MAX_PROBE && i < probe_count && spec_accum.a < 0.999; ++i) {
+		CubeData cd = probes_data[i];
+
+		float fade = probe_attenuation_cube(cd, worldPosition);
+
+		if (fade > 0.0) {
+			vec3 spec = probe_evaluate_cube(float(i), cd, worldPosition, spec_dir, roughness);
+			accumulate_light(spec, fade, spec_accum);
+		}
+	}
+
+	/* World Specular */
+	if (spec_accum.a < 0.999) {
+		vec3 spec = probe_evaluate_world_spec(spec_dir, roughness);
+		accumulate_light(spec, 1.0, spec_accum);
+	}
+
+	/* Ambient Occlusion */
+	vec3 bent_normal;
+	float final_ao = occlusion_compute(N, viewPosition, ao, rand.rg, bent_normal);
+
+	/* Get Brdf intensity */
+	vec2 uv = lut_coords(dot(N, V), roughness);
+	vec2 brdf_lut = texture(utilTex, vec3(uv, 1.0)).rg;
+
+	out_light += spec_accum.rgb * F_ibl(f0, brdf_lut) * specular_occlusion(dot(N, V), final_ao, roughness) * float(specToggle);
+
+	return out_light;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 7c320253cd3..e9f7fb338c9 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2661,6 +2661,9 @@ layout(std140) uniform lightSource {
 /* bsdfs */
 void node_bsdf_diffuse(vec4 color, float roughness, vec3 N, out Closure result)
 {
+#ifdef EEVEE_ENGINE
+	vec3 L = eevee_surface_diffuse_lit(N, vec3(1.0), 1.0);
+#else
 	/* ambient light */
 	vec3 L = vec3(0.2);
 
@@ -2672,15 +2675,21 @@ void node_bsdf_diffuse(vec4 color, float roughness, vec3 N, out Closure result)
 		float bsdf = max(dot(N, light_position), 0.0);
 		L += light_diffuse * bsdf;
 	}
+#endif
 
 	result = Closure(L * color.rgb, 1.0);
 }
 
 void node_bsdf_glossy(vec4 color, float roughness, vec3 N, out Closure result)
 {
+#ifdef EEVEE_ENGINE
+	vec3 L = eevee_surface_glossy_lit(N, vec3(1.0), roughness, 1.0);
+#else
 	/* ambient light */
 	vec3 L = vec3(0.2);
 
+	direction_transform_m4v3(N, ViewMatrix, N);
+
 	/* directional lights */
 	for (int i = 0; i < NUM_LIGHTS; i++) {
 		vec3 light_position = glLightSource[i].position.xyz;
@@ -2693,6 +2702,7 @@ void node_bsdf_glossy(vec4 color, float roughness, vec3 N, out Closure result)
 		bsdf += 0.5 * max(dot(N, light_position), 0.0);
 		L += light_specular * bsdf;
 	}
+#endif
 
 	result = Closure(L * color.rgb, 1.0);
 }
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c
index 01ca0bd6512..27dd4f5f58f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c
@@ -52,9 +52,7 @@ static void node_shader_init_anisotropic(bNodeTree *UNUSED(ntree), bNode *node)
 static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
 {
 	if (!in[4].link)
-		in[4].link = GPU_builtin(GPU_VIEW_NORMAL);
-	else
-		GPU_link(mat, "direction_transform_m4v3", in[4].link, GPU_builtin(GPU_VIEW_MATRIX), &in[4].link);
+		GPU_link(mat, "world_normals_get", &in[4].link);
 
 	return GPU_stack_link(mat, "node_bsdf_anisotropic", in, out);
 }
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c
index e86d2677a61..fdbf9307f5f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c
@@ -44,9 +44,7 @@ static bNodeSocketTemplate sh_node_bsdf_diffuse_out[] = {
 static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
 {
 	if (!in[2].link)
-		in[2].link = GPU_builtin(GPU_VIEW_NORMAL);
-	else
-		GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link);
+		GPU_link(mat, "world_normals_get", &in[2].link);
 
 	return GPU_stack_link(mat, "node_bsdf_diffuse", in, out);
 }
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c
index 5569fe85489..5bdbabc9182 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c
@@ -50,9 +50,7 @@ static void node_shader_init_glass(bNodeTree *UNUSED(ntree), bNode *node)
 static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
 {
 	if (!in[3].link)
-		in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
-	else
-		GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
+		GPU_link(mat, "world_normals_get", &in[3].link);
 
 	return GPU_stack_link(mat, "node_bsdf_glass", in, out);
 }
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c
index 7e1bc971c73..c89b56396ad 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c
@@ -49,9 +49,7 @@ static void node_shader_init_glossy(bNodeTree *UNUSED(ntree)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list