[SOLVED] Error with simple Shader

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
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

[SOLVED] Error with simple Shader

Post by alberto_lara »

EDIT: this is love 11.4
EDIT 2: I just realized I'm using extern instead of uniform, that doesn't fix the issue (same problem)

Do you people see anything wrong with this? I'm building an app related to color palettes and I was able to isolate the issue:

Code: Select all

shader = love.graphics.newShader([[
  extern vec3 colors[3];

  vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
    vec4 pixel = Texel(texture, texture_coords);
    number average = (pixel.r + pixel.g + pixel.b) / 3.0;
    
    for (int i = 0; i < 46; i++) {
      vec3 color = colors[i];
    }

    return pixel;
  }
]])

function love.update(dt)
  shader:send('colors', {1, 0, 0}, {0, 1, 0}, {0, 0, 1})
end

function love.draw()
  love.graphics.setShader(shader)
  love.graphics.setColor(1, 1, 0)
  love.graphics.rectangle("fill", 0, 0, 800, 600)
  love.graphics.setShader()
end
Image

EDIT 3: tried an even simpler version, same issue:

Code: Select all

shader = love.graphics.newShader([[
  uniform vec3 colors[3];

  vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
    vec4 pixel = Texel(texture, texture_coords);
    vec3 c = colors[0];
    return pixel;
  }
]])

function love.update(dt)
  shader:send('colors', {1, 0, 0}, {0, 1, 0}, {0, 0, 1})
end
Last edited by alberto_lara on Mon Jun 26, 2023 10:18 pm, edited 1 time in total.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Error with simple Shader

Post by slime »

Your shader code needs to use the uniform in a manner that affects the final output of the shader, otherwise your graphics driver will optimize out the uniform when compiling the shader.
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: Error with simple Shader

Post by alberto_lara »

holy cow, I missed that simple fact like 10 years ago lol, thanks! (it works now)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests