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.

Newcomers AppGameKit Corner / Noob guide to shaders.

Author
Message
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 6th Jun 2015 11:47
Is anyone up for giving a guide for 2d pixel shaders?

I have looked in the forums and still can't seem to get my head round them.
I have looked at the shaders which seem to be coded in c++ but they don't make sense or seem to have much code to them to create the effects they do and then they are loaded into tier 1 and used some how, as if by magic!

A few questions.

How can they be used?
Eg, are they just for lighting effects or can they be used for things like drawing and flood fill effects etc?

Can they be used on a full screen sprite for direct display effects?
Eg, pasting a sprite to the screensprite?

Is there a very well documented idiots guide to help with shaders and not just for a light effect.

Looking at a shadertoy example it seems shaders can be used for lots of things but I am not sure and am really interested in 2d stuff.

Thanks.

The Amiga and Amos were great!
Download my game - Paint Pot from Amazon and Google here - http://leap.my-free.website/
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 6th Jun 2015 14:06
Hi, Im a bit of a shader noob myself but I'v been experimenting with some of the examples found in the fourm and the Teie1 stuff is starting to make sence but I'm still very lost with shader code, anyhow, heres a breakdown:

this is a shader (2D Normalmapping.ps found on the fourm)


and in AppGameKit, load the shader and set the variables
// load


^^ thats about the basic nuts and bolts to getting a shader working the AppGameKit side is easy but the shader side will take a bit of research, hope that was of some help, I know it took me a while to get my head round it!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Jun 2015 22:00
I'd be happy to share what I've learned (not much) but it would be great to get an expert to provide some insight. For example there are some conditional statements that run much slower than others...

Using AppGameKit V2 Tier 1
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Jun 2015 03:02
Well I have been looking into pixel shaders and it seems they are quite powerful and can do some varied effects.

[href]http:// developer.download.nvidia.com/shaderlibrary/webpages/hlsl_shaders.html[/href]

Would these type of shaders work?

I am quite interested in the paintbrush shader.
Not sure if I am thinking on the right lines here but with AppGameKit being lacking on drawing commands I was wondering if shaders may come to the rescue?

Maybe I am not understanding them correctly but it seems they could.

The Amiga and Amos were great!
Download my game - Paint Pot from Amazon and Google here - http://leap.my-free.website/
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Jun 2015 03:10
@PartTimerCoder will check that out tomorrow but it just seems gibberish that .ps file at the minute lol

The Amiga and Amos were great!
Download my game - Paint Pot from Amazon and Google here - http://leap.my-free.website/
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 8th Jun 2015 11:18
as I see people have been struggling with arrays in shaders? I would have thought the bulk of any drawing operations would be AppGameKit side and would involve heavy communication between AppGameKit and the shader on each frame to tell it where to draw what shapes, I could see that getting quite cumbersome and slow but again I'm thinking out loud and as usual probably got it all wrong lol

that .ps file is gibberish to me to but I'm seeing the impotence of using shaders so its something I 'have' to get my head round, so yea I'll be watching this thread for some clues lol
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Jun 2015 13:00
@baxslash think your input would be very useful as I think you have a better understanding than most

The Amiga and Amos were great!
Download my game - Paint Pot from Amazon and Google here - http://leap.my-free.website/
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Jun 2015 15:58
Quote: "@baxslash think your input would be very useful as I think you have a better understanding than most"

Trust me, I'm a noob too!

Using AppGameKit V2 Tier 1
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Jun 2015 19:01
Quote: "Trust me, I'm a noob too!"
I must be a super NOOB then lol

Well hopefully someone will come to the rescue

The Amiga and Amos were great!
Download my game - Paint Pot from Amazon and Google here - http://leap.my-free.website/
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 8th Jun 2015 22:51 Edited at: 8th Jun 2015 22:56
Unfortunately I'm not your hero but I've been tinkering with shaders on and off for a while and found a couple of helpful resources:

http://www.lighthouse3d.com/tutorials/glsl-tutorial/

http://forum.thegamecreators.com/?m=forum_view&t=201508&b=41

I'm guessing you've seen the one from the forums already but I thought it worth mentioning anyway.

My problem is that I don't know any programing outside of BASIC so I've pretty much just been copying other people's shaders and then playing around to see how things work.

Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 8th Jun 2015 23:30
Cheers 29 games!

Quote: " I've pretty much just been copying other people's shaders and then playing around to see how things work"


This is a good way to learn.

Doing just that at the minute

The Amiga and Amos were great!
[href=http:leap.my-free.website/]My website LEAP - Download Paint Pot here![/href]
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Jun 2015 16:16 Edited at: 12th Dec 2015 23:13
In a 8 week praktika at NVIDIA at the age of 20 I learned glsl there and at the end I had some demos including one scene with Lights Bumpmapping and Bloom in opengl/c++... they were awesome...

I think a good start is to understand what the Shaders are for.
There are two types of Shaders:
•Vertex Shader (*.vs)
•Fragment Shader (*.ps)

The Vertex Shader changes the Vertices wich are basicaly the corners of an object (3D and also 2D)
You can make a polygon out of several vertexes connected via Indices also called face I think.
So Vertices have attributes like Position,Color,Normal(I think there should be a Tangent also)
The Normal is a perpendicularly Vector wich represents the Direction of the Face.
Hope that makes sense.

In the Fragment Shader you change the Color of an pixel only but since we are creating Games it is verry important to us right!?
A Picture to This:


By the way, I think if you load a Fragment Shader via LoadSpriteShader("*.ps") AppGameKit will take a default Vertex Shader for this.

Now we have the two shaders... we can take this as example:
Vertex Shader


Fragment Shader


They are from Any info on writing agk shaders? wich is a verry good reverence


You see there are three types of variables passed to the two shaders:
•Attributes
•Varyings
•Uniforms

The Attribute Variable is passed to the Vertex Shader only.
AGK passes some Attribute Variable automatically to the Vertex Shader:
•position (-1 to 1)
•normal (-1 to 1)
•uv (0 to 1)

The Varying Variable is also passed to the Vertext Shader(normaly they are "empty" at the start)
but after you worked with them they are passed to the Fragment Shader.
•You can name them as you want : )

The Uniform Variable is passed to the Vertext Shader and to the Fragment Shader.
AGK passes some automaticaly to both.
•agk_World
•agk_WorldNormal
•agk_View
•agk_Proj
•agk_Ortho
•agk_ViewProj
•agk_WorldViewProj
•agk_WorldOrtho
•agk_ObjColor
•agk_PLightPos
•agk_PLightColor
•agk_DLightDir
•agk_DLightColor
•agk_resolution
•agk_time
•texture0 to texture7
•uvBounds0 to uvBounds7

And A Picture Again:


Then there are Variable Types You can define and you will need:
•Float
•vec2 (x,y)
•vec3 (x,y,z)
•vec4 (x,y,z,w)
beware there are no Integers


And There is the sampler2D which is a vec4
Which you can access like so:



Now what you do with it is pretty much up to you.
There are many methods how to do things but I would start messing with the basic shader.
If you know these thing the rest is Math.

I hope I could help somehow and please correct me.

Using AGKv2 Tier1
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 13th Jun 2015 18:49
Thanks janbo, this is a really interesting read, going to take a further few reads to get my head around it but looks like there are lots of things possible with shaders!

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Jun 2015 11:38
Very useful. I wasn't aware of some of those variables.

Using AppGameKit V2 Tier 1

Login to post a reply

Server time is: 2024-11-23 20:17:13
Your offset time is: 2024-11-23 20:17:13