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.

Author
Message
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 15th Jul 2016 18:46 Edited at: 23rd Aug 2017 14:46
Hey,

I worked the last weeks on a 3D Shadow shader.
The PSM and 99% of the rest should be complete and working but there is the 1% that make problems.
Not that the rest was easy or I couldn't figure out the 1% but some of you offered help and I don't want to reject it
I wrapped it up in some functions, but the layout isn't perfect jet.
Lets make it rock solid and easy to use for the community.
So I open the Beta Phase to my Shadow Shader.

I had my own Matrix calculations... but for compatibility I use the functions from the Advanced math functions thread now.

Picture


Version 0.4: 3D Shadow Shader
Huge thanks to Preben for the cascade shadow shader part
•Fixed a bug where the VertexLighting didn't get updated by the right normals in the Animation Vertex shader.
•Moved the andoid specific string parsing into the init function so it don't get called so often.
•Removed the sundir vector from the agk shader constant but made it varring
also it is created by the second last row from the MVPLightMatrix not like I stated at first.

Version 0.2: 3D Shadow Shader
• Added Shadow_GetListLength() Returns length as Integer
• Added Shadow_GetListObject(Index as Integer) Returns object as Integer
• Added Shadow_RemoveAllObjects()
• Fixed bug where you get an error if you try to remove an object that isn't in the list

Version 0.1:
• Added PCF(Percentage Close Filtering)
• Added Shadow_SetSunDirection(DirX#,DirY#,DirZ#) again
• Added Shadow_SetSunPosition(PosX#,PosY#,PosZ#) (The Shadow_Update() will work with that for now)
• Fixed the shadow area that appears outside the far plane of the light's orthographic frustum

Attachments

Login to view attachments
blink0k
AGK Developer
Gold Codemaster
6
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 16th Jul 2016 00:00
WOW! Awesome! Will be having a good look at this
Jack
14
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 16th Jul 2016 03:37 Edited at: 16th Jul 2016 03:51
I see possible frustrum culling problems including some sort of matrix rotation issues, likely based on not debugged functions from the advanced math libarary.

I'll track this thread and gonna look inside the functions you've used. Thx for the code bro, I needed something to debug the functions! With your code I can see when or if the commands are working! The next days I'll take a deep look. We will get this done pal!
Do you have made any changes inside the math library, excluding the additions you have done?

[/url]
Blendman
5
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 16th Jul 2016 11:19
Hi Janbo

It's very good, but I have some artefact (if the camera is near the object for example).

I have tried to add a "soft shadows parameters" :


here is the fragment shader test (just some changes on your shader, most of them are from the link at the end of this message :


I have found some interesting informations here :
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

And specially the fragment shader :
https://github.com/opengl-tutorials/ogl/blob/master/tutorial16_shadowmaps/ShadowMapping.fragmentshader
AGK2 tier1 - http://www.dracaena-studio.com
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 16th Jul 2016 11:49 Edited at: 23rd Aug 2017 14:46
Nice responses !

Quote: "I see possible frustrum culling problems including some sort of matrix rotation issues"

Right that's the biggest problem.

Quote: "I have tried to add a "soft shadows parameters""

Looking good so far
Quote: "I have found some interesting informations here"

Trust me I know all sites google finds regarding shadows and shaders from memory

Thank you two
As soon as everything works I'll update the top post
Mobiius
Valued Member
16
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Jul 2016 14:02
Nice work guys/gals! Can't wait to see the final result! (And use it on my Zelda game!)
Stab in the Dark software
Valued Member
16
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 16th Jul 2016 22:36
I will test it in Tier2. Tier2 has all the matrix math done.
So if it works okay with that then it will show it is just the
math functions.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Blendman
5
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 17th Jul 2016 08:25
@Janbo : do you think we could use that to create a sort of lightmapper for AppGameKit ?
To not have the dynamic shadows for all object, but we could have static shadows for objects which doesn't move.
Do you know how we could have that ?
Thanks.
AGK2 tier1 - http://www.dracaena-studio.com
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 17th Jul 2016 12:33 Edited at: 23rd Aug 2017 14:46
@Stab: Thats a nice Idea, thanks, but it could be I changed some input parameters to compensate wrong calculations in the math functions... so don't rely to much on them.

@Blendman: The sun frustum must follow our camera frustum to light the map where it is needed.
So the LMVP Matrix changes constantly by moving the camera.
Also there comes two problems with it:
1. the flickering at the edges of the shadows which can be solved by snapping the texture to whole pixels
2. Something in the calculation for the LightViewProjection position is wrong I think
Thinking out lout: you could pass a static Matrix with a static Depth texture ... might work
You could try it with the unused Shadow_SetSunPosition function which I left in there.
But that would only light that particular area and you only save the matrix calculations in AGK.
Better bake the map using your favourite modelling program.
blink0k
AGK Developer
Gold Codemaster
6
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Jul 2016 21:07
Quote: "static shadows for objects which doesn't move. Do you know how we could have that ?"

Couldn't you use blender to bake the lighting conditions into the texture?
Blendman
5
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 18th Jul 2016 09:30
Quote: "Better bake the map using your favourite modelling program."

Quote: "Couldn't you use blender to bake the lighting conditions into the texture?"


That's what I made for my previous map, but now I create my map directly in AppGameKit (I have created a level editor), so I'm looking for a way to bake the shadows from my 3D levels made in AGK.
I have made some tests, with a sort of shadows from top view and it works (I can save the image easily), but I would like to get the shadows from this example too ^^.
AGK2 tier1 - http://www.dracaena-studio.com
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 18th Jul 2016 17:51 Edited at: 23rd Aug 2017 14:46
OKAY
I would do it like so:

1. You have the lit object
2. Select a triangle
3. Position the camera in front of it
4. Discard everything else
5. Render the triangle to a new image
6. Repeat from step 2. until you iterated through all triangles
7. Calculate the coordinates of all images for one large texture
8. Save the large texture
9. Save the coordinates in the model
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 4th Aug 2016 13:20
Bump! Is this ready for use? I guess i have to attach shadows.agc and math.agc to my project if i want to implement the shadows, right?
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 4th Aug 2016 14:35 Edited at: 23rd Aug 2017 14:46
Yeah that's right, include the .agc files and use Shadow_Init(), Shadow_AddObject() and Shadow_Update().
But it's not fully ready jet...I think the view matrix is calculated not correctly
I've come so far but somehow I can't encourage me to continue to work on it ...like so often
Stab in the Dark software
Valued Member
16
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 4th Aug 2016 14:41
Quote: "I think the view matrix is calculated not correctly"


That is why Paul needs to add the Matrix commands to Tier1.
AGK2 is falling behind.
The coffee is lovely dark and deep,and I have code to write before I sleep.
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 4th Aug 2016 15:23 Edited at: 23rd Aug 2017 14:46
Yeah would be nice to have build in Matrix commands... then we don't need to correct the self made Matrix library and new comers don't need to search for it.
Then he can also make 3D Shadows
I have nothing against making something my self (except the endurance you need sometimes ) but they should make it easier for us to create such things ...I think that's what AppGameKit is for
So:
Quote: "That is why Paul needs to add the Matrix commands to Tier1."
+1
Stab in the Dark software
Valued Member
16
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 4th Aug 2016 15:41 Edited at: 4th Aug 2016 15:43
I guess they are expecting everyone to move to Teir2. That way you have access to the matrix commands
and can add other missing code. TGC seem to have no clear roadmap of future additions to AGK.
This is unfortunate since it prevents users from getting there apps published.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 4th Aug 2016 16:15
Quote: "I've come so far but somehow I can't encourage me to continue to work on it ...like so often "

then i would like to encourage you to continue!

And i would encourage Paul to:
Quote: "add the Matrix commands to Tier1"

+1

I'm not gonna move to tier2...
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 11th Aug 2016 16:10
Got several problems:
-If i alter the position of the sun, the light in the scene does, but not the shadows.
-I got my objects colored by the setobjectcolor command. the colors do not show, it seems the shader is overwriting them.
-if i delete a object, even if i got the function "Shadow_RemoveObject" called before i do so, i recieve an error.

math.agc and shadow.agc not included as i did not alter them.


janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 11th Aug 2016 23:34 Edited at: 23rd Aug 2017 14:46
Im very busy but I did ...very few changes and the Shadow library isn't ready at all... its more like "early pre alpha"

3 Files are attached
+Added Shadow_SetSunDirection(DirX#,DirY#,DirZ#)
+Changed the Pixelshader to take the color into account (texturing didn't work as I wanted so ill leave it for now it is half past noon ... so ...)
+Fixed the Shadow_RemoveObject function

Green7 wrote: "then i would like to encourage you to continue! "
I like that thanks

Attachments

Login to view attachments
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 12th Aug 2016 09:06
Hey Janbo, sorry to disturb you, but first: thanks for your work!
There still are some issues, if you find the time to look into this:
Got the new stuff implemented. There are several points to mention:

sun direction works. Thanks!
deleting objects works. Thanks!

but:
color still is not showing, all is tinted green...
shadows "add" to eachother, if you stack some cubes they add their shadows to the ones beneath, so it gets darker. but not on the floor tiles...

Do not hurry, i'm soon off the net until sunday maybe. and if it gets later, no problem. i'm thankful for your work, as i could not do it on my own. so take your time.

Attachments

Login to view attachments
Preben
AGK Studio Developer
15
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 12th Aug 2016 12:33
janbo: this looks great but...

Tried it on my mac mini , but it dont work i get this error see pic. Also tried it on ipad2 with the same results, is this just me or is it only for windows ?


best regards Preben Eriksen,

Attachments

Login to view attachments
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 12th Aug 2016 23:29 Edited at: 23rd Aug 2017 14:46
I never tested it on mobile devices until now ... I modified the shaders until it worked for my Nexus 10
The version directive (the first line: #version 120 in the Object.ps) will be added automatically by AppGameKit wich is platform dependant
and then you can't use that kind of Array definition used for the Poisson Sampling...I'll rewrite it too... sometime

4 Files are attached
+Works on my Nexus 10
-Could not get the color working (does vec4 agk_ObjColor still work in the new version?)

Quote: "shadows "add" to eachother, if you stack some cubes they add their shadows to the ones beneath, so it gets darker. but not on the floor tiles..."

Maybe you mean the Vertex lighting "added" by the sun from AppGameKit? deactivate the sun ? ..ok i'll look into that

And again half past noon

Attachments

Login to view attachments
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 15th Aug 2016 10:47 Edited at: 15th Aug 2016 13:59
Color works now, had to pass it to the shader by "SetObjectShaderConstantByName" for each object. Not a big stress, as it works like the normal coloring. Only difference is that RGB 1.0,1.0,1.0 is white. Took me a while to get that.
"vec4 agk_ObjColor" is not, or no more, in the list of AppGameKit Shader Variables, at last in the help files.

Quote: "Maybe you mean the Vertex lighting "added" by the sun from AppGameKit? deactivate the sun ? ..ok i'll look into that"

nope, without the soft edge shadow it works, sun active. so it may be located there.

(edit)
Demo attached, happy building!

(2nd edit)
found somewhere that "there has been a change recently where all references to agk_ObjColor need to be replaced by agk_MeshDiffuse"
did not test... but will do soon.

Attachments

Login to view attachments
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 15th Aug 2016 18:29 Edited at: 23rd Aug 2017 14:46
Quote: "nope, without the soft edge shadow it works, sun active. so it may be located there."

I don't understand what you mean then...
Can you post a picture ?

And agk_MeshDiffuse is the right one.
Just replace it with agk_ObjColor or the constant you are passing to the shader and you can use SetObjectColor.
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 16th Aug 2016 11:21 Edited at: 16th Aug 2016 11:22
Quote: "Can you post a picture ?"

yes. I marked the glitches with red outlines. it does not really depend on where the sun is. the demo " cube_1.1.rar" some posts above has the problem, it runs with the soft shadows.
the demo "cube_1.2.rar" has hard edged shadows, there is nothing similar visible.

Quote: "And agk_MeshDiffuse is the right one.
Just replace it with agk_ObjColor or the constant you are passing to the shader and you can use SetObjectColor."

yes, it is. works as it should.

Attachments

Login to view attachments
MikeMax
AGK Academic Backer
7
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 16th Aug 2016 19:26
Only textured objects (animated ?) support is missing !

Great work !
--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 25th Aug 2016 11:58
@MikeMax: Here you go. Texture on stage 0. The Object Color is also in, so you can shade it in different colors, but with one texture. if you do not set object colors then they are all white, for neutral color set RGB 76,76,76. So you have to set object color besides texture.


Mobiius
Valued Member
16
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 25th Aug 2016 23:18
@Green7: I get an error with that shader? Complains about an invalid character 'Á'
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 26th Aug 2016 07:28
@Mobiius: I can not recreate this, got the code above in use, runs fine here... I will try to build a simple demo.
MikeMax
AGK Academic Backer
7
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 26th Aug 2016 08:28 Edited at: 26th Aug 2016 08:28
Thanks Green7 !

For me it's ok with static textured objects

Just one thing about applying Shadows on/with animated objects (.x model for example), the Shadow_AddObject function and especially the SetObjectImage and SetObjectShader methods make the model to be static. The PlayObjectAnimation no longer works. Tried also with SetObjectMeshImage and SetObjectMeshShader with no luck.

Any Idea ?
--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 26th Aug 2016 11:51
@MikeMax: This problems solution seems out of my reach, as i do not know enough about shaders, i'm still learning. maybe someone of the big players round here know the solution, i guess it could be the vertex shader? not sure about this.

@Janbo: i hope you know more about this?
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 26th Aug 2016 17:55 Edited at: 23rd Aug 2017 14:46
I see...
I uploaded a new demo in the first post
+Texturing (you must use textures now )
+Animated objects working (there is a second parameter in Shadow_AddObject now set it to 1 if it is animated)


I played with Variance shadow mapping but I think the wrong calculations in the View Matrix preventing me from succeeding
I would like to see how Paul did it in C++/OpenGL ... or wrap the maths calculations from Tier 2 to Tier 1 ...still hoping for the new version to have it build in
MadBit
Valued Member
10
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 26th Aug 2016 18:31
I have conveted some functions from glm (c++ lib) to agk. Dont know it works correctly. I will post it later. Hope today.

MadBit
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
MadBit
Valued Member
10
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 27th Aug 2016 00:02
Ok is uploaded in a seperate thread.

New 2D/3D-Math Lib
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 21st Sep 2016 11:01
Any news in here?
Sorry for bumping, but i do not want this to get lost.
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 21st Sep 2016 16:23 Edited at: 23rd Aug 2017 14:46
Quote: "Sorry for bumping, but i do not want this to get lost. "

Me neither, so thank you
As I mentioned above, I played with variance shadow mapping but didn't got it to work Jet.
I can really need someone who can confirm that one of the Math libraries is working correctly(I found flaws in all of them in some kind)
So that I know that everything else is my fault
And I don't have much time because I'm in project phase for school, should learn, and my brothers wedding is in a few days, then next month they change my pacemaker... and so on

But it's nice to see there is interest in my things.
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 22nd Sep 2016 08:11
Hey, nice to know you're still alive!
Take your time, get your own stuff up and running, no worries about this stuff here. Personal things come first, especially health. Take care, wish you good luck!
I can not look into math stuff, as its way above my knowledge. I normally do not work with codes and similar stuff, many of those things are highly strange to me. I do this as a hobby, for my own entertainment.
hoyoyo80
3
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 7th Oct 2016 03:43
i know nothing of shader programming...currently my game is 3d faking 2d and i use oval shape texture to act as shadow for my animated character if this is usable by me, then ill be like YAY!
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 2nd Nov 2016 16:52
Dear Sirs and Ladies, may I bump this?
Jack
14
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 9th Nov 2016 00:11 Edited at: 9th Nov 2016 01:04
Sorry for being late to the party^^ I had some work to do. "Reallife"
I have updated the advanced math function library to 0.60 and found some bugs in the Matrix4 code.
Maybe you try the new version with you code.
I have changed quite a bit and rewritten the Matrix4 part, maybe you also have to rewrite some parts, as some function input changed order.
Let's pray that this version will get the shadow shader running - or it will be even worse.

Quote: "I found flaws in all of them in some kind"

- Please post all bugs and errors, so I know what I could change.

[/url]
hoyoyo80
3
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 14th Dec 2016 11:07
Really have high hope on this
MikeHart
16
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 17th Dec 2016 09:58
Me too. I want to use it in my game Card Rogues.
Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200. Using AGK2 Tier 1.
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 17th Dec 2016 11:07 Edited at: 23rd Aug 2017 14:47
Hey,
I may/probably/will look into it again after the 10th of January... I have time then again.
I also want it to work for a game of mine.

@Jack: Thank you for that
I made a version with your functions but I don't get any results jet.
But I think I messed up some calculations.
MucMac
3
Years of Service
User Offline
Joined: 13th Sep 2015
Location: Munich, Germany
Posted: 18th Dec 2016 08:46
i left agk behind for some reasons, but this will bring me definitely back to it!
thanks janbo for this nice one!
--
Mac
Lead Programmer (Tier 1, AGK2) - MacOSX - want to go 3D with agk2!
Jack
14
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 28th Dec 2016 17:16
Bump for justice!

Quote: "
I may/probably/will look into it again after the 10th of January... I have time then again.
I also want it to work for a game of mine.

I made a version with your functions but I don't get any results jet.
But I think I messed up some calculations.
"


I try to be online to support you with the math 3d library.
Right now I work in GLSL and got more experience in it.
I try to see, if we could execute the matrix4 functions in the shader, in theory we should be able to compute everything with only the quaternion rotation and the position of the camera as shader vec3/vec4 input , the performance will blow the roof. Once we manage to get the raytracer to work in AppGameKit, I try to convert the whole code to GLSL.

[/url]
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 28th Dec 2016 17:32 Edited at: 23rd Aug 2017 14:47
I thought about calculating everything in the shader too
thanks for your support

I don't do anything in AppGameKit for a few more days as I would completely forget about everything else
which is far more important for me now
side note: the operation for my pacemaker went great
Green7
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 20th Jan 2017 12:54
janbo
10
Years of Service
Recently Online
Joined: 10th Nov 2008
Location: Germany
Posted: 20th Jan 2017 16:37 Edited at: 23rd Aug 2017 14:47
I guess calculating every (Model,View,Projection) Matrices in the shader would blow the roof for bad performance since the shader is executed per Vertex/Pixel but you only need the matrix calculation once for every Sun
I looked into it again and added Percentage close filtering which means another method for some smother shadow edges ...
I have 3 versions for three different matrix library's and 2 gives the same result for now..so I think I might screwed up or forgot something...
But I'm not quite sure where to look now.. so if someone can contribute ..I'll b happy
Jack
14
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 22nd Jan 2017 18:04 Edited at: 22nd Jan 2017 18:06
Quote: "I have 3 versions for three different matrix library's and 2 gives the same result for now"

At least I have not to worry about the advanced math functions lib.
Quote: "if someone can contribute ..I'll b happy"

Do you have a current project to look at?

[/url]

Login to post a reply

Server time is: 2019-07-19 12:15:02
Your offset time is: 2019-07-19 12:15:02