Spot Light Resources

Spot Light Resources

von Jack Heseltine -
Anzahl Antworten: 3

Hello,

Are there resources/tutorials that anyone can recommend for implementing a spot light in our framework? (One of the project requirements: phong shader/light node class combination.)


Thank you,

Jack

Als Antwort auf Jack Heseltine

Re: Spot Light Resources

von Jack Heseltine -
Etwas konkreter noch! Wie bekommt man eine Berechnung heraus, zum Beispiel durch console.log, die Shader passiert? Wir haben zB

//spot ... compute angle between spot light direction and light vector
float angle = dot(u_light2Direction,-lightVec);

... Und wissen noch nicht ob wir da überhaupt einen guten Wert bekommen.
Als Antwort auf Jack Heseltine

Re: Spot Light Resources

von Jonathan Kudlich -
Hi!

As far as I'm aware, there is no direct way to get output from your shader code to your console (remember that GLSL code is running several thousand times a second in parallel on your GPU, there's no way you could evaluate the amount of output that would generate), however, you can "cheat" a little by putting the information you want to output into the color the shader puts out.

There's two ways of doing this, one is making a condition that you want to check (say angle < 0.5) and then, if that condition is true, just set gl_fragment_color to an easily recognizble value (vec4(1, 0, 0, 1) = bright red for example). This can show you, where on your screen a certain condition holds.

The other way is just outputting variables directly into your color (by e.g. using gl_fragment_color = vexc4(angle, 0, 0, 1)) and using a screen-capture tool in combination with any painting tool or color-picker to read the exact values of variables from your screen.

These can really help with debugging GLSL code, even if they may seem a bit convoluted. ;)

Hope that helps a bit!
LG,
Jonathan
Als Antwort auf Jonathan Kudlich

Re: Spot Light Resources

von Klaus Eckelt -
Great tip Jonathan!

I can also recommend these resources (in general, not only for spotlights):
  • https://learnopengl.com/Lighting/Light-casters also on the slides
  • https://webglfundamentals.org/webgl/lessons/webgl-3d-lighting-spot.html

Best regards,
Klaus Eckelt