Two ways to add a sky box in WebGL

Source: Internet
Author: User

Sky Box add can make the scene of the model is very beautiful, and its principle is very simple, I believe that after reading the code below can understand.

When it comes to the two methods of the sky box, it is more like two ways of writing, respectively, using the two methods of texture loading: loadtexture and Loadtexturecube.

Special Note: The order of the pictures

"Method One"

var imageprefix = "images/";

var directions = ["Posx", "negx", "Posy", "Negy", "Posz", "Negz"];

var imagesuffix = ". jpg";

var skygeometry = new three. Cubegeometry (80000, 40000, 80000);

var materialarray = [];

for (var i = 0; i < 6; i++)

Materialarray.push (new three. Meshbasicmaterial ({

Map:three. Imageutils.loadtexture (Imageprefix + directions[i] + imagesuffix),

Side:three. Backside

}));

var skymaterial = new three. Meshfacematerial (Materialarray);

var skybox = new three. Mesh (Skygeometry, skymaterial);

Scene.add (Skybox);

"Method Two"

var r = "Textures/cloud/";

var URLs = [r + "Posx.jpg", R + "Negx.jpg",

R + "Posy.jpg", R + "Negy.jpg",

R + "Posz.jpg", R + "Negz.jpg"];

Texturecube = three.        Imageutils.loadtexturecube (URLs); Defining a square box texture path

= = = Shader = = =

var shader = three. shaderlib["Cube"];

shader.uniforms["Tcube"].value = Texturecube;

var material = new three. Shadermaterial ({

FragmentShader:shader.fragmentShader,

VertexShader:shader.vertexShader,

Uniforms:shader.uniforms,

Depthwrite:false,

Side:three. Backside

}),

Mesh = new three. Mesh (new three.      Cubegeometry (+, +), material); Create a square box and add the box scene

Scenecube.add (mesh);

Two ways to add a sky box in WebGL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.