在 Cesium 中,CustomShader 是一个非常强大的接口,用来自定义图形渲染过程中的 GLSL 着色逻辑,让开发者可以对 3D Tiles、模型(Model)或 Primitive 等对象实现更灵活、复杂的视觉效果。
CustomShader 让你可以在 Cesium 的标准渲染管线中插入自己的 GLSL 代码,从而控制模型的 顶点变换 和 片元着色 过程。
也就是说,你可以让模型发光、流动、闪烁、根据高度变色、按时间变化、根据法线方向渐变等。
基本原理
在 Cesium 中,每个 3D 模型或 Tileset 都会使用一个默认的渲染着色器(Shader Program)。
而 CustomShader 的作用就是允许你在保留 Cesium 默认功能的前提下,往其中注入自定义的 GLSL 代码。
它主要能影响两个阶段:
- Vertex Shader 阶段(顶点处理)
- Fragment Shader 阶段(像素着色)
在这些阶段里面可以获取到一些重要的数据
| Corresponding Attribute in Model | variable in shader | Type | Available in Vertex Shader? | Available in Fragment Shader? | Description |
| -------------------------------- | ------------------ | ------- | --------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `POSITION` | `positionMC` | `vec3` | Yes | Yes | Position in model coordinates |
| `POSITION` | `positionWC` | `vec3` | No | Yes | Position in world coordinates (WGS84 ECEF `(x, y, z)`). Low precision. |
| `POSITION` | `positionEC` | `vec3` | No | Yes | Position in eye coordinates. |
| `NORMAL` | `normalMC` | `vec3` | Yes | No | Unit-length normal vector in model coordinates. Only available in the vertex shader |
| `NORMAL` | `normalEC` | `vec3` | No | Yes | Unit-length normal vector in eye coordinates. Only available in the fragment shader |
| `TANGENT` | `tangentMC` | `vec3` | Yes | No | Unit-length tangent vector in model coordinates. This is always a `vec3`. For models that provide a `w` component, that is removed after computing the bitangent vector. |
| `TANGENT` | `tangentEC` | `vec3` | No | Yes | Unit-length tangent vector in eye coordinates. This is always a `vec3`. For models that provide a `w` component, that is removed after computing the bitangent vector. |
| `NORMAL` & `TANGENT` | `bitangentMC` | `vec3` | Yes | No | Unit-length bitangent vector in model coordinates. Only available when both normal and tangent vectors are available. |
| `NORMAL` & `TANGENT` | `bitangentEC` | `vec3` | No | Yes | Unit-length bitangent vector in eye coordinates. Only available when both normal and tangent vectors are available. |
| `TEXCOORD_N` | `texCoord_N` | `vec2` | Yes | Yes | `N`-th set of texture coordinates. |
| `COLOR_N` | `color_N` | `vec4` | Yes | Yes | `N`-th set of vertex colors. This is always a `vec4`; if the model does not specify an alpha value, it is assumed to be 1. |
| `JOINTS_N` | `joints_N` | `ivec4` | Yes | Yes | `N`-th set of joint indices |
| `WEIGHTS_N` | `weights_N` | `vec4` |

看不明白没关系,需要上述视频教程+源码
+下方↓↓小助手【cesium进阶】无偿获取
1946

被折叠的 条评论
为什么被折叠?



