Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

229 Neutral

About keym

  • Rank
  1. keym

    Deferred depth problem

    So I guees I have to also do this:     from: //From [0,1] to [-1,-1] in xyz float3 ndcPos = (float3(texCoord.x, 1 - texCoord.y, depth2) - 0.5) * 2.0;   to: //From [0,1] to [-1,1] only in xy, z stays in [0,1] float3 ndcPos = float3(texCoord.x, 1 - texCoord.y, depth2); ndcPos.xy = (ndcPos.xy - 0.5) * 2;   But this ^ and changing C to zNear*zFar sadly doesn't produce correct results. : /   Edit: For generating projection matrix I use D3DXMatrixPerspectiveFovRH (right handed coordinate system).  
  2. Hi guys, I'm struggling again with my deferred renderer. This time I'm rewriting it from OpenGL/Cg to DX11/HLSL. I have almost everything working but (I think) my reconstruction from depth is now working correctly (I compared normals and they look the same as in OGL renderer, so I guess they are fine). The result I get is somewhat correct but bad things start to happen when I move away from the lit object - It becomes darker and darker and eventually gets all black. The thing is that I use almost the same code as when dealing with Cg/OGL and perhaps I've overlooked something with conversion. Fun fact - walls that are closer to the camera gets darker quicker than walls that are further away - maybe this will give some hint.   Posting pics         //compute view space position     #define ZNEAR zNearZFar.x     #define ZFAR zNearZFar.y     #define A (ZNEAR + ZFAR)     #define B (ZNEAR - ZFAR)     #define C (2.0 * ZNEAR * ZFAR)     #define D (ndcPos.z * B)     #define ZEYE (-C / (A + D))     float depth2 = shaderTexture2.Sample(SampleType, texCoord);     float3 ndcPos = (float3(texCoord.x, 1 - texCoord.y, depth2) - 0.5) * 2.0; //<<<Here I had to flip Y coord when compared to the OGL/Cg shader     float4 clipPos;     clipPos.w = -ZEYE; = ndcPos * clipPos.w;     float3 vsPos = mul(invProj, clipPos).xyz;  
  3. Ok, it seems that the problem was related to my part of code responsible for resizing texture that I use for drawing. When I fixed it, it now works as I want (clipping on sides when the window is taller than wider). I don't even have to alter aspect value and perspective matrix in any way. Funny how often you resolve problems after posting ><   Anyways, thanks for looking ya'll.
  4. Yes, I was casting them to floats from the very beginning so that's not the issue. Thanks though.
  5. Hello, I'm having troubles with maintaining aspect ratio while my window is taller than wider. How do I readjust that in my perspective matrix? I calculate aspect ratio simply dividing width / height and it works great when window is wider than taller but the other way around my image is stretched. Any solutions to this? I make my perspective matrix using D3DXMatrixPerspectiveFovRH.
  6. keym

    Picking in DX11

    Solved.   Looks like all my math was ok but I forgot one thing - my rendering WinAPi control has an offset in x,y (cause I have sidebar and other stuff on the side) and I forgot to take that into account when reading mouse position over the viewport. For instance I got [0,0] at the origin of the window, not the rendering control. Now all works well. Thanks for looking.
  7. keym

    Picking in DX11

    Well... shouldn't this be that simple:   object space ----[world a.k.a. model matrix]----> world space world space ----[view a.k.a. camera matrix]----> view space view space ----[projection matrix]----> clip space   object space <----[inverse world a.k.a. model matrix]---- world space world space <----[inverse view a.k.a. camera matrix]---- view space view space <----[inverse projection matrix]---- clip space   ?   Anyways, this is how it *seems right* to me, but I'm not a guru here. Maybe I'm being picky ;) about naming and that was not the intention of this topic (but still I wanted to clarify naming before I ask my question(s) and make more confusion).   So, the reason I post is because (obviously) I have a problem with picking. The issue here is that in my renderer I use right hand coordinate system, like in OpenGL (for sake of compatibility, I have OGL renderer in this app too and I don't want to negate every needed value to get the same result, it would only make more future errors).   So I construct my projection matrix using D3DXMatrixPerspectiveFovRH() and view matrix using D3DXMatrixLookAtRH(). Before sending them to HLSL I transpose them (for some reason I have to do this, otherwise I get incorrect results [DX stores matrices in row major, but in HLSL they need to be in column major?]). All is sweet and dandy until picking occurs. I'm pretty sure that I'm doing something wrong, because this is my first attempt with renderer independent picking. I follow what's in the tutorial but intersection test gives incorrect results. For sake of simplicity my sphere is at (0,0,0) so I don't have to care about world and invWorld matrices. I'm guessing that something is wrong with my matrices but it's hard to track down.   Also I'm not sure what's going on here (tutorial):   // Adjust the points using the projection matrix to account for the aspect ratio of the viewport. m_D3D->GetProjectionMatrix(projectionMatrix); pointX = pointX / projectionMatrix._11; pointY = pointY / projectionMatrix._22;   and how exactly the unprojecting part works. I mean I have mouse coordinates that I rescale into -1, 1 range but how do I get from vec2 to vec3? Where does the 3rd component come from?
  8. Hello, I'm trying to make picking working following this tutorial:   I'm not sure is it me or the author confuses spaces at the end of this tutorial? Can someone have a fresh look at this? Namely he states that multyplying vector by inverse view matrix we get the result in view space. Shouldn't it be in world space? And then we go from world into object space and there make final test? His ray intersection doesn't take into account sphere position so final test looks like it's in object space, but he also says it's in world space... So yeah, thoughts?
  9. keym

    Texture from memory

    Thank you very much! Works like a charm. For other googlers - don't forget to set D3D11_BIND_SHADER_RESOURCE in your texture descriptor structure.
  10. Hello, I have simple (I think) problem for all guys with D3D11 background - I already have working TGA loader and now I want to pass this raw data to D3D, create a texture and use it in shader. How do I do that? I googled and only tutorials/helpful tips I could find cover D3D loaders with D3DX11CreateShaderResourceViewFromFile. I can see that there's a D3DX11CreateShaderResourceViewFromMemory but I'm not sure how to use it - the texture appears black (I get E_FAIL result so I must be doing something wrong). What's the usual procedure? I would really appreciate a sample code or snippet, cause it's hard to find anything useful except msdn which is still kinda mystical to me.
  11. keym

    SLERP issues

    Bump. Still stuck.
  12. keym

    SLERP issues

    Unfortunately normalising doesn't make a diffrence. I guess it only matters with (n)lerp anyway. I'm starting to think that maybe I should rebuild the positions, as C0lumbo suggested (even though I'm lerping in object space...), but not sure where to start with that.
  13. keym

    SLERP issues

    I'm interpolating in object space. Does this require rebuilding bone positions from hierarchy as well?   And my SLERP looks like this: quaternion quaternion::slerp(quaternion q1, quaternion q2, float percent) {     quaternion result;     float dot = q1.dotProduct(q2);              //Dot product - the cosine of the angle between 2 quats     if(dot < -1) dot = -1;                      //Clamp value to [-1,1], just to be sure     if(dot > 1) dot = 1;          if(dot < 0)                                  //If cos(angle) is <0 we negate the quaternion and dotp.     {                                            //(Go with smaller rotation)         q2=-q2;         dot=-dot;     }     if(dot > 0.99 && dot < 1.01) //If dotp is close to 1, do Lerp     {         result = q1 + ((q2 - q1) * percent);         result.normalize();         return result;     }     if(percent < 0.01)             //If percent is close to 0, return quat1     { result = q1;      return result; }     if(percent > 0.99)         //If percent is close to 1, return quat2     { result=q2;         return result;     }     float a = acos(dot);          //Get angle between quats     result = (q1 * (sin((1.0 - percent) * a) / sin(a))) +  ((q2 * sin(percent * a)) / sin(a));     return result; }
  14. keym

    SLERP issues

    First of all I doubt that the animation is wrong - it's directly ripped (for educational purposes only!) from Doom3 (directly meaning from the pk4 file, not downloaded from some crappy site). Walk cycle looks ok when played itself.   As I have written, that blending is capped to 0-50%, meaning at max we have 50%-50% of animation-bindpose mix and at min we have 0-100% proportion (no animation, just plain bind pose - parts of the vid where the model is not moving). I did it to emphasise where the problem occurs. If I would do 100%-0%, most of the time you would just see the original walk animation without popping. At the beginning of the video you see roughly 50%-50%.   I tried with Nlerp but it looks even worse - body is completely dismembered and limbs are spinning in various directions and I'm like WTF.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!