User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Writing graphics shaders design questions

Mon Aug 13, 2012 2:50 am

I am planning a shader for OpenGLES. It will be a multi-mode shader, with different features in different modes. Full feature set TBC. I need the following information. Hopefully I'll make an easy C wrapper for the setting up and running of the shader.

1) Are there any restrictions on the compiled shader's code size? A rough estimate of 1,000 flops per iteration gives a lowest res 25fps, at about about 4000 to 8000 instruction length (I could write it in multiple parts). So it's unlikely there is a restriction lower than this number of instructions, but I need to know before starting.
2) I won't be producing any complicated animated models to test, are there any complex models about 1000 polygons in size in the public domain?
3) There is more information on the internet about OpenGLSL and most of it applies, but this took a while to find, and not all of it applies. Making OpenGLES compatible GLSL shaders was a lucky Google. Are there any other potential Googlies?
4) Aside from python GLES and some SDL things, does anyone know of other source codes that may be available? As I don't have the need to buy a book.

Cheers Jacko
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

jmacey
Posts: 135
Joined: Thu May 31, 2012 1:05 pm

Re: Writing graphics shaders design questions

Mon Aug 13, 2012 8:28 am

1) there are limitations to the shader size but this is platform dependent and I'm unsure of the size for the pi. On a more practical note, a "multi mode" shader sounds like you will have one uber shader which will do many things, usually this implies an if statement in the shader which are best avoided.

Usually it is quicker to have lots of small shaders and change the active shader per model, (however this is the general case so many not always be true for the platform at hand).

2) there are many models available, many standard ones such as the bunny, buddha and dragon can be found here http://graphics.stanford.edu/data/3Dscanrep/ you will need to convert them to a format that you can load into the pi, I would suggest using the OBJ file format and write a loader. For other models have a look at turbo squid http://www.turbosquid.com/ which has many free models (as well as more expensive ones). I also have several models in some of my example code in obj format which you can find here http://nccastaff.bournemouth.ac.uk/jmac ... index.html (the troll models is quite small but still complex)

3) To learn GLSL I would get the Orange book http://www.opengl.org/documentation/boo ... g_language there are also loads of tutorials / examples online.

4) You would need to be a bit more specific about what you need to do, I have several tutorials on my blog on setting up an EGL context and starting to draw ( http://jonmacey.blogspot.co.uk/ ) you may also like my 3d Library piNGL which is here http://code.google.com/p/pingl/

Jon

User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: Writing graphics shaders design questions

Mon Aug 13, 2012 3:11 pm

jmacey wrote:Usually it is quicker to have lots of small shaders and change the active shader per model, (however this is the general case so many not always be true for the platform at hand).
I may include this as one of the modes for large hi-res multi models. But I was until now unaware of this possibility, thanks.

I have a look today, and get some models downloaded. Along with the GLSL docs.

In terms of setting up the library I'd be looking to make it work using a simple set of interface functions, which I'd have to write.
a) OpenGLMain(mode)
b) CloseGLMain() or set mode 0 in the above.
c) id = AddVertexGL(model, mode_options...) mode options include possible textures and such.
d) colide = PlaceVertexGL(id, xyz_struct, rot_struct, collision_group)
e) RemoveVertexGL(id)

This makes a simple interface to the main code on the CPU, suitable for beginners.

Cheers Jacko
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

dattrax
Posts: 52
Joined: Sat Dec 24, 2011 5:09 pm

Re: Writing graphics shaders design questions

Sun Aug 19, 2012 2:01 pm

some advise.... do not write uber shaders on the pi.

The compiler uses predication to flatten conditionals and you end up executing everything. There are no issues with changing shaders per draw call, so you are better off stitching multiple variants at startup and drawing with the correct one.

Return to “OpenGLES”