|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 birctreel 于 2024-2-23 19:52 编辑
改了 能用 但不一定那么有用……的一些shader分享,大多是画面效果类
基本上都是看到shadertoy站上很有趣的shader,一时兴起改了改,最后发现我的项目用不上的代码。放在那里也很可惜不如分享出来,说不定大家能用得上
Shader license 参考这里:https://www.shadertoy.com/terms
使用时请注意哈!
1.水彩效果
源代码:https://www.shadertoy.com/view/slcSRM
效果参考shadertoy站,(因为个人需求原因)去掉了白边、减弱了提亮效果,纯粹的水彩特效,因为是动态的,比其他水彩效果看起来有趣
(最后因为发现本来美术风格就是水彩用不上这玩意儿啊!!!而作罢)
[RenPy] 纯文本查看 复制代码 renpy.register_shader("shader.watercolor",
variables="""
uniform float u_time;
uniform vec2 u_model_size;
uniform vec2 res0;
uniform sampler2D tex0;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;
uniform vec4 u_color
""",
fragment_functions="""
#define M_PI 3.14159265358979323846
vec2 hash( vec2 p ) // replace this by something better
{
p = vec2( dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(p)*43758.5453123);
}
float noise( in vec2 p )
{
const float K1 = 0.366025404; // (sqrt(3)-1)/2;
const float K2 = 0.211324865; // (3-sqrt(3))/6;
vec2 i = floor( p + (p.x+p.y)*K1 );
vec2 a = p - i + (i.x+i.y)*K2;
float m = step(a.y,a.x);
vec2 o = vec2(m,1.0-m);
vec2 b = a - o + K2;
vec2 c = a - 1.0 + 2.0*K2;
vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );
vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));
return dot( n, vec3(70.0) );
}
float simp(vec2 uv) {
uv *= 5.0;
mat2 m = mat2( 1.6, 1.2, -1.2, 1.6 );
float f = 0.5000*noise( uv ); uv = m*uv;
f += 0.2500*noise( uv ); uv = m*uv;
f += 0.1250*noise( uv ); uv = m*uv;
f += 0.0625*noise( uv ); uv = m*uv;
f = 0.2 + 0.8*f;
return f;
}
vec4 bumpFromDepth(vec2 uv, vec2 resolution, float scale) {
vec2 step = 1. / resolution;
float height = simp(uv);
vec2 dxy = height - vec2(
simp(uv + vec2(step.x, 0.)),
simp(uv + vec2(0., step.y))
);
return vec4(normalize(vec3(dxy * scale / step, 1.)), height);
}
float sdRoundedBox( in vec2 p, in vec2 b, in vec4 r )
{
r.xy = (p.x>0.0)?r.xy : r.zw;
r.x = (p.y>0.0)?r.x : r.y;
vec2 q = abs(p)-b+r.x;
return min(max(q.x,q.y),0.0) + length(max(q,0.0)) - r.x;
}
""",
vertex_100="""
v_tex_coord = a_tex_coord;
""",
fragment_300="""
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = v_tex_coord;
vec4 offset = bumpFromDepth(uv + vec2(floor(u_time*4.0)/4.0), res0.xy, .05)/80.0;
// Output to screen
//texture(iChannel0, uv + offset.xy)*0.4;
gl_FragColor = (texture2D(tex0, uv + offset.xy)*0.4) + (texture2D(tex0, uv)*0.6);
gl_FragColor += length(bumpFromDepth(uv, res0.xy, .1))*0.05;
""")
2.描边效果
源代码:https://www.shadertoy.com/view/DtBBWd
超好用的描边!!!!想要修改描边粗细,就修改【line_thickness】这个参数,原帖默认是10,我这里改成3,效果已经很不错了。
注意描边粗细数值不能太大,因为这个描边逻辑实际上是把你的原图在背景的四个方向多粘了几遍,导致如果描边数值过大,描的边会出现重影
*因为我没有修改描边粗细的需求所以没有把这个变量放出来,如果你需要随时调整线宽,就在开头声明一个新变量赋到line_thickness上就行
我这里改了shader代码,便于使用shader的时候可以随时调整描边颜色,即你修改u_color这个参数后面跟的那个四位向量数值就行
不过注意glsl的颜色写法和renpy不同,这个四位向量数值为(RR/255,GG/255,BB/255,透明度),你需要把16进制颜色转换成RRGGBB之后再除255,变成小数才行。
比如我这个描边的颜色实际是16进制颜色#C69949
(这个用上了,非常好用,你甚至可以用它改描边颜色做按钮悬浮动效)
[RenPy] 纯文本查看 复制代码 renpy.register_shader("shader.outline",
variables="""
uniform float u_time;
uniform vec2 u_model_size;
uniform vec2 res0;
uniform sampler2D tex0;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;
uniform vec4 u_color
""",
fragment_functions="""
""",
vertex_100="""
v_tex_coord = a_tex_coord;
""",
fragment_300="""
vec2 uv = v_tex_coord;
vec2 texture_PIXEL_SIZE = vec2(0.0005, 0.0005);
float line_thickness = 3;
vec2 size = texture_PIXEL_SIZE * line_thickness;
float outline = texture2D(tex0, uv + vec2(-size.x, 0)).a;
outline += texture2D(tex0, uv + vec2(0, size.y)).a;
outline += texture2D(tex0, uv + vec2(size.x, 0)).a;
outline += texture2D(tex0, uv + vec2(0, -size.y)).a;
outline += texture2D(tex0, uv + vec2(-size.x, size.y)).a;
outline += texture2D(tex0, uv + vec2(size.x, size.y)).a;
outline += texture2D(tex0, uv + vec2(-size.x, -size.y)).a;
outline += texture2D(tex0, uv + vec2(size.x, -size.y)).a;
outline = min(outline, 1.0);
vec4 color = texture2D(tex0, uv);
vec4 COLOR = mix(color, u_color, outline - color.a);
gl_FragColor = COLOR;
""")
#用的时候就写XXX at outline就行
transform outline():
mesh True#这里表示描边仅用在外轮廓上,防止你层叠图它每一层都给你描一次边
shader 'shader.outline'
u_color (0.831,0.792,0.808,1)#这里修改描边颜色
3.又快又好的高斯模糊
试了一下之后发现果然又快又好
源码:https://www.shadertoy.com/view/Xltfzj
顺便定义了transform gsblur,使用的时候 就 at gsblur(rad值)就行,rad是你的模糊半径,建议不要大于10,不然虽然很快但是不那么好了……(汗)
[RenPy] 纯文本查看 复制代码 renpy.register_shader("shader.gsblur",
variables="""
uniform float u_radius;
uniform vec2 u_model_size;
uniform vec2 res0;
uniform sampler2D tex0;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;
""",
fragment_functions="""
""",
vertex_100="""
v_tex_coord = a_tex_coord;
""",
fragment_300="""
float Pi = 6.28318530718; // Pi*2
// GAUSSIAN BLUR SETTINGS {{{
float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
float Quality = 6.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
float Size = u_radius; // BLUR SIZE (Radius)
// GAUSSIAN BLUR SETTINGS }}}
vec2 Radius = Size/res0.xy;
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = v_tex_coord;
// Pixel colour
vec4 Color = texture2D(tex0, uv);
// Blur calculations
for( float d=0.0; d<Pi; d+=Pi/Directions)
{
for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality)
{
Color += texture2D(tex0, uv+vec2(cos(d),sin(d))*Radius*i);
}
}
// Output to screen
Color /= Quality * Directions - 15.0;
gl_FragColor = Color;
""")
先发几个库存的
之后如果还做了其他shader就更新在这个帖子下面
|
|