Skip to content

Commit

Permalink
UPBGE: Small optimization in cubemap mapping shader
Browse files Browse the repository at this point in the history
1 matrix less as uniform
  • Loading branch information
youle31 committed May 13, 2016
1 parent ba63419 commit 48571d6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/blender/gpu/intern/gpu_material.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ static void do_material_tex(GPUShadeInput *shi)
GPU_cube_map(tex->ima, &tex->iuser, false), shi->view, shi->vn,
GPU_select_uniform(&mtex->lodbias, GPU_DYNAMIC_TEX_LODBIAS, NULL, ma),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
GPU_builtin(GPU_VIEW_MATRIX), &tin, &trgb);
&tin, &trgb);
}
rgbnor = TEX_RGB;

Expand Down
4 changes: 2 additions & 2 deletions source/blender/gpu/shaders/gpu_shader_material.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -1331,10 +1331,10 @@ void mtex_cube_map(vec3 co, samplerCube ima, float lodbias, out float value, out
value = 1.0;
}

void mtex_cube_map_refl(samplerCube ima, vec3 vp, vec3 vn, float lodbias, mat4 viewmatrixinverse, mat4 viewmatrix, out float value, out vec4 color)
void mtex_cube_map_refl(samplerCube ima, vec3 vp, vec3 vn, float lodbias, mat4 viewmatrixinverse, out float value, out vec4 color)
{
vec3 viewdirection = vec3(viewmatrixinverse * vec4(vp, 0.0));
vec3 normaldirection = normalize(vec3(vec4(vn, 0.0) * viewmatrix));
vec3 normaldirection = normalize(viewmatrixinverse * vec4(vn, 0.0)).xyz;

This comment has been minimized.

Copy link
@panzergame

panzergame May 13, 2016

Contributor

Are you sure that normalize(vec3) gives the same result that normalize(vec4).xyz ?

vec3 reflecteddirection = reflect(viewdirection, normaldirection);
color = textureCube(ima, reflecteddirection, lodbias);
value = 1.0;
Expand Down

1 comment on commit 48571d6

@youle31
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so, except when vec4 v[3] == 0 .... This is the case here.
http://www.pasteall.org/pic/103058

Please sign in to comment.