Skip to content

Commit

Permalink
UPBGE: Use textureCubeLod when using realtime cubemap
Browse files Browse the repository at this point in the history
This way we can blurry the reflection easier.
  • Loading branch information
lordloki committed May 20, 2020
1 parent e8abf7a commit 8329513
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions source/blender/gpu/shaders/gpu_shader_material.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,13 @@ void mtex_cube_map_refl_from_refldir(
value = color.a;
}

void mtex_cube_map_refl_from_refldir_cubelod(
samplerCube ima, vec3 reflecteddirection, float lodbias, out float value, out vec4 color)
{
color = textureCubeLod(ima, reflecteddirection, lodbias);
value = color.a;
}

vec4 mtex_cube_map_refl_color(samplerCube ima, mat4 viewmatrixinverse, float lodbias, vec3 vn, vec3 viewdirection)
{
vec3 normaldirection = normalize(viewmatrixinverse * vec4(vn, 0.0)).xyz;
Expand Down
11 changes: 9 additions & 2 deletions source/blender/nodes/shader/nodes/node_shader_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node
static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
Tex *tex = (Tex *)node->id;
EnvMap *env = tex->env;

if (tex && tex->ima && (tex->type == TEX_IMAGE || tex->type == TEX_ENVMAP)) {
if (tex->type == TEX_IMAGE) {
Expand All @@ -129,8 +130,14 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
}
if (!GPU_material_use_world_space_shading(mat))
GPU_link(mat, "direction_transform_m4v3", in[0].link, GPU_material_builtin(mat, GPU_INVERSE_VIEW_MATRIX), &in[0].link);
GPU_link(mat, "mtex_cube_map_refl_from_refldir",
GPU_cube_map(tex->ima, &tex->iuser, false), in[0].link, in[1].link, &out[0].link, &out[1].link);
if (env && env->stype == ENV_REALT && env->type == ENV_CUBE) {
GPU_link(mat, "mtex_cube_map_refl_from_refldir_cubelod",
GPU_cube_map(tex->ima, &tex->iuser, false), in[0].link, in[1].link, &out[0].link, &out[1].link);
}
else {
GPU_link(mat, "mtex_cube_map_refl_from_refldir",
GPU_cube_map(tex->ima, &tex->iuser, false), in[0].link, in[1].link, &out[0].link, &out[1].link);
}
GPU_link(mat, "color_to_normal", out[1].link, &out[2].link);
}

Expand Down

1 comment on commit 8329513

@youle31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.