Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Aug 2012
Offline Last Active Mar 06 2013 08:19 PM

Topics I've Started

Difference between two ways of assigning values to variables in HLSL constant buffer

12 February 2013 - 01:47 AM

As far as I know, There are two way passing values to variables in HLSL constant buffer.

cbuffer cbGeometryRender : register( b0 )
    float4x4 WorldMatrix;
    float4x4 ViewMatrix;
    float4x4 ProjMatrix;
    float4x4 WVPMatrix;
    float4x4 VPMatrix;    
    float3 EyePos;
    float3 LightDir; // start at the sun
    float4 SplitPos;



The first way is to use Effect11 Library. For example

ID3DX11Effect *pEffect; // initialize when compiling the fx file
ID3DX11EffectVectorVariable *pEyePos = pEffect->GetVariableByName("EyePos")->AsVector();



The second way is to use the constant buffer created with the desc in the following.

 bd.Usage = D3D11_USAGE_DYNAMIC;
 bd.ByteWidth = sizeof( CONSTANT_BUFFER_STRUCT );
 bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
 bd.MiscFlags = 0;
 hr = pd3dDevice->CreateBuffer( &bd, NULL, &g_pCB ); 



On each frame, we map g_pCB to b0, assign the values, and then unmap it. After that, We set constant buffer for each stage.


IS Anyone who know what the differences are between these two methods?

which is better?

can Effect11 Library be used with deferred context?


Can these two ways be used together, i.e., using Effect Library compile the fx file and using the second way to pass the value to GPU?

real and complex fog representatin

02 February 2013 - 09:07 PM

There are some easy algorithms or formulars to simulate fog effect.

such as:


Linear fog adds a linear amount of fog based on the distance you are viewing the object from:

    Linear Fog = (FogEnd - ViewpointDistance) / (FogEnd - FogStart)

Exponential fog adds exponentially more fog the further away an object is inside the fog:

    Exponential Fog = 1.0 / 2.71828 power (ViewpointDistance * FogDensity)

Exponential 2 fog adds even more exponential fog than the previous equation giving a very thick fog appearance:

    Exponential Fog 2 = 1.0 / 2.71828 power ((ViewpointDistance * FogDensity) * (ViewpointDistance * FogDensity))

All three equations produce a fog factor. To apply that fog factor to the model's texture and produce a final pixel color value we use the following equation:

    Fog Color = FogFactor * TextureColor + (1.0 - FogFactor) * FogColor

For this tutorial we will generate the fog factor in the vertex shader and then calculate the final fog color in the pixel shader.


but the effect generated is not satisfying, for i think the scattaring effects must be considered. I know some indoor single scattaring formulars, but outdoor effect are different from that indoor.

DO anyone know if there are any complex method to simulate very real fog effect or if there are any physics based equations to simulate it?

And i prefer physics method.



TXAA details

19 August 2012 - 11:02 PM

does anyone know about details of TXAA anti-aliasing or have any articles or papers of it? I've been trying to look for them, but just find some introductions and advertisement.