- Home /
How can I pan a texture to specific location on a sheet?
I have a sheet of water normals. Is there a way to jump to specific sections of the sheet over time, ie frame 1 is the first 256x256 pixels of the texture and the next frame is the next set of 256 pixels etc..? I'm currently using the Shader Graph. I can get the texture to pan quite easily, but its a smooth pan and I specifically want to jump frame to frame so as to make it a smooth animation.
Answer by BastianUrbach · Apr 15, 2018 at 07:09 AM
Unfortunately I haven't used Shader Graph yet but in HLSL and CG there are many ways to do that and I would guess that at least one of them is also possible in Shader Graph. All of them are based on the same idea: have a float value that increases over time but then make it 'jump' through integers instead of increasing it gradually. That value can then be used in some formula to determine the texture offset.
trunc, ceil, floor, round: Functions that find a integer for a float according to different rules.
float f1 = trunc(_Time.y); // cut off the decimals float f2 = ceil(_Time.y); // next integer above float f3 = floor(_Time.y); // next integer below float f4 = round(_Time.y); // closest integerint cast: Converts a float to an int, following the same rules as trunc except that the data type changes here, while trunc still returns a float.
int i = (int)_Time.y;remainder: Gives the remainder of integer division, use it with 1 as second operand and subtract it from the original value to get an integer
float f = _Time.y - _Time.y % 1;
Your answer
Follow this Question
Related Questions
Tracing in Unity3D 2 Answers
How can I prevent lights overlapping in intensity? 1 Answer
There is an issue with texture wrapping around sphere's in unity 0 Answers
How to lighten/darken a greyscale shader 0 Answers
Shader: get back scene pixel color? 1 Answer