Alternative for texture support of CanvasRenderer in Three.js r49? - three.js

In Three.js r47, I used CanvasRenderer to draw some objects with image texture. Then I upgrade Three.js to r49 and all these objects dont show up anymore. The change log of r49 reads that "Removed Lamber Texture support in CanvasRenderer". So I think this is the reason.
My question is does Three.js support an alternative to draw texture objects by CanvasRenderer?
Thanks.

Try using MeshBasicMaterial instead?

Related

Separate materials in an instancedMesh react three fiber

I essentially have a bunch of geometries that I need to display unique and updating text.
The approach I've been using to display the text is using a canvas material which(along with the mesh position) is constantly updated in a useFrame.
However, the only way I've been able to get the texture to work is as follows, and all geometries are obviously sharing it.
<instancedMesh ref={meshRef} args={[null, null, intervalData.length]}>
<circleBufferGeometry args={[sizes.radius ?? 0.6, sizes.segments ?? 48]}>
<instancedBufferAttribute attachObject={['attributes', 'color']} args={[colorArray, 3]} />
</circleBufferGeometry>
<meshStandardMaterial vertexColors={THREE.VertexColors} map={texture}/>
</instancedMesh>
What would be the way to set the textures per instance? Is there somewhere I can store an array of textures and assign them to the mesh?
Probably pretty late for you, but maybe if someone else is stuck with same question. I have solved this like this https://codesandbox.io/s/instancedmesh-with-different-textures-forked-iy5xh?file=/src/App.js
Though I am passing each texture separately, it has down side that you can only pass 16 textures to single shader, so maybe you'll have to use texture atlas (basically single texture composed of multiple texture and you also pass couple of more attributes to crop the particular texture part from whole texture)
Probably any performance boost from InstancedMesh would be surpassed by using a Sprite, not to mention more useful.

Possible workaround for having color and texture with Three.js CanvasRenderer?

I am using CanvasRenderer to render numerous Sprite objects. I am mapping a texture (PNG image) to the Sprites. I'd like to be able to change the color of the texture programmatically.
With the WebGLRenderer, I can use ParticleSystem and ParticleSystemMaterial to achieve this. Here's a live demo of setting color to this texture (http://wxalert.info/private/dv/ball.png) with that technique: http://wxalert.info/private/dv/demo.html
But since CanvasRenderer does not support ParticleSystem, I am using Sprites instead with a SpriteBasicMaterial. Here's a live demo of this: http://wxalert.info/private/dv/demo2.html
I'd like to be able to set the color with CanvasRenderer just like with WebGLRenderer, but I'm not sure if this is possible.
One thought was perhaps to load the image to an HTML5 canvas element, apply the color there, and then load the canvas context from the material. But any other suggestions would be greatly appreciated.
UPDATE: Here's an example of kind of what I was thinking of doing if using the HTML5 canvas: http://wxalert.info/private/dv/html5canvas.html. Basically, I would do the color manipulation there and then just load the canvas from the material. But wasn't sure if there was a simpler or better way.

Use css3drenderer to render particleSystem in Three.js

I have a particleSystem which contains hundreds of thousands of particles and I can render it with webglrenderer in Three.js, But it seems that mobile devices don't support webgl and I may use css3drender.
I've tried to change webglrender to css3drender and it turns out that the css3drender can't render my particleSystem, I've searched on goole and can't get any examples using css3drender to render particlesystem ,either.
What I want to know is whether I can use css3drender to render my particleSystem, thanks.

Three.js no shadows on ShaderMaterial

I'm creating terrain editor with three.js and i have encountered few problems.
First. Shadows renders on MeshLambertMaterial, but it wont on ShaderMaterial.
Second. How to change object's material (from lambert to shader) on runtime?
Here's demo of my editor: http://78.62.160.169/webgl/editor/
And source code: http://78.62.160.169/webgl/editor/script.js
LambertMaterial is a built-in material, that's supported by the plugins. So shadow plugin supports rendering on the LambertMaterial, while ShaderMaterial is your own shader/material, that should manually enable shadow support, it's not set by the default.
Switching material: https://github.com/mrdoob/three.js/wiki/Updates
here is the example of ShaderMaterial with shadow and fog
https://gist.github.com/wmcmurray/6696fc95f25bbd2401d72a74e9493261
or you can also rewrite a shader from LambertMaterial or other,
make it support your own shader

Flat shading OpenGL using Three.js

I am trying to simulate the OpenGL flat shading model using Three.js. My idea is creating an example like http://en.wikipedia.org/wiki/File:Phong-shading-sample.jpg. I was trying to change some different shading models but I cannot obtain the desired result.
Is it possible to create this scene in three.js?
Thanks in advance
Materials e.g. the MeshBasicMaterial have an option called "shading". It can be set to THREE.None, THREE.FlatShading, THREE.SmoothShading.
I am not sure if you need a light source in the first place or wether you have to enable shading for a the whole scene. Look at the demos at the Three.js website for something with shading.

Resources