文章出處
文章列表
CSharpGL(40)一種極其簡單的半透明渲染方法
開始
這里介紹一個實現半透明渲染效果的方法。此方法極其簡單,不拖累渲染速度,但是不能適用所有的情況。
如下圖所示,可以讓包圍盒顯示為半透明效果。
原理很簡單,就是渲染包圍盒時,只渲染坐標值為奇數(或偶數)的那些fragment。很久以前,超級馬里奧就利用了這個方法。
在原有的fragment shader基礎上,判斷一下當前片段的位置即可。
1 #version 150 core 2 3 uniform vec3 boundingBoxColor = vec3(1, 1, 1); 4 5 out vec4 out_Color; 6 7 void main(void) 8 { 9 if (int(gl_FragCoord.x - 0.5) % 2 == 1 && int(gl_FragCoord.y - 0.5) % 2 != 1) discard; 10 if (int(gl_FragCoord.x - 0.5) % 2 != 1 && int(gl_FragCoord.y - 0.5) % 2 == 1) discard; 11 12 out_Color = vec4(boundingBoxColor, 1.0f); 13 }
總結
打完收工。
文章列表
全站熱搜