This repository has been archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 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
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,2 @@ | ||
apply plugin: 'java' | ||
apply plugin: 'kotlin' |
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,43 @@ | ||
#version 330 | ||
|
||
// list uniforms which are used by this shader | ||
uniform vec3 iResolution; // viewport resolution (in pixels) | ||
uniform float iTime; // shader playback time (in seconds) | ||
//uniform float iTimeDelta; // render time (in seconds) | ||
//uniform int iFrame; // shader playback frame | ||
//uniform float iChannelTimeN; // channel playback time (in seconds) | ||
//uniform vec3 iChannelResolutionN; // channel resolution (in pixels) | ||
//uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click | ||
//uniform sampler2D iChannelN; // input channel. XX = 2D/Cube | ||
//uniform vec4 iDate; // (year, month, day, time in seconds) | ||
//uniform float iSampleRate; // sound sample rate (i.e., 44100) | ||
|
||
// -- default output | ||
out vec4 o_color; | ||
|
||
void mainImage(out vec4 fragColor, in vec2 fragCoord); | ||
|
||
void main() { | ||
mainImage(o_color, gl_FragCoord.xy); | ||
} | ||
|
||
|
||
// ------------------------------ | ||
// SHADERTOY CODE BEGINS HERE - | ||
// ------------------------------ | ||
|
||
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); | ||
} | ||
|
||
// ---------------------------- | ||
// SHADERTOY CODE ENDS HERE - | ||
// ---------------------------- |
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,69 @@ | ||
import org.openrndr.Application | ||
import org.openrndr.Configuration | ||
import org.openrndr.Program | ||
import org.openrndr.draw.* | ||
import org.openrndr.filter.filterShaderFromUrl | ||
import org.openrndr.math.Vector3 | ||
import org.openrndr.math.Vector4 | ||
|
||
/** | ||
* The Shadertoy buffer, abstraction over Shadertoy tab containing GLSL code. | ||
*/ | ||
class ShadertoyBuffer : Filter(filterShaderFromUrl("file:shader-shadertoy-001/src/main/glsl/image.frag")) { | ||
// for live shader code reloading use: | ||
// Filter(null, filterWatcherFromUrl("file:shader-shadertoy-001/src/main/glsl/image.frag")) { | ||
|
||
var iResolution: Vector3 by parameters // viewport resolution (in pixels) | ||
var iTime: Double by parameters // shader playback time (in seconds) | ||
var iTimeDelta: Double by parameters // render time (in seconds) | ||
var iFrame: Int by parameters // shader playback frame | ||
var iChannelTime0: Double by parameters // channel playback time (in seconds) | ||
var iChannelTime1: Double by parameters | ||
var iChannelTime2: Double by parameters | ||
var iChannelTime3: Double by parameters | ||
var iChannelResolution0: Double by parameters // channel resolution (in pixels) | ||
var iChannelResolution1: Double by parameters | ||
var iChannelResolution2: Double by parameters | ||
var iChannelResolution3: Double by parameters | ||
var iMouse: Vector4 by parameters // mouse pixel coords. xy: current (if MLB down), zw: click | ||
var iChannel0: ColorBuffer by parameters // input channel. XX = 2D/Cube | ||
var iChannel1: ColorBuffer by parameters | ||
var iChannel2: ColorBuffer by parameters | ||
var iChannel3: ColorBuffer by parameters | ||
var iDate: Vector4 by parameters // (year, month, day, time in seconds) | ||
var iSampleRate: Double by parameters // sound sample rate (i.e., 44100) | ||
} | ||
|
||
/** | ||
* This is a basic example that shows how to use Shadertoy code. | ||
*/ | ||
class Example : Program() { | ||
|
||
private var frameCounter: Int = 0 | ||
|
||
lateinit var image: ShadertoyBuffer | ||
lateinit var imageOut: ColorBuffer | ||
|
||
override fun setup() { | ||
image = ShadertoyBuffer() | ||
imageOut = colorBuffer(width, height) | ||
} | ||
|
||
override fun draw() { | ||
populate(image) | ||
image.apply(arrayOf(), imageOut) | ||
drawer.image(imageOut) | ||
frameCounter++ | ||
} | ||
|
||
private fun populate(buffer: ShadertoyBuffer) { | ||
buffer.iTime = seconds | ||
buffer.iResolution = Vector3(width.toDouble(), height.toDouble(), 0.0) | ||
buffer.iFrame = frameCounter | ||
} | ||
|
||
} | ||
|
||
fun main(args: Array<String>) { | ||
Application.run(Example(), Configuration()) | ||
} |