利用者:Hypersomniac/PBR viewport/Bsdf rendering
目次
5. Direct Lighting
Direct Lighting is the influence of scene lamps on the bsdfs.
Optimization : Sampling Shadow map should be done once for all opaque bsdf.
As of now lights that are in the scenes are compiled inside each shaders with their attributes dynamically updated. This implies that all surfaces get the lighting cost no mater how far the light is, that adding/removing light (or changing static attribute) recompile every shaders in the scene. But this means that we can inject what is inside the light node tree directly to the shading pipeline.
We could optimize this and do a dynamic light loop with maybe light culling but loose the node tree injection part. So performance of functionnality? We could also render the nodetree to a texture and sample it in the shader when lighting.
Not all light type / bsdf combination have approximation technique. Therefore we should use the most appropriate fall back or use a fitted solution.
Shadows are still sharp even with variance shadow maps. But no ideal solution for now.
Note that when using Area light, the glossy shader approximation using Linearly Transformed Cosine needs 2 LUTs.
6. Indirect Lighting
Indirect lighting is the influence of the probe on the bsdfs.
There is two choices here:
Filtered Importance Sampling
First, we can use few approximations and do everything with Filtered Importance sampling:
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html
This has the benefit to not be confined to one Bsdf and mix bsdfs in one shader. Also Results is very similar to Cycles. But performance is poor due to the number of sample we have to use. Using filtering with mipmaps helps to lower this count but it's still remains a bit hard to render whole scene.
Also to get an even distribution of the samples, random samples has to be generated per pixel (and possibly per frame).
Optimization :Possibly make this random samples only once for all bsdfs. Grouping bsdfs in a loop. This could be achieve at the shader generation step.
For each bsdfs Setup bsdfs For each samples Generate Hammersley sample For each bsdfs Sample Probe For each Bsdfs outputs Color
But this means rejecting all shaders that have bsdf nodes plugged inside non-bsdf inputs. We could just reject bsdf that goes back into other bsdfs but that's a bit more complex.
Split Sum Approximation
The other solution is to prefilter (convolve) the probe to a specific Bsdf. Different Roughness level are baked into the mipmap of the cubemap. For the diffuse lighting the Spherical Harmonics are enough to contains the low frequency of the convolved lighting. But this mean the cubemap cannot be used for other bsdfs.
This needs a precomputation phase but it can be lowered to a few milisec. https://placeholderart.wordpress.com/2015/07/28/implementation-notes-runtime-environment-map-filtering-for-image-based-lighting
We also need a LUT to precompute the BSDF contribution. This is the split sum approximation from Unreal4. This would be a lot faster than importance sampling because all the complicated stuff get simplified to 2 texture lookup. With this method we loose the stretched reflection depending on the view angle.
Unlike Unreal, Cycles does not account for the fresnel effect inside the Glossy shader. This means we can omit the fresnel channel inside the LUT. The fresnel effect can be retrieve by using a trick inside the shader node tree itself so I don't see that as a problem.
With each methods we can use parallax correction to get the reflection grounded to the world and not sliding with the camera.
I also plan on supporting planar reflections. But we have to make them good looking even for rough materials.
When using planar reflections or parallax corrected probes we must have a fallback probe for rays that fails.
So textures that needs to be bound for these methods are :
- probe
- fallback probe
- Hammersley Samples (required for AO OR importance sampling)
- Per Pixel Rotation Texture (required for AO OR importance sampling)
- Bsdf LUT (required for split sum approximation OR SSR)
- For AO & SSR : Screen Depth buffer (Can have min - max Hierarchical levels)
- For SSR : Screen Color buffer
We might fallback to hacks for bsdfs that have no simplified algorithm.
Ambient Occlusion
Ambient Occlusion should be applied to the indirect lighting only so it must be rendered before merging the Direct and Indirect lighting.
It will be rendered when shading the geometry and before evaluating the bsdfs (or in parallel).
We could have different Ambient Occlusion algorithm. One high quality and one faster for preview. We can use the HiZ buffer to our advantage to accelerate tracing rays.
Also ambient occlusion need to be applied differently to diffuse and glossy shaders.
Screen Space Reflections
I aim to implement Screen space cone traced reflections as described in GPU Pro 5
HiZ Tracing is already done (needs a few correction) but the cone tracing is not done.