vec3 modulus error

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
LinusNeuman
Prole
Posts: 4
Joined: Mon Sep 28, 2015 10:39 am

vec3 modulus error

Post by LinusNeuman »

Hello!

I tried converting this shader I found to love2d, but I can't get it right.
This statement is the one in error:

Code: Select all

vec3 grain = vec3(((mod(mod(int(x), 13) + 1)* (mod(int(x), 123) + 1), 0.01) - 0.005) * noiseStrength); // 0.01 and - 0.005
Unable to find compatible overloaded function "mod(float)". I get the error because mod is supposed to get 2 values, 2 floats, but it gets one. And I don't know how the dude that made this wants it to be.

Shader:

Code: Select all

//layout(location = 0) out vec3 out_color;

//uniform sampler2D colorMap; // This is the original image without noise
uniform float time; // Time since the start of the frame

const float noiseStrength = 30.0; // The strength of the noise effect -- default 30.0

vec4 effect(vec4 col, Image texture, vec2 texturePos, vec2 screenPos)
{
    vec3 color = texture2D(texture, texturePos).xyz;
    float x = (texturePos.x + 4) * (texturePos.y + 4) * (time * 10);

    int a = 13;
    int b = 123;

    vec3 grain = vec3(((mod(mod(int(x), 13) + 1)* (mod(int(x), 123) + 1), 0.01) - 0.005) * noiseStrength); // 0.01 and - 0.005

    // This one is optional, it makes a small "tear" every now and then
    //if(mod(time, 100) > 98 && mod(texcoord.y, 10) > 7) grain = vec3(-3.0, -3.0, -3.0);
    //vec3 grain = vec3(0,0,0);
    color += grain;
    vec4 finalColor = vec4(color, 1.0);
    return finalColor;
}
Link to reddit forum that made this originally:
https://m.reddit.com/r/opengl/comments/ ... ain_noise/
LinusNeuman
Prole
Posts: 4
Joined: Mon Sep 28, 2015 10:39 am

Re: vec3 modulus error

Post by LinusNeuman »

Turns out that time was 0 all the time, so now I send time every frame.
I also deleted the error statement and replaced with this:

Code: Select all

float noise(vec2 seed)
{
  float x = (seed.x / 3.14159 + 4) * (seed.y / 13 + 4) * ((fract(time) + 1) * 10);
  return mod((mod(x, 13) + 1) * (mod(x, 123) + 1), 0.01) - 0.005;
}

Code: Select all

vec3 out_color = texture2D(texture, texturePos).xyz;

Code: Select all

vec2 seed = vec2(0.9,0.9);
    out_color += noise(seed);
    vec4 finalColor = vec4(out_color, 1.0);
    return finalColor;
Problem is.. Either the seed is so low that almost nothing happens, or it is so high that the screen flickers like crazy.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests