<!-- WebGL 2 shaders --> <script id="vs-render" type="x-shader/x-vertex"> #version 300 es #define POSITION_LOCATION 0 #define ATTRIBUTE_DATA_LOCATION 6 precision highp float; precision highp int; uniform mat4 MVP; layout(location = POSITION_LOCATION) in vec2 position; layout(location = ATTRIBUTE_DATA_LOCATION) in float data; out float v_attribute; void main() { gl_Position = MVP * vec4(position, 0.0, 1.0); v_attribute = data; } </script> <script id="fs-render" type="x-shader/x-fragment"> #version 300 es precision highp float; precision highp int; in float v_attribute; out vec4 color; void main() { const vec4 blue = vec4( 0.0, 0.0, 1.0, 1.0 ); const vec4 yellow = vec4( 1.0, 1.0, 0.0, 1.0 ); color = v_attribute >= 0.0 ? mix(blue, yellow, sqrt(v_attribute)) : yellow; } </script> <script id="vs-render-centroid" type="x-shader/x-vertex"> #version 300 es #define POSITION_LOCATION 0 #define ATTRIBUTE_DATA_LOCATION 6 precision highp float; precision highp int; uniform mat4 MVP; layout(location = POSITION_LOCATION) in vec2 position; layout(location = ATTRIBUTE_DATA_LOCATION) in float data; centroid out float v_attribute; void main() { gl_Position = MVP * vec4(position, 0.0, 1.0); v_attribute = data; } </script> <script id="fs-render-centroid" type="x-shader/x-fragment"> #version 300 es precision highp float; precision highp int; centroid in float v_attribute; out vec4 color; void main() { const vec4 blue = vec4( 0.0, 0.0, 1.0, 1.0 ); const vec4 yellow = vec4( 1.0, 1.0, 0.0, 1.0 ); color = v_attribute >= 0.0 ? mix(blue, yellow, sqrt(v_attribute)) : yellow; } </script>
本文将介绍如何使用着色器来进行几何造型,说到几何图形大家一定都不陌生,比如说三角形、圆形,在WebGL中除了直接使用顶点绘制,我们还可以使用片元着色器进行造型,以下将介绍三角形的绘制,以及应用场景。
自动化3D机房、微模块、3D机房、3D数据中心、科技感数据中心、三维机房、3d建筑,3d消防,消防演习模拟,3d库房,3d档案室,3d密集架,webGL,threejs,3d机房,bim管理系统
three.js、webgl、3D煤矿隧道、三维井下人员定位、掘进面三维可视化、纵采面可视化、采集面可视化展示、设备检测、数字孪生、物联网3D、3d建筑、3d库房,bim管理系统