-
Notifications
You must be signed in to change notification settings - Fork 28
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
12 changed files
with
280 additions
and
1 deletion.
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
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,30 @@ | ||
name: "noise" | ||
scale_along_z: 0 | ||
embedded_instances { | ||
id: "go" | ||
data: "components {\n" | ||
" id: \"drawtoquad\"\n" | ||
" component: \"/examples/material/noise/noise.script\"\n" | ||
"}\n" | ||
"embedded_components {\n" | ||
" id: \"model\"\n" | ||
" type: \"model\"\n" | ||
" data: \"mesh: \\\"/builtins/assets/meshes/quad.dae\\\"\\n" | ||
"name: \\\"{{NAME}}\\\"\\n" | ||
"materials {\\n" | ||
" name: \\\"default\\\"\\n" | ||
" material: \\\"/examples/material/noise/noise.material\\\"\\n" | ||
"}\\n" | ||
"\"\n" | ||
"}\n" | ||
"" | ||
position { | ||
x: 360.0 | ||
y: 360.0 | ||
} | ||
scale3 { | ||
x: 720.0 | ||
y: 720.0 | ||
z: 50.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
varying mediump vec2 var_texcoord0; | ||
uniform lowp vec4 time; | ||
|
||
// noise shader from https://www.shadertoy.com/view/XXBcDz | ||
|
||
// pseudo random generator (white noise) | ||
float rand(vec2 n) | ||
{ | ||
return fract(sin(dot(n, vec2(12.9898, 78.233))) * 43758.5453); | ||
} | ||
|
||
// value noise | ||
float noise(vec2 p) | ||
{ | ||
vec2 ip = floor(p); | ||
vec2 u = fract(p); | ||
u = u * u * (3.0 - 2.0 * u); | ||
|
||
float x = mix(rand(ip), rand(ip + vec2(1.0, 0.0)), u.x); | ||
float y = mix(rand(ip + vec2(0.0, 1.0)), rand(ip + vec2(1.0, 1.0)), u.x); | ||
float a = u.y; | ||
float res = mix(x, y, a); | ||
return res * res; | ||
} | ||
|
||
// used to rotate domain of noise function | ||
const mat2 rot = mat2( 0.80, 0.60, -0.60, 0.80 ); | ||
|
||
// fast implementation | ||
float fbm( vec2 p ) | ||
{ | ||
float f = 0.0; | ||
f += 0.500000 * noise( p ); p = rot * p * 2.02; | ||
f += 0.031250 * noise( p ); p = rot * p * 2.01; | ||
f += 0.250000 * noise( p ); p = rot * p * 2.03; | ||
f += 0.125000 * noise( p + 0.1 * sin(time.x) + 0.8 * time.x ); p = rot * p * 2.01; | ||
f += 0.062500 * noise( p + 0.3 * sin(time.x) ); p = rot * p * 2.04; | ||
f += 0.015625 * noise( p ); | ||
return f / 0.96875; | ||
} | ||
|
||
void main() | ||
{ | ||
float n = fbm(var_texcoord0.xy); | ||
gl_FragColor = vec4(n, n, n, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: "noise" | ||
tags: "model" | ||
vertex_program: "/examples/material/noise/noise.vp" | ||
fragment_program: "/examples/material/noise/noise.fp" | ||
vertex_space: VERTEX_SPACE_LOCAL | ||
vertex_constants { | ||
name: "mtx_worldview" | ||
type: CONSTANT_TYPE_WORLDVIEW | ||
} | ||
vertex_constants { | ||
name: "mtx_view" | ||
type: CONSTANT_TYPE_VIEW | ||
} | ||
vertex_constants { | ||
name: "mtx_proj" | ||
type: CONSTANT_TYPE_PROJECTION | ||
} | ||
vertex_constants { | ||
name: "mtx_normal" | ||
type: CONSTANT_TYPE_NORMAL | ||
} | ||
fragment_constants { | ||
name: "time" | ||
type: CONSTANT_TYPE_USER | ||
value { | ||
x: 1.0 | ||
y: 1.0 | ||
z: 1.0 | ||
w: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function init(self) | ||
self.time = 0 | ||
end | ||
|
||
function update(self, dt) | ||
self.time = self.time + dt | ||
go.set("#model", "time.x", self.time) | ||
end |
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,26 @@ | ||
|
||
// Positions can be world or local space, since world and normal | ||
// matrices are identity for world vertex space materials. | ||
// If world vertex space is selected, you can remove the | ||
// normal matrix multiplication for optimal performance. | ||
|
||
attribute highp vec4 position; | ||
attribute mediump vec2 texcoord0; | ||
attribute mediump vec3 normal; | ||
|
||
uniform mediump mat4 mtx_worldview; | ||
uniform mediump mat4 mtx_view; | ||
uniform mediump mat4 mtx_proj; | ||
uniform mediump mat4 mtx_normal; | ||
|
||
varying highp vec4 var_position; | ||
varying mediump vec3 var_normal; | ||
varying mediump vec2 var_texcoord0; | ||
|
||
void main() | ||
{ | ||
vec4 p = mtx_worldview * vec4(position.xyz, 1.0); | ||
var_texcoord0 = texcoord0; | ||
gl_Position = mtx_proj * p; | ||
} | ||
|
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,47 @@ | ||
varying mediump vec2 var_texcoord0; | ||
uniform lowp vec4 time; | ||
|
||
// noise shader from https://www.shadertoy.com/view/XXBcDz | ||
|
||
// pseudo random generator (white noise) | ||
float rand(vec2 n) | ||
{ | ||
return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453); | ||
} | ||
|
||
// value noise | ||
float noise(vec2 p) | ||
{ | ||
vec2 ip = floor(p); | ||
vec2 u = fract(p); | ||
u = u * u * (3.0 - 2.0 * u); | ||
|
||
float x = mix(rand(ip), rand(ip + vec2(1.0,0.0)), u.x); | ||
float y = mix(rand(ip + vec2(0.0, 1.0)), rand(ip + vec2(1.0, 1.0)), u.x); | ||
float a = u.y; | ||
float res = mix(x, y, a); | ||
return res * res; | ||
} | ||
|
||
// used to rotate domain of noise function | ||
const mat2 rot = mat2( 0.80, 0.60, -0.60, 0.80 ); | ||
|
||
// fast implementation | ||
float fbm( vec2 p ) | ||
{ | ||
float f = 0.0; | ||
f += 0.500000*noise( p ); p = rot*p*2.02; | ||
f += 0.031250*noise( p ); p = rot*p*2.01; | ||
f += 0.250000*noise( p ); p = rot*p*2.03; | ||
f += 0.125000*noise( p + 0.1 * sin(time.x) + 0.8 * time.x ); p = rot*p*2.01; | ||
f += 0.062500*noise( p + 0.3 * sin(time.x) ); p = rot*p*2.04; | ||
f += 0.015625*noise( p ); | ||
return f / 0.96875; | ||
} | ||
|
||
void main() | ||
{ | ||
float n = fbm(var_texcoord0.xy); | ||
gl_FragColor = vec4(n, n, n, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: "uvgradient" | ||
scale_along_z: 0 | ||
embedded_instances { | ||
id: "go" | ||
data: "embedded_components {\n" | ||
" id: \"model\"\n" | ||
" type: \"model\"\n" | ||
" data: \"mesh: \\\"/builtins/assets/meshes/quad.dae\\\"\\n" | ||
"name: \\\"{{NAME}}\\\"\\n" | ||
"materials {\\n" | ||
" name: \\\"default\\\"\\n" | ||
" material: \\\"/examples/material/uvgradient/uvgradient.material\\\"\\n" | ||
"}\\n" | ||
"\"\n" | ||
"}\n" | ||
"" | ||
position { | ||
x: 360.0 | ||
y: 360.0 | ||
} | ||
scale3 { | ||
x: 720.0 | ||
y: 720.0 | ||
z: 50.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
varying mediump vec2 var_texcoord0; | ||
|
||
void main() | ||
{ | ||
gl_FragColor = vec4(var_texcoord0.x, var_texcoord0.y, 0.5, 1.0f); | ||
} | ||
|
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,21 @@ | ||
name: "uvgradient" | ||
tags: "model" | ||
vertex_program: "/examples/material/uvgradient/uvgradient.vp" | ||
fragment_program: "/examples/material/uvgradient/uvgradient.fp" | ||
vertex_space: VERTEX_SPACE_LOCAL | ||
vertex_constants { | ||
name: "mtx_worldview" | ||
type: CONSTANT_TYPE_WORLDVIEW | ||
} | ||
vertex_constants { | ||
name: "mtx_view" | ||
type: CONSTANT_TYPE_VIEW | ||
} | ||
vertex_constants { | ||
name: "mtx_proj" | ||
type: CONSTANT_TYPE_PROJECTION | ||
} | ||
vertex_constants { | ||
name: "mtx_normal" | ||
type: CONSTANT_TYPE_NORMAL | ||
} |
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,24 @@ | ||
|
||
// Positions can be world or local space, since world and normal | ||
// matrices are identity for world vertex space materials. | ||
// If world vertex space is selected, you can remove the | ||
// normal matrix multiplication for optimal performance. | ||
|
||
attribute highp vec4 position; | ||
attribute mediump vec2 texcoord0; | ||
attribute mediump vec3 normal; | ||
|
||
uniform mediump mat4 mtx_worldview; | ||
uniform mediump mat4 mtx_view; | ||
uniform mediump mat4 mtx_proj; | ||
uniform mediump mat4 mtx_normal; | ||
|
||
varying mediump vec2 var_texcoord0; | ||
|
||
void main() | ||
{ | ||
vec4 p = mtx_worldview * vec4(position.xyz, 1.0); | ||
var_texcoord0 = texcoord0; | ||
gl_Position = mtx_proj * p; | ||
} | ||
|