#Material DoubleSide

1 messages · Page 1 of 1 (latest)

sacred atlas
#

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
  }
}
olive widget
#

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

sacred atlas
#

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 !

#

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

cloud stirrup
#

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, ...)