Commit Graph
213 Commits
Author SHA1 Message Date
alteredq d1514ca6a7 Refactored lights handling in WebGLRenderer.
This should be the last place where new arrays were created in "render".

Chrome memory now seems stable.

Firefox still grows like mad, though this used to be like this also with other demos (simply setting random values to existing arrays does this).

Seems like Mozilla folks themselves struggle with this:

http://www.flickr.com/photos/11280278@N04/5363335103/in/photostream/
2011-01-17 20:22:46 +01:00
alteredq e54d9519d0 Changed wireframe rendering in WebGLRenderer to show quads.
See discussion here:

https://github.com/mrdoob/three.js/issues#issue/92
2011-01-17 18:44:09 +01:00
alteredq 08f6ceef15 Small optimizations to matrix math.
For the moment just things that are executed every frame in WebGLRenderer.render.

Continuing with quest to minimize creation of new data structures. Should instead create per class/object structures and just reuse them (as gman does in ThreeD). Main goal is to avoid annoying garbage collection pauses.

Let's hope it didn't break something (could be if some code was dependent on cloning of return values of "flatten" or "makeInvert3x3", though from what I checked these are just used to set typed arrays uniforms).
2011-01-17 16:09:26 +01:00
alteredq d110c49c2f Added support for flipSided mesh property to WebGLRenderer.
Also doesn't seem to decrease performance so far (though most of demos have small number of objects).
2011-01-16 21:46:23 +01:00
alteredq 271ba6c524 Added support for "doubleSided" mesh property to WebGLRenderer.
Testing on current examples didn't show any noticeable performance degradation when enabling / disabling culling for every object in every frame.

"FlipSided" property could be probably done in very similar way, just setting "gl.frontFace( gl.CCW )" or "gl.frontFace( gl.CW )"
2011-01-16 15:10:58 +01:00
alteredq 61e0bf0289 Synced with mrdoob's branch. 2011-01-16 03:07:56 +01:00
alteredq a03f714244 Added postprocessing example.
For this had to extend WebGLRenderer a bit:

- MeshShaderMaterial now can take non-specific float array uniforms as "fv1"
  (there is already "fv" type for array of 3-item-vectors, which probably should be renamed to "fv3" to be consistent)

- render method has yet another parameter "clear" for clearing newly set framebuffer (defaults to true).
  This is a bit hackish but it seems necessary to control this somehow. I didn't manage to replicate
  desired behavior just with autoClear.

- another dirty thing is accessing GL context from the application side:
    renderer.context.disable( renderer.context.DEPTH_TEST );

    This should be refactored somehow, wrapped in some API call.
2011-01-15 02:20:47 +01:00
alteredq 7c9fe8ff82 Another update of render-to-texture example and related bugfix.
Rendering proper 3d object into the texture uncovered another issue - framebuffer had to be cleared after switching.

Texture is still flipped :( (original scene has small red torus on the top)

This is proving to be rather tricky. Yet again I tried to handle image coordinate mess in a proper way (UNPACK_FLIP_Y_WEBGL as texture parameter and non-inverted UVs), fixing hacks across the codebase.

This did indeed help with render-to-texture flipping, but instead it created really ugly problems with both normal map and minecraft AO demos. So back to square one :(
2011-01-14 12:39:57 +01:00
alteredq 9bc383e1ed Fixed discrepancy between ANGLE and OpenGL when rendering to texture.
Had to set viewport to make it work in OpenGL.

Also made it easier to see texture orientation in the example.

Now it's visible that there is indeed flipping. At least now it's consistent ;).
2011-01-13 22:10:38 +01:00
alteredq cee7205670 Added simple render-to-texture example.
Something is broken as OpenGL shows different result than ANGLE :(

Though this time it's ANGLE which seems correct.
2011-01-13 17:04:36 +01:00
alteredq b511fdc38b Merged szimek's render-to-texture branch.
This is untested, as example is in different branch, have to commit this merge first.

At least this didn't seem to break existing things.
2011-01-13 15:27:08 +01:00
alteredq 0f5652390f Added dynamic geometry support also for WebGL lines. Changed line strip example to use Hilbert curves.
Also fixed tons of bugs in lines handling.

TODO: make some example for dynamic lines.
2011-01-13 14:12:18 +01:00
alteredq fe6008b616 Added basic support for dynamic geometry in WebGLRenderer (with silly ocean example).
If you want to refresh VBOs (and thus have geometry changes reflected in renderer), you need to set dirty flags on geometry object.

There are separate flags for different buffers (as not always all buffers need to be updated and oh my is updating costly):

    mesh.geometry.__dirtyVertices = true;
    mesh.geometry.__dirtyNormals = true;
    mesh.geometry.__dirtyUvs = true;
    mesh.geometry.__dirtyTangents = true;

    mesh.geometry.__dirtyElements = true;

That was quite tough feature, a lot of refactoring, yet performance is still quite bad :(

The biggest remaining bottleneck seems to be translation between Three.js internal data formats and buffers. I removed as much per-frame arrays creation as I could, but even just iterating through existing data and setting of values is still very costly. Also per-frame normals computation is expensive.
2011-01-12 00:57:04 +01:00
Szymon Nowak 6294caed07 Added render-to-texture feature to WebGL renderer. 2011-01-11 10:10:05 +01:00
alteredq bc9cf2be75 Fixed scene check bug in allocateLights in WebGLRenderer.
Also some refactoring of initWebGLObjects slipped in this commit.
2011-01-09 07:37:20 +01:00
alteredq e43de3dcf7 Refactored lines handling in WebGLRenderer to use the same internal machinery as meshes.
No need to stuff them in different bucket, line-specific stuff is anyway done in `renderBuffer` method.

This was prompted by starting with implementation of ParticleSystem. It would be unwieldy to handle three different buckets of objects / buffers.
2011-01-08 17:33:55 +01:00
alteredq bbe2a3bf56 Refactored handling of continuous lines: now they are rendered using LINE_STRIP primitive. Added example for this.
Also renamed associated constant to THREE.LineStrip (was THREE.LineContinuous).
2011-01-08 01:15:01 +01:00
alteredq ef9bdf6b77 Small WebGLRenderer optimization: skip setting of uniforms which don't exist in shader program. 2011-01-06 02:57:05 +01:00
alteredq 8ea0f27602 Refactored lines grid in materials_gl example. 2011-01-04 05:14:10 +01:00
alteredq 548c331519 Added crude lines support to WebGLRenderer.
As expected, performance of one-to-one conversion from CanvasRenderer was horrible, so I had to change a bit how lines are handled.

Line object now has "type" property:

    - default type is "THREE.LineContinuous" which should behave as before: geometry represents one continuous line (v0 ... vn)

    - new option is "THREE.LinePieces" which tells renderer that geometry represents collection of individual line segments (v0,v1) ... (vn-1, vn)

(one Line object corresponds to one VBO)

(same limitations as with meshes - once VBO is baked, no changes are possible except object transforms - scale / rotation / position)
2011-01-04 04:38:25 +01:00
alteredq a8416bc8c1 Fixed implied globals in WebGLRenderer lights rgb init. 2011-01-02 21:01:01 +01:00
alteredq 771674d705 Refactored Loader parameters to allow optional separate paths for texture and binary files.
loader.loadAscii and loader.loadBinary now take just one parameter with following properties:

    - model (required)
    - callback (required)
    - texture_path (optional: if not specified, textures will be assumed to be in the same folder as JS model file)
    - bin_path (optional: if not specified, binary file will be assumed to be in the same folder as JS model file)

Example use:

    loader.loadBinary( { model: "model.js", bin_path: "path/bin", texture_path: "path/img",
                         callback: function( geometry ) { createScene( geometry ) } } );
2011-01-02 19:52:40 +01:00
Mr.doob c186b37be3 Pushed revision to 32.
Updated README.
2010-12-31 17:59:11 +00:00
alteredq ab360240dc Refactored common uniforms out from basic / lambert / phong shaders into UniformsLib. 2010-12-31 03:19:47 +01:00
alteredq ecad27eb11 Moved MeshPhongMaterial onto common shader builder machinery, ubershader is no more.
Code is still rough around edges (it can be made nicer), though it should already produce one-to-one results with ubershader.

Side-effect is that scene is no longer required as WebGLRenderer constructor parameter. Shader programs are now constructed upon first frame render and only then scene lights are examined.
2010-12-31 00:33:39 +01:00
alteredq ae60091a58 Small refactoring in WebGLRenderer. 2010-12-30 00:55:54 +01:00
alteredq dad635b64c Merged mrdoob's changes. 2010-12-30 00:18:31 +01:00
Mr.doob 9b755e827f Added "v2" uniform type to WebGLRenderer.
Added a shader demo (as in using only 2 triangles).
2010-12-29 23:09:59 +00:00
alteredq 06a977384d Synced with mrdoob's branch. 2010-12-30 00:01:06 +01:00
alteredq 6cfcdd1501 Moved MeshPhongMaterial out of ubershader.
One more to go ;)

Mess / code duplicities are temporary, hopefully they will go away once also Phong uses the same machinery.
2010-12-29 23:42:13 +01:00
alteredq 3cabd11849 Moved MeshBasicMaterial out of ubershader.
None of the demos seem to be slower, some are noticeably faster (especially terrain).

I suspect biggest performance gain comes from conditional include of environment mapping: if it's not used, it doesn't go into shader at all.
2010-12-28 21:50:57 +01:00
alteredq 0fe464c97a Refactored uniforms cloning into separate file so that it can be reused also for MeshShaderMaterials.
Also changed MeshShaderMaterial demos to show how to use cloning. For these particular demos uniforms cloning is not really necessary as they use only one instance of shader material, but for example, if there were two normal mapped models in one scene, each model would need separate material with own uniforms.
2010-12-28 17:11:50 +01:00
alteredq ecdbb2ef91 Fixed broken uniforms cloning. Fixed broken uqbiquity test.
TODO: start using uniforms cloning also for MeshShaderMaterials.
2010-12-28 14:33:52 +01:00
Mr.doob 513563117b Added method setClearColor( color, opacity ) to CanvasRenderer. 2010-12-28 01:18:43 +00:00
Mr.doob 3488a53798 Recompiled builds.
Re-tweaked normalmap2 demo.
2010-12-27 01:22:48 +00:00
Mr.doob 7e1321d084 Trying to avoid merge conflicts... I'm sure it's not going to work... 2010-12-27 01:16:14 +00:00
Mr.doob 4a486f858a Added uNormalScale to normal shader.
Updated normalmap2 demo inverting the X/Y components.
2010-12-26 23:54:35 +00:00
alteredq 1722242ee1 Added cloning of uniforms for MeshShaderMaterial & co.
This is necessary for having multiple materials using the same shaders with different parameters.
2010-12-26 19:03:24 +01:00
alteredq fb7788f0c6 Resurrected exponential fog as FogExp2.
For the moment, only one type of fog is baked into shader, depending on scene.fog initial value.

If use case arise for dynamic fog type switching, this could be changed, though than both fogs would need to be computed all the time :S.
2010-12-26 04:11:35 +01:00
alteredq 91b9539e02 Synced with mrdoob's branch. 2010-12-25 23:08:57 +01:00
alteredq 255c042b1e Added clear color parameter to WebGLRenderer constructor, also added setClearColor API call.
This allows to work around ANGLE antialiasing issue appearing when compositing WebGL framebuffer with transparent background color with HTML canvas element background (while keeping antialiasing on).

WebGLRenderer constructor now takes JSON object with few optional parameters:

    renderer = new THREE.WebGLRenderer { scene: scene,
                                         antialias: true,
                                         clearColor: 0x000000,
                                         clearAlpha: 0 };

Here is how to change clear color in runtime:

    renderer.setClearColor( 0xff0000, 1 );
2010-12-25 22:32:26 +01:00
Mr.doob e46346c9ba Cleaned up CanvasRenderer/MeshDepthMaterial code.
Moved near/far values from MeshDepthMaterial to Camera (CanvasRenderer/WebGLRenderer/WebGLRenderer2).
2010-12-25 18:14:10 +00:00
Mr.doob fbf26158fb Fog( color, density )Fog( color, near, far ) 2010-12-24 22:15:45 +00:00
Mr.doob bffdc03cf1 *.material*.materials 2010-12-24 21:24:58 +00:00
alteredq 323228ac72 Added antialiasing parameter to WebGLRenderer constructor.
This is a workaround for Chrome ANGLE antialiasing issue manifested in geometry_terrain_fog demo:

http://twitpic.com/3iftyh

Problem happens in Chrome ANGLE when geometry is rendered with the same color as canvas background - then instead of expected nothing to be seen, there is a faint white outline at geometry borders.

This issue is not specific to fog, even just rendering geometry with MeshBasicMaterial having the same color as background produces the same outline.

TODO: create isolated test case and file ANGLE / Chromium bug.
2010-12-23 22:23:56 +01:00
Mr.doob c39eca33ee Projector::projectScene now does a first pass through Projector::projectObject (which does frustum culling and object sorting).
So now CanvasRenderer and SVGRenderer feature frustum culling too.
2010-12-21 14:07:23 +00:00
alteredq 2c1e6a1368 Forgot to remove hardcoded fog color in shader. 2010-12-21 01:38:39 +01:00
alteredq 76a56f2f5c First attempt at fog ;)
For the moment, it works just on Basic / Lambert / Phong materials.

Fog must be added to the scene before initialization of WebGLRenderer and scene must be passed to WebGLRenderer constructor (like for lights).

I don't know yet how to solve properly MeshShaderMaterial & co :(
2010-12-21 01:22:44 +01:00
Mr.doob 02f81a26f4 Merging with alteredq's branch. 2010-12-20 22:16:04 +00:00
Mr.doob 5e2c480b89 Implemented Frustum checking to Projector::projectObjects (thanks errynp)
Added `boundingBox`, `boundingSphere` and `computeBoundingSphere` to Geometry.
2010-12-20 00:28:31 +00:00