Progress so far: I've managed to apply shader effects to individual images using Shader, but I'm unsure how to implement this across the entire layer.
Detailed research process:
After studying the insightful posts by user "章鱼" on Zhihu and delving into forum threads on shader research, I came up with an approach: modifying the shader to edit it into a Transform, and then applying it to the Layer.
Links to Zhihu posts:
https://zhuanlan.zhihu.com/p/348922729
https://zhuanlan.zhihu.com/p/349467983
Here are some Shader station codes I've referenced:
https://www.shadertoy.com/view/WdjfDy
https://www.shadertoy.com/view/wllBDM
Below is the Renpy-compatible Shader code I've adapted based on these references:
Code: Select all
init python:
renpy.register_shader("shadertoy.test", variables="""
uniform float u_time;
uniform vec2 u_model_size;
uniform vec2 res0;
uniform sampler2D tex0;
uniform sampler2D tex1;
""",fragment_functions="""
vec2 curve(vec2 uv)
{
uv = (uv - 0.5) * 2.0;
uv *= 1.1;
uv.x *= 1.0 + pow((abs(uv.y) / 5.0), 2.0);
uv.y *= 1.0 + pow((abs(uv.x) / 4.0), 2.0);
uv = (uv / 2.0) + 0.5;
uv = uv *0.92 + 0.04;
return uv;
}
""",
vertex_300="""
//v_tex_coord = a_tex_coord;
""",
fragment_300="""
//Curve
vec2 uv = gl_FragCoord.xy / res0.xy;
uv = curve( uv );
vec3 col;
// Chromatic
col.r = texture2D(tex0,vec2(uv.x+0.003,(1-uv.y))).x;
col.g = texture2D(tex0,vec2(uv.x+0.000,(1-uv.y))).y;
col.b = texture2D(tex0,vec2(uv.x-0.003,(1-uv.y))).z;
col *= step(0.0, uv.x) * step(0.0, uv.y);
col *= 1.0 - step(1.0, uv.x) * 1.0 - step(1.0, uv.y);
col *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y);
col *= vec3(0.95,1.05,0.95);
//col *= 0.9+0.1*sin(10.0*u_time+uv.y*1000.0);
col *= 0.99+0.01*sin(500.0*u_time);
float comp = smoothstep( 0.2, 0.7, sin(u_time) );
gl_FragColor = vec4(col,1.0);
""")
init python:
renpy.register_shader("test44.softlight", variables="""
uniform sampler2D tex0;
uniform sampler2D tex1;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;
""", vertex_300="""
v_tex_coord = a_tex_coord;
""", fragment_300="""
vec4 base = texture2D(tex0, v_tex_coord);
vec4 blend = texture2D(tex1, v_tex_coord);
vec4 ctemp = base * blend;
gl_FragColor = mix(base, ctemp+(base*(1-((1-base)*(1-blend))-ctemp)), 0.5);
""")
Code: Select all
transform shadercrt:
shader "shadertoy.test"
scene overlay at shadercrt
1. It can only be applied to individual images and cannot be universally applied to layers or the entire game screen.
2. When applying this effect to images like character portraits with transparent backgrounds, the transparent background turns completely black and becomes unusable.
While going through the Ren'Py documentation, I found code for applying a transform to an entire layer:
https://doc.renpy.cn/zh-CN/displaying_i ... show-layer
But if I use either of those codes:
Code: Select all
camera master at shadercrt
show layer master at shadercrt
Code: Select all
File "renpy/common/000window.rpy", line 114, in _window_auto_callback
_window_show(auto=True)
File "renpy/common/000window.rpy", line 69, in _window_show
renpy.with_statement(trans)
Exception: Shader ('renpy.geometry', 'renpy.solid', 'shadertoy.test') has not been given uniform tex0.
The second approach I thought of involves utilizing Pygame to call shaders. Here, I found a Pygame project that uses shaders:
https://github.com/JingShing/ModernGL-S ... ith-pygame
While I'm not very familiar with Python and Pygame, after examining the code, I noticed that the visual effect defined in this Python code is called 'crt_shader.'
So, how can I apply this 'crt_shader' from Pygame to the entire Ren'Py game interface or a specific layer?
I'm unsure if there's a method to achieve my goal eventually. If it's not possible, I might just have to let go of this idea... (:3√ L)