#Any example of updating Shadergraph shader's parameter through script?

1 messages · Page 1 of 1 (latest)

rare axle
#

something like this? getComponentInChildren(Renderer)?.sharedMaterial.setValues("_FadeAmount",1);

toxic arch
#

you just set the property in threejs, we expose all of them directly.
Your example: myMaterials._FadeAmount = 1

rare axle
toxic arch
#

You can use the sharedMaterials array as well

#

if you know that all those materials have that property/shader

#

this.gameObject.getComponentInChildren(Renderer).sharedMaterial._FadeAmount = 1

rare axle
#

be recognized as the variable of that material's shader

toxic arch
#

What error do you get

rare axle
#

Property '_FadeAmount' does not exist on type 'Renderer'

#

the script doesnt event know which material im using yet

#

so it's natural id get it

toxic arch
#

It doesnt exist on the renderer but on the material

rare axle
#

woops my bad

#

Property '_FadeAmount' does not exist on type 'Material'

#

im trying like so

#

just as a test

#

im sorry im clueless on this

toxic arch
#

That's typescript complaining since the base material type you get doesnt have / know your custom properties. So you have 3 options:

  1. chaotic: add @ts-ignore above that line
  2. neutral: access like sharedMaterial["_FadeAmount"]
  3. good: delcare a custom merged type with your properties
declare type MyMaterial = {
    _FadeAmount : number;
} & Material;
rare axle
#

btw

#

custom shadergraph sample is broken

#

prefabs are missing

toxic arch
#

The sample doesnt have those prefabs as far as I can see

rare axle
#

eh

#

i can't even get to the shader xd

#

ah this i might know

toxic arch
#

Mark it with @serializable(Material), it looks like you forgot that

rare axle
#

did it with (GameObject)

#

thankuuuu

toxic arch
#

ah sorry if its a renderer @serializable(Renderer)

rare axle
#

wait no it doesn't work, my material just becomes invisible

#

i have set the material as exportshader

#

i see, if i set "enable GPU instancing" the material breaks

#

@toxic arch sorry one more thing, is it possible to draw transparent shadergraph on top of worldspace UI?

toxic arch
#

Yes (if you dont set the canvas to "renderOnTop")

#

this must be off if you have that component (if not you dont need to do anything)

rare axle
#

but still it is being rendered on top

rare axle
toxic arch
#

uh

#

pretty sweet

#

I love your camera transitions and splines (?) too

#

it feels very good

#

and in general you built a fun world

rare axle
rare axle
#

also used your tip for pointer activation

#

so much better

toxic arch
#

Added a new sample for this and also code here: https://engine.needle.tools/docs/scripting-examples.html#change-custom-shader-property

import { Behaviour, serializable } from "@needle-tools/engine";
import { Material } from "three";

declare type MyCustomShaderMaterial = Material & {
    _Speed: number;
};

export class IncreaseShaderSpeedOverTime extends Behaviour {

    //@type UnityEngine.Material
    @serializable(Material)
    myMaterial?: MyCustomShaderMaterial;

    update() {
        if (this.myMaterial) {
            this.myMaterial._Speed *= 1 + this.context.time.deltaTime;
            if(this.myMaterial._Speed > 1) this.myMaterial._Speed = .0005;
        }
    }
}

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development, and can be deployed anywhere. It is flexible, extensible, and collaboration and XR come naturally. Needle Exporter for Unity bridges the Unity Editor and the web runtime. It helps you to export your assets, animations, lightmaps and so on to the web. It is...