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 / [AGKv2] 2D Normalmapping

Author
Message
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 14th Nov 2014 14:16 Edited at: 17th Jul 2017 16:42
Hey,

since my methond only works with AGKv2, I made a new thread for it and provide a Demo with normalmapping for "real" sprites.

New Demo:
2D Normalmapping Demo

Old Thread where it started(AGKv1):
[AGKv1] Normal mapping
Here it was discussed at the same time:
OMG look what i found
Old Demo:
2D Normalmapping Demo

Picture:


2D Normalmapping DynamicLightCount.ps

AGK Code:


2D Normalmapping.ps


2D NormalmappingIY.ps
Some Normal Maps have inverted y normals here is my solution


2D Normalmapping Illuminationmapping.ps
Provide a third texture as Illumination Map


</div>

Using AGKv2 Tier1

Attachments

Login to view attachments
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 14th Nov 2014 14:18 Edited at: 17th Jul 2017 16:42
What do you think?

And let me know what you have made with it

</div>

Using AGKv2 Tier1

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Nov 2014 14:31 Edited at: 14th Nov 2014 14:51
I really really love you janbo. Time to decide what to make with it...

EDIT: Here's a slight change to the shader allowing a different Falloff for each light:


Does anyone know how to add a dynamic number of lights so we can add as many as we like? I was thinking that if it was possible it would be easy to add a large number of lights to a scene and only calculate the lights whose range touches each "lit" sprite. I'd be happy to share a system that did this if someone who knows shaders could point me in the right direction for the shader code... would make an awesome demo for AppGameKit V2 as well!

Maybe Paul could add a command for Spine characters to add a shader to bones...
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 14th Nov 2014 15:00 Edited at: 17th Jul 2017 16:42
Thanks,

I think I get the knack of shaders.
Shaders are really powerfull.

I think there should be only one Falloff, but aditionally a LightRange parameter.

The shader is made.. to easily add additional Lights, just add
and the associated parameters.
We can't use Arrays in AppGameKit shaders... not?

</div>

Using AGKv2 Tier1
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Nov 2014 15:14 Edited at: 14th Nov 2014 16:53
That's a big shame... ok so I'd have to hard code in a max number of lights right? I'll be right back...

EDIT: Ok I have 10 lights running at roughly 500fps but I think I can improve that if I can get a little optimisation in the shader and in this version you can edit the Range. I'm keeping falloff separate now as you suggested:

Attachments

Login to view attachments
Van B
Moderator
16
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Nov 2014 16:54
Looking sweet

For the lights issue, maybe it would be an idea to pass the number of lights to the shader, then ignore any lights that are unused in the frag, then at least the lights could be optimised in AppGameKit to use a typed array or something, but the shader would only have to calculate the ones that are used.

Anyway, can't wait to mess with this - it's exactly the sort of thing people have been crying out for.

I am the one who knocks...
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 14th Nov 2014 20:08 Edited at: 17th Jul 2017 16:43
I added LightRange as the w component of the vec4 LightPos,
updated the first Post with my solution for the inverted y component in normalmaps and added my ettemp to make an illumination map.
I made the same in the Labyrinth Demo wich looks great if you add the bloomshader.

If you have something you want me to add to the first post... just ask.

</div>

Using AGKv2 Tier1
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Nov 2014 21:21
Quote: "For the lights issue, maybe it would be an idea to pass the number of lights to the shader, then ignore any lights that are unused in the frag, then at least the lights could be optimised in AppGameKit to use a typed array or something, but the shader would only have to calculate the ones that are used."

My exact thinking. In fact I tried several versions of this but for some reason it wasn't working. I'm assuming that int is a valid datatype in OpenGL?
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 15th Nov 2014 02:23 Edited at: 17th Jul 2017 16:43
Okay you want a Dynamic light Count here you have...

@baxslash: You are right I had problems with int too, but you can pass a float and typecast it to int.
(Do you read the PM's or your E-mail's ?)

2D Normalmapping with Dynamic Light Count:
For now 8 Lights possible


And the demo Code:


Soon we have covered all options

</div>

Using AGKv2 Tier1
unlikely
7
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 15th Nov 2014 06:17
Looking really, really sharp guys!

Good work!
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Nov 2014 09:16 Edited at: 17th Nov 2014 12:59
Quote: "You are right I had problems with int too, but you can pass a float and typecast it to int.
(Do you read the PM's or your E-mail's ?)"

Smart idea. You have something very similar to what I came up with. I might just optimise one part of it if I have time later.

I don't get a notification for PM's so I hardly ever notice them. Email me if you want to chat.

EDIT: Added screen for next post

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Nov 2014 12:57 Edited at: 17th Nov 2014 13:02
I've been playing with this a little and I have a version of your shader running up to ten lights at around 1800-1900fps on one sprite. I think if I do some tests on an actual game I might have something useful here. Test project attached.

For some reason it seems to run faster with the nested 'if' statements I'm using here than it did with a 'for' loop (at least for me). This version does not use your extremely cool 'Illumination Mapping' but I wanted to push the basic shader as far as I could for my own purposes.

Also I changed it to a linear calculation to speed it up a little too. My version gives the user a light "Range" value for each light and removes the need for the "Falloff" value needed for the quadratic calculation you have.



EDIT: Awesome work by the way! I couldn't have done any of this on my own...

Attachments

Login to view attachments
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 17th Nov 2014 13:42 Edited at: 6th Jun 2015 19:36
Why should if statments be faster than a for loop?

2D Normalmapping
-10 Lights
-Range parameter
-Quadratic Falloff




Now we need spine characters with normalmapping...
And I need drawing skills the spine tool and Sprite Dlight


Using AGKv2 Tier1

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Nov 2014 13:50 Edited at: 17th Nov 2014 13:53
Wow, I hope that runs as fast on my computer! Not sure what the issue is with the for loop but I did a version that run through a for loop and it was around 200-300 fps slower with 10 lights. Other than that the code was identical.

I'll take a look at your version when I get a chance...

EDIT: I don't see a range parameter?
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 17th Nov 2014 16:11 Edited at: 17th Nov 2014 16:13
The Range was the w component the whole time...
Quote: "I added LightRange as the w component of the vec4 LightPos"

Try SetShaderConstantByName( 1, "LightPos",LightX#,LightY#,LightZ#, LightW# )
And remember to set a suitable z component.

Linear Falloff is faster for sure but I'll keep it quadratic for now.

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Nov 2014 17:39
I see, I missed the w component there

I honestly prefer the quadratic method for the way it looks but yes, I'm after speed in my version for now.
Yodaman Jer
User Banned
Posted: 17th Nov 2014 18:29
Wow, this looks awesome!

As someone who is about to start out with AppGameKit, I can't wait to try this out!


Meh game development blaugh!
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Nov 2014 18:41
Hi Yodaman! Yes AppGameKit is getting pretty awesome
Yodaman Jer
User Banned
Posted: 17th Nov 2014 18:46
Hi baxslash!

Indeed it is getting pretty awesome, I've downloaded the demo and it runs a lot better than it did when I first tried it out a few years ago! Of course having a proper development/gaming rig might have something to do with that

I can't wait to really get going with it, I'm really considering pledging so that I can get access to the V2 alpha. Definitely seems worth it!

And this normalmapping that janbo has created looks beautiful, I really can't wait to try it out! Would be a very useful effect in a game I'm planning!


Meh game development blaugh!
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Nov 2014 21:31
If you want to use the 2D normal mapping you'll need V2 of AGK. It's not possible in V1.
Yodaman Jer
User Banned
Posted: 18th Nov 2014 03:41
Indeed, I noticed that, hence my wish to pledge haha.

Now that I've played with the demo of AppGameKit though, I know it's definitely something I want to invest in. It is like a much, much better version of DarkBASIC!


Meh game development blaugh!
Blendman
5
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 24th Nov 2014 15:25
Janbo : your example is excellent, thank you very much !

http://www.dracaena-studio.com
Van B
Moderator
16
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 1st Dec 2014 18:38
I'm thinking that the posVarying vector does nothing with sprites - doesn't seem to return anything, hopefully I'm using it wrongly as I'd really like to make a refraction sprite shader.

Could I be a pain and ask if someone could help me confirm that posVarying does nothing?

I am the one who knocks...
Ched80
8
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 7th Dec 2014 21:29
Great work guys, I've also been working on a normal mapping shader, but I've been combining it with my dynamic shadows. I'll post my workings soon, at the moment the fps is a little low as I'm rendering the quad too many times. Plus I'm trying to incorporate it into a game so that development is slowing me down a bit.

Van B
Moderator
16
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 1st Nov 2016 19:39
Attempting unlock...
The code is dark and full of errors
janbo
10
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 1st Nov 2016 22:11 Edited at: 1st Nov 2016 22:16
Hey, I made a little update to fit the new parameters and ability to use arrays in shader.
It's now in a separate agc file and wrapped in a few little functions.

Also maybe someone can say me why the images "pizza_x.png" file does not show up ?

Using AGKv2 Tier1

Attachments

Login to view attachments

Login to post a reply

Server time is: 2019-07-19 12:20:10
Your offset time is: 2019-07-19 12:20:10