I would like to try to make some form of simple texture animation for a shader, e.g. sliding UVs or something. But so far I haven’t been able to find anything that can get me started. Can anyone help me out here or point me to a tutorial on the subject? I would like to make a river water shader, with a sliding texture simulating the ripples due to current and the flow of the water - you know, like in computer games :):
I’m mainly writing my shaders for the 3ds max viewport and I would like to write a shader with an animation “connected” to the 3ds max timeline, so that I can preview the animation in max.
By the way, is there some online database over HLSL commands, like php.net for PHP scripting you can search for every function and read about it what it does and how it works?
[QUOTE=Nanne;3078]
By the way, is there some online database over HLSL commands, like php.net for PHP scripting you can search for every function and read about it what it does and how it works?[/QUOTE]
You might find some of what you are looking for here, basic commands and syntax and such:
As for the shader, you could use the TIME semantic and then offset you uv coordinates with that. There is an example of the shader you want to do in the ShaderFX examples.
Your best bet is to download shaderFX (www.lumonix.net), build a simple test shader, export to .fx, and look at what they do. It is an extremely effective way to learn.
I also endorse the use of ShaderFX for learning (although my opinion might be biased. )
The most important part of Lithium’s posted code is:
float Time : Time < string UIWidget=“None”; >;
With that line in the header of your shader, you’re bringing in the current time from Max’s time slider. Then you’d just add that value to your U coord or V coord with perhaps a speed multiplier.
Wow! Thanks Lithium, that’s amazing of you. I’ll dig into that code tomorrow - thank you!
By the way, what is “Atlas Walk”? I never heard that term before.
ShaderFX looks very cool and I think it is very noble of you to offer it for free for individuals whom are learning :): But I really like the extra “geekiness” you get from actually writing the shader from scratch - I’m a nerd and damn proud of it :D: Plus it really impresses my teacher that I know a little programming
We’re not suggesting that you use ShaderFX to write the shaders - just that you use it for code reference. So in this case, you’d make a shader that animates the UV coords in ShaderFX and then spit out the code and look at it. It’s a way to learn. Then you can apply the same ideas to your own code.
Atlasing is combining several textures into a grid - so multiple textures become one big texture.
Yes, that sound like a good idea. But I don’t feel comfortable with the syntax and semantics of HLSL yet, so I going to stick with newbie tutorial for a little while. Then I give ShaderFX a go. We have it in school and my teacher knows the basics of it.
An “atlas walk” is the act of traversing through an atlas. An atlas, as ben said, is a collection of images. In this particular example, the atlas is a sequence, like an animated gif. You can use it to do something like animate an explosion, or flash the words “hot damn an atlas” to the screen one after another.
If you’d like the animation to play corresponding to the timeline, you can also animate DirectX shader parameters through the material editor interface, as with any other material. Just add a UV offset to your water, expose it as a parameter in the shader, and key it.
As an aside, you can also add new controllers to any shader parameter. Wire controllers can be especially useful for doing things like blending wrinkle normal maps in a character’s shader based on bone orientations, or creating look-at targets for projected/parameterized UVs. If you didn’t want to key anything, so that if you extend your timeline the water will just keep flowing, you could use an expression controller that references time.
Of course, any of that stuff will be max-only (and specific to your one material instance), so if you try to take the shader to another app, you’ll have to find a different way of driving the animation. But if you’re primarily prototyping in Max to prove out ideas, animating your parameters can save you a lot of time.
The basics of scrolling the UVs is that you want to add a value to the texture coordiantes.
UV.x + 0.5
would shift all your uvs in the x direction by 0.5
But it would be static, not moving
So if you send a value that changes every frame instead of 0.5
you will get moving UVs that change every frame.
This time can be a value as Bronwen says, that you can animate in Max
UV.y + time
UV.xy+time would scroll the UVs diagonal
if you want to adjust the speed you need to multiply time by speed
(time * speed)
Just mess around with shaders that work,changing code, thats the best way to learn