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 / [Code + shader] AGK V2 Sprite Shader Tests

Author
Message
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 28th Jun 2014 16:23 Edited at: 28th Jun 2014 20:08


Was playing around today with sprite shaders, it's fun and there will be loads of stuff we can do to improve our games visually.

Anyway, attaching code, media and shaders for what's in the video below.

Disclaimer: The code is a little bit messy, not setup to be a tutorial really, but I think it's fairly clear to see how to use the shader.

The pointlights to not use the usual quadratic falloff function. I think they blend quite nicely because of this.

I only just did the spotlight, lots left to do on that one. But it's on its way.


I would enjoy it if more people filled this thread with their own sprite shaders

Edit: Made the spotlight nicer with smoother edges. Attachment updated

My hovercraft is full of eels

Attachments

Login to view attachments
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 29th Jun 2014 22:13
This is nice! I really need to get up to speed with shader coding!

Thanks for sharing!

nickele upgraded
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Birthplace of Democracy
Posted: 30th Jun 2014 02:15
I know you might laugh with this question, but since I am a rookie in this... where can I find some decent documentation about the shaders used in AppGameKit?

Since the AppGameKit documentation is not so rich in details, can anyone point to any articles so as to get some idea about the what, how, when of shaders and how someone can make his own shaders and use them in Tier 1?

"For Those About to Program We Salute You"
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 30th Jun 2014 09:49 Edited at: 30th Jun 2014 10:13
You can read up on GLSL if you want to learn to make shaders.

When it comes to how they work with AppGameKit we don't actually have any documentation. However, Paul posted an example sprite shader that revealed some information of what AppGameKit sends to the shaders.

So, to conclude, read up on GLSL, then look at other shaders written for AppGameKit to learn the specifics for AppGameKit shaders.

On 3d shaders there are other older threads you might able to find if you search.

Sidenote:
Question to Paul maybe, but still:
I made a shader with 4 point lights and 4 spot lights that used FOR loops to iterate each lights. I could specify in AppGameKit how many the shader was to iterate. This ran at about 40fps on my PC.
Then, I did the same thing but removed the FOR loop and just calculated all possible lights without specifying how many were used in AppGameKit and the FPS jumped up to 900.

One of the problems might have been that I had to copy each vector to an array in the fragment shader to be able to iterate it, so being able to send an array/matrix from AppGameKit might be useful?


Oh and here are my latest sprite shaders:
Vertex:


Fragment:





My hovercraft is full of eels
nickele upgraded
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Birthplace of Democracy
Posted: 30th Jun 2014 10:49
Thank you for your advice lilpissywilly. I will start searching at once.

"For Those About to Program We Salute You"
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 3rd Jul 2014 17:37 Edited at: 3rd Jul 2014 17:39
Here is a plain no-nonsense shader for sprites that will apply color from the sprites image and SetSpriteColor(), and also supports alpha set with SetSpriteColor() plus blending mode.




Example:

Red backgrund: (255,0,0) +
white sprite with SetSpriteColor(0, 0, 255, 255) (thusly it's now colored blue, like without using a shader)
And then we set SetSpriteTransparency to mode 2 on that sprite, it will now blend to the color (255, 0, 255, 255).
(Of course SetSpriteTransparency mode 0 and 1 also works if you don't want blending)


I think this is a good starting ground for sprite shaders. Non-intrusive if you will

sprite.vs:



sprite.ps:


My hovercraft is full of eels
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 3rd Jul 2014 18:05
Ok yeah, if you do want to go nuts:

Use the same vertex shader as above.


This will allow, 2 spotlights, 8 pointlights, ambient lighting, pixelation if wanted, blending and alpha.

If anyone needs example code, give a shout. I'll keep posting shaders as I perfect them, if only to have an online safekeeping

sprite_2spot_8point_pixelate_amb.ps


My hovercraft is full of eels
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 22nd Aug 2014 05:42
I'd like to see some example code if you have some handy.

Apps published: 4
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 22nd Aug 2014 21:36
Sure. A small sample project attached as zip.


I haven't touched this stuff since I ran into a few problems with full screen shaders on android, decided to leave shaders until AGKv2 is more mature.

My hovercraft is full of eels

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-25 07:40:10
Your offset time is: 2024-11-25 07:40:10