Godot Shader笔记:2D着色器(三)

原文地址:Docs » Shading » Shading reference » CanvasItem shaders

内置光属性(Light built-ins)

相对于3D着色器,2D着色器光函数的工作方式有所不同。在2D着色器中,光函数会在物体被绘制的时候调用一次,然后对场景中每一个触及到这个物体的光都调用一次。如果你不希望任何光影响到某一个物体可以使用unshaded渲染模式。如果你只希望一个物体被光覆盖的地方可见,那么可以使用light_only渲染模式。

当一个着色器(所属的物体)处于光照中时,内置光属性AT_LIGHT_PASS的值将为true

内置光属性 描述
in vec4 FRAGCOORD Fragment coordinate of pixel center. Origin at lower left.
in vec3 NORMAL Input Normal. Although this value is passed in, normal calculation still happens outside of this function.
in vec2 UV UV from vertex function, equivalent to the UV in the fragment function.
in vec4 COLOR Input Color. This is the output of the fragment function with final modulation applied.
sampler2D TEXTURE Current texture in use for CanvasItem.
in vec2 TEXTURE_PIXEL_SIZE Normalized pixel size of default 2D texture. For a Sprite with a texture of size 64x32px, TEXTURE_PIXEL_SIZE = vec2(1/64, 1/32)
in vec2 SCREEN_UV SCREEN_TEXTURE Coordinate (for using with screen texture).
in vec2 POINT_COORD UV for Point Sprite.
in float TIME Global time in seconds.
inout vec2 LIGHT_VEC Vector from light to fragment, can be modified to alter shadow computation.
inout float LIGHT_HEIGHT Height of Light. Only effective when normals are used.
inout vec4 LIGHT_COLOR Color of Light.
in vec2 LIGHT_UV UV for Light texture.
out vec4 SHADOW_COLOR Shadow Color of Light.
inout vec4 LIGHT Value from the Light texture and output color. Can be modified. If not used, the light function is ignored.

你可能感兴趣的:(Godot Shader笔记:2D着色器(三))