shader from shadertoy

Started by leejenshil, July 25, 2015, 18:54:04

Previous topic - Next topic

leejenshil

hi, i am extremely new to lwjgl and this might seam like a stupid question but how would i take a shader from shadertoy and implement it into my program? i can read vertex and fragment shader just fine and run them in game, but writing them is a different story.

on shadertoy you can see just one shader, is that a fragment or vertex or some other kind? if it's only fragment / vertex how can i complete the other shader?

thanks for the help

Kai

Technically, Shadertoy shaders are fragment shaders. But they are very much unlike what you'll see with traditional OpenGL shaders which are used to implement a shading and lighting model.
Shadertoy has a setup that rasterizes a fullscreen rectangle and then provides the shader implementor with input varyings (position on the viewport of a certain fragment/pixel) and uniforms, such as "time", and then you are free to compute whatever color value you want for that fragment/pixel.
Most people choose to implement raytracers, because with shadertoy the only way you can have a scene description is by data held within your shader or using implicit functions. To keep memory requirements and register pressure low, implicit functions are mostly the way to go to specify your geometries.
Normally, in OpenGL the scene description (i.e. geometry) is specified via a sequence of triangles in a large GPU memory buffer that are then transformed via a vertex shader and the final primitives shaded via a fragment shader.

But to answer your question of how to do that with LWJGL 3: Just search for "OpenGL shader example" applications on the internet. LWJGL 3 is basically just OpenGL together with GLFW for window and input handling.

For a working example of a raytracer with LWJGL 3 implemented as a fragment shader, see this example from LWJGL 3's demo repository.