6

I can get a solid clearColor in threejs, but is there a way to achieve a gradient clearColor. Or some similar way to achieve a little more depth in my sky, maybe with lights?

Here's my relevant code:

renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setClearColor( 0x3dc800 );

var light = new THREE.HemisphereLight( 0xffffff, 0xeeeeee, 0.75 );
  light.position.set( 0.5, 1, 0.75 );
  scene.add( light );

scene.fog = new THREE.Fog( 0x4ff904, 0, 750 );

enter image description here

gman
  • 100,619
  • 31
  • 269
  • 393
mheavers
  • 29,530
  • 58
  • 194
  • 315

2 Answers2

3

I ran across this codepen:

http://codepen.io/billimarie/pen/mJLeBY

I take no credit, but it answers the question perfectly.

The relevant chunks are:

renderer = new THREE.CanvasRenderer( { alpha: true }); // gradient

withe the css:

body {
            background-color: #1A8FCF;
            margin: 0px;
            overflow: hidden;
            background-image: -webkit-gradient(#1A8FCF,#D1236A,#1A8FCF);
            /* Safari 5.1, iOS 5.0-6.1, Chrome 10-25, Android 4.0-4.3 */
            background-image: -webkit-linear-gradient(#1A8FCF,#D1236A,#1A8FCF);
            /* Firefox 3.6 - 15 */
            background-image: -moz-linear-gradient(#1A8FCF,#D1236A,#1A8FCF);
            /* Opera 11.1 - 12 */
            background-image: -o-linear-gradient(#1A8FCF,#D1236A,#1A8FCF);
            /* Opera 15+, Chrome 25+, IE 10+, Firefox 16+, Safari 6.1+, iOS 7+, Android 4.4+ */
            background-image: linear-gradient(#1A8FCF,#D1236A,#1A8FCF);
        }

**Note, my own colors...

Tim Gottgetreu
  • 483
  • 1
  • 8
  • 21
  • Unfortunately they moved `CanvasRenderer` to `/examples/js/renderers/CanvasRenderer.js`, so you also need that in the latest releases. – Ákos Kovács Mar 19 '17 at 15:54
0

See Transparent background with three.js for transparent background rendering and then you can apply CSS gradients http://www.w3schools.com/Css/css3_gradients.asp however it won't move with your scene unless you get really tricky.

Community
  • 1
  • 1
Flux
  • 626
  • 1
  • 6
  • 15