diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 9 | ||||
-rw-r--r-- | source/blender/gpu/GPU_material.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/GPU_shader_interface.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 30 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_interface.c | 1 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 24 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_tex_coord.c | 2 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_tex_image.c | 9 |
10 files changed, 34 insertions, 51 deletions
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index c2d89819c58..4d74a95bf20 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -104,7 +104,6 @@ enum { DRW_CALL_MODELVIEWINVERSE = (1 << 2), DRW_CALL_MODELVIEWPROJECTION = (1 << 3), DRW_CALL_NORMALVIEW = (1 << 4), - DRW_CALL_NORMALVIEWINVERSE = (1 << 5), DRW_CALL_NORMALWORLD = (1 << 6), DRW_CALL_ORCOTEXFAC = (1 << 7), DRW_CALL_OBJECTINFO = (1 << 8), @@ -127,7 +126,6 @@ typedef struct DRWCallState { float modelviewinverse[4][4]; float modelviewprojection[4][4]; float normalview[3][3]; - float normalviewinverse[3][3]; float normalworld[3][3]; /* Not view dependent */ float orcotexfac[2][3]; /* Not view dependent */ float objectinfo[2]; @@ -260,7 +258,6 @@ struct DRWShadingGroup { int modelviewinverse; int modelviewprojection; int normalview; - int normalviewinverse; int normalworld; int orcotexfac; int callid; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index 003a89307b2..b7225275d72 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -838,7 +838,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) shgroup->modelviewinverse = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW_INV); shgroup->modelviewprojection = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MVP); shgroup->normalview = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_NORMAL); - shgroup->normalviewinverse = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_NORMAL_INV); shgroup->normalworld = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_WORLDNORMAL); shgroup->orcotexfac = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_ORCO); shgroup->objectinfo = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_OBJECT_INFO); @@ -860,9 +859,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) if (shgroup->normalview > -1) { shgroup->matflag |= DRW_CALL_NORMALVIEW; } - if (shgroup->normalviewinverse > -1) { - shgroup->matflag |= DRW_CALL_NORMALVIEWINVERSE; - } if (shgroup->normalworld > -1) { shgroup->matflag |= DRW_CALL_NORMALWORLD; } diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 2c35d718f1f..f98c2cb1025 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -801,14 +801,11 @@ static void draw_matrices_model_prepare(DRWCallState *st) if (st->matflag & DRW_CALL_MODELVIEWPROJECTION) { mul_m4_m4m4(st->modelviewprojection, DST.view_data.matstate.mat[DRW_MAT_PERS], st->model); } - if (st->matflag & (DRW_CALL_NORMALVIEW | DRW_CALL_NORMALVIEWINVERSE)) { + if (st->matflag & (DRW_CALL_NORMALVIEW)) { copy_m3_m4(st->normalview, st->modelview); invert_m3(st->normalview); transpose_m3(st->normalview); } - if (st->matflag & (DRW_CALL_NORMALVIEWINVERSE)) { - invert_m3_m3(st->normalviewinverse, st->normalview); - } /* Non view dependent */ if (st->matflag & DRW_CALL_NORMALWORLD) { copy_m3_m4(st->normalworld, st->model); @@ -850,10 +847,6 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call) GPU_shader_uniform_vector( shgroup->shader, shgroup->normalview, 9, 1, (float *)state->normalview); } - if (shgroup->normalviewinverse != -1) { - GPU_shader_uniform_vector( - shgroup->shader, shgroup->normalviewinverse, 9, 1, (float *)state->normalviewinverse); - } if (shgroup->normalworld != -1) { GPU_shader_uniform_vector( shgroup->shader, shgroup->normalworld, 9, 1, (float *)state->normalworld); diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index da61dc76422..1640209c717 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -107,7 +107,7 @@ typedef enum eGPUBuiltin { GPU_VOLUME_TEMPERATURE = (1 << 18), GPU_BARYCENTRIC_TEXCO = (1 << 19), GPU_BARYCENTRIC_DIST = (1 << 20), - GPU_INVERSE_NORMAL_MATRIX = (1 << 21), + GPU_WORLD_NORMAL = (1 << 21), } eGPUBuiltin; typedef enum eGPUMatFlag { diff --git a/source/blender/gpu/GPU_shader_interface.h b/source/blender/gpu/GPU_shader_interface.h index 563868311c2..1b10de45cee 100644 --- a/source/blender/gpu/GPU_shader_interface.h +++ b/source/blender/gpu/GPU_shader_interface.h @@ -45,7 +45,6 @@ typedef enum { GPU_UNIFORM_VIEWPROJECTION_INV, /* mat4 ViewProjectionMatrixInverse */ GPU_UNIFORM_NORMAL, /* mat3 NormalMatrix */ - GPU_UNIFORM_NORMAL_INV, /* mat3 NormalMatrixInverse */ GPU_UNIFORM_WORLDNORMAL, /* mat3 WorldNormalMatrix */ GPU_UNIFORM_CAMERATEXCO, /* vec4 CameraTexCoFactors */ GPU_UNIFORM_ORCO, /* vec3 OrcoTexCoFactors[] */ diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index a77bba5ab86..310c57fdbee 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -520,9 +520,6 @@ const char *GPU_builtin_name(eGPUBuiltin builtin) else if (builtin == GPU_INVERSE_OBJECT_MATRIX) { return "unfinvobmat"; } - else if (builtin == GPU_INVERSE_NORMAL_MATRIX) { - return "unfinvnormat"; - } else if (builtin == GPU_LOC_TO_VIEW_MATRIX) { return "unflocaltoviewmat"; } @@ -532,6 +529,9 @@ const char *GPU_builtin_name(eGPUBuiltin builtin) else if (builtin == GPU_VIEW_POSITION) { return "varposition"; } + else if (builtin == GPU_WORLD_NORMAL) { + return "varwnormal"; + } else if (builtin == GPU_VIEW_NORMAL) { return "varnormal"; } @@ -786,15 +786,15 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final else if (input->builtin == GPU_INVERSE_OBJECT_MATRIX) { BLI_dynstr_append(ds, "objinv"); } - else if (input->builtin == GPU_INVERSE_NORMAL_MATRIX) { - BLI_dynstr_append(ds, "norinv"); - } else if (input->builtin == GPU_VIEW_POSITION) { BLI_dynstr_append(ds, "viewposition"); } else if (input->builtin == GPU_VIEW_NORMAL) { BLI_dynstr_append(ds, "facingnormal"); } + else if (input->builtin == GPU_WORLD_NORMAL) { + BLI_dynstr_append(ds, "facingwnormal"); + } else { BLI_dynstr_append(ds, GPU_builtin_name(input->builtin)); } @@ -879,9 +879,6 @@ static char *code_generate_fragment(GPUMaterial *material, if (builtins & GPU_INVERSE_OBJECT_MATRIX) { BLI_dynstr_append(ds, "\t#define objinv ModelMatrixInverse\n"); } - if (builtins & GPU_INVERSE_NORMAL_MATRIX) { - BLI_dynstr_append(ds, "\t#define norinv NormalMatrixInverse\n"); - } if (builtins & GPU_INVERSE_VIEW_MATRIX) { BLI_dynstr_append(ds, "\t#define viewinv ViewMatrixInverse\n"); } @@ -897,9 +894,22 @@ static char *code_generate_fragment(GPUMaterial *material, BLI_dynstr_append(ds, "\tworld_normals_get(n);\n"); BLI_dynstr_append(ds, "\tvec3 facingnormal = transform_direction(ViewMatrix, n);\n"); BLI_dynstr_append(ds, "#else\n"); - BLI_dynstr_append(ds, "\tvec3 facingnormal = gl_FrontFacing? viewNormal: -viewNormal;\n"); + BLI_dynstr_append(ds, "\tvec3 facingnormal = gl_FrontFacing ? viewNormal: -viewNormal;\n"); BLI_dynstr_append(ds, "#endif\n"); } + if (builtins & GPU_WORLD_NORMAL) { + BLI_dynstr_append(ds, "\tvec3 facingwnormal;\n"); + if (builtins & GPU_VIEW_NORMAL) { + BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n"); + BLI_dynstr_append(ds, "\tfacingwnormal = n;\n"); + BLI_dynstr_append(ds, "#else\n"); + BLI_dynstr_append(ds, "\tworld_normals_get(facingwnormal);\n"); + BLI_dynstr_append(ds, "#endif\n"); + } + else { + BLI_dynstr_append(ds, "\tworld_normals_get(facingwnormal);\n"); + } + } if (builtins & GPU_VIEW_POSITION) { BLI_dynstr_append(ds, "\t#define viewposition viewPosition\n"); } diff --git a/source/blender/gpu/intern/gpu_shader_interface.c b/source/blender/gpu/intern/gpu_shader_interface.c index 1c9e9e42bcc..207a218b5d1 100644 --- a/source/blender/gpu/intern/gpu_shader_interface.c +++ b/source/blender/gpu/intern/gpu_shader_interface.c @@ -61,7 +61,6 @@ static const char *BuiltinUniform_name(GPUUniformBuiltin u) [GPU_UNIFORM_VIEWPROJECTION_INV] = "ViewProjectionMatrixInverse", [GPU_UNIFORM_NORMAL] = "NormalMatrix", - [GPU_UNIFORM_NORMAL_INV] = "NormalMatrixInverse", [GPU_UNIFORM_WORLDNORMAL] = "WorldNormalMatrix", [GPU_UNIFORM_CAMERATEXCO] = "CameraTexCoFactors", [GPU_UNIFORM_ORCO] = "OrcoTexCoFactors", diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 1cbf58f9d16..ca05a9b6238 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2,7 +2,6 @@ uniform mat4 ModelViewMatrix; uniform mat4 ModelViewMatrixInverse; uniform mat3 NormalMatrix; -uniform mat3 NormalMatrixInverse; #ifndef USE_ATTR uniform mat4 ModelMatrix; @@ -204,9 +203,9 @@ void direction_transform_m4v3(vec3 vin, mat4 mat, out vec3 vout) vout = (mat * vec4(vin, 0.0)).xyz; } -void mat3_mul(vec3 vin, mat3 mat, out vec3 vout) +void normal_transform_transposed_m4v3(vec3 vin, mat4 mat, out vec3 vout) { - vout = mat * vin; + vout = transpose(mat3(mat)) * vin; } void point_transform_m4v3(vec3 vin, mat4 mat, out vec3 vout) @@ -2092,9 +2091,7 @@ void generated_texco(vec3 I, vec3 attr_orco, out vec3 generated) } void node_tex_coord(vec3 I, - vec3 N, - mat4 viewinvmat, - mat4 obinvmat, + vec3 wN, vec4 camerafac, vec3 attr_orco, vec3 attr_uv, @@ -2107,22 +2104,17 @@ void node_tex_coord(vec3 I, out vec3 reflection) { generated = attr_orco; - normal = normalize(NormalMatrixInverse * N); + normal = normalize(transform_normal_world_to_object(wN)); uv = attr_uv; - object = (obinvmat * (viewinvmat * vec4(I, 1.0))).xyz; + object = transform_point_view_to_object(I); camera = vec3(I.xy, -I.z); vec4 projvec = ProjectionMatrix * vec4(I, 1.0); window = vec3(mtex_2d_mapping(projvec.xyz / projvec.w).xy * camerafac.xy + camerafac.zw, 0.0); - - vec3 shade_I = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0); - vec3 view_reflection = reflect(shade_I, normalize(N)); - reflection = (viewinvmat * vec4(view_reflection, 0.0)).xyz; + reflection = reflect(cameraVec, normalize(wN)); } void node_tex_coord_background(vec3 I, vec3 N, - mat4 viewinvmat, - mat4 obinvmat, vec4 camerafac, vec3 attr_orco, vec3 attr_uv, @@ -2141,11 +2133,7 @@ void node_tex_coord_background(vec3 I, co = normalize(co); -#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE) vec3 coords = (ViewMatrixInverse * co).xyz; -#else - vec3 coords = (ModelViewMatrixInverse * co).xyz; -#endif generated = coords; normal = -coords; diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c index fd62e8ce960..eed53f5c286 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c @@ -60,7 +60,7 @@ static int node_shader_gpu_tex_coord(GPUMaterial *mat, in, out, GPU_builtin(GPU_VIEW_POSITION), - GPU_builtin(GPU_VIEW_NORMAL), + GPU_builtin(GPU_WORLD_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), inv_obmat, GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index 91d58bc41d0..109690cf423 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -111,7 +111,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, } GPUNodeLink *norm, *col1, *col2, *col3, *input_coords, *gpu_image; - GPUNodeLink *vnor, *nor_mat_inv, *blend; + GPUNodeLink *vnor, *ob_mat, *blend; GPUNodeLink **texco = &in[0].link; int isdata = tex->color_space == SHD_COLORSPACE_NONE; @@ -146,12 +146,13 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, break; case SHD_PROJ_BOX: - vnor = GPU_builtin(GPU_VIEW_NORMAL); - nor_mat_inv = GPU_builtin(GPU_INVERSE_NORMAL_MATRIX); + vnor = GPU_builtin(GPU_WORLD_NORMAL); + ob_mat = GPU_builtin(GPU_OBJECT_MATRIX); blend = GPU_uniform(&tex->projection_blend); gpu_image = GPU_image(ima, iuser, isdata); - GPU_link(mat, "mat3_mul", vnor, nor_mat_inv, &norm); + /* equivalent to transform_normal_world_to_object */ + GPU_link(mat, "normal_transform_transposed_m4v3", vnor, ob_mat, &norm); GPU_link( mat, gpu_node_name, *texco, norm, GPU_image(ima, iuser, isdata), &col1, &col2, &col3); if (do_color_correction) { |