Created
September 4, 2019 14:47
-
-
Save ripter/4ba94d032ad5f78c63e85f4c67c14ec5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// https://threejs.org/examples/webgl_lights_hemisphere.html | |
AFRAME.registerShader('gradient', { | |
schema: { | |
timeMsec: {type: 'time', is: 'uniform'}, | |
topColor: {type: 'color', is: 'uniform', default: '#0077ff'}, | |
bottomColor: {type: 'color', is: 'uniform', default: '#ffffff'}, | |
offset: {is: 'uniform', default: 33}, | |
exponent: {is: 'uniform', default: 0.6}, | |
}, | |
raw: false, | |
vertexShader: ` | |
varying vec3 vWorldPosition; | |
void main() { | |
vec4 worldPosition = modelMatrix * vec4( position, 1.0 ); | |
vWorldPosition = worldPosition.xyz; | |
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); | |
} | |
`, | |
fragmentShader: ` | |
uniform vec3 topColor; | |
uniform vec3 bottomColor; | |
uniform float offset; | |
uniform float exponent; | |
varying vec3 vWorldPosition; | |
void main() { | |
float h = normalize( vWorldPosition + offset ).y; | |
gl_FragColor = vec4( mix( bottomColor, topColor, max( pow( max( h , 0.0), exponent ), 0.0 ) ), 1.0 ); | |
} | |
` | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment