Friday, 19 February 2010

GLSL effect #1

I'm going to type in 3 cryptic lines in GLSL. Try them out yourself - maybe they can find a cozy home in one of your demos.



gl_Position.x=float(int(quant*gl_Position.x))/quant+gl_Position.x*0.001;
gl_Position.y=float(int(quant*gl_Position.y))/quant+gl_Position.y*0.001;
gl_Position.z=float(int(quant*gl_Position.z))/quant+gl_Position.z*0.001;


you can probably contract that into 1 line.

9 comments:

  1. That's actually a quite neat effect in it's simple glory.

    ReplyDelete
  2. super nintendo mosaic effect with borken triangles ?

    ReplyDelete
  3. not so broken (thats why you need the +gl_Position. factor)

    ReplyDelete
  4. isnt it easier to go 1-line way from the beginning?
    gl_Position.xyz=mix(gl_Position.xyz,floor(gl_Position.xyz*quant)/quant,vec3(0.9));

    ReplyDelete
  5. btw. its cool to do that twice=) :
    gl_Position.xyz=mix(gl_Position.xyz,floor(gl_Position.xyz*quant)/quant,vec3(0.7));

    quant*=0.13;

    gl_Position.xyz=mix(gl_Position.xyz,floor(gl_Position.xyz*quant)/quant,vec3(0.33));

    ReplyDelete
  6. Also as already pointed out I am pretty sure using "floor()" instead of cast-to-int and cast-to-float is WAY more optimized (depends on the compiler but I believe the GLSL compilers aren't all that advanced right now).

    ReplyDelete
  7. Using rendermonkey, I get this : http://tof.canardpc.com/show/8a57624d-bf10-404f-9d72-643f34342bfc.html
    Did I do something wrong ?

    ReplyDelete
  8. try that:

    gl_Position=gl_Vertex;
    //transform here
    //...
    //
    gl_Position=gl_ModelViewProjectionMatrix*gl_Position;

    ReplyDelete
  9. Oh in object space instead of worldspace, right...

    ReplyDelete