Extending Ren'Py visuals with custom OpenGL shaders

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
sawer
Newbie
Posts: 5
Joined: Sat Feb 07, 2015 2:00 pm
Contact:

Extending Ren'Py visuals with custom OpenGL shaders

#1 Post by sawer »

I hope this is the right forum section for this.

While slowly working on own visual novel, I have been doing some experiments to add more control to the Ren'Py visuals by using OpenGL vertex- and pixel-shaders. Ren'Py already uses OpenGL and shaders in many cases if they are available, but it has been abstracted away from normal users (maybe to increase portability, which is not a bad goal at all).

If you are not familiar with any of that jargon, in practice shaders make possible for us to perform complex, customizable, real-time image manipulation within Ren'Py. This includes many effects from simple color adjustment to heavy image distortion. An image is better than a thousand words, so here is a video demonstrating some of the possible effects:

https://www.youtube.com/watch?v=nyDbvAy0Xa4

That video contains some basic things you can do with it. Waving hair, eye/mouth distortion to change expressions and that kind of stuff. It even supports 3D-rendering.

The project is still VERY experimental, so don't use it in any production work. If you want to try it out here is the source code for it: https://github.com/bitsawer/renpy-shader It would be great to know what kind of systems does it even run on. I have tested it on a few relatively new computers (Windows and Mac), so feedback about that would be nice. It should work on Linux, too, but I haven't tested it yet. Android and iOS could be supported in the future, but that is not a priority right now. If it crashes or doesn't work, it would be nice to get the error stack trace (it's usually in the log.txt file) so I can improve the library.

I was surprised how little I had to abuse Ren'Py, but there are some hacks in my code that probably require some minor changes to the Ren'Py itself. At the moment those modifications are done at runtime by reaching into Ren'Pys undocumented internals, which works but is not very safe or futureproof. Still, using custom Displayables together with screens turned out to be a pretty flexible solution. There is also some room for optimizations, so if things run slowly there is no need to despair yet.

Any comments and feedback is welcome. What kind of visual effects have you always wanted to do to your images in your visual novels?

User avatar
bunnyvoid
Regular
Posts: 59
Joined: Tue Sep 22, 2015 2:37 am
Projects: Lots of BG Commissions
Tumblr: bunnyvoid
Deviantart: bunnyvoid
Skype: https://www.twitch.tv/bunnyvoid
Soundcloud: bunny-void
Contact:

Re: Extending Ren'Py visuals with custom OpenGL shaders

#2 Post by bunnyvoid »

this looks like a really good project. i just so this now. I hope you still continue to experiment on this one.
i'm interested in using this for backgrounds. i happen to be a 3d artist so i'm interested if it can manage light and shadows to emulate time lapse.

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: Extending Ren'Py visuals with custom OpenGL shaders

#3 Post by indoneko »

In the requirement, you mentioned "Graphics card with a decent OpenGL support".
Which Radeon/Geforce card is the lowest limit that you consider "decent" for this?
Can we run it on older systems with onboard graphic too?
My avatar is courtesy of Mellanthe

User avatar
jack_norton
Lemma-Class Veteran
Posts: 4084
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

Re: Extending Ren'Py visuals with custom OpenGL shaders

#4 Post by jack_norton »

Very interesting stuff :)
follow me on Image Image Image
computer games

User avatar
Donmai
Eileen-Class Veteran
Posts: 1958
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Extending Ren'Py visuals with custom OpenGL shaders

#5 Post by Donmai »

Awesome! I tried the demo on my six years old machine, and everything worked wonderfully.
I'm sending you a PM with more details.
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
Morhighan
Miko-Class Veteran
Posts: 975
Joined: Sun Jun 27, 2010 12:54 pm
Completed: AIdol, When Our Journey Ends, Forgotten Not Lost
Organization: MysteryCorgi
Tumblr: MysteryCorgi
Deviantart: MysteryCorgi
Soundcloud: MysteryCorgi
itch: MysteryCorgi
Location: USA
Contact:

Re: Extending Ren'Py visuals with custom OpenGL shaders

#6 Post by Morhighan »

Hey there! I tried it, it worked really well on my setup, so I thought I'd give you the specs. I'll hopefully have more feedback soon!

Image

trentdb
Newbie
Posts: 1
Joined: Wed Jun 06, 2018 1:38 am
Skype: smgonline
Contact:

Re: Extending Ren'Py visuals with custom OpenGL shaders

#7 Post by trentdb »

I wish I could make this script work but I get the duplicate script.ry and script.ryc error

then I remove the duplicate files from the Renpy Shader folder and keep the ones in Shader Demo folder intact and get a whole host of other errors

I hope you're still alive or someone is to guide me a little as this looks awesome

User avatar
Tayruu
Regular
Posts: 141
Joined: Sat Jul 05, 2014 7:57 pm

Re: Extending Ren'Py visuals with custom OpenGL shaders

#8 Post by Tayruu »

With some work, I managed to get this at least running for me in my project.
I copied the shader and OpenGL folders into my project, as well as the director.rpy, though I then I reduced a lot of code in that file down to the only part I needed: blurring.

Code: Select all

init python:
    import shader
    def show_blurred(image, update=None, layer="master"):
        displayable = ShaderDisplayable(shader.MODE_2D, image, shader.VS_2D, shader.PS_BLUR_2D, None, {}, None, update)
        return renpy.show(image, what=displayable, layer=layer)
    def BlurSize(context):
        context.uniforms["blurSize"] = 2.0
Using the following line serves the same as a show command:

Code: Select all

$ show_blurred("bg t wilderness2", update=BlurSize)
... but it's still not working how I'd like, unfortunately. After blurred images have displayed, ATL transforms in my choice screen no longer occur until the game is closed and restarted, and the shader in general only accepts "images", not "general displayables". This rules out my portrait engine or other character art created with Composite.
(For the record, these issues still occur without my heavy edits above.)

I'm not completely sure if OP is still around, but I thought I'd at least share my above code for those that want to use shader-based blur without the demo's roundabout method of putting shader content inside a screen.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Extending Ren'Py visuals with custom OpenGL shaders

#9 Post by Remix »

You might note that there is consideration to expose some limited access to OpenGL shaders within some future version of Ren'Py. The full details haven't been disclosed though and (with all the other stuff on his plate) it might not be too high on RenpyTom's ToDo list.
Don't expect too much, just keep your fingers crossed ;)

That old shoe-horn-in addition might not be playing as nicely in recent Ren'Py as it did in the versions around when it was released. It might have something to do with modern Ren'Py using SDL2 rather than just SDL. Pure speculation though.
Frameworks & Scriptlets:

abysswatcher
Regular
Posts: 42
Joined: Sun Apr 12, 2020 11:50 pm
Projects: To-Live:The Struggle
Organization: Youyu de Shijie(憂鬱的世界)
Github: LuYifeng112
itch: https://luyifeng.itc
Location: New Zealand
Contact:

Re: Extending Ren'Py visuals with custom OpenGL shaders

#10 Post by abysswatcher »

Sorry for necro,
I was wondering if there was a way to define these as image. For example defining a wind effect image in an image block so you can add it to scenes and screens alike. What would that kind of supporting code look like or be implemented?
The goal of the revolution is to achieve the people's rights, but during the course of the revolution, we must stress military power - and the two are mutually contradictory.
-Sun Yat-sen
"Become a Visual Novel writer they said, it will be fun" (little did they know they were right)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], GetOutOfMyLab