Variable from vertex to pixel 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
NoreoAlles
Party member
Posts: 130
Joined: Mon Jan 03, 2022 5:42 pm

Variable from vertex to pixel shader.

Post by NoreoAlles »

Hello i want to compute the normal to lighting direction dotproduct inside of my vertex shader and then have this value used in the pixel shader for simple lighting but i cant seem to find a way to do this. On stackoverflow they suggest modifying the geometry shader inbetween the two to pass the variable but i dont know.
Tldr: How do i get float computed inside of vertex shader to fragment shader?
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
User avatar
NoreoAlles
Party member
Posts: 130
Joined: Mon Jan 03, 2022 5:42 pm

Re: Variable from vertex to pixel shader.

Post by NoreoAlles »

NoreoAlles wrote: Sat Jul 06, 2024 6:59 am Hello i want to compute the normal to lighting direction dotproduct inside of my vertex shader and then have this value used in the pixel shader for simple lighting but i cant seem to find a way to do this. On stackoverflow they suggest modifying the geometry shader inbetween the two to pass the variable but i dont know.
Tldr: How do i get float computed inside of vertex shader to the the fragment shader?
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
User avatar
marclurr
Party member
Posts: 158
Joined: Fri Apr 22, 2022 9:25 am

Re: Variable from vertex to pixel shader.

Post by marclurr »

Should be something like this. In your vertex shader

Code: Select all

out float myval

vec4 position( mat4 transform_projection, vec4 vertex_position ) {
    myval = ...
}
In your fragment shader

Code: Select all

in float myval

vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
    ... use myval ...
}
The value will be linearly interpolated by opengl.
User avatar
NoreoAlles
Party member
Posts: 130
Joined: Mon Jan 03, 2022 5:42 pm

Re: Variable from vertex to pixel shader.

Post by NoreoAlles »

marclurr wrote: Sat Jul 06, 2024 12:07 pm Should be something like this. In your vertex shader

Code: Select all

out float myval

vec4 position( mat4 transform_projection, vec4 vertex_position ) {
    myval = ...
}
In your fragment shader

Code: Select all

in float myval

vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
    ... use myval ...
}
The value will be linearly interpolated by opengl.
Ok thank you, so the in and out keywords are used for that.
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 2 guests