Skip to content

Shaders

zeganstyl edited this page Sep 18, 2020 · 1 revision

Any object that implements IShader can be used as shader.

Simple creating:

Vertex code:

attribute vec3 POSITION;
attribute vec2 UV;

varying vec2 uv;

uniform mat4 viewProj;

void main() {
	uv = UV;
	gl_Position = viewProj * vec4(POSITION, 1.0);
}

Fragment code:

varying vec2 uv;

void main() {
	gl_FragColor = vec4(uv, 0.0, 1.0);
}
val vertexCode = """
put here vertex code...
"""

val fragmentCode = """
put here fragment code...
"""

val shader = Shader(vertexCode, fragmentCode)

Here we using attributes with names POSITION and UV. If you want to know which attribute names may be used, you must check vertex inputs of your mesh.

mesh.vertices?.vertexInputs.forEach { println(it.name) }

Thelema uses by default shader version 110. If you want, you can specify version: shader.version = 330.

Note, if you will using version 330, better to replace attribute with in and replace varying with in or out.

Setting uniforms:

shader["viewProj"] = ActiveCamera.viewProjectionMatrix

In post package you can find postprocessing shaders.

Clone this wiki locally