当前位置:网站首页>Chapter 9 of OpenGL super classic (version 7): fragment processing and frame buffering
Chapter 9 of OpenGL super classic (version 7): fragment processing and frame buffering
2022-06-30 05:01:00 【Jason_ Chen__】
Chapter 9 fragment processing and frame buffering
Preface
This chapter mainly introduces the backend , Introduce all operations after rasterization , Including data processing , Improve image quality , High dynamic range rendering , Anti-Aliasing , Alternative color spaces that can be rendered
One 、 Fragment Shader
sketch : Clip shaders set the color of vertices , The rasterization phase will be interpolated , Generate interpolation segments , You can control whether to interpolate through the storage qualifier
(1) Disable interpolation :
flat in vec4 foo; This is the flat field input , The storage qualifier is flat, Description is to disable interpolation
smooth in vec4 foo; This is the smooth input , The storage qualifier is smoot, The explanation is to use interpolation
The storage qualifier interpolation of the front end and clip shaders must match
Use flat field input , When rendering primitives are lines and triangles , Use the first or last vertex ,( Use void glProvokingVertex() To make sure )
(2) No perspective correction interpolation
sketch : When the plane of the triangle is not perpendicular to our line of sight , Interpolation errors will occur , Because the compensation of screen space is not linear
Perspective correction is enabled by default
noperspective Storage qualifier , Using linear interpolation , Do not use perspective correction , Will affect the texture effect
Two 、 Single segment test
1. Cut test
Clipping tests are similar to viewport clipping , The difference is :
(1) Geometry does not crop directly from the crop rectangle , Instead, test each fragment
(2) Disabled by default
(3) it is to be noted that glClear() and glClearBufferv() Clear frame buffer
2. Template testing
sketch : It's like painting a cut cardboard , The cut part can be painted through , Form a pattern .
commonly 8 position
glEnable(GL_STENCIL_TEST): Enable template testing
glStencilFuncSeparate()、glStencilFunc(): Set whether to pass or not
glStencilOpSeparate()、glStencilOpI(): Set the operation after passing
3. Depth testing
sketch : Depth test the existing fragments
glEnable(GL_DEPTH_TEST): Enable global depth testing
glDepthMask(): Settings section ( Specific objects ) Whether to conduct depth test
glDepthFunc(): Set the conditions for passing the depth test
glEnable(): Start deep clamping , You can optimize the clipping of the near plane
Generally run the fragment shader first , Then run template test and depth test
Set layout qualifier (depth_any、depth_less、depth_greater、depth_unchanged) You can run the depth test first , Running clip shaders
3、 ... and 、 Color output
sketch : Display colors on the screen , Is the last pipeline stage before the clip is written to the frame cache
1. Color blending
glEnable(GL_BLEND): Turn on
glBlendFunc()、glBlendFuncSeparate(): Set mixed function
glBlendColor(): Used to set the last value constant of the blending function
Dual source mixing ...
glBlendEquation()、glBlendEquationSeparate(): The mixed equation
what?????
2. Logical operations
Not commonly used ...
glLogicOp(): Calculate the final value
3. color mask
sketch : Apply a mask to the color cache , Just like template buffer and depth buffer
glColorMask()( Disable and enable write buffering )、glColorMaski()
application : Depth information fills the shadow volume 、 Prevent contamination of depth data when mapping
Four 、 Off screen rendering
sketch : Replace the default frame buffer with a custom frame buffer
1. Multiple frame buffer attachments
sketch : You can attach multiple textures to a single frame cache and render to multiple textures of that frame cache at the same time using a single clip shader
Be careful :glDrawBuffers() This is the plural
2. Layered rendering
The difference from the above is : It can add textures in different states to a single frame cache and display , Specifically gsLayered Listing example
Cube maps are a special case of array textures , Special functions :glFramebufferTexture2D()
3. Integrity of frame buffer
sketch : Frame buffer is set , This does not mean that you can render writes
(1) Attachment integrity
Determine whether the template format can be rendered. You can call :glGetInternalformativ()
(2) Full frame cache integrity
Use this function to check ,GLenum fboStatus = glCheckFramebufferStatus()
The read frame buffer must also be complete
4. volume rendering
sketch : Improve the scene depth of the image by providing images for two eyes respectively
5、 ... and . Anti aliasing ( Anti-Aliasing )
Aliasing is the artifact of under sampled data ( It's serration )
1. Filter anti aliasing
sketch : Enable GL_LINE_SMOOTH You can antialiase wireframes ; Use GL_POLYGON_SMOOTH You can antialiase geometry edges , But the jagged edges on the inside will be obvious
2. Multiple anti aliasing (MSAA)
sketch : Increase the sampling frequency of each pixel
glEnable(GL_MULTISAMPLE)
3. Various textures
sketch : Create a multi sample texture and attach it to the frame cache object for rendering
GL_TEXTURE_2D_MULTISAMPLE、GL_TEXTURE_2D_MULTISAMPLE_ARRAY
glTextureStorage2DMultisample()、glTextureStorage3DMultisample()
Sample coverage : fragment “ Cover ” Percentage of pixels
How to generate ?
One way is : By enabling GL_SAMPLE_ALPHA_TO_COVERAGE, Convert clip transparency values directly to coverage values
Another kind : Set this information explicitly in the clip shader , Built-in variables gl_SampleMaskIn[] and gl_SampleMask[]
4. Sample rate coloring
sketch : The entire shader will run at the sample rate
glEnable(GL_SAMPLE_SHADING)
void glMinSampleShading()
5. Center of gravity sampling
sketch : Anti aliasing optimization for multi sample frame cache only
Barycentric storage qualifier centroid( stay “ Front end shaders ” establish , Input to clip shader , bring into correspondence with )
Using barycentric sampling is to achieve edge detection : Only most edge pixels can be marked
6、 ... and 、 Advanced frame buffer format
sketch : Find advanced texture formats for custom frame buffering
1. Render without attachments
The frame buffer can have no attachments , But use glFramebufferParameteri() To set the frame buffer object parameters , You can also use... In clip shaders imageStore() Write memory and atomicCounterIncrement、atomicCounterDecrement Function to increase and decrease the atomic counter
2. Floating point frame buffer
sketch : Texture precision bit floating point , Improve texture storage accuracy , Can be applied HDR、 Lens halo and other effects
(1) Tone mapping
You can put more than 1.0 Data mapped to 0-1.0 Between
(2) Highlight overflow
By setting the brightness limit, you can achieve the effect of Omni lighting ( A separate Gaussian filter is used )
3. Integer frame buffer
sketch : Integer precision textures are attached to the frame buffer
The clip shader output should match the type of attachment
The component width is less than 32 position , Or it is to discard other most significant bits , Or you can convert floating-point data to integers through a packed function
What happened : Not suitable for mixing ; The existence of integer internal format means that the final texture to which the image is rendered cannot be filtered
4.sRGB Color space
sketch : Because the relationship between light output and voltage is highly nonlinear , So use gamma correction
Frame buffer can be used sRGB Create texture in internal format , however sRGB The write of frame buffer attachment cannot be linear data , however opengl You can use to open GL_FRAMEBUFFER_SRGB Automatically convert the color value output by the clip shader into non-linear data
7、 ... and 、 Point Sprite
sketch : Dot elves usually trim their fingerprints , Is to texture the dots , Making particle systems
1. Point texturing
Change the vertex into 2d texture
2. Render the starry sky
Example starfield
3. Point parameters
sketch : Use glPointParameteri() You can change the point into 2D Polygon shape in plane , The origin of the point sprite coordinate should be set as GL_LOWER_LEET
4. Shaped point
ditto
5. Spin point
sketch : By trigonometric function , send 2D The graphics in the plane generate the visual effect of rotation
8、 ... and 、 Get images
sketch : Print image 、 Screenshots and screenshots 、 Background screenshots and screenshots 、 Offline processes, etc
1. Read from the frame cache
sketch : Reading of frame cache data
Use glReadPixels() Function to read frame cache data ( Default frame cache ), Use glMapBufferRange() And use GL_MAP_READ_BIT Set the mapping cache , Use glReadBuffer() Specify the read attachment or set the default frame cache attachment
When writing , according to y The coordinates are read and written from left to right in ascending order ,glPixelStorei() Change this setting
2. Copy data between frame buffers
sketch : Quickly copy data through bit blocks
glReadBuffer(): data source
glDrawBuffer(): Paint cache for the current paint frame cache ( Target cache )
glReadPixels(): Read frame buffered data into application memory ( Cache object ), Low efficiency
glBlitFramebuffer(): Read the frame cache into another frame cache
glCopyTexSubImage2D() and glCopyTextureSubImage2D(): Copy data to texture , Get the data source from the frame cache
glCopyImageSubData(): Copy texture data to another texture , If you want to change the texture size when copying , Then use glBlitFramebuffer()
3. Read texture data
sketch : Read data directly from the texture to the memory of the application ( cache ), Mechanism and glReadPixels be similar
glGetTexImage() and glGetTextureImage(): Read image data directly from texture
glGetTextureSubImage(): Read a small piece of texture
Example : call glGenerateMipmap(), With higher resolution mip Mapping fills the lower resolution mip mapping , Or you can write images directly from shaders , Then read the image
边栏推荐
- Sailing experience not to be missed in New York Tourism: take you to enjoy the magnificent city scenery from different perspectives
- Unreal 4 learning notes - Animated Montage
- Unity3d Google Earth
- On mask culling of unity
- Pit of smoothstep node in shadergraph
- Unity enables simple music visualization
- Unit screenshot saved on the phone
- Unity notes_ SQL Function
- Ripple effect of mouse click (unity & shader)
- Error about the new version of UE4: unavigationsystemv1:: simplemovetoactor has been deprecated
猜你喜欢
UE4 method of embedding web pages
Unity automatic pathfinding
Universal Studios Singapore: a good place for a one-day parent-child tour in Singapore
Unity realizes rotation and Revolution
Autowired注解警告的解决办法
On mask culling of unity
Some books you should not miss when you are new to the workplace
Qos(Quality of Service)
Procedural animation -- inverse kinematics of tentacles
PBR material: basic principle and simple fabrication
随机推荐
深度学习------不同方法实现Inception-10
Deep learning ----- different methods to realize inception-10
redis集群概念
Webots learning notes
The role of break
Brew install NVM command not found solution
Force buckle 59 Spiral matrix II
A virtual reality secret room escape adventure, let you see Technology Singapore
Approaching history, introduction to the London Guard Museum
Some books you should not miss when you are new to the workplace
JS 数组的排序 sort方法详解
Unity3d Google Earth
Photon pun refresh hall room list
Pycharm database tool
Circle center technology, very anxious?
Leetcode 180 Consecutive numbers (2022.06.29)
【VCS+Verdi聯合仿真】~ 以計數器為例
Operation file file class method
力扣(LeetCode)180. 连续出现的数字(2022.06.29)
Oracle-数据的基本操作