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 / [AGK v2 T1] How do I use sprite shaders?

Author
Message
Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 1st Jan 2014 15:20
Hi and happy new year everyone.

I'm testing the AppGameKit v2 alpha and I'm trying to figure out how to use shaders on sprites. I've looked at the shader example but it uses planes and not sprites and I couldn't find a way to aply it to sprites.

I've never used shaders before so I'm wondering if someone has a simple example that could help me get started. I'm using tier 1 by the way...
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 1st Jan 2014 19:28
Just posting to subscribe to this thread. No time to explore on my own yet. Also can we use shaders on text objects?

Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 3rd Jan 2014 16:58
Too bad no one is responding.

I've tried on my own but I can't even get the simplest shaders to work.

Is this the correct way of applying a shader to a sprite? and if yes, what should the shader file look like? No matter what I try the sprite will not appear if I apply a shader.


This is the simples example of a pixel shader I could find but it's not working. Do I need to set some parameters before the "void main()" part?
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 3rd Jan 2014 17:49 Edited at: 29th Oct 2014 18:28
The following code should work with Alpha 1

Sprite.vs


Sprite.ps


AGK Tier 1
Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 3rd Jan 2014 18:03
Thank you Paul! It works now.

I was using the loadSpriteShader() command before but I couldn't get it to work. I'll use the loadShader() command from now on instead.

Thanks again.
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 3rd Jan 2014 23:10
Thanks for posting this.

Any tips for where we can read up on shaders? I'd like to write some custom ones.

Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 3rd Jan 2014 23:55
I have no idea where to start but I found this site with a lot of fragment shader examples: http://glsl.heroku.com/
Some of the examples can be used in AppGameKit with some tweaking.
Ranietz
AGK Gold Backer
20
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 4th Jan 2014 18:24
I've been playing around with shaders on sprites for a day now and here's two examples I came up with for those who are interested.

main.agc file


sprite.vs (the same as Paul wrote earlier in this thread)


pixelate.ps


grayscale.ps
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 5th Jan 2014 11:52
Shadertoy is a really useful site for testing fragment shader stuff in real time and finding inspiration. Also, cliff had a thread a while back with a lot of info about writing AppGameKit shaders for the 3d stuff but I immagine most of that is the same

Say ONE stupid thing and it ends up as a forum signature forever. - Neuro Fuzzy

Login to post a reply

Server time is: 2024-11-24 23:18:04
Your offset time is: 2024-11-24 23:18:04