找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 108|回复: 0

[其它] 伪3D旋转 Shader分享

[复制链接]
发表于 2025-3-19 21:01:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
此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
    "..."

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|RenPy中文空间 ( 苏ICP备17067825号|苏公网安备 32092302000068号 )

GMT+8, 2025-3-29 22:26 , Processed in 0.044975 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表