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?
Variable from vertex to pixel shader.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- NoreoAlles
- Party member
- Posts: 130
- Joined: Mon Jan 03, 2022 5:42 pm
Variable from vertex to pixel shader.
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
- NoreoAlles
- Party member
- Posts: 130
- Joined: Mon Jan 03, 2022 5:42 pm
Re: Variable from vertex to pixel shader.
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
Re: Variable from vertex to pixel shader.
Should be something like this. In your vertex shader
In your fragment shader
The value will be linearly interpolated by opengl.
Code: Select all
out float myval
vec4 position( mat4 transform_projection, vec4 vertex_position ) {
myval = ...
}
Code: Select all
in float myval
vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
... use myval ...
}
- NoreoAlles
- Party member
- Posts: 130
- Joined: Mon Jan 03, 2022 5:42 pm
Re: Variable from vertex to pixel shader.
Ok thank you, so the in and out keywords are used for that.marclurr wrote: ↑Sat Jul 06, 2024 12:07 pm Should be something like this. In your vertex shader
In your fragment shaderCode: Select all
out float myval vec4 position( mat4 transform_projection, vec4 vertex_position ) { myval = ... }
The value will be linearly interpolated by opengl.Code: Select all
in float myval vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) { ... use myval ... }
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
Who is online
Users browsing this forum: Bing [Bot] and 5 guests