Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 3:01 pm

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Slick ShaderTest ?
PostPosted: Mon Jul 09, 2012 4:46 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Hello, I used tutorial to update to development branch of slick, and I want to test ShaderTest, but I have no idea how to use it.

Can someone please explain it, and maybe write a super - simple program on using it ?


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Wed Jul 11, 2012 5:19 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Shaders are a rather advanced topic -- they require a pretty good understanding of Java, math, graphics (e.g. RGBA color model, screen space coordinates), and programming in general. With that said, I'm working on a tutorial series that will hopefully be understandable to newbies. See here:
http://slick.cokeandcode.com/wiki/doku.php?id=shaders

The first lesson is super simple -- just going over the basics and coloring a red square via GLSL. Other examples in the "tests/shader" source go into a bit more detail -- setting uniforms, sampling from textures, blurring, etc. The tests live here and their shader files here.


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Wed Jul 11, 2012 8:57 am 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Thank you !

Is there part 2 already up ?


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Wed Jul 11, 2012 11:26 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Nope. :)


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Wed Jul 11, 2012 4:10 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
When can I expect tutorial number 2 ?


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Wed Jul 11, 2012 4:54 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Probably not for a while. What are you trying to accomplish? What are you still confused about? Lesson 1 goes over the basics of setting things up -- i.e. all you need to start playing with shaders in Slick.

Tutorial 2 boils down to:
Uniforms are like variables in a fragment shader that are read-only; instead of setting them in GLSL, you set them from Java like this:
Code:
program.setUniform2f("resolution", 512, 512);


Look at the other shader tests for examples of how to do that.


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Wed Jul 11, 2012 5:31 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
I read ShaderTest, but I didn't go into vert and frag files, so, I managed to load them and use the Invert shader on my image. Now my question is: Is there any way to mask image using shape, with shader, or anyway ?


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Wed Jul 11, 2012 7:59 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
You can mask with alpha maps, described here:
http://slick.cokeandcode.com/wiki/doku. ... alpha_maps

You could also mask with a shape by using ShapeRenderer and texture.


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Thu Jul 12, 2012 7:51 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Quote:
You can mask with alpha maps, described here:
http://slick.cokeandcode.com/wiki/doku. ... alpha_maps


I managed to do the masking, and thanks for that.

But just out of curiosity I wanted to test your source code, and it didn't work for me. Window opens, count shows up, and counts, but lights don't appear.

Do you know what's the problem ?


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Fri Jul 13, 2012 10:08 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
Nevermind, I coded the whole thing again, trying to understand every line of code ( managed to do that ), and it finally works.

I saw that if I bind the tint of light, and use the drawEmbedded function tint works, but if I use only draw, it doesn't.

Can you please explain to me what's the difference between drawEmbedded and draw ?


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Sun Jul 15, 2012 12:49 pm 
Offline

Joined: Thu May 19, 2011 9:43 am
Posts: 50
The advanced shader test is not working correctly.
It looks like you can't apply two shaders at the same time:

Image


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Sun Jul 15, 2012 6:13 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
PixelDeBurner wrote:
Nevermind, I coded the whole thing again, trying to understand every line of code ( managed to do that ), and it finally works.

I saw that if I bind the tint of light, and use the drawEmbedded function tint works, but if I use only draw, it doesn't.

Can you please explain to me what's the difference between drawEmbedded and draw ?

"draw" is a utility method that does the following: bind a colour filter (or white if none was specified), rotate the image, and render it. drawEmbedded is used to improve performance when you are drawing multiple images that share the same texture -- i.e. tiles in a sprite sheet. Instead of sending every image to the GPU individually, you can "batch" a lot of images in the same draw call with Image.startUse() and endUse(). However, certain things like changing the draw mode and rotating the graphics context won't work within startUse/endUse.

Here's an example of how you might use it:
Code:
img = spriteSheet.getSubImage(0, 0, 32, 32);
img2 = spriteSheet.getSubImage(32, 32, 32, 32);
...

spriteSheet.startUse();

//binds the colour white for all proceeding sprites
Color.white.bind();
img.drawEmbedded(x, y, w, h);

//tint the following sprites blue
Color.blue.bind();
//using Image.setRotation/setAlpha/etc won't work with startUse/endUse
//we have to specify it like this
img.drawEmbedded(x, y, w, h, rotation);

spriteSheet.endUse();


Usually you are fine to use Image.draw over drawEmbedded, but if you want more performance out of your game, you should try using more sprite sheets and more batching. :) drawEmbedded isn't as well documented since most people don't need that much performance in a simple 2D game.

pekhe - will check it out..


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Sun Jul 15, 2012 9:17 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
pekhe - Blur example fixed. The old ShaderTestAdvanced was a bit messy and didn't really make sense. Now it should work as expected, and you might notice the blur quality is a lot smoother, too. :)


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Sun Jul 15, 2012 10:06 pm 
Offline

Joined: Thu May 19, 2011 9:43 am
Posts: 50
Where can I get it?
I don't see updates yet at https://bitbucket.org/kevglass/slick


Top
 Profile  
 
 Post subject: Re: Slick ShaderTest ?
PostPosted: Sun Jul 15, 2012 10:24 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Oops, check again. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group