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/AppGameKit Studio Showcase / Simple 2D sprite drop shadow shader

Author
Message
vennis73
7
Years of Service
User Offline
Joined: 12th Sep 2016
Location:
Posted: 14th Dec 2019 14:46 Edited at: 14th Dec 2019 20:51
** Warning, Virtual Nomad pointed me on a problem on android and it seems my shader has some issues on other platforms, i'm not going to remove it but be aware if you're planning to use it, i think it's a bug and i'll try to solve it or address the issue if it's a AppGameKit thing **


My first post..

I created a shader for sprites that generates a dynamic shadow. Works with animations etc.

I had a tough search for documentation (still no real good found) and debugging shaders is very hard. Unless i miss something like a debuglog where you could output to but i found it most by trial and error.

But i think it works ok, it suits my need, i'm still not sure the shadow_offset is managed well, seems a bit off when changeing resolutions. Also some other parameters might nog be proof for your own resolution but the demo project might help you get it to use in your own project.

It creates a shadow based on the alpa of the pixels above the shadow line. Took me a while to come up with such a simple idea.

It requires the actual position within the sprite and therfor the shader values sprite_y and sprite_height must be set within AGK.
And if the sprite moves you will need to keep setting it and reapplying the shader to the Sprite (this vars are not dynamically applied to the shader when changed i think)

Also the baseline of the shadow must be set by setting shadow_offsety

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 14th Dec 2019 19:20 Edited at: 14th Dec 2019 19:22
i'm seeing no shadow on my pc and an error when broadcast to android:


Attachments

Login to view attachments
vennis73
7
Years of Service
User Offline
Joined: 12th Sep 2016
Location:
Posted: 14th Dec 2019 20:14
Thanks for the report.

I fixed those int/float errors, i didn't get them on the PC.

I changed the 0 to 0.00 and forced some floats. That should be ok now.

But! I also found an issue on my ipad with the shadow not showing. It has to do with how to find the position in the shader. I get some weird results on PC vs IOS.

gl_FragCoord.y seems to give a total different value then on the PC. It's hard to debug since you can't log or have breakpoints (or at least i didn't found a way yet)

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 14th Dec 2019 20:49
shader compiles now but neither pc nor phone have a shadow

vennis73
7
Years of Service
User Offline
Joined: 12th Sep 2016
Location:
Posted: 14th Dec 2019 20:53
Hey Virtual Nomad,

Thanks for the report. It seems there is some problem between the OS's in the way i try to use my shader.

I personally have a PC and Nvidia.

The origin (0,0) is bottom-left on IOS and it's top-left on PC, at least that seems to be the issue. I'm starting a thread on this in normal app-kit platform and added a warning on top of this one that it might have issues.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 15th Dec 2019 00:50
I think what virtual nomad is asking can we see the code your using the shader in
or a small example that works
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 15th Dec 2019 04:43
Quote: "I think what virtual nomad is asking..."

not asking anything; just reporting.

vennis73
7
Years of Service
User Offline
Joined: 12th Sep 2016
Location:
Posted: 15th Dec 2019 10:20
I added the project zip. I think in first post i forgot to add or maybe because i'm a newbie my attachments are reviewed first or something.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 15th Dec 2019 12:49 Edited at: 15th Dec 2019 12:50
I just downloaded the attachment but I cant see any shadow with it on pc, I also had to modify to the latest shader code above
because of the errors. My apologies didn't notice it before

I did notice a couple of strange things with your code
SetSpriteShader(iKnight, iKnight_Shader)

Should only need to be declared once and not be in the main loop the same for variable declarations

but definitely no shadow in studio or classic on pc
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
vennis73
7
Years of Service
User Offline
Joined: 12th Sep 2016
Location:
Posted: 15th Dec 2019 13:15 Edited at: 15th Dec 2019 13:16
Hm weird, my setup is a PC with Nvidia videocard.
It probably has to do with the issue i found between my PC and IOS where the shaders origin is either top-left or bottom-left (it seems like that). Which normally isn't that of a problem but i am looking a specific direction in my shader and only on a specific Y (the base line of the shadow).

The shadow should look like this and it follows the animation



I find shaders almost impossible to debug. I don't know if anyone has tips for that.

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 15th Dec 2019 13:28 Edited at: 15th Dec 2019 14:24
Strange I have nvidia aswell might need one of the shader gurus to have a look

The only thing I can think of is perhaps your using an older version of AppGameKit and TGC have made some changes over time

EDIT I just found this link of shadow functions by Bengismo https://forum.thegamecreators.com/thread/221455
Its another alternative if you don't wish to use a shader

and there is dynamic 2d shader code here by Ched80 https://forum.thegamecreators.com/thread/212525
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
vennis73
7
Years of Service
User Offline
Joined: 12th Sep 2016
Location:
Posted: 15th Dec 2019 15:02
Thanks a lot for the references. The Ched80 shader code i saw before but i couldn't get it to work and is a bit overkill for my needs.

The Bengismo one i didn't see before. I'll look into it, looks interesting.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 15th Dec 2019 18:26
vennis,

to be honest, i don't see a need for a shader to produce the type of shadow that you are depicting, here.

i appreciate that it seems "weighted" where the relatively-thin sword produces a thinner, lighter shadow compared to the character's shadow but none of the shadow appears to extend beyond the rectangle/image of the original sprite?

IE, the shadow should be added to the sprite itself/pre-rendered?

i could see writing a function "weighing" the pixels above and adding appropriate shadow to the image itself being easy enough (hmm... i'll put that on the to-do-someday list).

but, maybe this is part of a larger project that could require live/dynamic shadows? or, you are simply testing your skills and/or exploring shaders?

all of which i can appreciate where i've never had the guts to tinker with shaders myself.

in the end, good luck with your endeavor

vennis73
7
Years of Service
User Offline
Joined: 12th Sep 2016
Location:
Posted: 15th Dec 2019 19:09
Hi,

Thanks for your feedback.

The reason i want dynamic shaders is it makes creating animations easier/faster and the shadow is probably more accurate then i do it myself by hand.
I know the shader i made doesn't seem much but the effect it adds to an animation is superb, It's like 1+1 = 3 (mho). But the problems i ran into are a bit of a showstopper on shaders for me.

I do 'Spriter' animations and adding shadows manually would be just + 5-10% work on all animations i'm planning to do.
I'm just a solo developer so creating convients to save me work are my first object atm.

But i get your point ! i found that Bengismo-link of fubarpk very useful. Wish i had seen it before.

Although I had some fun and interesting challenges with this shaders last days, developing shaders is a bit of a hassle and i don't mind if i leave it for others.

Login to post a reply

Server time is: 2024-03-29 14:04:03
Your offset time is: 2024-03-29 14:04:03