Jump to content

  • Log In with Google      Sign In   
  • Create Account

ekba89

Member Since 02 Apr 2011
Offline Last Active Today, 01:09 PM

#5164185 Problems passing an XMFLOAT4 to a shader

Posted by ekba89 on 01 July 2014 - 07:16 PM

I think the reason is you are not adding D3D11_CPU_ACCESS_WRITE flag to your constant buffer. Since you are writing data from CPU you need to use that flag.




#5163004 Questions about game developing

Posted by ekba89 on 26 June 2014 - 07:18 AM

I have Direct X SDK.So, I must link it to visual studio and start learning ,right?

Yes. And if you start with the tutorial in that web page it starts with a tutorial to how to link it properly. Also I forgot to mention but Frank Luna's books are great for Direct X reference, it tells you most of the stuff that you need to know with detail. http://www.d3dcoder.net/ this is his web page and you can buy the book depending on the version of Direct X you want to learn. I am assuming you are going for Direct X 11.




#5162878 Questions about game developing

Posted by ekba89 on 25 June 2014 - 06:05 PM

Hey.

 

1- I haven't tried Code::Blocks so I can't say anything about that but I am using Visual Studio and I am pretty happy with it. Also you might need Windows SDK or Direct X sdk. Windows SDK is newer but you need Windows 7 or 8.

2- If you really want to learn what is going on with Direct X I recommend you to create your own small applications. Since most of the game engines hide the complexities from the user it is hard to learn really what is going on by learning a game engine.

3-http://www.rastertek.com/




#5151713 Constant buffers and shader variables

Posted by ekba89 on 05 May 2014 - 03:39 PM

It makes sense that different shaders have different constant buffers. One trick that you can do if you are trying to get some global variables is you can create a header file.

// MyGlobalShaderHeader.hlsli

cbuffer globalEveryFrame : register(b0)
{
     matrix viewMatrix;
     float4 elapsedTime; // size needs to be multiple of 16 anyways
} 

And lets say you are using this for vertex shader. Then you can set it once in the beginning of rendering

deviceContext->VSSetConstantBuffers(0, 1, &myBuffer);

Now you can use it for all the vertex shaders that include that header. Only thing you need to be careful about is you have to make sure that you don't change register 0 between shaders that need those global variables.

 

So if you are trying to create a global buffer you can use that trick. But if those variables are shader specific I think it is better idea to have different constant buffers for different shaders. It is much more manageable that way. So every material can know which buffers they are responsible from.

 

One side not though as I wrote in the comment above constant buffers are automatically become multiple of 16 bytes. So lets say you put 1 float2 and 1 float it occupies float4 space. So when you are setting your bytewidth it needs to be multiple of 16 bytes otherwise you will get an error.




#5150624 vs 5_0 texture sampling

Posted by ekba89 on 30 April 2014 - 02:33 PM

Yeah that fixed my problem thanks for the help.




#5148622 Understanding a (d3dx) model matrix's content

Posted by ekba89 on 21 April 2014 - 05:55 PM

Your vector should be like [ 1.0 ] [ 2.0 ] [ 0.0 ] [ 1.0 ] since you are using row major and your vector should be on the left side of your matrix when you are multiplying. (V x M).

 

- if I want to extract a vector from the matrix, that gives my either X, Y or Z orientation (without translation), I could use the 1st three components of row 1, 2 or 3

Yes but you should take scaling into consideration so you need to normalize each axis.

 

=> the X component of the vector is only affected by the 1st row of the matrix

=> the Y component of the vector is only affected by the 2nd row of the matrix

=> the Z component of the vector is only affected by the 3rd row of the matrix

Your result vector's x component is effected by first column of the matrix, y is effected by second column and so on. And as a result you get another row vector. I suggest you to read some tutorials about matrices if you are having trouble with multiplication before starting to get deeper since you will need a good understanding for the basics.

 




#5148392 3D model render sequence

Posted by ekba89 on 20 April 2014 - 12:55 PM


@ekba89 Do I need to reset the render states every draw cycle?

 

You might have different render states for different models. So you have to change them depending on what you are trying to do. But for the normal 3D rendering default settings should suffice. If all your models are using default render states you just need to set them once in the beginning of your application. But as I said SpriteBatch changes it before it does its 2D rendering. So if you are using SpriteBatch and some 3D models you need to reset your render states every time before you render your 3D models.




#5148284 3D model render sequence

Posted by ekba89 on 19 April 2014 - 10:45 PM

It looks like you have problem with your depth stencil state. If you are using SpriteFonts they might change your render states so you need to reset them before 3D rendering. Try to put the code below just before your rendering.

GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;



#5145359 raw input mouse problem

Posted by ekba89 on 08 April 2014 - 08:53 AM

 


if(PeekMessage(&message, hWnd, 0, 0, PM_REMOVE)) { if(message.message == WM_QUIT) { return false; } else { TranslateMessage(&message); DispatchMessage(&message); } }

The delay you mention above is likely because you process only one message per render loop. That will probably be corrected if you change that to:

while( PeekMessage(..))
{
   ...
}

 

Thanks this solved my problem and increased my FPS. Also I change my mouse position code a little

This

mouseInfo.movementX = raw->data.mouse.lLastX;
mouseInfo.movementY = raw->data.mouse.lLastY;

to

mouseInfo.movementX += raw->data.mouse.lLastX;
mouseInfo.movementY += raw->data.mouse.lLastY;

Since that while loop can call this function more than once. And in my Update function for input manager I reset them to 0 after I process the current value.




#5144432 raw input mouse problem

Posted by ekba89 on 04 April 2014 - 02:24 PM

Mine never gets absolute motion. I have tried putting it inside if statement to see what I get and it is always relative. And I tried printing it out too and I get values between -3 and 3.




#5144428 raw input mouse problem

Posted by ekba89 on 04 April 2014 - 01:57 PM

According to MSDN lastX and lastY value are relative to the last position. So they are not screen coordinates and they become 0 if you dont move the mouse. Also as I said as soon as I stop take of my finger from the left mouse button values become 0 again. My problem is they are not getting updated when mouse button is clicked.




#5144405 raw input mouse problem

Posted by ekba89 on 04 April 2014 - 12:29 PM

I created a simple input system and it works mostly. Right now I have a camera that is moved with the mouse when left button is clicked. The problem I am having is when mouse button is clicked even when I stop moving the mouse lastX or lastY doesnt become 0 and camera keeps moving until I stop clicking the button. Here is my code

//InputManager::HandleInput() function

UINT dwSize;

GetRawInputData(rawInput, RID_INPUT, 0, &dwSize, sizeof(RAWINPUTHEADER));

LPBYTE lpb = new BYTE[40];
	
if(GetRawInputData(rawInput, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize)
{
	OutputDebugString("Cannot get raw input data!");
}

if(raw->header.dwType == RIM_TYPEMOUSE)
    {
        mouseInfo.movementX = raw->data.mouse.lLastX;
        mouseInfo.movementY = raw->data.mouse.lLastY;
        //printf("mouse movement x=%d, y=%d\n", raw->data.mouse.lLastX, raw->data.mouse.lLastY);

        bool downState = (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) > 0;
        bool upState = (raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) > 0;

        if(downState == true && upState == false)
        {
            mouseInfo.leftButton = true;
        }
        if(upState == true)
        {
            mouseInfo.leftButton = false;
        }

        downState = (raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) > 0;
        upState = (raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) > 0;

        if(downState == true && upState == false)
        {
            mouseInfo.rightButton = true;
        }
        if(upState == true)
        {
            mouseInfo.rightButton = false;
        }
    }



#4961299 Rendering a space skybox

Posted by ekba89 on 20 July 2012 - 06:36 AM

It is most likely because of your texture size is small for the skybox you are using.You can resize your skybox to lets say half of its current size with scale matrix and see if it looks good. And if it looks good that means you need double of the size of your current texture. By using different scale matrices you can find how big texture you need.


#4946790 volumetric cloud

Posted by ekba89 on 06 June 2012 - 10:17 AM

I have managed to solve that issue and make it work but it is not as good as I hoped there are artifacts when I try to move camera around the cloud . And now I'm trying to render real volumetric clouds so I can rotate around it and it look better. So I started this tutorial series. But he uses a loop with 512 iterations in his shader for sampling volume and when I try to do the same thing with directx 11 it shows a white screen for a while and i get error. Then I tried his code with my laptop (because xna is installed in it) which has a lot worse specs than my pc and it worked with 3 fps. So obviously I'm doing something wrong but before trying to solve what is wrong with my code I want to know if it is possible to get good framerates in games using volumetric rendering techniques since I get 3 fps with just rendering the volume with decent computer. If not are there any techniques that you can suggest for me for rendering clouds.


#4941618 volumetric cloud

Posted by ekba89 on 20 May 2012 - 04:55 AM

Hi I'm trying to create volumetric clouds using this tutorial. (And here is the original slides). I don't have any problems to the part where I need to distort the cloud map.Currently I'm using only one sphere just to test it. Here is the code where I do distortion.

[maxvertexcount(4)]
void GSMain(point VS_In p[1], inout TriangleStream<PS_In> billboardStream)
{
float3 eyeVec = normalize(p[0].position - cameraPosition);
float3 sideDir = cross(cameraUp, eyeVec);
PS_In vertex = (PS_In)0;
//left bottom
vertex.position = float4(p[0].position - sideDir*CLOUD_SIZE - cameraUp*CLOUD_SIZE, 1.0f);
vertex.worldPos = vertex.position;
vertex.position = mul(vertex.position, viewProjectionMatrix);
vertex.projectedPos = vertex.position;
vertex.textureCoords = float2(0, 1);
billboardStream.Append(vertex);
//left top
vertex.position = float4(p[0].position - sideDir*CLOUD_SIZE + cameraUp*CLOUD_SIZE, 1.0f);
vertex.worldPos = vertex.position;
vertex.position = mul(vertex.position, viewProjectionMatrix);
vertex.projectedPos = vertex.position;
vertex.textureCoords = float2(0, 0);
billboardStream.Append(vertex);
//right bottom
vertex.position = float4(p[0].position + sideDir*CLOUD_SIZE - cameraUp*CLOUD_SIZE, 1.0f);
vertex.worldPos = vertex.position;
vertex.position = mul(vertex.position, viewProjectionMatrix);
vertex.projectedPos = vertex.position;
vertex.textureCoords = float2(1, 1);
billboardStream.Append(vertex);
//right top
vertex.position = float4(p[0].position + sideDir*CLOUD_SIZE + cameraUp*CLOUD_SIZE, 1.0f);
vertex.worldPos = vertex.position;
vertex.position = mul(vertex.position, viewProjectionMatrix);
vertex.projectedPos = vertex.position;
vertex.textureCoords = float2(1, 0);
billboardStream.Append(vertex);
billboardStream.RestartStrip();
}
float4 PSMain(PS_In fragment) : SV_TARGET0
{
float2 offset = perlinNoise.Sample(cloudSampler, fragment.textureCoords).rg;
offset = offset * 2.0f - 1.0f;
float4 color;
color = cloudTexture.Sample(cloudSampler, fragment.projectedPos + offset / length(cameraPosition - fragment.worldPos));
//color = float4(1.0f, 0.0f, 0.0f, 1.0f);
return color;
}

As you can see in the first screenshot billboard and sphere is fine (It was the easy part anyways :D). And other two screenshots are the results with different camera positions.

And lastly are there any other good looking volumetric cloud tutorials you can suggest. I searched a little but most of the tutorials are very old so I am curious if there are any newer techniques for volumetric clouds. Thanks.

Attached Thumbnails

  • SphereAndBillboard.jpg
  • Result1.jpg
  • Result2.jpg



PARTNERS