Skip to content

Commit

Permalink
Simple but working custom shader with textures
Browse files Browse the repository at this point in the history
Custom uniforms, vertex shader, and fragment shader
Based on http://stackoverflow.com/questions/12627422/custom-texture-shader-in-three-js
  • Loading branch information
deathcap committed Jan 9, 2014
1 parent d4022d1 commit 87a33c2
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@ function Texture(game, opts) {

console.log(this.THREE.ShaderLib.lambert.uniforms);

//this.uniforms = this.THREE.UniformsUtils.clone(this.THREE.ShaderLib.lambert.uniforms);
this.uniforms = {
map: {type: 't', value: null}
};

console.log('vertex=');
console.log(this.THREE.ShaderLib.lambert.vertexShader);
console.log('fragment=');
console.log(this.THREE.ShaderLib.lambert.fragmentShader);

this.options = {
crossOrigin: 'Anonymous',
materialParams: {
Expand All @@ -56,19 +50,22 @@ function Texture(game, opts) {
side: this.THREE.DoubleSide,

uniforms: this.uniforms,
vertexShader: this.THREE.ShaderLib.lambert.vertexShader,
//fragmentShader: 'void main() { gl_FragColor = vec4(0.2, 0.2, 0.2, 1.0); }'
//fragmentShader: this.THREE.ShaderLib.lambert.fragmentShader
vertexShader: [
'varying vec2 vUv;',
'',
'void main() {',
' vUv = uv;',
'',
' gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);',
'}'
].join('\n'),
fragmentShader: [
'uniform sampler2D map;',
//'varying vec2 vUv;',
'',
'varying vec2 vUv;',
'',
'void main() {',
//' vec4 texelColor = texture2D(map, vUv);',
' gl_FragColor = vec4(0.3, 0.2, 0.5, 1.0);',
//' gl_FragColor = texture2D(map, gl_PointCoord);',
//' gl_FragColor = vec4(0.3, gl_FragCoord.x, gl_FragCoord.y, 1.0);',
//' gl_FragColor = texelColor;',
' gl_FragColor = texture2D(map, vUv);',
'}'
].join('\n')
},
Expand Down

0 comments on commit 87a33c2

Please sign in to comment.