Not sure where to put this, but I guess w/o g3d this loses any context (plus it might be useful for others?)
Also, sorry for double-posting ( I think it's justified in this case?) and for a long post.
TL;DR
I can't understand this article I'm mentioning below, but I want shadows.
Long story:
I've figured out multiple point light sources with Blinn-Phong fragment shading
- 1.5beta_2.love
- Blinn-Phong frag shader
- (4.76 MiB) Downloaded 435 times
and was ready to get into shadows, but I'm overwhelmed again.
I'm trying to follow this
https://learnopengl.com/Advanced-Lighti ... w-Mapping article.
As far as I understand, they're creating a framebuffer for rendering shadows.
Googling for "love2d framebuffer" I found out canvases ARE framebuffers.
So, I've created a canvas, made sure it's "readable" by shaders and got lost..
Code: Select all
local SFBO = love.graphics.newCanvas(1024,1024, {readable=true})
I'm not entirely sure whether I need that explicit "readable" thing, but I did that due to what wiki at
https://love2d.org/wiki/Texture:setDepthSampleMode says:
When using a depth texture with a comparison mode set in a shader, it must be declared as a sampler2DShadow and used in a GLSL 3 Shader. The result of accessing the texture in the shader will return a float between 0 and 1, proportional to the number of samples (up to 4 samples will be used if bilinear filtering is enabled) that passed the test set by the comparison operation.
Depth texture comparison can only be used with readable depth-formatted Canvases.
Now, I can't say I comprehend any of what that means.
It doesn't help that I couldn't find any other mention of "sampler2DShadow" on wiki pages and/or how to use it.
Here
https://www.programmerall.com/article/39771418621/ it is said that GLSL's texture is just an Image in love2d.
But I thought I can't draw depthbuffer things to anything but a canvas?
And even if I could, creating a new image every frame seems just #oof.
Especially to copy from a canvas
Does it even matter?
Well, I figured that if that would turn out to be irrelevant, I'd really be sorry for not trying to persist.
The vertex shader below (taken from the article I linked) looks like it makes the light source to be the camera. Well, the explanation near the snippet looks that way
Code: Select all
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 lightSpaceMatrix;
uniform mat4 model;
void main()
{
gl_Position = lightSpaceMatrix * model * vec4(aPos, 1.0);
}
So I figured I can use the default g3d.vert shader if the light will come from the camera itself.
I've read about layouts here
https://www.khronos.org/opengl/wiki/Lay ... ier_(GLSL) and can't say I got it all.
Am I right that aPos is just "a position" of a light source?
If so, the fragment shader should be my next stop.
They're supplying an empty one.
So, do I need to use anything as the second parameter?
I figured no, I don't seem to have to.
But then, assuming all the above is correct (which is highly improbable), I need to render the scene on a texture.
So.. I rendered my scene onto a canvas..
Only to realize, I did
nothing to make it look any different from a standard scene rendered with g3d default shaders
So.. what should I change to get away from a normal canvas to a depthbuffer image?
But even if I got some crap as a framebuffer image, how to apply that to a second pass of a shader?
They're using this code:
Code: Select all
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D depthMap;
void main()
{
float depthValue = texture(depthMap, TexCoords).r;
FragColor = vec4(vec3(depthValue), 1.0);
}
Now, "sampler2D" looks a lot like that "sampler2DShadow" form the wiki.
But I can't just
Code: Select all
depthShader:send("depthMap", SFBO)
It yields an error, that my canvas is actually a "love_texture", and that shader can't do anything with it, since "no matching overloaded function found".
I mean it DOES pass it into a shader, but it seems there's no way to cast "love_texture" to "texture".
So..how to properly do it?
I can't even formulate the question correctly.
In general sense I want to draw some point light shadows.
But I can't get even directional light shadows to work.