Skip to content

Commit

Permalink
UPBGE: Fix discard at edge option according to scale
Browse files Browse the repository at this point in the history
fixes issue: #575
  • Loading branch information
youle31 committed Aug 25, 2017
1 parent ff92967 commit acf534b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions source/blender/gpu/intern/gpu_material.c
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ static void do_material_tex(GPUShadeInput *shi)
GPU_image(tex->ima, &tex->iuser, false),
GPU_select_uniform(&mtex->parallaxsteps, GPU_DYNAMIC_TEX_PARALLAXSTEP, NULL, ma),
GPU_select_uniform(&mtex->parallaxbumpsc, GPU_DYNAMIC_TEX_PARALLAXBUMP, NULL, ma),
GPU_select_uniform(mtex->size, GPU_DYNAMIC_TEX_UVSIZE, NULL, ma),
GPU_uniform(&discard),
GPU_uniform(&comp),
&parco);
Expand Down
6 changes: 3 additions & 3 deletions source/blender/gpu/shaders/gpu_shader_material.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4097,7 +4097,7 @@ void node_output_world(vec4 surface, vec4 volume, out vec4 result)
}

void mtex_parallax(vec3 texco, vec3 vp, vec4 tangent, vec3 vn, sampler2D ima, float numsteps,
float bumpscale, float discarduv, float comp, out vec3 ptexcoord)
float bumpscale, vec3 scale, float discarduv, float comp, out vec3 ptexcoord)
{
// Compute binormal/bitangent from tangent and normal.
vec3 binormal = cross(-vn, tangent.xyz) * tangent.w;
Expand Down Expand Up @@ -4158,8 +4158,8 @@ void mtex_parallax(vec3 texco, vec3 vp, vec4 tangent, vec3 vn, sampler2D ima, fl
vec2 finaltexuv = mix(texuv, texuvprelay, weight);

// Discard if uv is out of the range 0 to 1.
const vec2 clampmin = vec2(-0.5);
const vec2 clampmax = vec2(0.5);
vec2 clampmin = vec2(-0.5) * scale.xy;
vec2 clampmax = vec2(0.5) * scale.xy;

if ((discarduv == 1.0) &&
(finaltexuv.x - 0.5 < clampmin.x || finaltexuv.x - 0.5 > clampmax.x ||
Expand Down
3 changes: 2 additions & 1 deletion source/blender/nodes/shader/nodes/node_shader_parallax.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static int gpu_shader_parallax(GPUMaterial *mat, bNode *node, bNodeExecData *UNU
GPUNodeLink *texco;
GPUNodeLink *norm;
GPUNodeLink *outuv;
float one[3] = { 1.0f, 1.0f, 1.0f };

for (unsigned short i = 0; i < 3; ++i) {
if (!in[i].link) {
Expand All @@ -62,7 +63,7 @@ static int gpu_shader_parallax(GPUMaterial *mat, bNode *node, bNodeExecData *UNU
float comp = (float) node->custom1;
float discard = (float) node->custom2;
GPU_link(mat, "mtex_parallax", texco, GPU_builtin(GPU_VIEW_POSITION), GPU_attribute(CD_TANGENT, ""), norm, texlink,
in[1].link, in[2].link, GPU_uniform(&discard), GPU_uniform(&comp), &outuv);
in[1].link, in[2].link, GPU_uniform(one), GPU_uniform(&discard), GPU_uniform(&comp), &outuv);

GPU_link(mat, "parallax_uv_attribute", outuv, &out[0].link);

Expand Down
2 changes: 1 addition & 1 deletion source/tools
Submodule tools updated from b11375 to 9d841e

0 comments on commit acf534b

Please sign in to comment.