Gradient Sky In A-Frame
NickName:cnzac Ask DateTime:2016-11-07T04:24:19

Gradient Sky In A-Frame

How might I make a gradient color for the sky without using images?

This is what I have so far (I know why it doesn't work - it is only reference for what I am trying to do):

<a-sky color="linear-gradient(red, yellow)"></a-sky>

ThreeJS solutions welcome as well, but I would need help integrating them into an A-Frame scene.

Copyright Notice:Content Author:「cnzac」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40454143/gradient-sky-in-a-frame

Answers
cnzac 2016-11-07T03:44:02

I ended up solving it with help from the given examples. Thank you Marko, Pablieros, ngokevin, and Mr Doob!\n\nI ended up creating a custom shader and a primitive element to go along with it: \n<a-gradient-sky material=\"topColor:0 1 0; bottomColor:1 0 0;\"></a-gradient-sky>\n\nAFRAME.registerShader('gradient', {\n schema: {\n topColor: {type: 'vec3', default: '1 0 0', is: 'uniform'},\n bottomColor: {type: 'vec3', default: '0 0 1', is: 'uniform'},\n offset: {type: 'float', default: '400', is: 'uniform'},\n exponent: {type: 'float', default: '0.6', is: 'uniform'}\n },\n vertexShader: [\n 'varying vec3 vWorldPosition;',\n\n 'void main() {',\n\n 'vec4 worldPosition = modelMatrix * vec4( position, 1.0 );',\n 'vWorldPosition = worldPosition.xyz;',\n\n 'gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0 );',\n\n '}'\n ].join('\\n'),\n fragmentShader: [\n 'uniform vec3 bottomColor;',\n 'uniform vec3 topColor;',\n 'uniform float offset;',\n 'uniform float exponent;',\n 'varying vec3 vWorldPosition;',\n 'void main() {',\n ' float h = normalize( vWorldPosition + offset ).y;',\n ' gl_FragColor = vec4( mix( bottomColor, topColor, max( pow( max(h, 0.0 ), exponent ), 0.0 ) ), 1.0 );',\n '}'\n ].join('\\n')\n});\n\nAFRAME.registerPrimitive('a-gradient-sky', {\n defaultComponents: {\n geometry: {\n primitive: 'sphere',\n radius: 5000,\n segmentsWidth: 64,\n segmentsHeight: 20\n },\n material: {\n shader: 'gradient'\n },\n scale: '-1 1 1'\n },\n\n mappings: {\n topColor: 'material.topColor',\n bottomColor: 'material.bottomColor',\n offset: 'material.offset',\n exponent: 'material.exponent'\n }\n});\n",


More about “Gradient Sky In A-Frame” related questions

Gradient Sky In A-Frame

How might I make a gradient color for the sky without using images? This is what I have so far (I know why it doesn't work - it is only reference for what I am trying to do): &lt;a-sky color="lin...

Show Detail

Rotating sky in latest version of A-Frame

Can anybody help me convert code from 0.8.2 to what the latest version of A-Frame requires? The following code worked fine in 0.8.2 to rotate the sky, but I can't figure out how to get it to conti...

Show Detail

A-Frame cursor listener on sky element not firing

I am trying to attach a cursor listener to a sky element (equirectangular image as texture mapped to sphere) in A-Frame. The ultimate goal is to get the 2D coordinates of the texture at the point the

Show Detail

Using CSS Mask Transition with A-Frame sky entity

I'm working on a school project and we are developing an interactive story with the A-Frame framework. The idea is to visit your old house and to have memories about good old times. So we're using ...

Show Detail

A-Frame not loading assets from Angular

im testing a-frame with ionic and angular. I get a-frame runs great with them, even tried on my device and looks awesome. The problem comes when i try to load an img on the a-sky from a property o...

Show Detail

Networked A-Frame Gallery a-sky change for all the people in the room

I am trying to create A-Frame 360 gallery using Networked A-Frame. When one person in the room clicks on the link to change the image, the environment has to change for everyone in the room. I hav...

Show Detail

How to create a <a-sky></a-sky> image with zoom?

i am newbie in a-frame , and i have a simple question(actually it's hard for me) &lt;script src="https://aframe.io/releases/0.5.0/aframe.min.js"&gt;&lt;/script&gt; &lt;a-scene&gt

Show Detail

How to create a <a-sky></a-sky> image with right size

A-Frame sky default radius= 5,000 diameter=10,000 So if I was to create a equirectangular image in photoshop or other program, which size should I use? 10,000 x 5,000 pixels or 10,000 x 5,000 met...

Show Detail

A-sky a-frame rounded borders

I'm setting an a-sky element with an image 360: &lt;a-sky id="sky_salon_izq" src="#salon_izq"&gt;&lt;/a-sky&gt; The img show cool in normal mode: normal mode img But i have probl

Show Detail

A-frame.js a-sky occasionally using cube geometry instead of sphere on successive embedded loads

In a current project that loads successive a-frame scenes (using vue-router, on different routes) a-sky will sometimes appear with a cube instead of sphere geometry. The pano image texture will be

Show Detail