GPU Gem, nvidia texture Shadow implementation comparison

Source: Internet
Author: User

Code down, compile with 2012,
Http://developer.download.nvidia.com/SDK/10.5/direct3d/samples.html


Find the example of soft shadowmap, the thumbnail is a samurai standing on the grass with a sword


The GLSL version of my notebook card is 4.3,
After compiling a run on the error,
Modify SoftShadows.cpp 288 lines
Nvscopedshaderprefix switched (
(Getglcontext ()->getconfiguration (). Apiver.api = = NVGFXAPI::GL)
? "#version 430\n":------------turned out to be 440, the author changed to 430
"#version 310 es\n#extension gl_android_extension_pack_es31a:enable\nprecision mediump float;");

The final result is to run a few frames, the video card is dead, the author of the video card is the Intel R HD graphics family, internet a check, is said to be very low-end,
Another look at the shader code, PCF minimum two times 25x25 poisson sampling (once used to determine whether in the shadow, once for weighted calculation of the shadow)
The higher the 100x100, the shading texture sampled 20,000 times for rendering a pixel.


The author's configuration run code seems to be hopeless.


Look at the shader code, actually also simple.


There are two versions of the rendering, in the comparison depth is, with the texture, the main contribution of soft shadows should be this code,
Return ((uvz.x <= 1.0) && (uvz.y <= 1.0) &&
(uvz.x >= 0.0) && (uvz.y >= 0.0))? Texture (Tex, UVZ):
((uvz.z <= 1.0)? 1:0.0);




The first random sampling is used to determine if the point is between shadows,
Judging by the distance, the table (Poisson distribution), the total value of the sampling point contribution to determine whether in the shadow,
The sample radius expands with the distance between the point and the light source, and the effect of LOD


The second random sampling begins to formally calculate the shadow weights for that point




The end result is, in the author's rotten book, the frame rate is single digit, and runs a few frames to die


========================= Split Line =================================


Another example of GPU gems,
LOD uses DDX ddy (opengl corresponding function is Dfdy DFDX)


The size of the sample block is calculated according to the DDX Ddy, that is, the closer the Observer (that is, the projection near plane) from the point, the smaller the number of sample blocks (at which time the value of DDX Ddy is small),
And when observing away from the point is, the greater the value of the DDX Ddy, the larger the number of sample blocks, and sets a upper and lower limit.
Achieve the Lod effect
The real contribution of the soft yin is the sampling filter function Samplecmplevelzero


The final soft shadow effect is also good, in the author's rotten book, the medium effect of the soft shadow ran nearly 150 of the frame rate (the highest PCF sample frame rate will be to the single digit, but will not crash),
The effect has been accepted, and some examples have been observed, and the phenomenon of the separation of shadows from objects in PCF should be caused by z_proj nonlinearity.




In a comprehensive comparison, the gem example is more realistic.


====================== Split Line =========================
The author's practice:


Step one: render depth to texture
Step two: Draw the entire scene
Step three: Draw shadows


2, 3 can be combined into a single step, separated just for the benefit of code organization.


When a shadow is drawn, the shadow texture is bound to the Sampler2dshadow type, and the shadow2d is used for weight filtering. Don't be silly to write code filtering weights yourself,
Thankless. The use of Poisson random filter effect, will only produce some noise points, closer to see, or will feel weird.


1 The depth value of the perspective projection is zproj, the bias pressure is not easy to calculate, and the farther away from the light, the more prone to shadow and object separation phenomenon,
So the depth value can try to make a workaround. Change to (Zview-znear)/(zfar-znear) so that the nonlinear problem of Zproj is bypassed
2 bias pressure using triangular surface and the angle of the light source to calculate, the smaller the angle, the less the bias pressure can
3 Too many samples will reduce the frame rate, so it is best to do edge detection, only need to be near the edge of the PCF, can increase the number of PCF sample block


The 3rd can save a lot of sampling, because the shadow texture feature is a large shadow, a large area is no shadow, for some "internal sampling" do not need to do extra texture sampling operations.
Edge detection can be simply based on the size of the sample block, scanning only the Perimeter 8 sample points, and the current sample point, if all are in the shadow, or are not in the shadow, it is considered

Internal Point, no PCF


The author's soft Shadow Effect


GPU Gem, nvidia texture Shadow implementation comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.