VRChat
Ryason55 May 13, 2018 @ 8:34pm
Animating a Shader based off of Speed
I'm trying to make a Doom-style billboard Shader that self-animates when the Avatar is moving. The code I set up is supposed to have it flip through sprites based off of the speed (handled as a comparison between positions), returning to a neutral frame when the Avatar comes to a stop... but instead the frame selected is chosen based on how far the Avatar is from the center of the world, seemingly ignoring the comparison against its position from the last frame. Here's the relevant bit from the Shader:
float frameCount = (_AnimEndFrame-_AnimStartFrame)+1; float newTime = _Time.y; float timeDiff = (newTime-_PrevTime); if (_MaxRunSpeed>0) { float4 currPos = float4(unity_ObjectToWorld._m03,unity_ObjectToWorld._m13,unity_ObjectToWorld._m23,1); float4 currVel = (currPos - _PrevPos) / timeDiff; float moveSpeed = min(length(currVel), _MaxRunSpeed); if (moveSpeed > 0.1) _AnimTime = _AnimTime + ((timeDiff*_AnimSpeed)*(moveSpeed/_MaxRunSpeed)); else _AnimTime = 0; _PrevPos = currPos; } else _AnimTime = _AnimTime + (timeDiff*_AnimSpeed); float animFrame = (_AnimStartFrame-3)+(frameCount-floor(_AnimTime) % frameCount); _PrevTime = newTime;
Is there anything glaringly obvious that I'm doing wrong here? I'm not really all that familiar with how Unity's scripting handles things.
< >
Showing 1-4 of 4 comments
Ryason55 May 14, 2018 @ 12:33pm 
Well, got an answer elsewhere. Basically variables on shaders don't persist at all between frames, so what I was trying to do with the shader was impossible. Back to the drawing board, I guess.
Rokk May 15, 2018 @ 6:10am 
I'm pretty sure you don't want to do it this way. Just override your avatar's walking animation instead. You can make a custom walk cycle where you switch materials or game objects.
Last edited by Rokk; May 15, 2018 @ 6:11am
Ryason55 May 15, 2018 @ 6:46am 
Yeah, animating the shader with the Animator was one of the first things I tried, but it didn't seem like it was working ingame because mirrors and cameras don't reflect the changes to the shader for some reason. Ended up having to stick the mesh 2 feet in front of the first-person view point to see that it actually was working.
Rokk May 15, 2018 @ 7:24am 
Originally posted by Ryason55:
Yeah, animating the shader with the Animator was one of the first things I tried, but it didn't seem like it was working ingame because mirrors and cameras don't reflect the changes to the shader for some reason. Ended up having to stick the mesh 2 feet in front of the first-person view point to see that it actually was working.

I think they fixed mirrors, they now correctly show what you're doing. You might want to revisit this project if you haven't already.
Last edited by Rokk; May 15, 2018 @ 7:24am
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: May 13, 2018 @ 8:34pm
Posts: 4