GhGl shader respecting lights in the scene

Hi,

Could someone help me to understand how I can modify the code in the GL Mesh Shader button to respect the lights in a scene? Or am I just missing how the GL Mesh Shader works?

Thanks!

Hi,

Resources GHGL

Cheers,
BVR

GhGL grabs the lights in the display pipeline and sets them up as uniforms available in the shader

Ok, I think I understand now. Do I just need to work within those 4 light direction options? Or is there another way to override this and tell it to use the scene lights for the lighting?

edit(2):

I was able to manipulate the direction of the lighting by creating a vector input (as an MD Slider) named lightdir and then multiplying it by the _lightDirection in the Main function in the fragment portion of the shader. I hope this helps someone else.

vec3 l = normalize(_lightDirection[0]*lightdir);

The code in the shader needs to decide if ift is going to support more lights. I never got around to writing a sample that used more than the standard camera oriented light.

If have seen this thread too late. Thank you all!
At the bottom you can see a working solution in combination with a glslify lambert function -.
(With just one light source)

The changed fragment shader:

#pragma glslify: diffuse_lambert = require(‘glsl-diffuse-lambert’)

//Input variables
uniform vec4 diffuse;
uniform vec4 ambient;

uniform vec3 _lightDirection[4];

in vec3 normal;
in vec3 ligthDir;

out vec4 fragment_color;

void main() {
vec3 l = -normalize(_lightDirection[0]);
float power = diffuse_lambert(l,normal);

vec3 c = ambient.rgb + diffuse.rgb * abs(power);
vec4 shadingColor = vec4(c, diffuse.a);

fragment_color = shadingColor;
}

Now, I just would like to implement some kind of drop shadow, but as I understood, this will be right now not possible, because PostDrawObject is used to draw the object within the gl mesh shader component (GLMeshShaderComponent.cs, Line 212) - so it is too late for a shadow pass.

See this Issue;
https://mcneel.myjetbrains.com/youtrack/issue/RH-54147

@stevebaer Is this assumption correct?

Greetings,
Leon

Yes, that is correct

1 Like