Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

216 Neutral

About menohack

  • Rank
  1. menohack

    Directional Light

    Are you transforming cameraPos?   If you were using visual studio 2012 you could debug the shader and inspect values after it runs.
  2. menohack

    D3D10 question

    I think it only allocates memory on the GPU. There is no reason to mirror data in CPU RAM as well. Also, you are more likely to have more RAM than GPU memory.
  3. menohack

    Compile HLSL at Runtime ?

    D3DReadFileToBlob loads from a file to a ID3DBlob, but it looks like it is only available for D3D11. I don't know if you can just fopen and fread the .cso file, but you can definitely compile at run-time the first time and just write the blob to a file. Then the next time your program runs you can just fopen the compiled file.   If you have to go with the second way then you can still have visual studio compile your shaders to make sure they are correct at build-time. You just won't actually use the object files that it produces.
  4. menohack

    Per-Pixel Point Light

    The whiteness looks like your specularity is too high (if materialPower is too big) and the darkness is something you should expect from a point light. The brightness decreases with the square of the distance. So it may be the case that it is just falling off too quickly from lightRange being too small.   VS_OUTPUT and PS_INPUT are the same thing--use a typedef or just use one of them to avoid mistakes.
  5. menohack

    Compile HLSL at Runtime ?

    It was from SV_POSITION. It used to be VPOS in D3D9.   http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx#VPOS   Also I recommend using visual studio 2012 and compiling offline. My solution used to take 15 seconds to load because it compiled the shaders at run-time. I didn't have that many shaders. I switched to offline compiling and the screen comes up in under a second. It's huge for productivity. And according to some guy I'm not going to cite there's no real advantage to compiling at run-time since it increases loading by so much.
  6. menohack

    Shadow volumes Z-fail

    Solved it! My geometry shader was producing front caps and back caps with inverted normals. This caused the stencil count to be off because front faces increment and back faces decrement.   For future reference, the way mhagain set up the DepthStencil is the correct way. The front-facing shadow polygons could increment and the back-facing polygons could decrement, but it doesn't matter. The depth test should be LESS, so that failures are equal to or greater than the depth buffer.   The accidental inverted normal is like the missed decimal place for graphics programmers: 
  7. It sounds like your are forgetting to set your world matrix properly in between draw calls for your grid and your text. If you don't update the constant buffers on the cpu or the gpu with VSSetConstantBuffers then they will remain the way they were set for the previous draw call.
  8. menohack

    Working with Light Shader

    If you are in debug mode for D3D then there should be warnings or errors in the output window of Visual Studio.
  9. menohack

    Debugging the stencil buffer

    Just for future reference: I believe that the Shader Debugger in Visual Studio 2012 can also check the stencil buffer.
  10. menohack

    DX11 - HLSL - Billboarding

    You don't rotate billboards. Billboards always face the camera because they are just 2-D sprites. The only matrix you need to store per instance in your instance buffer is the world matrix. This matrix will have the position and scale of the billboards, such that the further it is the smaller it gets.   Anyway for instancing models this is what I do: #define NUM_MAX_INSTANCES 128 struct InstanceBuffer { XMFLOAT4X4 InstanceWorld[NUM_MAX_INSTANCES]; }; Then my shaders (note this is a normal model, not a billboard) look something like this: PS_INPUT VS( VS_INPUT input, uint iid : SV_InstanceID) { PS_INPUT output = (PS_INPUT)0; output.Pos = mul( input.Pos, InstanceWorld[iid] ); output.Pos = mul( output.Pos, View ); output.Pos = mul( output.Pos, Projection ); output.Norm = mul(float4(input.Norm, 0), InstanceWorld[iid] ).xyz; output.Tex = input.Tex; return output; } #define NUM_MAX_INSTANCES 128 cbuffer InstanceBuffer : register(b1) { matrix InstanceWorld[NUM_MAX_INSTANCES]; } Someone else can chime in with the max size of the instance buffer. I just guessed 128 for now.   Any time I need to render a batch of instanced models I call UpdateSubresource() with my new instance buffer and then DrawInstanced(). For drawing thousands of models I would probably have multiple DrawInstanced() calls, but I don't know if there is a better way.
  11. menohack

    Debugging the stencil buffer

    Exactly what I needed. Thank you very much!
  12. Is it possible to display the stencil buffer as a texture? The only formats available to a shader resource view are DXGI_FORMAT_R24_UNORM_X8_TYPELESS and DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS. When I try to draw this as a quad I only seem to have access to the x or r component, which is the depth.   Thanks!
  13. menohack

    Shadow volumes Z-fail

    Yeah I'm doing all of those things. Like I said, Z-pass works. That implies that I have culling disabled. I use a stencil ref of 127 and clear to that as well. It may be worth using the saturate option for the stencil operation but it shouldn't be a problem for my simple test case.   I've been trying to get this for weeks and I just can't figure it out. There has to be something going on behind the scenes that I'm missing.   I've attached a picture of Z-pass working and what happens when I try z-fail using StencilDepthFailOp = INCR/DECR and DepthFunc = LESS. Note that StencilDepthFailOp is KEEP for z-pass and StencilPassOp is INCR/DECR instead.   The third image is when I set DepthFunc to GREATER_EQUAL and StencilDepthFailOp to INCR/DECR. This should be another method of z-pass because I have inverted the depth function. Now values that are less than the depth value will fail the depth test and cause the stencil value to change. But I can't explain the squares of grey pixels around the chair. Is D3D doing the depth test at a lower resolution, then using that decision for a whole square of fragments? I can't think of any other reason why those little grey squares would appear.   One place where I am confused by the API: what happens if the depth AND the stencil tests fail? There is a case for the depth fail operation and a case for the stencil fail operation. Which one occurs?   I appreciate the replies mhagain.
  14. menohack

    Shadow volumes Z-fail

    That makes sense but it doesn't work. It makes the floor black except where geometry is behind the floor. Don't I need to change DepthFunc to GREATER? I want only fragments behind the depth map to be counted. Even when I try that it doesn't work.
  15. I have Z-pass working for my D3D11 application but no matter what I try I can't get z-fail to work. Here is my depth stencil state for building the stencil buffer with z-pass: D3D11_DEPTH_STENCIL_DESC depthStencilDesc = {0}; depthStencilDesc.DepthEnable = true; //Disable depth writes when rendering the volumes depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS; depthStencilDesc.StencilEnable = true; depthStencilDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; depthStencilDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK; //Stencil operation for front-facing polygons should increment depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_INCR; depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; //Stencil operation for back-facing polygons should decrement depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_DECR; depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; hr = g_pd3dDevice->CreateDepthStencilState(&depthStencilDesc, &buildShadowVolumeDepthStencilState); How would I modify this to do z-fail?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!