Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Experts help needed - custom shadows

Author
Message
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 16th Jun 2020 18:16 Edited at: 19th Jun 2020 16:50
I've spent some time looking at shadows within AppGameKit, and specifically at trying to create custom spot and point light shadows, and the facility for multiple shadows.

I have been folowing these tow guides, which take the same approach but with different code:
https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

I cannot get it to work however. I have generated the depth image (not ortho, but that doesn't work), which the screen show shows attached (image.png - why is the embed button gone now????) - the shader is currently set to cast from the highlighted spotlight down to the ground and the depth image is displayed as a sprite.

I have recreated both veresions of the code in a T2 plugin so I can use the GLW extensions, and they do seem to be calculating correctly. When I get to the shader, it doesn't map the shadow but instead just adds to the lights in the scene. The second screen shot (image 2) shows what happens when the code from the first link is implimented. I do wonder if part of the problem is the scale of my world - I cannot use the ortho camera or the 3D is all scrambled - the spaceship is actually thousands of units wide.

Anyone have any ideas?

The C code is as follows:


The shader code is as follows (PS):


I can change the texturing on the objects to slot 6 and the depth image appears on them, so I know that texture is being applied to the objects, so I think it;s the conversion of the depth image coords back to 3D space that are at fault, but I cannot get this to work any way.

Attachments

Login to view attachments
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 16th Jun 2020 22:28
I've managed to pull everything out into a seperate project and upload here. The issue seems to be that the entire scene is being recognised as in shadow.....which suggests the depth image is not accurately capturing the data that is needed to do the comparrison. I assume AppGameKit internally is using a generated depth buffer rather than a depth image.

Anyone got any thoughts?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 16th Jun 2020 23:54 Edited at: 16th Jun 2020 23:54
I've discovered that if you change the look up in the current depth from the .r swizzle to the .g, it kind of almost half works - the square appears to cast a shadow on the sphere, but the artifacts are horrible. I'll try adding a bias tomorrow, and rendering a better depth texture.
Mambazo
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location:
Posted: 17th Jun 2020 00:22
Folllowing!
If at first you don't succeed, sky-diving isn't for you.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 19th Jun 2020 16:27
So I've isolated the lightviewmatrix is the issue, it's not positioning the vertex properly.

Am I right in thinking that what is called the model in this code would be the position attribute in AppGameKit?
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 19th Jun 2020 22:26 Edited at: 19th Jun 2020 22:29
So you construct a MVP matrix from the lights point of view pointing into the scene with lookat using GLW and passing it in collumn major order as it should... seems fine.
Now I can't see your vertex shader so I assume you have something along the lines of:


And you transform it into clip space using w devide...not sure if you have to get it into normal device coordinates with "* 0.5 + 0.5" here but could be possible...
So that all seems fine.
But I guess I need more code and maybe a video of you moving through the scene ...does it flicker ??
You are trying to get directional shadows at the moment right ?

Quote: "Am I right in thinking that what is called the model in this code would be the position attribute in AppGameKit?"

model in what code ?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 20th Jun 2020 03:36
Hi Janbo.

I've attached the project here. For now, it is in deed just directional shadows, but once I got this working I wanted to try and extend to point and spot light shadows. The issue is with the lightmatrix that transforms the lighting I think....though I have called the code to readout each valeu in the plugin and the AppGameKit code, and they match perfectly and have what appear to be the correct values. An thing is that the texture also rotates 45 degrees to one side.

The plug in runs the following (versions for both guides):

janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 20th Jun 2020 19:49 Edited at: 20th Jun 2020 19:50
I can't see the problem in your C code. the two versions are identical as you can ignore the model matrix cause its initialised with 1.0 so one times the rows and colums of a matrix is the matrix itself again...
This should create a stationary box with directional lighting, I never saw your vertex shader so either I fail to see the problem too or it is in the vertex shader ?

Quote: "An thing is that the texture also rotates 45 degrees to one side"

You mean the depth texture ? it looks good for me.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 21st Jun 2020 20:56
Well a big part of the problem seems to be that AppGameKit keeps getting the float points back out of the memblock with a combination of values that are "nan" or "-nan(ind)".

Not idea why this keep s changing over, the C++ code never changed.....
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 22nd Jun 2020 11:56 Edited at: 22nd Jun 2020 13:08
What is the reason for "off = off + 25;" don't you want the values to be next to each other so +4 ?
Also make sure the offset is a multiple of 4 for speed.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 22nd Jun 2020 17:44
Increasing the off by that much was just something a threw in. I changed it to multiples of 4 later, made no odds. I also tested the C code by forcing a float valve in, then displaying it as a message in both the C code and AppGameKit and ot worked fine.....so it seems to be the GLW ortho function that is the issue. Sometimes it gives numbers, other values just return that error code - even when AppGameKit is told to read a float.....I dont know of this is an AppGameKit error or not.

I'm shelfing this for now - spent a full 7 days trying every possible thing I can think of, and the ortho matrix wont allow any form of depth map generation at all, even when just drawing objects instead of using render3d. Even if I take the values output and manually assign them in the shader, still nothing. There must be something internally in AppGameKit causing a clash, or both versions of that code just wont work at less than 330 core.

Login to post a reply

Server time is: 2024-04-19 12:29:06
Your offset time is: 2024-04-19 12:29:06