Hello guys, on the first image my object looks exactly how I want it to look. On the second image is the same object from a different POV and inside I can see the walls of the other boxes.
Is there any way to fix this with the approach I have taken on displaying this object?
I am using instances because these objects will be bigger than 4 squares, and it will lie on an uneven grid which means that each of the cubes can have different position than the rest, and also a different height depeneding on the type of object, so I cannot merge it into one geometry and i need individual control of the composing cubes
const Map3DObstacleComponent = (props: Map3DObstacleProps): JSX.Element => {
const { obstacle } = props;
const [edgesOn, setEdgesOn] = useState<boolean>(false);
const [selected, setSelected] = useState(false);
return (
<Instances
onAfterRender={() => {
setEdgesOn(true);
}}
position={[0, 0, 0]}
limit={obstacle.cubes.length}
onClick={() => setSelected(true)}
>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial
color={selected ? 'red' : 'yellow'}
transparent
opacity={0.6}
/>
{obstacle.cubes.map((cube, index) => (
<Instance
key={index}
scale={cube.hidden ? [0.00001, 0.00001, 0.00001] : cube.dimensions}
position={cube.hidden ? [0, 0, 0] : cube.position}
>
{edgesOn && <Edges color='black' />}
</Instance>
))}
</Instances>
);
};
const Map3DObstacle = Map3DObstacleComponent;
export { Map3DObstacle };
I can put only links:
https://raw.githack.com/pailhead/three.js/depth-peel-example/examples/webgl_materials_depthpeel.html
mrdoob:dev
← pailhead:own-depthstencil-target-buffer
opened 08:23PM - 29 Dec 18 UTC
### Problem
Multiple `WebGLRenderTarget` can't share the same depth / stenci… l render buffer because `WebGLRenderer` creates them in a private cache. This is possible to do with webgl, [but not with three.js. ](https://github.com/mrdoob/three.js/issues/15440)
### Proposal
Have the `WebGLRenderer` attempt to use an existing buffer if one is provided. And allow the targets to be used so:
```
targetA.ownDepthBuffer = buffer
targetB.ownDepthBuffer = buffer
```
### Use case
This [depth peel example](https://raw.githack.com/pailhead/three.js/depth-peel-stencil/examples/webgl_materials_depthpeel.html), goes from not being interactive to working on phones when stencil masking is used ([video](https://www.youtube.com/watch?v=nMfQeotbN8s)).
### Argument for
There are a few things in three.js that already work like this i think. `defines`, `customDepthMaterial` are the two that pop to mind - you could set them, and they would make `WebGLRenderer` do certain things, but were not present in documentation for a long time. This does not change the behavior of the renderer in any way, and allows WebGL to be fully utilized.
### Optional
Document it:
> Sets the render buffer on the target. If one is not provided, three creates one internally for this target. You can share render buffers between targets:
```
const gl = renderer.getContext()
const buffer = gl.createRenderBuffer()
targetA.ownDepthBuffer = buffer
targetB.ownDepthBuffer = buffer
```
### Future (if accepted)
Make an API:
```
const buffer = new THREE.RenderBuffer(config)
targetA.depthBuffer = buffer
targetB.depthBuffer = buffer
```
https://tsherif.github.io/webgl2examples/oit-dual-depth-peeling.html
1 Like
Okay managed to find a pretty easy solution, just render the object twice - once with colorWrite = false, and once with colorWrite = true
javascript, three.js