Jump to content

  • Log In with Google      Sign In   
  • Create Account


angelmu88

Member Since 09 Dec 2011
Offline Last Active Nov 24 2013 11:26 AM
-----

#4995463 Billboard problem

Posted by angelmu88 on 30 October 2012 - 10:13 AM

Hi, i am using this method for my billboarding.
But it seems that i can only set my billboards at position(0,0,0)
otherwise it displays incorrcect.

I have tried to translate before and after but nothing works.

How can i set any other position than origin?

this is my method:
[source lang="cpp"]void CreateBillboardMatrix(const D3DXVECTOR3& particlePos, const D3DXVECTOR3& cameraPos, D3DXMATRIX& out) { // compute billboard basis D3DXVECTOR3 look = particlePos; look = look - cameraPos; D3DXVec3Normalize(&look,&look); const D3DXVECTOR3 CAMERA_UP_VECTOR(0, 1, 0); D3DXVECTOR3 camUp = CAMERA_UP_VECTOR; D3DXVec3Normalize(&camUp,&camUp); D3DXVECTOR3 right; D3DXVec3Cross(&right,&camUp,&look); D3DXVec3Normalize(&right,&right); D3DXVECTOR3 up; D3DXVec3Cross(&up,&look,&right); D3DXVec3Normalize(&up,&up); // set matrix values D3DXMatrixIdentity(&out); out._11 = right.x; out._12 = right.y; out._13 = right.z; out._21 = up.x; out._22 = up.y; out._23 = up.z; out._31 = look.x; out._32 = look.y; out._33 = look.z; out._41 = particlePos.x; out._42 = particlePos.y; out._43 = particlePos.z; }[/source]


I see an error in your code, the look vector is CameraPos-billboardPos (not the other way around). Take into acount that if you have two positions A and B the vector B-A is facing B.


#4978212 Changing Screen Resolution and Windowed<->Full Screen Toggle

Posted by angelmu88 on 09 September 2012 - 02:31 AM

Hi I'll try to answer your question

I have read that I need to change the D3DPRESENT PARAMS and call Reset() via the Direct3D Device object... But this blew up my game and im not sure why.


That's true you have to call Reset(), but you have to keep some things in mind. Take a look at my enableFullScreen() function:
[source lang="cpp"]void D3DApp::enableFullScreenMode(){// Are we already in fullscreen mode?if( !md3dPP.Windowed ) return;int width = GetSystemMetrics(SM_CXSCREEN);int height = GetSystemMetrics(SM_CYSCREEN);md3dPP.BackBufferFormat = D3DFMT_X8R8G8B8;md3dPP.BackBufferWidth = width;md3dPP.BackBufferHeight = height;md3dPP.Windowed = false;// Reset the device with the changes.onLostDevice();HR(gd3dDevice->Reset(&md3dPP));onResetDevice();}[/source]
md3dPP is a D3DPRESENT_PARAMETERS (like the one you use to create the device).
Notice that before calling device->Reset() I call a method named onLostDevice() and after calling device->Reset() I call onResetDevice().
What onLostDevice() does is to prepare all your game assets (textures, meshes, etc) for a device resetting, for instance, any D3DAsset has to placed in what is called a memory pool, let's say you create a texture and you specify you're going to use de D3DPOOL_DEFAULT, in that case, objects placed in that pool need to be destroyed before calling device->Reset() and reinitialized after that. Some other objects like dynamic renderTargets need to be destroyed too. I suppose that's why you're game is crashing when you call Reset(), because you're not taking this into account. (In the previous example you can place your texture in the D3DPOOL_MANAGED so that you don't have to destroy the texture)

How do you guys handle rendering? For example, say my window is of size 1024 by 768. Lets say I render my Texture (with the transformation matrix) at point 1024, 768 (centred) - This obviously renders right at the bottom right of the screen... but lets say the user changes the resolution settings to 1920 by 1080. That image is no longer rendered at the bottom right of the screen


That's true, for 2D objects you have to take into account the window size when you're rendering them, so if you were drawing your texture like this:
texture->Draw(0,0,1024,768)
Now you have to draw like this:
texture->Draw(0,0,1920,1080)

(The same goes with other 2D objects like plain Text)

For 3D objects you don't have to worry, the only thing you have to know is that when you change to a higher resolution you're going to see more things of your scene, i.e, your field of view is going to change to a bigger one (usually you specify a vertical field of view, so It's the horizontal field of view that changes).


#4975499 Support Directx 9 and Directx 11 (both)

Posted by angelmu88 on 01 September 2012 - 12:15 PM




In most cases I tried to create a hierarchical model, so I have classes that interacts directly with D3D (basic classes) and classes that only use those basic classes and do not interact with D3D. is that what you mean?

Yes that's what I meant. So, the lower level of your hierarchy, which deals directly with D3D9, will have to be entirely re-written Posted Image
Large parts of it may be similar in the D3D11 rewrite, but none of it will likely be reusable without modification.

I would recommend separating your D3D9 and D3D11 code via #ifdefs, and only compiling for one at a time (which means you've got two different EXEs - one for people on WinXP, and one for people on Win7).
However, you could alternatively make your "wrapper" into abstract-base-classes with virtual methods if that's more attractive to you.


The good thing about the second option (virtual methods) is that I only have one .exe and I can decide wheter I use D3D9 or D3D11 at run-time, isn't it?

Actually I was looking in the Crysis 2 installation folder (Crysis 2 let you use both D3D9 and D3D11) and I found only one .exe(Crysis2.exe) and two dll's :one for D3D9 (CryRenderD3D9.dll) and another for D3D11(CryRenderD3D11.dll); So I supose they're using something similar to the "virtual method approach". Am I right?


Actually if ou think about it, this means they used the #ifdef approach, because there are 2 different DLLs. I expect this is because there is overhead with virtual functions (very very small), and they want their graphics to run as quickly as possible


But #ifdef is a preprocessor directive, that means you have to recompile every time you change from D3D9 to D3D11 (or from D3D11 to D3D9). You could aslo have two .exe files but as I said there's only one .exe and I don't think they recompile every time you enable or disable D3D11 in the options menu. Maybe there's another option I'm missing.


#4975466 Support Directx 9 and Directx 11 (both)

Posted by angelmu88 on 01 September 2012 - 10:11 AM


In most cases I tried to create a hierarchical model, so I have classes that interacts directly with D3D (basic classes) and classes that only use those basic classes and do not interact with D3D. is that what you mean?

Yes that's what I meant. So, the lower level of your hierarchy, which deals directly with D3D9, will have to be entirely re-written Posted Image
Large parts of it may be similar in the D3D11 rewrite, but none of it will likely be reusable without modification.

I would recommend separating your D3D9 and D3D11 code via #ifdefs, and only compiling for one at a time (which means you've got two different EXEs - one for people on WinXP, and one for people on Win7).
However, you could alternatively make your "wrapper" into abstract-base-classes with virtual methods if that's more attractive to you.


The good thing about the second option (virtual methods) is that I only have one .exe and I can decide wheter I use D3D9 or D3D11 at run-time, isn't it?

Actually I was looking in the Crysis 2 installation folder (Crysis 2 let you use both D3D9 and D3D11) and I found only one .exe(Crysis2.exe) and two dll's :one for D3D9 (CryRenderD3D9.dll) and another for D3D11(CryRenderD3D11.dll); So I supose they're using something similar to the "virtual method approach". Am I right?


#4975439 Support Directx 9 and Directx 11 (both)

Posted by angelmu88 on 01 September 2012 - 08:59 AM

but I don't want to rewrite the whole code

Any of your code that interacts with the Direct3D API will need to be re-written.

Have you written your own D3D wrapper so that only some of your code interacts with D3D directly (and the rest interacts with your wrapper), or does your whole engine use parts of D3D?


No, not all my code interacts with D3D. In most cases I tried to create a hierarchical model, so I have classes that interacts directly with D3D (basic classes) and classes that only use those basic classes and do not interact with D3D. is that what you mean?


#4975431 Support Directx 9 and Directx 11 (both)

Posted by angelmu88 on 01 September 2012 - 07:56 AM

Hi!
I have my own graphic engine written in DirectX 9.0c. Now I want to add new DirectX 11 features like hardware tesselation, but I don't want to rewrite the whole code, I just want to support both DirectX 9 and DirectX 11. For instance, Unreal let you switch between a DirectX 9 renderer and a DirectX 11 one.
How could I do that as soon as posible?
Thanks!


#4897434 Per pixel point light: interpolating vertex world pos

Posted by angelmu88 on 26 December 2011 - 07:26 AM

You will get the same results by interpolating the positing and then computing the light direction in the pixel shader...this is because vertex positions can be linearly interpolated. So you don't have anything to worry about.

Out of curiosity, wich kind of data can I interpolate?
Because I was thinking of interpolating tangents too for normal mapping, for the same reason I stated earlier (add as many lights as possible)
Thanks!





#4897104 Per pixel point light: interpolating vertex world pos

Posted by angelmu88 on 24 December 2011 - 11:34 AM

Hi!
I'm working on a point light per-pixel based shader. I've read a lot of info about this topic, and most of the time people compute light direction in the vertex shader and pass it to the pixel shader along with vertex normal. The problem is that I want to add multiple point lights, so I am limited by the number of registers the vertex shader can pass to the pixel shader. I've seen another web example and I think that I could propably pass the vertex world position to the pixel shader and compute the light Direction in the pixel shader, but I don't know if it results in a good per-pixel light effect, I mean, I am no longer interpolating the light direction, instead I am interpolating vertex position in worldspace. Does anyone know if it's ok?


#4895324 Fixing environments too flat

Posted by angelmu88 on 19 December 2011 - 09:47 AM

that grass in that video is fine, you just got to cast a pack of secondary rays out for shadows, if you use the heightmap of the terrain with the grass noise map you could even get the parallax shadows to capture divots and small hills, thats whats happening in that shot I showed you... that must be the only difference. Its actually not very hard, what about it dont you understand? (but yeh its heavy on samples or you get a noisy output)

I think I get your point. But I think I will go fo ar less heavy effect without self shadowing, at least int he beginning. Thanks for your help.





PARTNERS