马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
此Shader为Godot社区的Shader,我移植了一下,希望大家喜欢
此Shader不需要在3D舞台下也可以使用。并且摄像头永远正对物体。
(按钮的判定无法正确被获取,尽量不要用它做UI)
以下是代码以及使用例
[RenPy] 纯文本查看 复制代码 init python:
renpy.register_shader("fake_3d_rotate", variables="""
uniform sampler2D tex0;
uniform vec2 u_model_size;
uniform float u_yrot;
uniform float u_xrot;
attribute vec4 a_position;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;
varying vec2 t_uv
""", vertex_300="""
t_uv = a_tex_coord;
gl_Position.xy += (t_uv-0.5) * -1.;
""", fragment_300="""
float sin_b = sin(u_yrot / 180.0 * 3.1415926);
float cos_b = cos(u_yrot / 180.0 * 3.1415926);
float sin_c = sin(u_xrot / 180.0 * 3.1415926);
float cos_c = cos(u_xrot / 180.0 * 3.1415926);
mat4 inv_rot_mat = mat4(
cos_b, 0., -sin_b, 0.,
sin_b * sin_c, cos_c, cos_b * sin_c, 0.,
sin_b * cos_c, -sin_c, cos_b * cos_c, 0.,
0., 0., 0., 1.
);
vec4 camera_position = inv_rot_mat * vec4((t_uv - 0.5), 0.5, 1.);
camera_position.xy *= inv_rot_mat[2].z;
vec2 offset = inv_rot_mat[2].xy;
if (camera_position.z <= 0.0) discard;
vec2 uv = (camera_position.xy / camera_position.z).xy - offset;
vec4 COLOR = texture2D(tex0, uv + 0.5);
//COLOR.a *= step(max(abs(uv.x), abs(uv.y)), 0.5);
if (abs(uv.x)>0.5||abs(uv.y)>0.5){
discard;
}
gl_FragColor = COLOR;
""")
transform fake_3d:
shader "fake_3d_rotate"
xalign 0.5
yalign 0.5
u_xrot -50
u_yrot -30
pass
image i = "liutao.png"
label start:
show i at fake_3d
"..."
|