sky and water domes using shaders
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
varying vec3 vWorldPosition;
|
||||
void main() {
|
||||
vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
|
||||
vWorldPosition = worldPosition.xyz;
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// https://gamedevelopment.tutsplus.com/tutorials/a-beginners-guide-to-coding-graphics-shaders--cms-23313
|
||||
uniform vec3 topColor;
|
||||
uniform vec3 horizontColor;
|
||||
uniform float offset;
|
||||
uniform float exponent;
|
||||
varying vec3 vWorldPosition;
|
||||
void main() {
|
||||
float h = normalize( vWorldPosition + offset ).y;
|
||||
gl_FragColor = vec4(
|
||||
mix(
|
||||
horizontColor,
|
||||
topColor,
|
||||
max(
|
||||
pow(
|
||||
max( h , 0.0),
|
||||
exponent
|
||||
),
|
||||
0.0
|
||||
)
|
||||
), 1.0
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// https://gamedevelopment.tutsplus.com/tutorials/a-beginners-guide-to-coding-graphics-shaders--cms-23313
|
||||
uniform vec3 waterColor;
|
||||
uniform vec3 bottomColor;
|
||||
uniform float wateroffset;
|
||||
uniform float waterexponent;
|
||||
varying vec3 vWorldPosition;
|
||||
|
||||
void main() {
|
||||
float h = normalize( vWorldPosition * -1.0 + wateroffset ).y;
|
||||
gl_FragColor = vec4(
|
||||
// mix(x, y, a) performs a linear interpolation between x and y using a to weight between them.
|
||||
// The return value is computed as x×(1−a)+y×a.
|
||||
mix(
|
||||
waterColor,
|
||||
bottomColor,
|
||||
max(
|
||||
pow(
|
||||
max( h , 0.0),
|
||||
waterexponent
|
||||
),
|
||||
0.0
|
||||
)
|
||||
),
|
||||
1.0
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user