Roll your own lighting shader with this code

I just shared a project on CC that includes a shader with a lot of lighting effects. Normally, if you do this, you slow down your app because of all the if tests you have to do.

But this project creates special shader code with just the features you want, ie it leaves out the parts you don’t want, to make the shader run faster. You can copy this code to your own project.

There is a Notes tab to explain how to use the code, and what the different parameters mean.

(I used Reflector to record this, because it gives you the whole iPad screen, and I played with adding captions on this video, using youTube’s editing options).

And before Jmv38 asks, here is an alternative link:

Very nice. I particularly like that you are using this to generate a shader with just what you need.

That’s really clever, dynamically building a shader. The results look great too.

Nice, fogs look really good as well, great way of building the right lighting environment!

@spacemonkey - you got me started with shaders - and I still haven’t got my head around bump mapping!

Nice idea. Just a black screen when using Codea beta though. I haven’t figured out why…

That is really nice… Will be useful.

I couldn’t find it on CC, so just copied from the gist.

@Ignatz - Yeah, if I can find the time and spare mental capacity to get back into some Codea I was thinking of looking at what you’ve built and how bump mapping could be worked into it.

Very nice! Thank you.

@tnlogy @Ignatz it does not work in the beta due to a shader compile error — the variable reflect which you define is actually a new GLSL function in OpenGL ES 3.0, and GLSL complains that your use is a redefinition. If you rename it to something else then it works.

Edit: corrected OpenGL version

Hang about, so IOS 7 now gives us OpenGL ES 3.0, and that maybe opens the door to textures in vertex shaders, I HAVE to get Codea back out and try and play with this :wink:

Dynamicly deformed meshes from a texture… I guess it breaks compatibility with IOS 6, but still.

Edit: I’m sad again
Suggests it’s only latest gen ipads that support 3.0…

ReEdit: although the same page in the OpenGL ES 2.0 on Power VR suggests maybe you can now have textures in the vertex… I’ll have to have a look.

@ignatz lol! Thanks. Looks really good!

@ignatz This is very cool, great idea.

I updated to fix the problem with the name reflect, affecting 2.0 beta versions

Also it wasn’t sharing on CC, fixed now

Textures in Vertex shaders do now work, I’ve only tested on ipad 3rd gen, but it should work on any ipad as long as it’s IOS 7.

Project is on CC called texture driven hieghtfield. Basically it’s a flat mesh of 20,000 triangles, and dependant on the texture it will height it based on the “brightness” of the pixel for the vertex. For real dynamic, you can even point the camera at it.

The lighting is a bit shabby because I used @Ignatz solution from above, but I think I haven’t plumbed it in correctly :wink:

@tnlogy - I’m interested in that, would appreciate seeing it if possible ;:wink:

Nice! I’m using perlin noise to make an infinite landscape. should be able to speed it up by saving the height map instead of calculating it for each draw…

Aw, I had dynamically built shaders in my projects… You beat me to posting it. :frowning:


@Ignatz here is it, without using a texture though.