Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Gradients for Ren'Py

Gradient shaders for unique effects in Ren'Py. · By Feniks

Need Support? Post here! Sticky

A topic by Feniks created Feb 12, 2024 Views: 72 Replies: 7
Viewing posts 1 to 3
Developer

If you're having trouble or run into any bugs with the code, post a comment here! I will try to get back to you within a few days.

(+1)

Hi Shawna!!!

Thank you sm for all the resources you're always giving the community; your generosity and talent are so appreciated!!!! I'm trying to use your gradient shader as an alpha mask right now for an image to turn transparent. I'm running into some issues because the image itself is displayed based on a variable, so I've defined it as "image_[variable].png" for example. When I try to add the gradient as a mask to it, I get the error: "In DynamicImage 'image_[variable].png': Could not find substitution 'variable'. It was working perfectly find when I used a normal image but now that I've included a variable, it seems to be running into some issues q.q Do you happen to have any advice or is it just not compatible with this kind of code (or am I just doing something wrong LOL :pained smile:). Thank you sm!!! <3

Developer(+1)

Thanks for your kind words!

Can you share the code you're using to declare the AlphaMask? I ran a quick test with the following code:

image radial_mask = GradientDisplayable(["#fff", "#0000"], xysize=(800, 800), kind='radial')
image feniks_masked = AlphaMask("feniks", "radial_mask")
default who = "feniks"
image test_masked = AlphaMask("[who]", "radial_mask")

which I was able to get working in 8.1, so with luck it'll just be a declaration issue :)

Yes! I should've mentioned it's on a screen, so I'm not sure if that changes things, but here's the current code:

define replaydate = ["aisaflower", "drukcafe", 
"drukflower", "drukmarket", "etzacafe", "etzaflower", 
"etzamarket","etzariver", "fenircafe", "fenirflower",
"fenirmarket", "fenirriver", "kayncafe", "kaynflower", 
"kaynmarket", "kaynriver", "kunaflower"]
default replayCurrent = 0
screen scenegallery():
    tag menu
    add "menu/extramemories.jpg"
    $ currentreplayDate = replaydate[replayCurrent]
    add AlphaMask("menu/memories_[currentreplayDate].png", GradientDisplayable(
        ["#FFF", "#0000"], kind="linear",
        thresholds=[0.1, 1.0], center=(0.25,0.5), angle=0)):
        xalign 0.85 yalign 0.5 zoom 0.5
        at bw

Basically, I want the image to update as it goes through the list of dates, so $ currentreplayDate helps me get the location on the list and show an image based on the date in focus. When I take out the variable and just put the image name, it works perfectly, but as soon as I want it to update based on the list variable, it doesn't work q.q 

Developer

Ah it's because the variable you're substituting doesn't exist all the time! You can use `format` or fstrings to fix this, for example:

add AlphaMask("menu/memories_{}.png".format(replaydate[replayCurrent]),

The problem is that your `$ currentreplayDate = replaydate[replayCurrent]` line only runs when the screen is up, so most of the time that variable doesn't exist and Ren'Py doesn't know what to search for in the dynamic image. Using fstrings or format substitutes the variable right in the path instead, so it isn't trying to search for an incomplete image path.

(+1)

AHHHHH yes that worked!!!! I had no idea the format/fstrings were a thing. Thank you so much!!!! YOURE A LIFESAVER <3 

Hey, first of all, I wanted to say I absolutely LOVE this tool! It was a huge help for Artificial Fashionista (along with your amazing outline shader)!

I wanted to test if I could get a web build to work, and ran into the following error in the main menu:

This happens as soon as I hover over buttons that make use of gradients. Regular textbuttons work fine in the web build, so maybe this is something worth looking into?

Later on, it also throws the following error which could be related to the outline shader, but I'm really not sure:


This is absolutely non-urgent on my end, and I know Ren'Py Web is currently still in Beta — just thought it might be helpful to report this. 

Thanks again for your awesome work!

Developer

Thank you for the report! I can't say for sure what the issue is, though my understanding is that the web builds use a different version of Python and potentially a slightly different renderer. I did quite a lot of fiddling to get the shaders to work with both ANGLE2 and GL2, and it wouldn't really surprise me that if a slightly different renderer is used for web that it has its own idiosyncrasies. I will put it down on my list when I have a chance to look at it!