Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Oct 2012
Offline Last Active Feb 14 2013 06:08 PM

Topics I've Started

D3D11 integration with MFC

16 January 2013 - 11:58 AM

Hi everyone!


I need to integrate a program in DirectX11 already done with the view window on an MFC application, could you guys help me out somehow?

Some examples any idea how I should tackle this situation because I'm pretty clueless here.


I did create the MFC application, I know that the .cpp I should focus is the one ending in view where there are kind of a start function for creating the object and OnDrawn and such but i have no idea how to get my already done program and add it to the MFC application.


Anything would help here, a simple example made (I was trying to make this integration with a simple draw the triangle from the D3D SDK), anything really!


Thanks very much in advance!

Attributing linear color variation on shader

08 January 2013 - 09:49 AM

Hi everyone!


I'm trying, through the PixelShader on the HLSL, to define the color of the pixel based on its height taken from the heightmap texture.


The program now takes the color from a texture sampling it linearly and I would like to change that to one defined by me based on the height of that pixel.

It's a terrain so basically i get the heightmap, calculate and add to it a normal map on CPU.

Since i need this to be really fast (the user must be allowed to change the colors on real time) this logic must be held on the shaders.


Below follows a cut of the function that gets the color for a given pixel considering all the lights and information from the texture with the color.


float4 ComputeIllumination( float2 texCoord, float3 vLightTS, float3 vViewTS )
   // Sample the normal from the normal map for the given texture sample:
   float3 vNormalTS = normalize( g_nmhTexture.Sample(g_samLinear, texCoord) * 2.0 - 1.0 );
  // Sample base map
   float4 cBaseColor = g_baseTexture.Sample( g_samLinear, texCoord );

  // Compute diffuse color component:
   float4 cDiffuse = saturate( dot( vNormalTS, vLightTS ) ) * g_materialDiffuseColor;
  // Compute the specular component if desired:  
   float4 cSpecular = 0;
   // Composite the final color:
   float4 cFinalColor = ( g_materialAmbientColor + cDiffuse ) * cBaseColor + cSpecular; 
   return cFinalColor;  

When i try to change that logic by adding something like seen below it has no linear variation between pixels its flat that color and the normal map loses its effect for some reason.


float unit = 0.00390625;

 if((vHeight.w >= (0 * 63.75 + 1) * unit)
   &&   (vHeight.w < (1 * 63.75 + 1) * unit)
   //&& (vHeight.w > clipThreshold)
        cBaseColor.rgb = uint3(0, 0, 255);
        //cBaseColor.a = 255;
   else if((vHeight.w >= (1 * 63.75 + 1) * unit)
   &&   (vHeight.w < (2 * 63.75 + 1) * unit))
        cBaseColor.rgb = uint3(0, 255, 255);
        //cBaseColor.a = 255;
   else if((vHeight.w >= (2 * 63.75 + 1) * unit)
   &&   (vHeight.w < (3 * 63.75 + 1) * unit))
        cBaseColor.rgb = uint3(0, 255, 0);
        //cBaseColor.a = 255;
   else if((vHeight.w >= (3 * 63.75 + 1) * unit)
   &&(vHeight.w < (4 * 63.75 + 1) * unit))
        cBaseColor.rgb = uint3(255, 255, 0);

   else if(vHeight.w == 1)
        cBaseColor.rgb = uint3(255, 0, 0);



Below first is how it looks using only the provided texture and second with the added logic AFTER relating it with the texture, meaning not taking of the: 

float4 cBaseColor = g_baseTexture.Sample( g_samLinear, texCoord );

and adding:

float4 vHeight = g_nmhTexture.Sample( g_samLinear, texCoord );

to get information from the heightmap.






Grid tessellation size limit

16 October 2012 - 03:15 PM

Hi guys!

Well sorry for the weird topic title as i don't really get the concept i`m talking about as clearly as i should.

So, i started my project on top of the sample "DetailTessellation11" from DirectxSDK and one of my intentions was to make it create a cylindrical terrain with a size of 1440 x 1653. I can use the image but it doesn't look as detailed as it should be.
Then i found this variable:
[source lang="cpp"]DWORD g_dwGridTessellation[/source]
It is used in a few functions during the program but it's main use is for creating the grid ( in this case a square with the amount of vertex of the grid equal to g_dwGridTessellation*g_dwGridTessellation ).
What i did get is that it determines the amount of vertex of the grid it's creating.

The problem:
Since I need to plot a 1440 x 1653 (or bigger) grid I changed the value of the variable and found out that it can't go over 180 and through breakpoints i have found out that this functions causes an Access violation probably because i`m overflowing a pointer or type of variable.

[source lang="cpp"] // Allocate memory for buffer of indices in system memory WORD* pIndexBuffer = new WORD [nNumIndex]; WORD* pIndex = &pIndexBuffer[0]; // Fill index buffer for ( DWORD i=0; i < dwLength; ++i ) { for ( DWORD j=0; j < dwWidth; ++j ) { *pIndex++ = (WORD)( i * (dwWidth+1) + j ); *pIndex++ = (WORD)( i * (dwWidth+1) + j + 1 ); *pIndex++ = (WORD)( (i+1) * (dwWidth+1) + j ); *pIndex++ = (WORD)( (i+1) * (dwWidth+1) + j ); *pIndex++ = (WORD)( i * (dwWidth+1) + j + 1 ); *pIndex++ = (WORD)( (i+1) * (dwWidth+1) + j + 1 ); } }[/source]
Since this variable is inside a grid creation function it's name has changed to dwLength and dwWidth.

I did some researches and i thought that could be the change from DWORD ( unsigned long) to WORD ( unsigned short ) but couldn't change it in the program for some reason.

So basically am i correct about anything?
Is this a problem with this function or I simply cannot handle that many vertex?
What can i do here? If no possible to handle that should i just make the program create several grids and stick then together?

Thank you for you time!

Making holes on a heightmap based terrain

09 October 2012 - 01:50 PM

I'm currently working on a cylinder shaped terrain produced by a height map. What happens in the program is simple, there is a texture for the colors of the terrain that has the alpha value of regions in with i want it to be invisible and another texture ARGB with the A being the gray scale for the heights and RGB is the normal for the light. The texture is such that the A value goes from 1 to 255 and I'm reserving the 0 for the regions with holes, meaning i don't want then to exist. So in theory no problem, I'm making those regions invisible based on the first texture but on practice what's happening is that the program is considering the 0 as the minimum height and, even with the texture on top, is creating some lines towards this regions of 0, like trying to make its triangle but not getting there because i cut the next vertex by making it invisible.

The image below is with a clip() function making the region invisible

Posted Image

This next image is without the clip function:

Posted Image

Notice the lines going to the center of the cylinder This is how it gets when i stop making those vertex invisible
So, just to say, i used the function Clip() on the pixel shader to make it invisible.

My questions are: Is it possible, the same way i used clip() on the pixel shader i do something like that on the vertex shader and get rid of the unwanted vertex? Basically, is possible to just say to ignore value 0? Any ideas to fix this? Another thing is that we can see that the program is interpolating the values from one vertex to the next, that is why i cuts on halfway through to the invisible vertex.

On a more technical point of view the domain shader is the one picking the heights from the texture and plotting it.

I managed to fix this somehow by modifying the texture, through the program, by changing the 0 values of the heights to a more proper one, but i'd like to know if there's a possibility through the HLSL.

I'm working with Directx11 API with C++ and the program uses Tessellation.
Thank you for your time and will be very glad with any input on this!