Support for cubemap reflections in the viewport

D1756 by @youle, uses existing texture mapping option.
This commit is contained in:
Campbell Barton 2016-02-05 04:28:16 +11:00
parent 45071fa0f5
commit d80f8baba5
2 changed files with 28 additions and 4 deletions

View File

@ -1221,8 +1221,19 @@ static void do_material_tex(GPUShadeInput *shi)
talpha = 0;
if (tex && tex->type == TEX_IMAGE && tex->ima) {
GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, false), &tin, &trgb);
if (tex && tex->ima &&
((tex->type == TEX_IMAGE) ||
((tex->type == TEX_ENVMAP) && (mtex->texco == TEXCO_REFL))))
{
if (tex->type == TEX_IMAGE) {
GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, false), &tin, &trgb);
}
else {
GPU_link(mat, "mtex_cube_map_refl",
GPU_cube_map(tex->ima, &tex->iuser, false), shi->view, shi->vn,
GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
GPU_builtin(GPU_VIEW_MATRIX), &tin, &trgb);
}
rgbnor = TEX_RGB;
talpha = ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0);
@ -1268,9 +1279,13 @@ static void do_material_tex(GPUShadeInput *shi)
GPU_link(mat, "set_value_one", &tin);
}
if (tex->type == TEX_IMAGE)
if (GPU_material_do_color_management(mat))
if ((tex->type == TEX_IMAGE) ||
((tex->type == TEX_ENVMAP) && (mtex->texco == TEXCO_REFL)))
{
if (GPU_material_do_color_management(mat)) {
GPU_link(mat, "srgb_to_linearrgb", tcol, &tcol);
}
}
if (mtex->mapto & MAP_COL) {
GPUNodeLink *colfac;

View File

@ -1284,6 +1284,15 @@ void mtex_cube_map(vec3 co, samplerCube ima, out float value, out vec4 color)
value = 1.0;
}
void mtex_cube_map_refl(samplerCube ima, vec3 vp, vec3 vn, mat4 viewmatrixinverse, mat4 viewmatrix, out float value, out vec4 color)
{
vec3 viewdirection = vec3(viewmatrixinverse * vec4(vp, 0.0));
vec3 normaldirection = normalize(vec3(vec4(vn, 0.0) * viewmatrix));
vec3 reflecteddirection = reflect(viewdirection, normaldirection);
color = textureCube(ima, reflecteddirection);
value = 1.0;
}
void mtex_image(vec3 texco, sampler2D ima, out float value, out vec4 color)
{
color = texture2D(ima, texco.xy);