[Bf-blender-cvs] [d4eb28a] master: BI Viewport(GLSL): support for envmap in Texture node

Alexander Romanov noreply at git.blender.org
Mon Jul 4 10:22:18 CEST 2016


Commit: d4eb28ab7e486dad0d16e363f3576b19630a0aa4
Author: Alexander Romanov
Date:   Mon Jul 4 11:19:13 2016 +0300
Branches: master
https://developer.blender.org/rBd4eb28ab7e486dad0d16e363f3576b19630a0aa4

BI Viewport(GLSL): support for envmap in Texture node

This patch is another step to achieve BI and it's Viewport consistency for cubemap textures.
{F318879}

To test world_space_shading flag D2072 is required.

Alexander (Blend4Web Team)

Reviewers: campbellbarton, brecht

Subscribers: homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov

Differential Revision: https://developer.blender.org/D2074

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

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

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

diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 02e9ba1..f3bd817 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -1358,6 +1358,13 @@ void mtex_cube_map(vec3 co, samplerCube ima, out float value, out vec4 color)
 	value = 1.0;
 }
 
+void mtex_cube_map_refl_from_refldir(
+        samplerCube ima, vec3 reflecteddirection, out float value, out vec4 color)
+{
+        color = textureCube(ima, reflecteddirection);
+        value = 1.0;
+}
+
 void mtex_cube_map_refl(
         samplerCube ima, vec3 vp, vec3 vn, mat4 viewmatrixinverse, mat4 viewmatrix,
         out float value, out vec4 color)
diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c
index 6edf6c2..b0b25a4 100644
--- a/source/blender/nodes/shader/nodes/node_shader_texture.c
+++ b/source/blender/nodes/shader/nodes/node_shader_texture.c
@@ -33,6 +33,8 @@
 
 #include "node_shader_util.h"
 
+#include "GPU_material.h"
+
 /* **************** TEXTURE ******************** */
 static bNodeSocketTemplate sh_node_texture_in[] = {
 	{	SOCK_VECTOR, 1, "Vector",	0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},	/* no limit */
@@ -121,9 +123,20 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
 {
 	Tex *tex = (Tex *)node->id;
 
-	if (tex && tex->type == TEX_IMAGE && tex->ima) {
-		GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false);
-		GPU_stack_link(mat, "texture_image", in, out, texlink);
+	if (tex && tex->ima && (tex->type == TEX_IMAGE || tex->type == TEX_ENVMAP)) {
+		if (tex->type == TEX_IMAGE) {
+			GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false);
+			GPU_stack_link(mat, "texture_image", in, out, texlink);
+		}
+		else { /* TEX_ENVMAP */
+			if (!in[0].link)
+				in[0].link = GPU_uniform(in[0].vec);
+			if (!GPU_material_use_world_space_shading(mat))
+				GPU_link(mat, "direction_transform_m4v3", in[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[0].link);
+			GPU_link(mat, "mtex_cube_map_refl_from_refldir",
+				GPU_cube_map(tex->ima, &tex->iuser, false), in[0].link, &out[0].link, &out[1].link);
+			GPU_link(mat, "color_to_normal", out[1].link, &out[2].link);
+		}
 
 		ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL);
 		if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&




More information about the Bf-blender-cvs mailing list