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

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

内置片元属性(Fragment built-ins)

一些节点(例如:Sprite),会显示一个默认的纹理。然而当给这些节点添加了自定义片元函数以后,纹理的查找则需要手动来完成。在内置属性COLOR中,Godot并没有提供纹理的颜色。如果想在这些节点中读取纹理颜色,需要如下方法:

COLOR = texture(TEXTURE, UV);

这和法线贴图有所不同,如果一个节点添加了法线贴图,则Godot可以默认使用它并且把它赋值给内置的NORMAL属性。如果你使用了一个本用于3D的法线贴图,它将呈现为翻转状态。如果你想在自己的Shader中使用它你需要把它赋值给NORMALMAP属性,Godot会把它转换成2D模式并重写NORMAL属性

NORMALMAP = texture(NORMAL_TEXTURE, UV).rgb;
内置片元属性 描述
in vec4 FRAGCOORD Fragment coordinate, pixel adjusted.
inout vec3 NORMAL Normal read from NORMAL_TEXTURE. Writable.
out vec3 NORMALMAP Configures normal maps meant for 3D for use in 2D. If used, overwrites NORMAL.
inout float NORMALMAP_DEPTH Normalmap depth for scaling.
in vec2 UV UV from vertex function.
inout vec4 COLOR Color from vertex function and output fragment color. If unused, will be set to TEXTURE color.
in sampler2D TEXTURE Default 2D texture.
in sampler2D NORMAL_TEXTURE Default 2D normal texture.
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 UV for use with SCREEN_TEXTURE.
in vec2 SCREEN_PIXEL_SIZE Size of individual pixels. Equal to inverse of resolution.
in vec2 POINT_COORD Coordinate for drawing points.
in float TIME Global time in seconds.
in bool AT_LIGHT_PASS True if this is a light pass.
in sampler2D SCREEN_TEXTURE Screen texture, mipmaps contain gaussian blurred versions.

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