You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于背景法线图扭曲阴影的Godot Shader实现问询

基于背景法线图实现阴影扭曲的Shader需求

我正尝试在Shader中基于背景法线图扭曲「阴影」,当前可访问该法线图。可见角色在法线圆形背景前跳跃(因引擎光照导致显示异常,但底层可获取纯净法线图)。

尽管我使用过法线图,但从未以此实现此类效果,目前毫无头绪,甚至不知该需求的正确术语。我使用类OGL着色语言(具体为Godot Shader Language),伪代码即可为我指明方向,十分感谢。

已尝试的方案及问题

  • 错误尝试:将法线图与光照方向的点积代入相关位置,但并未奏效
  • 初始方案:使用高度图,但仅能实现单方向扭曲,且渲染效果随物体不同出现异常

当前Shader代码(运行于Godot的Light处理器)

vec4 heightTex = texture(bg_height, UV) + depthBrightness;
float depth = heightTex.x;
// (1.0 - depth): b/c LightDirection is in opposite direction, we need to 
// "flip" the depth.
// The mix call is to reinterpret the resulting depth to a smaller range
// [0,1] is too large and results in huge shadows even at depths of .7
vec4 normalTex = texture(bg_normal, UV);
vec2 sample = UV + (LIGHT_DIRECTION.xy * (mix(0.0, depthRemap, (1.0 - depth)) + depthMod));
vec4 grab = texture(TEXTURE, sample);
vec4 d4 = abs(grab - vec4(.5));
float d = max(max(d4.r, d4.g), d4.b);
if(d >= 0.1) {
    LIGHT = LIGHT_COLOR;
}
else {
    LIGHT = vec4(0.0);
}

额外信息

  • 当前未使用法线图,但可通过normalTex = texture(normalMap, UV)获取并随意修改法线与UV
  • 相关纹理由视口合成:将前景与背景元素分别渲染至对应视口,以此获取合成的高度图与法线图

内容的提问来源于stack exchange,提问作者Tyo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 01:50:28