relaxok

Members
  • Content count

    31
  • Joined

  • Last visited

Community Reputation

137 Neutral

About relaxok

  • Rank
    Member
  1. HLSL - Billboarding a mesh

      I'm not quite following your description, sorry... but maybe this is going back to what you're referring to.. this and showing both sides of the mesh, I do get fairly close.. // billboard? if( flags & PER_MESH_FLAG_BILLBOARD ) { matrix worldViewMat = mul( worldMatrixInstance, viewMatrix ); output.position = skinnedPos + float4( worldViewMat._41, worldViewMat._42, worldViewMat._43, 1.0f ); } output.position = mul( output.position, projectionMatrix ); But as you can see, while the distance of the camera is accounted for fine.. the proper translation doesn't happen when the camera rotates on axes..   http://bh.polpo.org/billboard_rotate_issue.wmv   What's the reason for this?
  2. HLSL - Billboarding a mesh

    Because it undoes the rotation applied by the camera…   Why don’t you just quickly make the WBP (world-billboard-projection) matrix and be done with all that ridiculous math?   XMMATRIX mBillboard; XMMatrixInverse( &mBillboard, m_matView ); // m_matView is the inverse of another matrix, so instead of inverting it again you could just copy that matrix. // Only keep the upper-left 3×3. mBillboard._41 = mBillboard._42 = mBillboard._43 = 0.0f; // Billboard matrix complete. XMMATRIX mBillboardView = mBillboard * m_matView; // Can be used instead of the view matrix. XMMATRIX mBillboardViewProjection = mBillboardView * m_matProj; // Can be used instead of the view-projection matrix. Why make it so complicated? L. Spiro     The reason it's all spread out is that it's not working yet, and this way I can experiment with changing individual elements.   I have tried everything suggested in this thread and it's still not working.  Using your suggested method in the above quote, the mesh simply doesn't appear at all, the same as most other attempts..   Still the closest I've gotten is using the inverses of the rotation matrices, but the vertices translate all over the place in this case.. as shown in the video i linked.
  3. HLSL - Billboarding a mesh

    My new idea was to try making a billboarding view matrix which does the translation based on the real camera rotations, but for the rotation part of the view matrix, uses the inverse matrices.   This results in ALMOST the correct result.. the mesh now stays 'camera facing' no matter what the camera is doing, however the translation seems to put it all over the place.  I'm wondering how this can be when the translation is the same as when not billboarding:   http://bh.polpo.org/quad_no_rot1.avi   What adjustment can I make to keep the translation correct? void CCamera::transform( float x, float y, float z, float fOrientation ) { XMMATRIX matRotationX = XMMatrixRotationX( m_Pitch ); XMMATRIX matRotationY = XMMatrixRotationY( XMConvertToRadians( fOrientation * 360.0f ) + m_Yaw ); XMVECTOR unitVec = XMVectorSet( 0.0f, m_Height, -m_Distance, 0.0f ); XMVECTOR transVec = XMVector3TransformCoord( unitVec, matRotationX * matRotationY ); m_posX = x + XMVectorGetX( transVec ); m_posY = y + XMVectorGetY( transVec ); m_posZ = z + XMVectorGetZ( transVec ); XMMATRIX matTranslation = XMMatrixTranslation( m_posX, m_posY, m_posZ ); XMVECTOR matInvDeter; XMMATRIX matInverse = XMMatrixInverse( &matInvDeter, matRotationX * matRotationY ); XMMATRIX matTransInverse = XMMatrixInverse( &matInvDeter, matTranslation ); // Billboard version XMVECTOR matRotBillboardDeter; XMMATRIX matRotationXBillboard = XMMatrixInverse( &matRotBillboardDeter, matRotationX ); XMMATRIX matRotationYBillboard = XMMatrixInverse( &matRotBillboardDeter, matRotationY ); XMMATRIX matInverseBillboard = XMMatrixInverse( &matInvDeterBillboard, matRotationXBillboard * matRotationYBillboard ); XMStoreFloat4x4( &m_matView, matTransInverse * matInverse ); XMStoreFloat4x4( &m_matBillboard, matTransInverse * matInverseBillboard ); XMStoreFloat4x4( &m_matRotationX, matRotationX ); XMStoreFloat4x4( &m_matRotationY, matRotationY ); XMStoreFloat4x4( &m_matTranslation, matTranslation ); calculateViewFrustum(); }
  4. HLSL - Billboarding a mesh

      Why would that accomplish not rotating it?
  5. HLSL - Billboarding a mesh

    Isn't the line:   float3 position = input.position + float3( boneWorldViewMatrix._41, boneWorldViewMatrix._42, boneWorldViewMatrix._43 );   supposed to do exactly that?  adjust by the translation only..
  6. HLSL - Billboarding a mesh

      It seems like that's what I'm doing?   Latest attempt: // billboard? if( flags & PER_MESH_FLAG_BILLBOARD ) { matrix boneWorldMatrix = mul( bonematrix, worldMatrixInstance ); matrix boneWorldViewMatrix = mul( boneWorldMatrix, viewMatrix ); float3 position = input.position + float3( boneWorldViewMatrix._41, boneWorldViewMatrix._42, boneWorldViewMatrix._43 ); output.position = mul( float4( position, 1.0f ), projectionMatrix ); } else { output.position = mul(output.position, projectionMatrix); }
  7. Guys:   I have a vertex shader that I use for all my non-terrain models.  My per-mesh structure has a flags uint where i can set things like billboard, unlit, etc.  Some models have single meshes that need to be billboarded, like a light halo that looks the same from any angle.  However, I can't figure out how to successfully billboard the mesh.   Below is my vertex shader.. in the billboard section I've tried various combinations of matrices as you can see.. based on MJP's response in this topic:     http://www.gamedev.net/topic/507808-hlsl-billboard/ PixelInputType VS(VertexInputType input, uint InstanceID : SV_InstanceID ) { PixelInputType output; // Fix w input.position.w = 1.0f; // Calculate animation matrices matrix bonematrix = ( float( input.boneweight0 ) / 255.0f ) * BoneMatrices[ input.boneindex0 ]; bonematrix += ( float( input.boneweight1 ) / 255.0f ) * BoneMatrices[ input.boneindex1 ]; bonematrix += ( float( input.boneweight2 ) / 255.0f ) * BoneMatrices[ input.boneindex2 ]; bonematrix += ( float( input.boneweight3 ) / 255.0f ) * BoneMatrices[ input.boneindex3 ]; // World matrix from instance buffer matrix worldMatrixInstance = InstanceLocations[ InstanceID ]; // Transform via combined bones + world matrix output.position = mul(input.position, bonematrix); output.position = mul(output.position, worldMatrixInstance ); // Animate normal the same way output.normal = mul(input.normal, bonematrix); output.normal = mul(output.normal, worldMatrixInstance ); // Camera view output.position = mul(output.position, viewMatrix); float4 cameraPosition = output.position; // vertex color output.vertex_color = input.vertex_color; // billboard? if( flags & PER_MESH_FLAG_BILLBOARD ) { matrix boneWorldMat = mul( bonematrix, worldMatrixInstance ); matrix boneWorldViewMat = mul( boneWorldMat, viewMatrix ); //output.position = input.position + float4( boneWorldMat._41, boneWorldMat._42, boneWorldMat._43, 1.0f ); output.position = input.position + float4( boneWorldViewMat._41, boneWorldViewMat._42, boneWorldViewMat._43, 1.0f ); //output.position = input.position + float4( viewMatrix._41, viewMatrix._42, viewMatrix._43, 1.0f ); } output.position = mul(output.position, projectionMatrix); output.tex = input.tex; // Fog calc output.fogFactor = saturate((fogEnd - cameraPosition.z) / (fogEnd - fogStart)); output.instance = InstanceID; return output; } I am using a y-up system, if it matters.   Please note there are no issues with the shader outside of the billboarding so please no recommendations on other things I can do differently.  I just want to know how to billboard within the context of what you see here.   Thanks..
  8. I finally figured out the issue. Apparently, you can't bind a cbuffer to to register cb1 and set it in code to slot 1, if there's nothing in slot 0. If you do, the shader will just use garbage data for the values in your cbuffer structure (well, seemed to be 0's in this case). I don't know if this is a driver bug or just a quirk, but there you go.
  9. [quote name='phantom' timestamp='1333402560' post='4927648'] Assuming you aren't using deferred contexts then all draw calls are executed when the draw functions are called' nothing is deferred until 'later' and all state during execution would be as it is when that call is made. [/quote] I am using deferred contexts but only to prepare buffers and stuff, not when drawing... Everyone always tells me it's just a PIX bug if it shows wrong values in registers and that it's not reliable.. I guess i can't really be sure until i get a machine with 2 videcoards and can debug shaders with nsight? This is flat out insane that it seems to be doing this..
  10. [quote name='phantom' timestamp='1333401123' post='4927635'] OMSetBlendState isn't so much 'per draw call' as it is 'set until it is changed again'. Based on what you are seeing it sounds like on the 2nd run of the rendering loop the blend state isn't being set correctly, which I personally would attribute to a bug in your code rather than any sort of DX/driver issues. The best advice I can give is to look at the device state at each draw call in PIX to see what is going on; you'll probably want to capture a couple of frames and certainly will want to grab the first frame to see if your state is even being set correctly. [/quote] Speaking of PIX this kind of relates to the other issue -- if i use PIX, the values in the lighting params constant buffer seem to be wrong as if they're using the values from the most recent map/unmap to the cbuffer. The same deal as the above, im updating the lighting cbuffer inbetween draw calls but in PIX when i debug that first draw call, the registers show the values of what would be the cbuffer state used for the 2nd draw call. I thought maybe these two items were both related to some setup/config error, where all the draw calls are actually deferred to the end and only use the 'last' states set in the frame. If i debug the copy to cbuffer, or the OMSetBlendState and look at the values they're 100% correct. It is however wrong in practice and in PIX. Again, PIX shows cbuffer values set inbewteen 1st and 2nd draw call, even when looking at the device state during the first draw call.
  11. [quote name='iedoc' timestamp='1333356231' post='4927405'] try drawing transparent objects last. You should always draw the transparent objects last anyway so that they have something to blend with on the back buffer. if they are drawn first, they will only blend with whatever is drawn before them, which in this case, it sounds like nothing is drawn before the transparent object, so it probably doesn't appear transparent if it happens to be in front of the opaque object, since the opaque object is drawn last, hope that makes sense Otherwise, try just adding the line "clip(diffuse.a - 0.25f);" in your pixel shader. this will "clip" or just not draw any pixels with an alpha value of less than .25. [/quote] Hmm let me try to be more clear.. i'm drawing 2 meshes 1) uses a transparent blend state, imagine a model of a plant where you want to not render the parts of the texture that have 0 alpha 2) drawn opaquely - blending turned off. this is just a regular basic textured model mesh the two meshes are not the same object, the geometry is in different areas. i do the following 1) set blend state to the alpha enabled state (your basic alpha, inv alpha blend) 2) draw mesh #1 (needs this transparency) 3) set blend state to the blend disabled state 4) draw mesh #2 (needs to be opaque) The result on the backbuffer is that mesh #1 is drawn opaquely, not just mesh #2. If i change the code to draw mesh #1 only, it is drawn correctly with transparency. This seems to indicate that the first blend state I set is not used for the first draw call. Regardless of best practices for rendering order, doesn't this seem wrong?
  12. Hi! I have a situation that boggles my mind. If i have two meshes, and i use OMSetBlendState before drawing each one (with DrawIndexed), both of them seem to be using whatever the most recent blend state that was set. EIther that, or the map/unmap of the lighting properties buffer is only using the most recent settings. Using PIX seems unreliable here but if it's not bugging out, it would seem to be the latter. Basically, the first mesh is drawn with an alpha blending blend state, the second mesh is drawn with blending disabled (opaque). If i draw only the first mesh, it's correctly rendered - a plant texture with alpha blending around the branches. If i draw the second mesh after the first mesh, which disables alpha blending (for the 2nd mesh draw only), the first mesh that was working fine is also drawing opaquely. Can anybody give me any ideas of things to try? OMSetBlendState should only be per draw call right? I'm out of ideas... I'm not sure what other info would be relevant but feel free to ask.. Thanks
  13. Hello! I have a situation where when I am debugging with PIX: -- i am drawing 4 meshes, each with different cbuffer values that i'm mapping inbetween -- when i only draw the first mesh, it looks correct and the values in the cbuffer in PIX look right -- when i enable drawing all 4 meshes in the loop, and go to that FIRST mesh's draw call, the cbuffer values are wrong as if they are getting values from cbuffer fills that happen AFTER that first draw call in time how is this possible? Do I have to do anything during rendering or initialization to keep this from happening? Thanks
  14. UPDATE: Solved!! The person who mentioned the floating point comparisons was on the right track. I needed to be round()-ing the floats, not just casting to int. There were apparently lots of 250.999999 in there (Showing up as 251.000 in PIX) and int was rounding them down to 250 which is a different set of textures in TexIndices... and so on for other areas of the terrain. Thanks to MaulingMonkey on gamedev irc.. And thanks to all for your suggestions, I learned a lot along the way..
  15. [quote name='MJP' timestamp='1330485457' post='4917608'] Also this might be unrelated, but are you actually using alpha to coverage? If not, you could try disabling it to see if it helps. [/quote] OK -- Just tried the REFERENCE driver and it's still happening (albeit at 0.5 fps!) - so a driver bug is not my savior =( I am using alpha to coverage yeah, however I have tried disabling it and it had no effect. It's really weird to me that even with the reference driver it's happening, and that PIX debugging is actually incorrect as far as the values it's showing. I really can't imagine what the issue is, other than some kind of memory corruption/scribbling (but by whom?!) or something related to the multithreading? I don't think the deferred context is doing anything though.. OK, i've VERY much simplified the shader code to show the precise problem now.. here is the current very trimmed down HLSL: [url="http://codepad.org/1LgyyBhh"]http://codepad.org/1LgyyBhh[/url] here is PIX showing that the MESHNUM variable in the vertex structure is 251 (it's 251 all the way down but this is just a still shot of the top few:) Pre-VS: [img]http://bh.polpo.org/pixelshader_wtf10.png[/img] Post-VS: [img]http://bh.polpo.org/pixelshader_wtf10b.png[/img] As you can see for this test I default the pixel color to 'see through' basically (0,0f/0.0f/0.0f/0.0f), so you can see the bad pixels show through to the background.. here is a video: [url="http://bh.polpo.org/simplify_badpixels.wmv"]http://bh.polpo.org/simplify_badpixels.wmv[/url] If you simply comment out lines 108-110 of the shader there, and uncomment line 106, the result SHOULD be identical. A video of this method shows it's perfect: [url="http://bh.polpo.org/simplify_goodpixels.wmv"]http://bh.polpo.org/simplify_goodpixels.wmv[/url] So, to my eyes the only possible things that can be happening are: -- the bytes of memory that contain the last float in the vertex structure are getting corrupted in memory. And it can't be something specific to the videocard because it happens in the REFERENCE device. DirectX is doing it somehow. And it's not affecting the rest of the vertex structure, otherwise there'd be issues with the vertices and texture coords, etc.. OR -- PIX isn't really showing what the real vertex structure values are, and it's not really 251. If not, why not, and what could possibly be overwriting it.. and is there anything else I can do besides getting a setup that can use NSight and seeing what the hardware shows?