Fix T47288 Vector transform not behaving correctly with camera space and cycles
authorAlexander Romanov <a.romanov@blend4web.com>
Mon, 1 Feb 2016 15:46:32 +0000 (18:46 +0300)
committerAlexander Romanov <a.romanov@blend4web.com>
Mon, 1 Feb 2016 15:46:32 +0000 (18:46 +0300)
source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/nodes/shader/nodes/node_shader_vectTransform.c

index c8ce9f7a229d9b74cdae1f259a1647de4a0470c9..4429770f998a4668285bf725e2e68696363a518b 100644 (file)
@@ -384,6 +384,12 @@ void vec_math_negate(vec3 v, out vec3 outv)
        outv = -v;
 }
 
+void invert_z(vec3 v, out vec3 outv)
+{
+        v.z = -v.z;
+        outv = v;
+}
+
 void normal(vec3 dir, vec3 nor, out vec3 outnor, out float outdot)
 {
        outnor = nor;
index d31a175b9b45d74ea4c91aeac026232d581dbbcc..35a12d52b2d236c2cb1af86579750f37601e21ef 100644 (file)
@@ -163,6 +163,8 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat
        const char *ptransform = "point_transform_m4v3";
        const char *func_name = 0;
 
+       bool new_shading = GPU_material_use_new_shading_nodes(mat);
+
        NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage;
 
        if (in[0].hasinput)
@@ -173,8 +175,22 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat
        fromto = get_gpulink_matrix_from_to(nodeprop->convert_from, nodeprop->convert_to);
 
        func_name = (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) ? ptransform : vtransform;
-       if (fromto)
-               ret = GPU_link(mat, func_name, inputlink, fromto,  &out[0].link);
+       if (fromto) {
+               if (new_shading) {
+                       /* For cycles we have inverted Z */
+                       /* TODO: pass here the correct matrices */
+                       if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
+                               ret = GPU_link(mat, "invert_z", inputlink, &inputlink);
+                       }
+                       ret = GPU_link(mat, func_name, inputlink, fromto,  &out[0].link);
+                       if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
+                               ret = GPU_link(mat, "invert_z", out[0].link, &out[0].link);
+                       }
+               }
+               else {
+                       ret = GPU_link(mat, func_name, inputlink, fromto,  &out[0].link);
+               }
+       }
        else
                ret = GPU_link(mat, "set_rgb", inputlink,  &out[0].link);