OpenGL ES 3.0頂點著色器(一),opengles
OpenGL ES 3.0流程圖
1.Vertex Shader(頂點著色器)
頂點著色實現了一種通用的可程式化方法操作頂點。
頂點著色器的輸入包括以下幾個:
• Shader program.程式的頂點著色程式原始碼或可執行程式,描述將在頂點上執行的操作。
• Vertex shader inputs (or attributes)-頂點著色去支援的頂點數組。
• Uniforms。頂點(片段)著色器使用的常量資料。
• Samplers。Uniforms使用的特殊類型,在紋理中使用(Texture)
在OpenGL ES2.0中頂點著色器的輸出被稱為變數,而在3.0中重新命名了。在最初的光柵化階段,它計算每個產生的輸出值,作為輸入傳遞給片段著色器。用於產生每個的值的機制從頂點著色輸出到每個頂點的片段原始的被稱為插值。此外,OpenGL ES 3加
種新的特徵稱為變換反饋,它允許頂點著色輸出選擇寫入到輸出緩衝區。
頂點著色器
它使用在傳統的基於頂點的操作。如矩陣變換,計算光線,產生每頂點顏色,紋理產生和座標變換。
2. uniform mat4 u_mvpMatrix; // matrix to convert a_position3. // from model space to normalized4. // device space5.6. // attributes input to the vertex shader7. in vec4 a_position; // position value8. in vec4 a_color; // input vertex color9.10. // output of the vertex shader - input to fragment11. // shader12. out vec4 v_color; // output vertex color13. void main()14. {15. v_color = a_color;16. gl_Position = u_mvpMatrix * a_position;17. }