solaris-js
Version:
A reusable component for interactive visualization of the Solar System
39 lines (33 loc) • 1.21 kB
text/coffeescript
import publicize from './helpers/publicizer'
import {ShaderMaterial, TextureLoader, Mesh, SphereGeometry} from 'three'
# Based on Ian Webster's blog post: http://www.ianww.com/blog/2014/02/17/making-a-skydome-in-three-dot-js/
class $Background
constructor: (sceneSize, root) ->
material = new ShaderMaterial
uniforms:
texture: {type: 't', value: new TextureLoader().load("#{root}/img/background.jpg")}
vertexShader: '''
varying vec2 vUV;
void main() {
vUV = uv;
vec4 pos = vec4(position, 1.0);
gl_Position = projectionMatrix * modelViewMatrix * pos;
}
'''
fragmentShader: '''
uniform sampler2D texture;
varying vec2 vUV;
void main() {
vec4 sample = texture2D(texture, vUV);
gl_FragColor = vec4(sample.xyz, sample.w);
}
'''
# @public
export default class Background extends publicize $Background,
properties: ['mesh']