Skip to content

Instantly share code, notes, and snippets.

@ripter
Created September 4, 2019 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripter/4ba94d032ad5f78c63e85f4c67c14ec5 to your computer and use it in GitHub Desktop.
Save ripter/4ba94d032ad5f78c63e85f4c67c14ec5 to your computer and use it in GitHub Desktop.
// 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