• Content count

  • Joined

  • Last visited

Community Reputation

2398 Excellent

1 Follower

About knarkowicz

Personal Information


  • Twitter
  1. Gamma correction - sanity check

    No. When you read from R8G8B8A8_unorm_srgb HW automatically does sRGB->linear conversion for you. Similar case with writes - you get linear->sRGB at the end. Basically, this means that you can use either R10G10B10A2_unorm or R8G8B8A8_unorm_srgb as your intermediate main color target without any observable difference in case of outputting that directly to the screen. If you don't need HDR then you don't have to use a fp render target - you can use R8G8B8A8_unorm_srgb or R10G10B10A2_unorm. EDIT: BTW custom gamma is usually done on top of HW sRGB, as sRGB is more complicated than simple x^1/2.2.
  2. Gamma correction - sanity check

    sRGB is linear in a sense of brightness perception and sRGB->linear correction is obviously non linear. To store linear values you need at least 10 bits of precision, as after SRGB->linear conversion you need more precision in the bottom of the color range. All this means that if you don't do HDR (or pre-expose inside shaders) then you need to use at least 8888_srgb as your main color target. If you want to expose at the end of the pipeline, then you need also some extra range and precision and need to use at least 11_11_10_float as your main color target.
  3. There are two good ways: 1. Brute force - read 4 samples in a loop (4 samples per loop iteration are a sweat spot on most GPUs). You may want to finish your iterations with a linear interpolation between two last samples for better quality. 2. CSM (Cone Step Mapping) - much less samples than bruteforce, but every sample is slower as you can do only 1 tfetch per loop iteration and you are fetching "fatter" texels. It also requires a special pre-computed texture with height and cone angle, which may be an issue for your asset pipeline. In any way, first you should calculate tex LOD using GLSL function or emulating it inside the shader (faster, but requires to pass tex size to shader). Then derive number of steps from tex LOD. Finally, inside the loop just use previously calculated tex LOD level.
  4. S3TC and gamma correction

    HW interpolation doesn't work directly on BC data - first entire BC (S3) 4x4 block is decoded and stored in texture cache. BC decoding is obviously based on BC specs - so during BC decoding interpolation is always done in sRGB space. Next, filtering is done in linear space using values from texture cache (on post DX9 HW).
  5. Tone map theory questions.

    Exposure is just a simple color mult before the tonemapping. Auto exposure means automatically calculating this exposure value based on scene avg luminance, histogram or something else, but still it doesn't change the tonemapping. It works the same way as for a real-world camera - exposure is manual/auto "brightness setting" and tonemapping is analog film. Shameless plug: some time ago I wrote a lengthy post about auto-exposure in games: .  
  6. IMHO in this case (mip map generation) difference between ^2.2 and proper sRGB is negligible, so you shouldn't worry about that. As for NVTT and mip map generation - just do a simple test. Provide some random data in mips (e.g. one mip level red, second green etc.) and check if NVTT outputs the same texture or if NVTT will generate new mips from the top level.
  7. Lightmapping and UVs

    I would recommend generating a second UV set just for lightmaps. This way you can fix light bleeding (cut UV charts at hard edges), light seams (stitch or use "seamless" UV mapping), control density, tightly pack generated charts etc. If you decide to use an external renderer, keep in mind that it needs to be able to support all your custom materials. This may be hard to do with something like 3dsMax. Additionally, it may be hard to extend it to use smarter lightmaps with normal map support (like SH or dir+ambient). Personally I would go with UVAtlas (+bruteforce UV chart packer and object chart bin packer) for UVs and either custom GPU lightmapper or custom CPU lightmapper using Embree for rendering. BTW some time ago I wrote a lengthy post about my lightmapping implementation (UV gen, packing, rendering) which may interest you:
  8. Tonemapping questions

    1. Log/exp are used in order to calculate geometric mean. Imagine a very dark scene with a single extremely bright pixel. Without log you would get a very high average luminance. 2. It looks like that your skybox simply isn't bright enough compared to the rest of the scene.
  9. With single pass you need to process every cubemap per pixel (if you don't use compute shader with tiles). With deferred you process only required pixels per cubemap, but with some overhead. It can be faster or slower depending on the number of cubemaps.
  10. @IoreStefani you are 100% correct, sorry pseudomarvin for the misinformation. I just checked my own clipper and I'm also doing linear interpolation in homogeneous space.
  11. Guard-band's idea is that you reduce amount of clipping to minimum. You clip only if a triangle intersects near plane or intersects massively offseted frustum sides. In your case it look like you will be clipping more triangles, as you clip with non-offseted frustum sides.   This is just an explanation what's is guard band. It's not crucial for a fast rasterizer, as clipping is a relatively rare operation. The crucial part is to do some clipping with (offseted or not) frustum sides, so your interpolation math won't explode.
  12. You don't divide by accumulated alpha value. Just use vanilla alpha blend. There is no correct formula for the blend weights. Just some do falloff in order to hide the transitions.
  13. You can't use linear interpolation in screen space for attributes which aren't linear in screen space (e.g. UV, position, normal etc.).   BTW you need also some guard-bard (clipping against offseted frustum sides). Without guard-band you will have precision issues when interpolating attributes.
  14. Hi,   It's impractical to use SH for high freq IBL, as you need a crazy amount of terms. Additionally, Brian's split sum approximation splits the radiance integral into two parts - one which can be stored in a cube map and second which can be stored in a small 2D texture (this is why there is no L(i) term in the second equation). Anyway, I'm not sure what are you trying to calculate here, as your equations look quite strange - e.g. f(l,v) term is missing.
  15. Some HDR, tonemapping and bloom questions

      You could use RGB16_UNORM by manually scaling shader outputs and inputs, but RGB16_Float render target is more convenient and precise (you want a lot of precision for the low values and not too much for the very high ones).     Tonemapping is about reducing color range for the final display, so yes a common tonemapper (one designed for LDR displays) will bring image to the [0;1] range.     Yes. Output values will be clamped to [0;1] range.     Yes. You want bloom before tonemapping (so it works with linear HDR values) and FXAA after tonemapping (so edge blending works "correcly").