GPUMaterial: Fix regressions concerning background texco
This commit is contained in:
parent
2a0c91b70c
commit
c47926542a
|
@ -160,6 +160,7 @@ struct DRWInterface {
|
|||
int viewprojectioninverse;
|
||||
int normal;
|
||||
int worldnormal;
|
||||
int camtexfac;
|
||||
int eye;
|
||||
/* Dynamic batch */
|
||||
GLuint instance_vbo;
|
||||
|
@ -528,6 +529,7 @@ static DRWInterface *DRW_interface_create(GPUShader *shader)
|
|||
interface->modelviewprojection = GPU_shader_get_uniform(shader, "ModelViewProjectionMatrix");
|
||||
interface->normal = GPU_shader_get_uniform(shader, "NormalMatrix");
|
||||
interface->worldnormal = GPU_shader_get_uniform(shader, "WorldNormalMatrix");
|
||||
interface->camtexfac = GPU_shader_get_uniform(shader, "CameraTexCoFactors");
|
||||
interface->eye = GPU_shader_get_uniform(shader, "eye");
|
||||
interface->instance_count = 0;
|
||||
interface->attribs_count = 0;
|
||||
|
@ -1369,6 +1371,9 @@ static void draw_geometry(DRWShadingGroup *shgroup, Batch *geom, const float (*o
|
|||
if (interface->worldnormal != -1) {
|
||||
GPU_shader_uniform_vector(shgroup->shader, interface->worldnormal, 9, 1, (float *)wn);
|
||||
}
|
||||
if (interface->camtexfac != -1) {
|
||||
GPU_shader_uniform_vector(shgroup->shader, interface->camtexfac, 4, 1, (float *)rv3d->viewcamtexcofac);
|
||||
}
|
||||
if (interface->eye != -1) {
|
||||
GPU_shader_uniform_vector(shgroup->shader, interface->eye, 3, 1, (float *)eye);
|
||||
}
|
||||
|
|
|
@ -624,6 +624,8 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
|
|||
else if (input->source == GPU_SOURCE_BUILTIN) {
|
||||
if (input->builtin == GPU_INVERSE_VIEW_MATRIX)
|
||||
BLI_dynstr_append(ds, "viewinv");
|
||||
else if (input->builtin == GPU_CAMERA_TEXCO_FACTORS)
|
||||
BLI_dynstr_append(ds, "camtexfac");
|
||||
else if (input->builtin == GPU_INVERSE_OBJECT_MATRIX)
|
||||
BLI_dynstr_append(ds, "objinv");
|
||||
else if (input->builtin == GPU_VIEW_POSITION)
|
||||
|
@ -693,6 +695,8 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, bool use
|
|||
BLI_dynstr_append(ds, "void main()\n{\n");
|
||||
|
||||
if (use_new_shading) {
|
||||
if (builtins & GPU_CAMERA_TEXCO_FACTORS)
|
||||
BLI_dynstr_append(ds, "\tvec4 camtexfac = CameraTexCoFactors;\n");
|
||||
if (builtins & GPU_INVERSE_OBJECT_MATRIX)
|
||||
BLI_dynstr_append(ds, "\tmat4 objinv = ModelMatrixInverse;\n");
|
||||
if (builtins & GPU_INVERSE_VIEW_MATRIX)
|
||||
|
@ -701,9 +705,10 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, bool use
|
|||
BLI_dynstr_append(ds, "\tvec3 facingnormal = gl_FrontFacing? viewNormal: -viewNormal;\n");
|
||||
if (builtins & GPU_VIEW_POSITION)
|
||||
BLI_dynstr_append(ds, "\tvec3 viewposition = viewPosition;\n");
|
||||
|
||||
}
|
||||
else {
|
||||
if (builtins & GPU_CAMERA_TEXCO_FACTORS)
|
||||
BLI_dynstr_append(ds, "\tvec4 camtexfac = unfcameratexfactors;\n");
|
||||
if (builtins & GPU_INVERSE_OBJECT_MATRIX)
|
||||
BLI_dynstr_append(ds, "\tmat4 objinv = unfinvobmat;\n");
|
||||
if (builtins & GPU_INVERSE_VIEW_MATRIX)
|
||||
|
|
|
@ -10,6 +10,7 @@ uniform mat4 ModelViewMatrixInverse;
|
|||
uniform mat4 ViewMatrixInverse;
|
||||
uniform mat4 ProjectionMatrixInverse;
|
||||
uniform mat3 NormalMatrix;
|
||||
uniform vec4 CameraTexCoFactors;
|
||||
|
||||
#if __VERSION__ == 120
|
||||
#define fragColor gl_FragColor
|
||||
|
@ -2837,20 +2838,18 @@ void background_transform_to_world(vec3 viewvec, out vec3 worldvec)
|
|||
vec4 co_homogenous = (ProjectionMatrixInverse * v);
|
||||
|
||||
vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
|
||||
#ifdef WORLD_BACKGROUND
|
||||
worldvec = (ViewMatrixInverse * co).xyz;
|
||||
#else
|
||||
worldvec = (ModelViewMatrixInverse * co).xyz;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PROBE_CAPTURE) || defined(WORLD_BACKGROUND)
|
||||
void environment_default_vector(out vec3 worldvec)
|
||||
{
|
||||
#ifdef WORLD_BACKGROUND
|
||||
vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(viewPosition, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
|
||||
vec4 co_homogenous = (ProjectionMatrixInverse * v);
|
||||
|
||||
vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
|
||||
|
||||
co = normalize(co);
|
||||
worldvec = (ViewMatrixInverse * co).xyz;
|
||||
background_transform_to_world(viewPosition, worldvec);
|
||||
#else
|
||||
worldvec = normalize(worldPosition);
|
||||
#endif
|
||||
|
@ -2988,6 +2987,8 @@ void node_tex_coord_background(
|
|||
|
||||
#ifdef PROBE_CAPTURE
|
||||
vec3 coords = normalize(worldPosition);
|
||||
#elif defined(WORLD_BACKGROUND)
|
||||
vec3 coords = (ViewMatrixInverse * co).xyz;
|
||||
#else
|
||||
vec3 coords = (ModelViewMatrixInverse * co).xyz;
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue