Jump to content

When applying а shader to a sprite, it gets cut off on the bottom and right edges of the screen


SenPie
 Share

Recommended Posts

2021-06-25 14-18-28.mkv

Hi,

I've made a fragment shader that bends and stretches a given texture to give it a fluid flow. Here is the code:
 

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif

uniform sampler2D u_texture;
varying LOWP vec4 v_color;
varying vec2 vTextureCoord;

uniform float u_time;
uniform sampler2D uSampler;

vec4 normalizedSin(float speed, vec4 var, vec4 outputValue) {
	return ((sin(var * 3.14159 * speed) + 1.0) / 2.0);
}

float sphereMaskNode(float hardness, float radius, vec2 center, vec2 uv, float outputValue) {
	return 1.0 - clamp((distance(uv, center) - radius) / (1.0 - hardness), 0.0, 1.0);
}

vec4 normalizedCos(float speed, vec4 var, vec4 outputValue) {
	return ((cos(var * 3.14159 * speed) + 1.0) / 2.0);
}
void main() {
	vec4 normalizedSinVar1 = normalizedSin(0.22434203, vec4(u_time, u_time, u_time, 1.0), vec4(0.0));
	vec2 vec2Val0 = vec2(u_time, normalizedSinVar1.x);
	vec2 mathVar0 = sin(vec2Val0) * (vec2(0.4));
	vec2 vec2Val1 = vec2(0.5, 0.3);
	vec2 mathVar2 = (mathVar0) + (vec2Val1);
	float sphereMaskNodeVar0 = sphereMaskNode(0.5948184, 0.0, mathVar2, vTextureCoord, float(0.0));
	float mathVar1 = (sphereMaskNodeVar0) * (0.05);
	vec4 mathVar3 = pow(texture2D(uSampler, (vTextureCoord - 0.5)/(vec2(1.0, 1.0)) + 0.5 + vec2(mathVar1)), vec4(17.388779, 17.388779, 17.388779, 1.0));
	vec4 mathVar4 = (mathVar3) * (vec4(6.050579, 6.050579, 6.050579, 1.0));
	vec4 normalizedCosVar2 = normalizedCos(0.5, vec4(u_time, u_time, u_time, 1.0), vec4(0.0));
	vec4 mathVar6 = (mathVar4) * (normalizedCosVar2);
	vec4 mathVar5 = (mathVar6) + (texture2D(uSampler, (vTextureCoord - 0.5)/(vec2(1.0, 1.0)) + 0.5 + vec2(mathVar1)));
	gl_FragColor = mathVar5;
}

I applied that shader on a lava sprite with a PIXI.Filter, however it gets cut off on the sides. I intentional made the width and height of lava bigger than the screen width and height, so when it gets stretched it will still look fine. It seems like anything that is outside of the visible zone is not rendered at all, so when sprite is stretched I see nothing in place. Any ideas how can I fix this issue?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...