Fix T42622, environment texture GLSL result different from rendering.

Also included mirror ball shader, which was missing.
This commit is contained in:
Antonis Ryakiotakis 2014-11-20 19:43:32 +01:00
parent 6f7b4a3a3e
commit 102d3ad595
Notes: blender-bot 2023-02-14 09:49:28 +01:00
Referenced by issue #42622, Material vs Rendered - rendering inconsistency in the viewport
2 changed files with 25 additions and 5 deletions

View File

@ -2390,10 +2390,27 @@ void node_tex_clouds(vec3 co, float size, out vec4 color, out float fac)
fac = 1.0;
}
void node_tex_environment(vec3 co, sampler2D ima, out vec4 color)
void node_tex_environment_equirectangular(vec3 co, sampler2D ima, out vec4 color)
{
float u = (atan(co.y, co.x) + M_PI)/(2.0*M_PI);
float v = atan(co.z, hypot(co.x, co.y))/M_PI + 0.5;
vec3 nco = normalize(co);
float u = -atan(nco.y, nco.x)/(2.0*M_PI) + 0.5;
float v = atan(nco.z, hypot(nco.x, nco.y))/M_PI + 0.5;
color = texture2D(ima, vec2(u, v));
}
void node_tex_environment_mirror_ball(vec3 co, sampler2D ima, out vec4 color)
{
vec3 nco = normalize(co);
nco.y -= 1.0;
float div = 2.0*sqrt(max(-0.5*nco.y, 0.0f));
if(div > 0.0f)
nco /= div;
float u = 0.5*(nco.x + 1.0);
float v = 0.5*(nco.z + 1.0);
color = texture2D(ima, vec2(u, v));
}

View File

@ -72,8 +72,11 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
node_shader_gpu_tex_mapping(mat, node, in, out);
ret = GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, isdata));
if (tex->projection == SHD_PROJ_EQUIRECTANGULAR)
ret = GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
else
ret = GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
if (ret) {
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&