当前位置:网站首页>Vertex shader to slice shader procedure, varying variable
Vertex shader to slice shader procedure, varying variable
2022-07-07 15:39:00 【Vegetable chicken on the road】
varying Variable : Pass data from vertex shader to slice shader .
varying Variables can only be float( And related vec2,vec3,vec4,mat2,mat3,mat4).
We learned earlier that vertex shaders control the position of geometry 、 Dimensions even specify the color of the geometry , The final slice shader determines the color of the geometry ! But we don't know the specific process between them !
Now let's understand the two processes :
Graphic assembly process : The task of this step is , The left side of isolated vertices is assembled into geometry , The category of geometry is determined by gl.drawArrays() The first parameter of the function determines .
Grating process : The task of this step is to convert the assembled geometry into pieces .
The process from vertex shader to slice shader
******************************************************************************************
Ahead gl.deawArrays() The execution of the function (n=3):
step :
(1) according to gl.drawArrays() Parameters of n, Vertex shaders will be executed n Time ( Execute vertex shader results : Input and store the coordinates in the assembly area )
(2) Start assembly drawing . Use the incoming point coordinates , according to gl.drawArrays() The first parameter information of ( Such as :gl.TRANGLES) To decide how to assemble .
(3) Rasterize
Example :
// Vertex shader program
var VSHADER_SOURCE =
'attribute vec4 a_Position;\n'+
'attribute vec4 a_Color;\n'+
'varying vec4 v_Color;\n'+
'void main() {\n' +
'gl_Position = a_Position ;\n' +
'v_Color = a_Color;\n'+
'}\n';
// Chip shader program
var FSHADER_SOURCE =
'precision mediump float;\n' +
'varying vec4 v_Color;\n' +
'void main() {\n' +
'gl_FragColor = v_Color;\n' +
'}\n';
function main() {
// obtain <canvas> Elements
var canvas = document.getElementById('webgl');
// obtain WebGL Rendering context
var gl = getWebGLContext(canvas);
if (!gl) {
console.log('Failed to get the rendering context for WebGL');
return;
}
// Initialize shaders
if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {
console.log('Failed to intialize shaders.');
return;
}
// Set vertex position
var n = initVertexBuffers(gl);
if(n<0){
console.log("fail initialTextexBuffer");
return;
}
gl.clearColor(0.0, 0.0, 0.0, 1.0);
// Empty <canvas>
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES,0,n);
}
function initVertexBuffers(gl) {
var verticesColors = new Float32Array([
0.0 , 0.5 , 1.0,0.0,0.0,
-0.5 , -0.5 , 0.0,1.0,0.0,
0.5 , -0.5 , 0.0,0.0,1.0
]);
var n =3;
// Create buffer object
var vertexColorBuffer = gl.createBuffer();
if (!vertexColorBuffer) {
console.log("vertexColorBuffer not exit");
return;
}
// Bind the buffer object to the target
gl.bindBuffer(gl.ARRAY_BUFFER,vertexColorBuffer);
// Write data
gl.bufferData(gl.ARRAY_BUFFER,verticesColors,gl.STATIC_DRAW);
var FSIZE = verticesColors.BYTES_PER_ELEMENT;
var a_Position = gl.getAttribLocation(gl.program,"a_Position");
// Assign cache objects to a_position
gl.vertexAttribPointer(a_Position,2,gl.FLOAT,false,FSIZE*5,0);
// Connect a_position Change to the cache object assigned to it
gl.enableVertexAttribArray(a_Position);
var a_color = gl.getAttribLocation(gl.program,"a_Color");
// Assign cache objects to a_position
gl.vertexAttribPointer(a_color,2,gl.FLOAT,false,FSIZE*5,FSIZE*2);
// Connect a_position Change to the cache object assigned to it
gl.enableVertexAttribArray(a_color);
return n;
}
Running effect :
Why is it such an effect , Because it involves the process of color interpolation :
边栏推荐
- Oracle控制文件丢失恢复归档模式方法
- Unity's ASE achieves full screen sand blowing effect
- The difference between full-time graduate students and part-time graduate students!
- Gd32 F3 pin mapping problem SW interface cannot be burned
- Ctfshow, information collection: web14
- 从 1.5 开始搭建一个微服务框架链路追踪 traceId
- 众昂矿业:萤石继续引领新能源市场增长
- Comparable and comparator of sorting
- 2. 堆排序『较难理解的排序』
- 最安全的证券交易app都有哪些
猜你喜欢
【数字IC验证快速入门】22、SystemVerilog项目实践之AHB-SRAMC(2)(AMBA总线介绍)
【目标检测】YOLOv5跑通VOC2007数据集
居然从408改考自命题!211华北电力大学(北京)
写一篇万字长文《CAS自旋锁》送杰伦的新专辑登顶热榜
MongoD管理数据库的方法介绍
[quick start of Digital IC Verification] 23. AHB sramc of SystemVerilog project practice (3) (basic points of AHB protocol)
Ida Pro reverse tool finds the IP and port of the socket server
[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
Guangzhou Development Zone enables geographical indication products to help rural revitalization
2. Heap sort "hard to understand sort"
随机推荐
Wechat applet 01
@ComponentScan
Yunxiaoduo software internal test distribution test platform description document
leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
【数字IC验证快速入门】25、SystemVerilog项目实践之AHB-SRAMC(5)(AHB 重点回顾,要点提炼)
MongoD管理数据库的方法介绍
Configure mongodb database in window environment
Niuke real problem programming - Day17
[deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
Ctfshow, information collection: web6
Nacos一致性协议 CP/AP/JRaft/Distro协议
知否|两大风控最重要指标与客群好坏的关系分析
What are PV and UV? pv、uv
银行需要搭建智能客服模块的中台能力,驱动全场景智能客服务升级
[quick start of Digital IC Verification] 23. AHB sramc of SystemVerilog project practice (3) (basic points of AHB protocol)
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
【数字IC验证快速入门】18、SystemVerilog学习之基本语法5(并发线程...内含实践练习)
Introduction of mongod management database method
简述keepalived工作原理
【数字IC验证快速入门】24、SystemVerilog项目实践之AHB-SRAMC(4)(AHB继续深入)