Material DoubleSide

What’s the best way to set a material’s side as DoubleSide ? I’ve done this but I’m not sure that’s the best way to do it.

import { Behaviour } from '@needle-tools/engine'
import { DoubleSide } from 'three'

export class DoubleSided extends Behaviour {
  start() {
    this.gameObject.material.side = DoubleSide
  }
}

Original Post on Discord

by user 615280976855171083

You should be able to set it to double sided in Unity

have you tried that?

A better way to access materials if they’re used in the scene in general is using the sharedMaterials array on the Renderer component since it automatically handles multimaterial objects (e.g. this.gameObject.material might be null when you have a multimaterial object in Unity)

for(let i = 0; i < theRenderer.sharedMaterials.length; i++) theRenderer.sharedMaterials[i].side = Double

Just as a reference (not a recommendation) this would be another way to do it (and then just have one DoubleSided script in your scene)

import { Behaviour, Renderer } from '@needle-tools/engine'
import { prefix } from '@needle-tools/engine/engine/engine_util_decorator'
import { DoubleSide } from 'three'

export class DoubleSided extends Behaviour {
    
    @prefix(Renderer)
    onEnable(){
        //@ts-ignore
        const self = this as Renderer;
        if(!self.sharedMaterials) return;
        for(let i = 0; i < self.sharedMaterials.length; i++){
            const mat = self.sharedMaterials[i];
            mat.side = DoubleSide;
        }
    }
}

But i would recommend to setup the material in Unity with double sided enabled

Yes I see, I thought of a Three.js specification, but I never thought Unity would have such option as well. I’ll try that !

by user 615280976855171083

Okay I found it. For those who’re looking for the option (in URP) :
image.png

by user 615280976855171083

You’ll also have a lot of nice options when you use UnityGLTF/PBRGraph instead of URP/Lit shaders

UnityGLTF/PBRGraph maps 1:1 to glTF so we can have more features there that Unity doesn’t support (e.g. rough refraction, transmission, iridescence, …)

Ohh that’s interesting. Thanks for the tip ! :+1::sparkles:

by user 615280976855171083