Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 26, 2018 12:05 am

All times are UTC




Post new topic Reply to topic  [ 63 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
PostPosted: Mon Mar 19, 2012 9:08 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Ah very nice. That will be very helpful to beginners. Thanks for the hint, I thought that it might be because of that but wasn't sure xD

I will try it out as soon as I have some time (Toy Shader is a really nice tool to test stuff with imho).

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Tue Mar 20, 2012 8:32 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Okay, i tested it and it works as expected :)

I would suggest we clean the code and add some doc and push it into the dev branch if liamzebedee does not resist :D If that's done I would do some basic shaders (the first would be a simple texture-fragment shader like the one above). I'm more the fragment shader guy so my vertex shader input will go to one vertex shader positioning the vertices :D

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Wed Mar 21, 2012 8:01 am 
Well as of current I'm not liking davedes structuring of the shader code IMO. He is an excellent game developer, surely better than me in alot of regards. Currently the code is very messy (I assume this is just because of rapid dev, understandable) and the structure isn't flexible (there are probably reasons for this).

Currently my code is very simple, and adaptive. IMHO I think it would be simpler to let the user decide what shaders they want to use using program.attachShader(ShaderType.VERTEX, "vertexsource"). The way I have structured my code is flexible too.

Please view the NEW UNSTABLE code here in this commit

The only part not working now is variable location caching. @davedes help please?


Top
  
 
PostPosted: Wed Mar 21, 2012 8:23 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
The thing is, as davedes said you have on method for setting uniforms which is a bad idea imho. This means I have to keep an array of the floats values somewhere because allocating a new every loop (since you probatly want to update your's shader values) is simply overkill. Why don't you add the methods like there davedes? Of course it's clutter but that's how setter and getter are.

My point is not that your not a good programmer btw :) My point is that you cutting aways usability ;) I still can't get your code to work painless as Slick is meant to be.

Some points:
  • enable/disable breaks the convention of Slick using bind/unbind (minor stuff but still, you need to think HOW the dev uses this and how he can use it without much work or understanding. The same goes for finalies instead of destroy :D
  • let the user makes his own class for specific shaders. I know what you want to achieve but I rather have my own class subclassing Program and so on.
  • I can't extract a shader from a program. How is this good? Maybe I want to extract a shader and attach it to another program. Think of the simple fact that most Shaders use the same vertex shader.
  • Cutting away control. No checks for specific uniforms no real debugging possilities. No logging for errors.
  • Loading source. PLEASE take a path as string and load the source like davdes. You leave the developer with doing more work then he needs to do :D

Don't get me wrong your code is useable but not in a Slick way and not for real developer who want's control and simplified usability :) Of course davedes is currently a bit messy but why don't you try to merge your stuff with his? And please don't think that your worser then anyone else ;)

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Wed Mar 21, 2012 8:40 am 
@R.D. Liking the constructive criticism btw. The thing is, shader development is lower level, so I guess we have to find the perfect usability level while maintaining control over data.

I'll say go for @davedes implementation in Slick then. You guys think it's better for the user, I probably just have a different shader hat on. Feel free to use some of my cross platform code, though know that I think of it, probably just stick with OpenGL2 (unless you want geometry shaders).


Top
  
 
PostPosted: Wed Mar 21, 2012 8:46 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Don't get me wrong. I like the idea of having the program deciding what to use based on what runs on the enduser's computer. That's what I want for OffScreenGraphics too (tho your code misses a static method to check if anything of the 2 is supported so the dev can turn it off/use other posibilities :)).

So a nice mix with the open and debugging friendly way davedes uses and the automatism your code serves I guess we could give the devs a really cool shader support.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Wed Mar 21, 2012 12:05 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
liamzebedee wrote:
Well as of current I'm not liking davedes structuring of the shader code IMO. He is an excellent game developer, surely better than me in alot of regards. Currently the code is very messy (I assume this is just because of rapid dev, understandable) and the structure isn't flexible (there are probably reasons for this).

Currently my code is very simple, and adaptive. IMHO I think it would be simpler to let the user decide what shaders they want to use using program.attachShader(ShaderType.VERTEX, "vertexsource"). The way I have structured my code is flexible too.

Please view the NEW UNSTABLE code here in this commit

The only part not working now is variable location caching. @davedes help please?

You're still abstracting GL20/ARB methods in the Program class -- that should be done in SGL, like I've been saying. This is something that should apply to other areas of slick as well (e.g. FBO). Also, all constants (like GL20.GL_FRAGMENT_SHADER and ARBFragmentShader.GL_FRAGMENT_SHADER_ARB) internally point to the same enum, so you should just use GL20 for clarity.

I'd also like to see "attachShader/detachShader" methods -- it's the whole reason I started to introduced Shader as an inner class. But these shouldn't be the only way of creating a shader program -- it's too much work on the end user for little gained IMO.
  • Very, very few Slick users will actually need geometry shaders; before we start adding geometry support we should think about more important things like: attributes, vertex attributes, error logging, etc.
  • Even fewer users will actually reuse shaders. This might be a useful feature for a game like Skyrim, which has hundreds of shaders and can save a bit of memory by reusing them, but most Slick developers will not need to reuse shaders by attaching/detaching the same to multiple programs.
  • attach/detach are misleading names IMO, they imply that multiple shaders could be attached to a single program. In reality, a program can only have max one vertex, one frag, and one geom shader. By naming alone this might not be clear to the Slick user, who we assume "has no experience with OpenGL" (hence them using Slick).
  • The whole point of making a utility class like this is to make things easier and more convenient for the end user. Advanced OpenGL gurus that want a really particular feature can easily write their own ShaderProgram class.
  • If your class simply returns an int for attachShader, how do you plan to do error checking on the given shader? If the int returns -1, it might be clear that it failed, but in what way did it fail? i.e. what is the error message?


Top
 Profile  
 
PostPosted: Wed Mar 21, 2012 12:21 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Wouldn't it be better to just use something like "setVertexShader(Shader vertex) {...}" and so on? I can kinda thought the same thing you did about naming it attachShader. It means for a newbie: "Well nicht just let me attach 20 fragment shaders and 4 vertex shaders" :D

When resusing I mostly thought about Android Development. On Desktop I wouldn't mind about such stuff but if you use a lot shaders... well I wouldn't but yeah...

And error logging is indeed usefule. Think about it. Shaders will not tell you they didn't compiled if you don't ask for the errors. Might be a doog iea to through a exeception if the error log returns something after compliling the Shader.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Thu Mar 22, 2012 12:57 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
Image
:twisted:
The animated apple shader from Shader Toy, nicely being rendered to an Image, then some slick text also rendered to that image, then the image rotated... all at 60 FPS...


Top
 Profile  
 
PostPosted: Thu Mar 22, 2012 1:07 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
ShaderProgram
Shader

It's getting more complicated as you can see (in order to smoothly allow reusing shaders), but the same "Slick-esque" functionality has remained unchanged:
Code:
//option A: from file
ShaderProgram prog = ShaderProgram.load("blah.vert", "blah.frag");

//option B: from source code string
ShaderProgram prog = new ShaderProgram(VERTEX_SOURCE, FRAG_SOURCE);


Advanced users who want to reuse shaders/programs:
Code:
//each shader is compiled when created
Shader sharedVert = new Shader(Shader.VERTEX_SHADER, VERTEX_SOURCE);
Shader sharedFrag = new Shader(Shader.FRAGMENT_SHADER, FRAG_SOURCE);

//this links immediately
ShaderProgram prog = new ShaderProgram(sharedVert, sharedFrag);

//alternatively, we could link it all later
ShaderProgram prog = new ShaderProgram();
prog.setVertexShader(sharedVert);
prog.setFragmentShader(sharedFrag);
prog.link();

//once everything is linked we can release shaders if we no longer need them
//the ShaderProgram still works even if its shader objects have been detached and deleted
sharedVert.release();
sharedFrag.release();


  • Creating an empty ShaderProgram will throw an exception if shaders aren't supported.
  • Creating a new Shader will throw an exception if the shader doesn't compile.
  • Linking a shader program will throw an exception if the current shaders are null, invalid, or if there was an error in linking
  • Even if a shader compiles or a program is successfully linked, there might be some error logs.. it's worth checking getLog (or, individually, Shader.getCompileLog / ShaderProgram.getLinkLog
  • Advanced shader objects shouldn't be too hard to implement (geometry, tesselation, a vertex shader built from "chunks" of shader objects, etc)

Let me know if you have any issues with the design / structure.


Top
 Profile  
 
PostPosted: Thu Mar 22, 2012 8:36 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Very Nice! I will test it when I have the time :)
Can you post the source of the apple shader test too? I would like too how you did the drawing on the image (FBO?) :D

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Fri Mar 23, 2012 1:49 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
Pushed the shader stuff to org.newdawn.slick.opengl.shader. Still needs some attribute setters and a couple other minor things. Also added ShaderTest, showing the simple invert shader.

For the shader toy render-to-texture I used the FBO class I posted in the other thread:
http://pastebin.com/n67dfFqP

Although I'm sure it's possible with Slick's getGraphics (albeit slightly less efficient).


Top
 Profile  
 
PostPosted: Fri Mar 23, 2012 9:36 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Very nice, so I can start addong some Shaders :D I really like the class:
  • Onlys uses the extension since it's references the same enum anyway
  • Reusable Shaders
  • Setters and Getters for Uniforms
  • Compile Logs for error logging

btw, if we want to add the FBO later we might want to make "auto-flipped" ond the y axis so the dev can draw everything like he always does (tho as you your code shows only 2 lines of code make this possible xD)

It's also the end of the month... We might want to discuss pusing it all to the master branch and releasing the first "new" Slick version...

Edit:
What about using more then one Shader at once? e.g. having horizontal blur and vertical blur in a sperate fragment shaders? A TestCase for that would nice right? I see what I can do... never did it until now xD

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Fri Mar 23, 2012 1:30 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
One of the problems I've noticed is that it's hard if, say, a user wanted to call glAttachShader to reuse the same shader function between multiple shader programs. "setVertexShader" might be more Slick-esque but it's also a bit more limiting... :|

You can't use two shaders at once in OpenGL. For horizontal and vertical blurs, you'll have to separate that into two render calls, and then blend them together using render to texture (e.g. FBO).

The flipping is annoying right now, I agree. :)


Top
 Profile  
 
PostPosted: Fri Mar 23, 2012 6:08 pm 
Offline
Regular

Joined: Sun Oct 30, 2011 4:47 pm
Posts: 184
Location: Mittweida, Saxony, Germany
Shaders are cool and everything. But... do we need them twice?

org.newdawn.slick.shader
org.newdawn.slick.opengl.shader

Those even appear to be different implementations...
Is one of both obsolete?

Nitram

_________________
http://illarion.org


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 63 posts ]  Go to page Previous  1, 2, 3, 4, 5  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:  
cron
Powered by phpBB® Forum Software © phpBB Group