[orx-shader-phrases] Add shader embedding

This commit is contained in:
Edwin Jakobs
2021-06-25 09:55:35 +02:00
parent 4e1a2cf930
commit 4f0de6a39b
22 changed files with 111 additions and 479 deletions

View File

@@ -1,20 +1,11 @@
# orx-shader-phrases
A library that provides a `#pragma import` statement for shaders by using the JVM class loader.
A library that provides a `#pragma import` statement for shaders.
## Usage
Given a shader source:
Work in progress.
````glsl
#version 330
// -- this imports all phrases in Dummy
#pragma import org.openrndr.extra.shaderphrases.phrases.Dummy.*
void main() {
float a = dummy();
}
````
We can use the `preprocessShader()` function to resolve `#pragma import` statements.
@@ -28,20 +19,3 @@ Alternatively loading and preprocessing can be combined in a single function cal
val preprocessedSource = preprocessShaderFromUrl(resourceUrl("/some-shader.frag"))
```
To create importable shader phrases one creates a Kotlin class and adds the `ShaderPhrases` annotation.
For example the `dummy` phrase in our example is made available as follows:
```kotlin
// -- force the class name to be Dummy on the JVM
@file:JvmName("Dummy")
@file:ShaderPhrases
package org.openrndr.extra.shaderphrases.phrases
import org.openrndr.extra.shaderphrases.annotations.ShaderPhrases
// -- the shader phrase
const val dummy = """
float dummy() {
return 0.0;
}
"""
```