#Any example of updating Shadergraph shader's parameter through script?
1 messages · Page 1 of 1 (latest)
you just set the property in threejs, we expose all of them directly.
Your example: myMaterials._FadeAmount = 1
so id have to have a reference of just that material?
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
how can i get "_FadeAmount" to not throw error?
be recognized as the variable of that material's shader
What error do you get
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
It doesnt exist on the renderer but on the material
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
That's typescript complaining since the base material type you get doesnt have / know your custom properties. So you have 3 options:
- chaotic: add
@ts-ignoreabove that line - neutral: access like
sharedMaterial["_FadeAmount"] - good: delcare a custom merged type with your properties
declare type MyMaterial = {
_FadeAmount : number;
} & Material;
okay cool ill start with neutral xd
btw
custom shadergraph sample is broken
prefabs are missing
Mark it with @serializable(Material), it looks like you forgot that
ye seems like it's working!
did it with (GameObject)
thankuuuu
ah sorry if its a renderer @serializable(Renderer)
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?
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)
i dont have this component on my UI
but still it is being rendered on top
sheeeesh rate this transition
uh
pretty sweet
I love your camera transitions and splines (?) too
it feels very good
and in general you built a fun world
WE built it lool
ty so much, it's just the beginning (unless we can't get any funding)
also used your tip for pointer activation
so much better
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...
The little wall plane in the back is using that script: https://engine.needle.tools/samples/custom-shaders/