Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

3d Sin in a shader

edited February 2013 in Code Sharing Posts: 454

So to explore 1.5 I decided to port an old project of mine to a shader.

Only tested on iPad2 landscape. The main things I learnt:
1) you can mess with screen position in shaders
2) how to hook up custom attribute buffers
3) modifying vertexes dynamically on the lua side is still slow

Edit: fully rewritten...

Video doesn't capture the parameters, but that's the pauses when I'm interacting with them, can show a flat colored surface or textured surface including camera. It has a lighting model, and a colored light will mess with the colors on the texture etc.

Code in next post

Comments

  • edited February 2013 Posts: 454

    Code below. Main oddity is the fragment shader (in lab) kept dissapearing when I had an if in it, no idea. So I split it and switch shader when you add textures. Code is quite messy.

    Now in a gist cos it got too long:
    https://gist.github.com/sp4cemonkey/4977040

  • Bump as I did a major new version including textures along with lighting (rewrote previous posts) and added a video.

  • Posts: 2,161

    .@spacemonkey Where did you have the if? I found (the hard way) that you can't put an if outside a function. I wanted to set a flag on a shader that swapped various routines, but found that I could only do it with the if inside main, but then the if gets evaluated for every pixel/vertex which is a waste of time. So I did what you did: put the conditional in the lua part and loaded the shader accordingly.

  • .@Andrew_Stacey it was a bit weirder than that, I had it in the main() of the fragment shader, and it even worked when I ran it, however I had 2 or 3 occasions where I went back into codea and found that the fragment shader had reverted to the previous version.

    So I think it is more likely a fault in Codea shader lab, however at the same time I found on google that if statements in fragment shaders were frowned upon, so split it the way I did above instead.

  • SimeonSimeon Admin Mod
    Posts: 4,808

    That looks really cool, @spacemonkey. It gets really interesting when you attach the video stream to the texture input.

  • edited February 2013 Posts: 454

    Another modification (and gridSize lowered, but you can adjust it in the first line of setup). I've added a reasonably true wireframe mode. Basically it's a cheat using a texture for the wireframe and then "discard"ing black pixels in the shader. The shader is still quite heavy in wireframe, but just for the SIN piece, not lighting etc.

    Trickiest bit is texture orientation, I'm fairly sure the texture is oriented to the triangles, but could have gotten it wrong ;-)

Sign In or Register to comment.