Jump to content

  • Log In with Google      Sign In   
  • Create Account

MJP

Member Since 29 Mar 2007
Offline Last Active Today, 12:42 AM

#5297145 How to get patch id in domain shader.

Posted by MJP on 18 June 2016 - 04:12 PM

SV_PrimitiveID always starts at 0 for every draw call, and then increases for every primitive processed as part of that draw call. So if you only every draw 1 primitive per draw, then it's always going to be 0. If you need some sort of global ID, then you'll need to provide an offset in a constant buffer.




#5297000 gui rendering issue in dx12

Posted by MJP on 17 June 2016 - 12:50 PM

If you'd like, you can tell the debug layer to automatically break into the debugger whenever an error or warning or occurs. I always do this, since it ensures that I notice and fix every issue. You can do it like this during initialization:

 

ID3D12InfoQueue* infoQueue = nullptr;
d3d12Device->QueryInterface(IID_PPV_ARGS(&infoQueue));
infoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_WARNING, TRUE);
infoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, TRUE);



#5296832 DirectXMath - storing transform matrices

Posted by MJP on 16 June 2016 - 11:59 AM

_vectorcall is not the default for x64 (the default is _fastcall). You need to either decorate your function with it or set as the default calling convention if you want that behavior. However you need to be careful if you enable it as the default calling convention, since it will also apply to functions declared in headers from third-party libraries. This can lead to a mismatch where your calling code expects _vectorcall convention, but the pre-compiled third-party lib was compiled with _fastcall.




#5296533 Deferred Context Usage

Posted by MJP on 14 June 2016 - 04:47 PM

Yeah I'm going to piggy-back on what phantom said, and advise you to steer clear of deferred contexts in D3D11. Unfortunately the way that the D3D11 API is setup just doesn't work for multithreading, and so deferred contexts were never able to live up to their promise. The biggest problem comes from the fact that the driver often needs the full pipeline state at draw or dispatch time in order patch shaders and set low-level GPU state. With deferred contexts some of the state might be inherited from a previous context, and so the driver ends up having to serialize at submission time in order to figure out the full set of state bits for a draw. The lack of lower-level memory access is also an issue, since it makes the semantics of thinks like Map/Discard more complicated.




#5295575 Phong model BRDF

Posted by MJP on 08 June 2016 - 12:00 AM

1. Reflectance is the ratio of outgoing light to incoming light. In other words, for any beam of light striking the surface it tells you how much of that light will reflect off of it instead of getting absorbed. Since it's a ratio, only [0,1] values make sense if you're going to enforce energy conservation. You can compute it for a BRDF and a light direction by integrating the result of the BRDF over the entire hemisphere of viewing directions. So you can essentially think of that process as summing up all of the light that's reflected in all directions from a single ray of light.

 

2. Rspec is the reflectance of the specular BRDF.

 

3. By "glancing angle" they mean that the vector light source is close to parallel with the surface plane. This is consistent with the common usage of the term glancing angle in the field of optics, where it refers to an incoming ray striking a surface.

 

4. So as that paragraph says, they compute the directional-hemispherical reflectance of the specular BRDF with the light direction held constant at ThetaI = 0. Since the reflectance is highest when θi = 0, you know that the reflectance value represents the maximum possible reflectance value for the BRDF. So by computing the maximum reflectance and then dividing the BRDF by that value, you can be sure that the reflectance of the BRDF never exceeds 1 (as long as Cspec is <= 1).

 

If you want to derive this result yourself, first start with the specular BRDF. This is the right side of 7.46:

 

BRDF.png

 

As we established earlier, we can compute directional hemispherical reflectance by integrating our BRDF about the hemisphere of possible viewing directions. We'll call this set of directions Ωv, and in spherical coordinates we'll refer to the two coordinates as Φv and θ(not to be confused with θi, which refers to our incident lighting direction). The integral we want to evaluate looks like this:

 

Reflectance.png

 

The "sinθv" term is part of the differential element of a spherical surface, which is defined as dS = r2sinθdθdϕ. In our case we're working on a unit hemisphere, so r = 1.

 

Now we're going to evaluate this with θi held constant as zero. In this case α is equal to θv, and so we can make that substitution. We can also pull out Cspec / π, since that part is constant:

 

Result.png

 

You can verify the result of this integral using Wolfram Alpha.

 

EDIT: I accidentally left out the "dΩ" and "dθdϕ" from the integrals in the middle image. Please pretend that I put them in there.  :)




#5295168 SampleLevel not honouring integer texel offset

Posted by MJP on 05 June 2016 - 06:50 PM

It's possible to just use the new compiler and still use the old SDK, if for some reason you're really keen on not switching. If you're using fxc.exe it's easy: just use the new version. If you're linking to the D3DCompiler DLL it's a little trickier, since you will probably have trouble making sure that your app links to the correct import lib. One way to make sure that you use the right version is to not use an import lib at all, and instead manually call LoadLibrary/GetProcAddress to get a pointer to the function you want to use from d3dcompiler_47.dll.




#5294517 [D3D12] Issue pow HLSL function

Posted by MJP on 01 June 2016 - 12:51 PM

If you pass a hard-coded to 0.0f as the exponent parameter of of pow, the compiler is going to optimize away the pow() completely and just replace the whole expression with 1.0f. However if the exponent is not hard-coded and instead comes from a constant buffer or the result of some other computation, then it will need to actually evaluate the pow(). On catch with pow() is that DX bytecode doesn't contain a pow assembly instruction, which is consistent with the native ISA of many GPU's. Instead the compiler will use the following approximation:

pow(x, y) = exp2(y * log2(x))

If you take a look at the generated assembly for your program, you should find a sequence that corresponds to this approximation. Here's a simple example programming and the resulting bytecode:

cbuffer Constants : register(b0)
{
    float x;
    float y;
}

float PSMain() : SV_Target0
{
    return pow(x, y);
}

ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer CB0[1], immediateIndexed
dcl_output o0.x
dcl_temps 1
log r0.x, cb0[0].x
mul r0.x, r0.x, cb0[0].y
exp o0.x, r0.x
ret

Notice the log instruction (which is a base-2 logarithm) followed by the exp instruction (which is also base-2).

The one thing you need to watch out for with log instruction is that it will return -INF if passed a value of 0, and NAN if passed a value that's < 0. This is why the compiler will often emit a warning if you don't use saturate() or abs() on the value that you pass as the first parameter to pow(). 

 

In light of all of this, I would take a look at the assembly being generated for your shader. It may reveal why you don't get the results your expect, or possibly an issue with how the compiler is generating the bytecode. You should also double-check that you're not passing a negative value as the first parameter of pow(), which you can avoid by passing saturate(RdotV).




#5294228 (Physically based) Hair shading

Posted by MJP on 30 May 2016 - 02:33 PM

 

 

In fact, I did not solve the IBL problem yet. In my knowledge The Order uses tangent irradiance maps

 

 

We didn't end up shipping with that, since we removed all usage of SH from the game towards the end of the project. Instead we applied specular from the 9 spherical gaussian lobes stored in our probe grid.




#5294083 Question about GI and Pipelines

Posted by MJP on 29 May 2016 - 05:15 PM

As Hodgman already explained, you can implement VCT as part of a deferred or forward renderer. However a deferred renderer will generally give you more flexibility in how you can fit into your rendering pipeline. Back when UE4 was telling everyone that they were going to use VCT, their presentations mentioned that they couldn't afford to perform the cone traces at full resolution. Instead they were were doing specular at half-resolution and diffuse even lower than that, and then upsampling. This is really only feasible with a deferred renderer, since a forward renderer typically rules out any kind of mixed-resolution shading.




#5293844 Still no DX12 Topic Prefix for the forums?

Posted by MJP on 27 May 2016 - 12:49 PM

I don't think I have permission to do this, so I'll need to get in touch with the admins.




#5293843 When will SlimDX be updated so as to contain also DirectX 12 ?

Posted by MJP on 27 May 2016 - 12:49 PM

Promit answered this question yesterday.




#5293675 does video memory cache effect efficiency

Posted by MJP on 26 May 2016 - 03:35 PM

I think you'll find more results if you search for "GPU cache" instead of "video memory cache". This is because the cache structure is really a part of a GPU and not its onboard memory, and also because the term "video memory" is pretty outdated.

 

Unlike CPU's, there's no generic cache structure that's used by all GPU's. Instead GPU's have a mixture of special-case and general-purpose caches where the exact number and details can vary significantly between hardware vendors, or even across different architectures from the same vendor. They also tend to be much smaller and much more transient compared to the CPU caches. CPU's actually dedicate a relatively large portion of their die space to cache, while GPU's tend to dedicate more space to their SIMD ALU units and corresponding register files. Ultimately this all means that the cache behavior ends up being different then what you would expect from a CPU with large L1/L2 caches, and you can't always apply the same rules-of-thumb.




#5292928 How to organize worlds/levels as seen in the new Doom

Posted by MJP on 22 May 2016 - 02:39 PM

The new Doom uses Umbra, it says so right when you start up the game.

 

A lot of games still use some form of PVS, but probably not based on BSP's like in the Quake days. The games that I have worked on used manual camera volumes where the set of visible meshes/lights/particles/whatever was computed at build-time based on generated or hand-placed sample points. Other games compute visibility completely at runtime by rasterizing a coarse depth buffer on the CPU, and then testing bounding volumes for visibility. Some newer games are moving towards doing all occlusion culling and scene submission on the GPU.




#5292920 Phong model BRDF

Posted by MJP on 22 May 2016 - 02:16 PM

 

Why is the outgoing radiance equal to 0 when the angle between n and l is <= 0?

Because the surface is back-facing from the light's point of view. The rendering equation itself -- which the BRDF plugs into -- multiplies the entire BRDF by N⋅L, so having this condition within the BRDF is actually superfluous. I guess it's just mentioned because most realtime renderers actually don't implement the rendering equation properly, so that condition is required to avoid getting specular highlights on the wrong side of an object.
 
As for the rest, this cosm term seems weird. Phong is based around (L⋅reflect(V,N))m, which is equivalent to cos(θr)m, where θr is the angle between the reflection direction and the light direction...

 


It's not cosm, it's cosmαr, where αr is the angle between the light direction and the reflected view direction.




#5292549 What's the advantage of Spherical Gaussians used in The Order vs. Envirom...

Posted by MJP on 19 May 2016 - 06:36 PM

Let's back up a bit here. Our ultimate goal for our baked lightmap/probe data was to store a representation of the incoming radiance on the sphere or hemisphere surrounding a point, so that we can integrate our diffuse and specular BRDF's against that radiance in order to determine the outgoing reflectance for the viewing direction. In simpler terms we need to store the incoming lighting in a way that's convenient to compute the visible light coming out. Spherical Guassians (SG's) are nice for this purpose, since a small number of them can potentially represent the radiance field as long as the radiance is somewhat low-frequency. They can do this because they have a "width", which means that the sum of them can potentially represent the entire surface area of a hemisphere or sphere. SG's also convenient because it's possible to come up with a reasonable closed-form approximation for the integral of (BRDF * SG). This ultimately means that computing the outgoing lighting for a pixel is an O(N) operation, where N is the number of SG's per sample point.

 

This is all somewhat separate from the issue of how the data is actually stored in textures so that it can be accessed at runtime. In our game, we stored the data in 2D textures for static meshes (just like standard lightmaps) and in 3D textures for our probe grids. In practice we actually keep an array of textures, where each texture contains just 1 SG for each texel. Storing as textures means that we can use texture filtering hardware to interpolate spatially between neighboring texels, either along the surface for static meshes or in 3D space for dynamic meshes. Textures also allow you to use block compression formats like BC6H, which can let you save memory.

 

So to finally get your question, you're asking why you wouldn't store the baked data in lots of mini 3x3 or 4x4 environment maps. Let's look at this in terms of the two aspects I just mentioned: how the data is stored, and what you're actually storing. Having a set of environment maps allows you to interpolate in the angular domain, since each texel essentially represents a path of surface area on a sphere or hemisphere. However if we're using SG's, then we don't actually need angular interpolation. Instead we consider each SG individually, which requires no interpolation. However we do want to interpolate spatially, since we'll want to shade pixels at a rate that's likely to be greater than the density of the baked texels. As I mentioned earlier 2D or 3D textures work well for spatial interpolation since we can use hardware filtering, whereas if you used miniature environment maps you would have to manually interpolate between sample points.

 

Now to get the other part: what you actually store in the texture. You seem to be suggesting an approach where the environment contains some kind of single radiance value in each texel, instead of a distribution of radiance like you have with an SG. The problem here is how to do you integrate against your BRDF(s)? If you consider each texel to contain the radiance for an infinitely small solid angle, then you can essentially treat each texel as a directional light and iterate over each. However this is not great since there will be "holes" in the hemisphere that aren't covered by your sparse radiance samples. So instead of doing that, you might try to pre-integrate your BRDF against a whole bunch of radiance samples, and store that result per-texel (I believe that this is what you're suggesting when you say "approximate a cone"). This is pretty much exactly the approach used by most games for their specular IBL probes. The big catch with pre-filtering is that you can't actually pre-integrate a specular BRDF against a radiance field and store the result in a 2D texture, since the view dependence adds too many dimensions. So you're forced to pre-integrate the NDF assuming that V == N, sample the environment map based on the peak specular direction, and apply the fresnel/visibility terms after the fact. Separating the NDF from fresnel/visibility leads to error, and unfortunately this error gets worse as your roughness increases. The pre-integration also assumes a fixed roughness, and so you need to store a mip chain with different roughness values that you interpolate between. This doesn't sound particularly appealing to me due to the error from pre-integration and mip interpolation, and you also lose the benefit of being able to spatially interpolate between your sample points. On top of all of this you still need to handle your diffuse BRDF, which requires an entirely different pre-integration.

 

TL:DR - our approach also us to use hardware filtering to interpolate samples, and we can use an analytical approximation for both diffuse and specular without having to rely on pre-integration.






PARTNERS