[Bf-blender-cvs] [e8dd5e5cc6b] blender2.8: GPUMaterial: Make Mapping node use UBO storage

Clément Foucault noreply at git.blender.org
Wed Aug 1 22:10:42 CEST 2018


Commit: e8dd5e5cc6b7366c36f19035f94864a1b320cb83
Author: Clément Foucault
Date:   Wed Aug 1 19:37:18 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBe8dd5e5cc6b7366c36f19035f94864a1b320cb83

GPUMaterial: Make Mapping node use UBO storage

This means tweaking parameter is now interactive and does not need to
recompile the shaders.

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

M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/nodes/shader/node_shader_util.c
M	source/blender/nodes/shader/nodes/node_shader_mapping.c

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

diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 8cc603696df..064ee42907e 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -238,13 +238,11 @@ void point_map_to_tube(vec3 vin, out vec3 vout)
 	vout = vec3(u, v, 0.0);
 }
 
-void mapping(vec3 vec, mat4 mat, vec3 minvec, vec3 maxvec, float domin, float domax, out vec3 outvec)
+void mapping(vec3 vec, vec4 m0, vec4 m1, vec4 m2, vec4 m3, vec3 minvec, vec3 maxvec, out vec3 outvec)
 {
+	mat4 mat = mat4(m0, m1, m2, m3);
 	outvec = (mat * vec4(vec, 1.0)).xyz;
-	if (domin == 1.0)
-		outvec = max(outvec, minvec);
-	if (domax == 1.0)
-		outvec = min(outvec, maxvec);
+	outvec = clamp(outvec, minvec, maxvec);
 }
 
 void camera(vec3 co, out vec3 outview, out float outdepth, out float outdist)
diff --git a/source/blender/nodes/shader/node_shader_util.c b/source/blender/nodes/shader/node_shader_util.c
index 9190f0d53cd..63c1cac566d 100644
--- a/source/blender/nodes/shader/node_shader_util.c
+++ b/source/blender/nodes/shader/node_shader_util.c
@@ -253,13 +253,18 @@ void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in
 	float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0;
 
 	if (domin || domax || !(texmap->flag & TEXMAP_UNIT_MATRIX)) {
-		GPUNodeLink *tmat = GPU_uniform((float *)texmap->mat);
-		GPUNodeLink *tmin = GPU_uniform(texmap->min);
-		GPUNodeLink *tmax = GPU_uniform(texmap->max);
-		GPUNodeLink *tdomin = GPU_uniform(&domin);
-		GPUNodeLink *tdomax = GPU_uniform(&domax);
-
-		GPU_link(mat, "mapping", in[0].link, tmat, tmin, tmax, tdomin, tdomax, &in[0].link);
+		static float max[3] = { FLT_MAX,  FLT_MAX,  FLT_MAX};
+		static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX};
+		GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3;
+
+		tmin = GPU_uniform_buffer((domin) ? texmap->min : min, GPU_VEC3);
+		tmax = GPU_uniform_buffer((domax) ? texmap->max : max, GPU_VEC3);
+		tmat0 = GPU_uniform_buffer((float *)texmap->mat[0], GPU_VEC4);
+		tmat1 = GPU_uniform_buffer((float *)texmap->mat[1], GPU_VEC4);
+		tmat2 = GPU_uniform_buffer((float *)texmap->mat[2], GPU_VEC4);
+		tmat3 = GPU_uniform_buffer((float *)texmap->mat[3], GPU_VEC4);
+
+		GPU_link(mat, "mapping", in[0].link, tmat0, tmat1, tmat2, tmat3, tmin, tmax, &in[0].link);
 
 		if (texmap->type == TEXMAP_TYPE_NORMAL)
 			GPU_link(mat, "texco_norm", in[0].link, &in[0].link);
diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c
index a84e88e9551..2541b3bc842 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mapping.c
+++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c
@@ -88,13 +88,18 @@ static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
 	TexMapping *texmap = node->storage;
 	float domin = (texmap->flag & TEXMAP_CLIP_MIN) != 0;
 	float domax = (texmap->flag & TEXMAP_CLIP_MAX) != 0;
-	GPUNodeLink *tmat = GPU_uniform((float *)texmap->mat);
-	GPUNodeLink *tmin = GPU_uniform(texmap->min);
-	GPUNodeLink *tmax = GPU_uniform(texmap->max);
-	GPUNodeLink *tdomin = GPU_uniform(&domin);
-	GPUNodeLink *tdomax = GPU_uniform(&domax);
-
-	GPU_stack_link(mat, node, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
+	static float max[3] = { FLT_MAX,  FLT_MAX,  FLT_MAX, 0.0};
+	static float min[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX, 0.0};
+	GPUNodeLink *tmin, *tmax, *tmat0, *tmat1, *tmat2, *tmat3;
+
+	tmin = GPU_uniform_buffer((domin) ? texmap->min : min, GPU_VEC3);
+	tmax = GPU_uniform_buffer((domax) ? texmap->max : max, GPU_VEC3);
+	tmat0 = GPU_uniform_buffer((float *)texmap->mat[0], GPU_VEC4);
+	tmat1 = GPU_uniform_buffer((float *)texmap->mat[1], GPU_VEC4);
+	tmat2 = GPU_uniform_buffer((float *)texmap->mat[2], GPU_VEC4);
+	tmat3 = GPU_uniform_buffer((float *)texmap->mat[3], GPU_VEC4);
+
+	GPU_stack_link(mat, node, "mapping", in, out, tmat0, tmat1, tmat2, tmat3, tmin, tmax);
 
 	if (texmap->type == TEXMAP_TYPE_NORMAL)
 		GPU_link(mat, "texco_norm", out[0].link, &out[0].link);



More information about the Bf-blender-cvs mailing list