Posts

Showing posts with the label time

shader scroll UVs

This nice short & sweet shader scrolls the texture using time & some float values, in the x/y or u/v directions. All we're doing is manipulating the u and v values. Unity provides us with the time variable "_Time". According to the docs, the time is in Seconds & is scaled by the game's time multiplier. Beneath the shader are some docs time variables and info.    Shader "Dave/Unlit/UVSCROLL"{     Properties{         _MainTex("Texture",2D) = "white"{}         _ScrollX("Scroll X",Range(-5,5))=1         _ScrollY("Scroll Y",Range(-5,5))=1              }         SubShader{         CGPROGRAM         #pragma surface surf Lambert         sampler2D _MainTex;         float _ScrollX...

Compute Shader, read from calculated buffer

 Use case - get the GPU to calculate a bunch of X,Y,Z coordinates for an arbitrary number of instanced prefabs in Unity.  On the Unity C# side, we need : To specify a compute shader, a handle for the compute shader, a buffer that we'll be writing to in the shader, a prefab, the number of prefabs we want, an array for the instanced prefabs, an array for the coordinate data. Any extra variables we want to pass over, eg time. On the compute shader side we need : To specify a read-write buffer, instead of a texture that we created in the previous post. The buffer will be of float3 type, which is how HLSL calls a vector3. That's actually it... Here's the Compute Shader code - #pragma kernel boxMove RWStructuredBuffer<float3> yesBlad; float time; [numthreads(64,1,1)] void boxMove (uint3 id : SV_DispatchThreadID) {     float xpos = (float)id.x;     float ypos = sin(id.x+time)*50;     float zpos = cos(id.x +time)* 50;    ...

Messing with VFX Graph time scale/playback rate

Unity Forum user Olmi did a nice code snippet for this https://forum.unity.com/threads/what-is-the-right-way-to-pause-particles.837889/ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.VFX; public class vfxgraph_playrate : MonoBehaviour {     [SerializeField] float timeScale = 1.0f;     [SerializeField] VisualEffect VFX;     void Start()     {         VFX = GetComponent<VisualEffect>();     }     void Update()     {         VFX.playRate = timeScale;     } } NEAT AS HECK. WHY ISN'T THIS A NODE IN VFX GRAPH?