WebGL

three.js shadow cutoff

痞子三分冷 提交于 2019-12-04 19:51:28
问题 As the title says. When i render the current scene everything works fine. Only the shadow of the white monkey gets cut off. How can this happen, and is there a resolution for it? Here is the site: http://hammer.bz/test/ and a screen ;) http://i.stack.imgur.com/6jd0h.png I guess it has to do with the camera or with the lights.. so here are they: renderer.shadowMapEnabled = true; renderer.sortObjects = false; renderer.shadowMapWidth = 3072; renderer.shadowMapHeight = 3072 renderer

Why do my three.js examples not load properly?

点点圈 提交于 2019-12-04 19:41:23
I just downloaded Mr. Doob's three.js project. In the examples folder, anything that doesn't use a model or texture will load up properly. The ones with models or textures show up blank. I don't understand why. I can webgl examples with models and textures to work on the three.js website. Can anybody help, I am stumped... You need to run chrome using the --allow-file-access-from-files flag. https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally Also, here's some discussions on how they're trying to solve this: http://code.google.com/p/chromium/issues/detail?id=121406 http://code

Webgl gl.viewport change

天大地大妈咪最大 提交于 2019-12-04 19:03:33
问题 I have a problem with canvas resizing and gl.viewport sync. Let's say that I start with both the canvas 300x300 canvas, and the initialization of gl.viewport at the same sizes ( gl.vieport(0, 0, 300, 300) ). After that, in browser's console I make my tests: I'm changing size of my canvas, using jquery, calling something like $("#scene").width(200).height(200) After this, i'm calling my resizeWindow function: function resizeWindow(width, height){ var ww = width === undefined? w.gl

White edges appearing at edge of cube

我们两清 提交于 2019-12-04 18:41:07
When I render a cube and texture it I end up with white edges along the cube. I've checked the vertex and texture coordinates and they look fine to me. My texture is a power of 2. It is a texture map containing 4x4 textures in which each texture is 16x16 pixels. Does anyone have any suggestions? I guess you are experiencing texture bleeding. You can solve it by either using GL_CLAMP on your textures or adjusting slightly your UV coordinates to 0.0005 and 0.0095 (for instance) instead of 0 and 1 to compensate for the texture sampling artifacts. 来源: https://stackoverflow.com/questions/5201115

Why does this state that WebGL is a 2D API, not a 3D API?

回眸只為那壹抹淺笑 提交于 2019-12-04 18:30:31
问题 According to HTML5 Rocks, WebGL is actually a 2D API, not a 3D API. Why do they say that, and what does it mean? We can specify X, Y, Z coordinates in WebGL vertex shaders and fragment shaders. I can't understand the difference between a 2D and 3D graphics API. Could you explain why they say this is a 2D API? 回答1: WebGL is a rasteration API not a 3D api. You have to provide it with projected coordinates. This many ways it is no different than Canvas. It's just faster. Let's compare. Here's 3D

WebGL学习笔记(十六):遮罩

跟風遠走 提交于 2019-12-04 18:16:42
这里总结下几种WebGL中实现遮罩的方法。 模板缓冲 模板缓冲可以实现渲染剔除,但是剔除范围是基于上一次渲染的结果,且上一次的渲染也会进行显示(这么设定是为了实现特殊的显示效果),并不适合用来实现遮罩。 scissor 仅绘制指定的矩形区域,可以用来实现简单的无旋转遮罩。 使用着色器 传入一张用来进行遮罩的图片,通过着色器判断这张图片的像素值,来决定当前的像素是否需要丢弃,还是进行alpha值的改变,可以实现任意形状的遮罩,缺点是对于较大的图片会出现掉帧的情况。 使用混合 blendfunc实现的遮罩效果是最简单的,首先绘制遮罩图的,遮罩图的blendfunc需要设置为: mask:setBlendFunc(gl.ONE_MINUS_SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) 然后绘制被遮罩对象,其blendfunc需要设置为: sprite:setBlendFunc(gl.ONE_MINUS_DST_ALPHA, gl.DST_ALPHA) 原理其实很简单,遮罩图绘制到framebuffer的时候只保留alpha值,而sprite绘制的时候使用遮罩的apha值。不过需要注意的是,如果使用该方法,需要保证opengl的Config中有配置alpha通道,例如在使用OpenGL ES的安卓环境中,需要设置 mGLSurfaceView

Three js - Cloning a shader and changing uniform values

守給你的承諾、 提交于 2019-12-04 17:59:31
问题 I'm working on creating a shader to generate terrain with shadows. My starting point is to clone the lambert shader and use a ShaderMaterial to eventually customise it with my own script. The standard method works well: var material = new MeshLambertMaterial({map:THREE.ImageUtils.loadTexture('images/texture.jpg')}); var mesh = new THREE.Mesh(geometry, material); etc The result: However I'd like to use the lambert material as a base and work on top of it, so I tried this: var lambertShader =

What are WebGL's draw primitives?

回眸只為那壹抹淺笑 提交于 2019-12-04 17:43:25
问题 I've been doing some graphics programming using webgl to draw OBJMesh's, but it hasn't gone too well as it is not drawing it correctly. I think thats because of the drawing primitives that I'm using e.g : gl.drawArrays(gl.TRIANGLE_STRIP, 0, vertexBuffer.numItems); So can I ask what primitives do webGL allow? is it the same as openGL? I've been trying to use gl.QUADS as I thought it would allow it as openGL does, so I'm not too sure anymore. 回答1: From https://www.khronos.org/registry/webgl

Serve three.js?

巧了我就是萌 提交于 2019-12-04 17:27:46
I'm trying to serve the example found here over a [Node] http server with socket.io. The example runs just fine. The code below... var app = require('http').createServer(handler) , io = require('socket.io').listen(app) , fs = require('fs') app.listen(8086); function handler (req, res) { fs.readFile(__dirname + '/spinnycube.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading spinnycube.html'); } res.writeHead(200); res.end(data); }); } io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event',

three.js - apply different material to extruded shape

房东的猫 提交于 2019-12-04 17:18:55
I have Three.Shape which I can apply Extrusion To get a plane I drew a square first and then apply extrusion var squareShape = new THREE.Shape(); squareShape.moveTo( 0,0 ); squareShape.lineTo( 0, sqLength ); squareShape.lineTo( sqLength, sqLength ); squareShape.lineTo( sqLength, 0 ); squareShape.lineTo( 0, 0 ); var geometry = new THREE.ExtrudeGeometry( squareShape,extrudeSettings); now a 3D square is appearing on my browser. Next I want to apply a image texture of 256x256 on its top face. How to do this? If you look at src/extras/geometries/ExtrudeGeometry.js in THREE.js you will see these