-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #57: Shader.fromFile (load ext GLSL)
- Loading branch information
1 parent
840c8c5
commit 629a88b
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | ||
{ | ||
// Normalized pixel coordinates (from 0 to 1) | ||
vec2 uv = fragCoord/iResolution.xy; | ||
|
||
// Time varying pixel color | ||
vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4)); | ||
|
||
// Output to screen | ||
fragColor = vec4(col,1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
ultraviolet/shared/src/test/scala/ultraviolet/macros/ShaderMacrosTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ultraviolet.macros | ||
|
||
import ultraviolet.DebugAST | ||
import ultraviolet.syntax.* | ||
|
||
class ShaderMacrosTests extends munit.FunSuite { | ||
|
||
// ...and from resource? | ||
test("Loading a shader from a file") { | ||
|
||
val code: String = | ||
""" | ||
|void mainImage( out vec4 fragColor, in vec2 fragCoord ) | ||
|{ | ||
| // Normalized pixel coordinates (from 0 to 1) | ||
| vec2 uv = fragCoord/iResolution.xy; | ||
| | ||
| // Time varying pixel color | ||
| vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4)); | ||
| | ||
| // Output to screen | ||
| fragColor = vec4(col,1.0); | ||
|} | ||
|""".stripMargin.trim | ||
|
||
inline def shader: Shader[Unit, Unit] = | ||
Shader.fromFile("./test-resources/shader.frag") | ||
|
||
// DebugAST.toAST(shader) | ||
|
||
val actualAst: ShaderAST = | ||
ShaderMacros.toAST(shader).main | ||
|
||
val expectedAst: ShaderAST = | ||
ShaderAST.RawLiteral(code) | ||
|
||
val actualCode: String = | ||
shader.toGLSL[WebGL2].code | ||
|
||
val expectedCode: String = | ||
code | ||
|
||
assertEquals(actualAst, expectedAst) | ||
assertEquals(actualCode, expectedCode) | ||
|
||
} | ||
|
||
} |