Hello and happy holidays to all! ^^
I’m again facing a small problem with a shader that I’m trying to reproduce from a Löve2d project I did a while ago.
Here’s what I’ve rewritten so far (I made quite a few versions of it but I always have the same problem, this one is one of several others):
varying mediump vec4 position;
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D texture_sampler;
uniform lowp vec4 tint;
uniform lowp vec4 img_size;
uniform lowp vec4 phase;
void main() // Sine distortion of sprite
{
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
mediump vec2 sample_pos;
sample_pos.x = var_texcoord0.x - img_size.x * sin(phase.x + img_size.y * var_texcoord0.y);
sample_pos.y = var_texcoord0.y;
mediump vec4 _sample = texture2D(texture_sampler, sample_pos.xy);
gl_FragColor = _sample * tint_pm;
}
Here is an overview of the material file:
So there is the phase
value that needs to be set from a script, so I do it like this:
function init(self)
self.phase = 0
end
function update(self, dt)
self.phase = self.phase + dt
go.set("#sprite", "phase", vmath.vector4(self.phase, 0, 0, 0))
end
But I get this error:
ERROR:GRAPHICS: OpenGLSetConstantM4(2044): gl error 1282: invalid operation
dmengine: ../src/opengl/graphics_opengl.cpp:2044: void dmGraphics::OpenGLSetConstantM4(dmGraphics::HContext, const dmVMath::Vector4 *, int, int): Assertion `0' failed.
I just noticed that if I change this line:
mediump vec4 _sample = texture2D(texture_sampler, sample_pos.xy);
By that:
mediump vec4 _sample = texture2D(texture_sampler, var_texcoord0.xy);
It ignores the superfluous and it works, so the error comes from the lines I added but why? I don’t even know if this assertion error comes from my code or not. I’m very far from being a shader expert so excuse me if an obvious detail escapes me…