Wave Shader

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
XT9K
Newbie
Posts: 14
Joined: Sun Nov 01, 2020 10:50 pm
Contact:

Wave Shader

#1 Post by XT9K »

Hiya again. I'm back with an update to my wave rendering code I put out last year. Ever since I put that out, I've been a bit bothered by how easy it is for it to lag out systems. The fact it ran on the CPU and not the GPU was always a known problem, but I didn't yet understand how to use Renpy shaders at the time. The biggest issue being I couldn't make them look smooth at all and always seemed to lag for some unknown reason. u_time just never seemed to update at an acceptable rate.

Thankfully, a couple of months ago, a friend let me know that you can inject time using ATL, which was updated at the screen's framerate. That got me motivated enough to get this working in a shader! This project includes options to customize each wave to your own parameters and can add melt, doubling and dampening effects as well. The demo project even features a simulator where you can adjust these parameters interactively and see the results.

I haven't grandfathered in all effects featured in that project. Namely the rotating wave and palette cycling I have decided to leave behind. Though those were pretty niche to begin with.
All that said, here are the links to where you can find it: And now for the juicy screenshots:
itch-thumbnail.gif
bg1.gif
bg2.gif
demo_compressed.gif
Installation Instructions:
As usual for my projects, you simply need to take the wave_shader.rpy and put it in the game folder (or subfolder of it) of your project to have the code needed to run it. I've also included a wavey_tag.rpy as well if you would want to apply it as a text tag. Examples for how to use it can be found in the demo project's script.

Note: You will need kinetic_text_tags.rpy in order for wavey_tag.rpy to work.

How it Works:
The main way I have it setup to make it easy to add the shader is by using the function statement in ATL to have a function that sets up the transform and applies all the parameters for you. This is done by using my WaveShader class, which has a __call__ function, so that when ATL tries to use it as a function, it can handle the transform. That said, the shader can be applied by yourself manually, but you'll have to instantiate the uniform parameters for the shader yourself. From there, it updates u_shader_time itself using the animation_time parameter that ATL provides to the function, which allows it up update smoothly. The advance_time function is something I plan on using if I develop further shaders so that all of them can piggyback off of it and all use it for their time updates.

Important Notes:
Because this function has to keep updating the shader time, it will never pass control onto ATL code below it. So if you want to apply the WaveShader and do some other ATL, I recommend you split it up into parallel blocks. Such as:

Code: Select all

show my_image:
    parallel:
        # Your ATL
    parallel:
        function WaveShader()
This should avoid most issues you might be having, unless you're using another shader on the displayable, in which case you may want to override this behavior. Though, if you're using other shaders, I assume you probably already know what you're doing. If I ever make more though, I'll be sure to include how to make them work together, if it would make sense to do so.

Credits
Conclusion
That's all I have for this project. If you missed the links: here they are again. I'm really glad to be able to finally amend the wave rendering stuff I put out last year. I hope this proves more useful to more projects with it's improvements to speed and versatility. And I'm really happy that I have finally been able to make a renpy shader I'm happy with and hope I can make some more in the future. Maybe even a big pack of 'em for people to play with. Would be a lot of fun. Also should say I'll be putting out an update to Kinetic Text Tags soon as I made a couple tweaks to ATL and the DispTextStyle stuff while working on this project. So maybe keep an eye out for those.
Furthermore, if you'd like to learn more about shaders beyond Ren'py's documentation, I highly recommend checking out The Book of Shaders and Shadertoy to start learning the craft. They are invaluable tools and helped a lot in the development of this project.

Post Reply

Who is online

Users browsing this forum: No registered users