Jump to content
  • Advertisement

terryeverlast

Member
  • Content Count

    106
  • Joined

  • Last visited

Everything posted by terryeverlast

  1. I have a exercise in my book that says draw a circle with a LineStrip then make a cylinder with the geometry shader with no caps. Here is what I want in the image.   So far I have worked on making the like the image above but no luck   Here is what I got.     Here is my code.   My geometry shader code is [maxvertexcount(2)] void GS(line VertexOut gin[2], inout LineStream<GeoOut> stream) { float3 up = float3(0.0f, 1.0f, 0.0f); float3 look = gEyePosW - gin[0].CenterW; look.y = 0.0f; // y-axis aligned, so project to xz-plane look = normalize(look); float3 right = cross(up, look); float halfWidth = 0.5f*gin[0].SizeW.x; float halfHeight = 0.5f*gin[0].SizeW.y; float4 v[3]; v[0] = float4(gin[0].CenterW + halfHeight*up*10, 1.0f); v[1] = float4(gin[0].CenterW - halfHeight*up*10, 1.0f); GeoOut gout; [unroll] for(int i = 0; i < 2; ++i) { gout.PosH = mul(v[i], gViewProj); gout.PosW = v[i].xyz; gout.NormalW = look; gout.Tex = gTexC[i]; stream.Append(gout); } } My vertex code is void TreeBillboardApp::BuildCylinder() { Vertex::Cyl v[vertexcount]; UINT count = 20; for(UINT i = 0; i < count; ++i) { v[i].Pos = XMFLOAT3(5 * cosf(i),1.0f, 5 * sinf(i)); } D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_IMMUTABLE; vbd.ByteWidth = sizeof(Vertex::Cyl) * count; vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vinitData; vinitData.pSysMem = v; HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &CylinderVB)); } How can I make mine like the first image? Need some ideas.
  2. terryeverlast

    Cylinder done in the geometry shader in Directx 11.

    Ok,got the cylinder now.   Vertex::TreePointSprite v[TreeCount]; const UINT numSlices = 32; const UINT numCircleVerts = 33; const UINT vertexCount = 2*numCircleVerts; float dTheta = 2.0f*XM_PI/numSlices; Vertex::Basic32 vertices[vertexCount]; for(UINT i = 0; i < numCircleVerts; ++i) { float x = 5*cosf(i*dTheta); float z = 5*sinf(i*dTheta); v[i].Pos = XMFLOAT3(x, 0.0f, z); } D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_IMMUTABLE; vbd.ByteWidth = sizeof(Vertex::TreePointSprite) * 34; vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vinitData; vinitData.pSysMem = v; HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mTreeSpritesVB)); The geo shader code [maxvertexcount(7)] void GS(line VertexOut gin[2], inout LineStream<GeoOut> stream) { float4 v[2]; float4 b[1]; v[0] = float4(gin[0].CenterW.xyz, 1.0f); v[1] = float4(gin[1].CenterW.xyz, 1.0f); const float StripWidth = 0.5f; float2 dir = normalize(v[1].xy - v[0].xy); float4 off = float4(-dir.y, dir.x, 0, 0); GeoOut gout; gout.PosH = mul(v[0]-off*5, gViewProj); stream.Append(gout); gout.PosH = mul(v[0]+off*5, gViewProj); stream.Append(gout); gout.PosH = mul(v[1]-off*5, gViewProj); stream.Append(gout); stream.RestartStrip(); gout.PosH = mul(v[0]-off*5, gViewProj); stream.Append(gout); gout.PosH = mul(v[1]-off*5, gViewProj); stream.Append(gout); stream.RestartStrip(); gout.PosH = mul(v[0]+off*5, gViewProj); stream.Append(gout); gout.PosH = mul(v[1]+off*5, gViewProj); stream.Append(gout); }
  3. terryeverlast

    Where can i start and how?

    There are alot  tutorials on c++ and most gaming books are written for c++. Next, probally visual basic. Visual basic has lots of stuff. And visual is a good *starting language but will be for older out dated. either part will work good.
  4. terryeverlast

    Where can i start and how?

    I would start programming games with C++. Most games are programmed with it as it is the most used language for game making.  
  5. I'm on chapter 10 stenciling, question 8 dealing with Depth complexity.   Anyone read this book by Frank Luna?   Here is part of the question that im not understanding.        8.  Depth complexity refers to the number of pixel fragments that compete, via the depth test, to be written to a particular entry in the back buffer. For example, a pixel we have drawn may be overwritten by a pixel that is closer to the camera (and this can happen several times before the closest pixel is actually figured out once the entire scene has been drawn). The pixel in Figure 10.12 has a depth complexity of 3 since three pixel fragments compete for the pixel. Potentially, the graphics card could fill a pixel several times each frame. This overdraw has performance implications, as the graphics card is wasting time processing pixels that eventually get overridden and are never seen. Consequently, it is useful to measure the depth complexity in a scene for performance analysis. We can measure the depth complexity as follows: Render the scene and use the stencil buffer as a counter; that is, each pixel in the stencil buffer is originally cleared to zero, and every time a pixel fragment is processed, we increment its count with D3D11_STENCIL_OP_INCR. The corresponding stencil buffer entry should always be incremented for every pixel fragment no matter what, so use the stencil comparison function D3D11_COMPARISON_ALWAYS. Then, for example, after the frame has been drawn, if the ijth pixel has a corresponding entry of five in the stencil buffer, then we know that those five pixel fragments were processed for that pixel during that frame (i.e., the pixel has a depth complexity of five). Note that when counting the depth complexity, technically you only need to render the scene to the stencil buffer. To visualize the depth complexity (stored in the stencil buffer), proceed as follows:       Associate a color ck for each level of depth complexity k. For example, blue for a depth complexity of one, green for a depth complexity of two, red for a depth complexity of three, and so on. (In very complex scenes where the depth complexity for a pixel could get very large, you probably do not want to associate a color for each level. Instead, you could associate a color for a range of disjoint levels. For example, pixels with depth complexity 1–5 are colored blue, pixels with depth complexity 6–10 are colored green, and so on.) (b)  Set the stencil buffer operation to D3D11_STENCIL_OP_KEEP so that we do not modify it anymore. (We modify the stencil buffer with D3DSTENCILOP_INCR when we are counting the depth complexity as the scene is rendered, but when writing the code to visualize the stencil buffer, we only need to read from the stencil buffer and we should not write to it.) For each level of depth complexity k:     (i)  Set the stencil comparison function to D3D11_COMPARISON_EQUAL and set the stencil reference value to k.   (ii)  Draw a quad of color ck that covers the entire projection window. Note that this will only color the pixels that have a depth complexity of k because of the preceding set stencil comparison function and reference value. Figure 10.13. Sample screenshot of the solution to Exercise 8. With this setup, we have colored each pixel based on its depth complexity uniquely, and so we can easily study the depth complexity of the scene. For this exercise, render the depth complexity of the scene used in the “Blend” demo from Chapter 9. Figure 10.13 shows a sample screenshot. The depth test occurs in the output merger stage of the pipeline, which occurs after the pixel shader stage. This means that a pixel fragment is processed through the pixel shader, even if it may ultimately be rejected by the depth test. However, modern hardware does an “early z-test” where the depth test is performed before the pixel shader. This way, a rejected pixel fragment will be discarded before being processed by a potentially expensive pixel shader. To take advantage of this optimization, you should try to render your non-blended game objects in front-to- back order with respect to the camera; in this way, the nearest objects will be drawn first, and objects behind them will fail the early z-test and not be processed further. This can be a significant performance benefit if your scene suffers from lots overdraw due to a high depth complexity. We are not able to control the early z-test through the Direct3D API; the graphics driver is the one that decides if it is possible to perform the early z-test. For example, if a pixel shader modifies the pixel fragment’s depth value, then the early z-test is not possible, as the pixel shader must be executed before the depth test since the pixel shader modifies depth values. We mentioned the ability to modify the depth of a pixel in the pixel shader. How does that work? A pixel shader can actually output a structure, not just a single color vector as we have been doing thus far:   struct PixelOut { float4 color : SV_Target; float depth : SV_Depth; }; PixelOut PS(VertexOut pin) { PixelOut pout; // … usual pixel work pout.Color = float4(litColor, alpha); // set pixel depth in normalized [0, 1] range pout.depth = pin.PosH.z - 0.05f; return pout; } Im suppose to get a picture like  the one on the right.    Can someone give me a idea on what I need to do here? Does this need to be done in the pixel shader?
  6. This is what I got: I redrew everything, rendered the scene twice but in the loop as described above. Like for the box I did this code boxTech->GetDesc(&techDesc); for (UINT p = 0; p < techDesc.Passes; ++p) { for (UINT i = 0; i < 4; i++) { md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Set per object constants. XMMATRIX world = XMLoadFloat4x4(&mBoxWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMMatrixIdentity()); Effects::BasicFX->SetMaterial(mdc[i-1]); md3dImmediateContext->OMSetDepthStencilState(RenderStates::overdraw, i); md3dImmediateContext->RSSetState(RenderStates::NoCullRS); boxTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(36, 0, 0); // Restore default render state. md3dImmediateContext->RSSetState(0); } } This is my STENCIL SETTINGS D3D11_DEPTH_STENCIL_DESC drawDepth; drawDepth.DepthEnable = true; drawDepth.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; drawDepth.DepthFunc = D3D11_COMPARISON_LESS; drawDepth.StencilEnable = true; drawDepth.StencilReadMask = 0xff; drawDepth.StencilWriteMask = 0xff; drawDepth.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; drawDepth.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; drawDepth.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; drawDepth.FrontFace.StencilFunc = D3D11_COMPARISON_EQUAL; drawDepth.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; drawDepth.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; drawDepth.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; drawDepth.BackFace.StencilFunc = D3D11_COMPARISON_EQUAL; HR(device->CreateDepthStencilState(&drawDepth, &overdraw)); This is right? Also, in the first post I made, the part where it says "(ii)  Draw a quad of color ck that covers the entire projection window. Note that this will only color the pixels that have a depth complexity of k because of the preceding set stencil comparison function and reference value." Is this another way get depth? Or part of the I?   Oh yeah, I still working on getting the stencil ref to the shader...so that will be in the future
  7. Are there any good tutorials for directx 11 for creating a quad that is see through? Maybe with or without using vertex buffers.
  8. I'm not getting draw a quad over the projection window. A quad is a plane right? So when I draw the quad and disable depth, you will be able to see through the plane at other objects? am I right?
  9. I'm on a new blending question. I have fog in my scene and when my object goes in the part where it should disappear, it does not.   In front of the fog still visible   As you see, you can still see the object it the part where it should disappear!   I used a multiply blend. my code D3D11_BLEND_DESC myblend2 = { 0 }; myblend2.AlphaToCoverageEnable = false; myblend2.IndependentBlendEnable = false; myblend2.RenderTarget[0].BlendEnable = true; myblend2.RenderTarget[0].SrcBlend = D3D11_BLEND_ZERO; myblend2.RenderTarget[0].DestBlend = D3D11_BLEND_SRC_COLOR; myblend2.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&myblend2, &MULTIPLYBLEND)); For the BlendOp, when I use D3D11_BLEND_OP_MIN or MAX, it will disappear in the fog, but using ADD,SUBTRACT,REV_SUBTRACT, it does not. I also narrowed it down to the DestBlend, when it is set to zero(D3D11_BLEND_ZERO), it will disappear in the fog.   Maybe its my image? maybe the pixel shader? I also have my HLSL pixel shader code, here it is float4 PS(VertexOut pin, uniform int gLightCount, uniform bool gUseTexure, uniform bool gAlphaClip, uniform bool gFogEnabled) : SV_Target { // Interpolating normal can unnormalize it, so normalize it. pin.NormalW = normalize(pin.NormalW); // The toEye vector is used in lighting. float3 toEye = gEyePosW - pin.PosW; // Cache the distance to the eye from this surface point. float distToEye = length(toEye); // Normalize. toEye /= distToEye; // Default to multiplicative identity. float4 texColor = float4(1, 1, 1, 1); if (gUseTexure) { // Sample texture. texColor = gDiffuseMap.Sample(samAnisotropic, pin.Tex); } // // Lighting. // float4 litColor = texColor; if (gLightCount > 0) { // Start with a sum of zero. float4 ambient = float4(0.0f, 0.0f, 0.0f, 0.0f); float4 diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f); float4 spec = float4(0.0f, 0.0f, 0.0f, 0.0f); // Sum the light contribution from each light source. [unroll] for (int i = 0; i < gLightCount; ++i) { float4 A, D, S; ComputeDirectionalLight(gMaterial, gDirLights[i], pin.NormalW, toEye, A, D, S); ambient += A; diffuse += D; spec += S; } // Modulate with late add. litColor = texColor*(ambient + diffuse) + spec; } // // Fogging // if (gFogEnabled) { float fogLerp = saturate((distToEye - gFogStart) / gFogRange); // Blend the fog color and the lit color. litColor = lerp(litColor, gFogColor, fogLerp); } // Common to take alpha from diffuse material and texture. litColor.a = gMaterial.Diffuse.a * texColor.a; return litColor; } Maybe something wrong in there?
  10. terryeverlast

    Fog blending not working with object.

    anyone? need some insight.Could the problem be from depth settings? I tried some different ones with no luck.
  11. terryeverlast

    Fog blending not working with object.

    The problem only happens when using additive blend or subtractive blend and multiplitie blend.   Basically when adding,subtracting or multiplying two images, kina like the picture below.       Here is my code for blending. When adding two images. myblend2.RenderTarget[0].BlendEnable = true; myblend2.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&myblend2, &addBLEND)); myblend2.RenderTarget[0].BlendEnable = FALSE; HR(md3dDevice->CreateBlendState(&myblend2, &mb2)); Subtractive blend: myblend2.RenderTarget[0].BlendEnable = true; myblend2.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOp = D3D11_BLEND_OP_SUBTRACT; myblend2.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&myblend2, &subBLEND)); myblend2.RenderTarget[0].BlendEnable = FALSE; HR(md3dDevice->CreateBlendState(&myblend2, &mb2)); ?   When doing a transparent blend, for some reason, it will disapperar in the fog and I get the right results D3D11_BLEND_DESC myblend2 = { 0 }; myblend2.AlphaToCoverageEnable = false; myblend2.IndependentBlendEnable = false; myblend2.RenderTarget[0].BlendEnable = true; myblend2.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; myblend2.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; myblend2.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; myblend2.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&myblend2, &transBLEND));  also, the fog and background are both silver.     Like when im adding, i will see a white box. when subtracting, I will see a black box in the fog and multiplying, a gray box?
  12. terryeverlast

    Fog blending not working with object.

    In the code: teContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Draw the box. XMMATRIX world = XMLoadFloat4x4(&mBoxWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMMatrixIdentity()); Effects::BasicFX->SetMaterial(mBoxMat); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV); //BRICK WALL md3dImmediateContext->OMSetBlendState(0, 0, 0xffffffff); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2); // ORANGE SUN md3dImmediateContext->OMSetBlendState(MULTIPLYBLEND, blendFactor, 0xffffffff); md3dImmediateContext->OMSetDepthStencilState(mydepth, 0); // set to D3D11_COMPARISON_LESS_EQUAL md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); } I use md3dImmediateContext->OMSetBlendState(MULTIPLYBLEND, blendFactor, 0xffffffff); to blend two images, which is causing the box not to blend in. The fog color is silver and so is the background, still not working. I tried editing depth, no luck. so its either depth or the blend, which i cannot figure out. Any more ideas? I will post more code if needed
  13. terryeverlast

    Blending two images together.

    The code does:     In the draw scene function: for(UINT p = 0; p < techDesc.Passes; ++p) { md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Draw the box. XMMATRIX world = XMLoadFloat4x4(&mBoxWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMMatrixIdentity()); Effects::BasicFX->SetMaterial(mBoxMat); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV); md3dImmediateContext->OMSetBlendState(defaultblend, 0, 0xffffffff); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2); // alpha texture md3dImmediateContext->OMSetBlendState(subtractblend, blendFactor, 0xffffffff); md3dImmediateContext->OMSetDepthStencilState(mydepth, 0); // set to D3D11_COMPARISON_LESS_EQUAL md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); } and the Init function D3D11_BLEND_DESC myblend2 = { 0 }; myblend2.AlphaToCoverageEnable = false; myblend2.IndependentBlendEnable = false; myblend2.RenderTarget[0].BlendEnable = true; myblend2.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOp = D3D11_BLEND_OP_SUBTRACT; myblend2.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&myblend2, &subtractblend)); myblend2.RenderTarget[0].BlendEnable = FALSE; HR(md3dDevice->CreateBlendState(&myblend2, &defaultblend)); D3D11_DEPTH_STENCIL_DESC dsDesc2; dsDesc2.DepthEnable = true; dsDesc2.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; dsDesc2.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; dsDesc2.StencilEnable = false; dsDesc2.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; dsDesc2.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK; dsDesc2.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; dsDesc2.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; dsDesc2.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE; dsDesc2.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; dsDesc2.BackFace = dsDesc.FrontFace; md3dDevice->CreateDepthStencilState(&dsDesc2, &mydepth);
  14. terryeverlast

    Blending two images together.

    Im trying to Subtract a image with blending. I made a image(brick wall) with a alpha channel(black and white image..vines) so it is one image. Is this right. ? Here is my code D3D11_BLEND_DESC myBlend = { 0 }; myBlend.AlphaToCoverageEnable = false; myBlend.ransparentDesc.IndependentBlendEnable = false; myBlend.RenderTarget[0].BlendEnable = true; myBlend.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; myBlend.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO; myBlendRenderTarget[0].BlendOp = D3D11_BLEND_OP_SUBTRACT; myBlend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; myBlendRenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; myBlend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; myBlend.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&myBlend &BLENDTEST)); The alpha channel is not being subtracted from the image image. It should be a brick wall with vines.   What is wrong with my code?
  15. terryeverlast

    Blending two images together.

    Alright, thx to all the guys that helped me out, I got it working   Here it is  
  16. terryeverlast

    Blending two images together.

    So my code should be for(UINT p = 0; p < techDesc.Passes; ++p) { md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Draw the grid. XMMATRIX world = XMLoadFloat4x4(&mGridWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*view*proj; // Draw the box. world = XMLoadFloat4x4(&mBoxWorld); worldInvTranspose = MathHelper::InverseTranspose(world); worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMMatrixIdentity()); Effects::BasicFX->SetMaterial(mBoxMat); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV); // brick wall image md3dImmediateContext->OMSetBlendState(0, 0, 0xffffffff); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2); // alpha texture md3dImmediateContext->OMSetBlendState(mb, blendFactor, 0xffffffff); md3dImmediateContext->OMSetDepthStencilState(myds, 0); // set to D3D11_COMPARISON_LESS_EQUAL md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); md3dImmediateContext->OMSetBlendState(0, 0, 0xffffffff); md3dImmediateContext->OMSetDepthStencilState(myds2, 0); // set to LESS_EQUAL } and my depth func should be D3D11_DEPTH_STENCIL_DESC dsDesc; dsDesc.DepthEnable = false; dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; dsDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; dsDesc.StencilEnable = TRUE; dsDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; dsDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK; dsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; dsDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; dsDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; dsDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; dsDesc.BackFace = dsDesc.FrontFace; md3dDevice->CreateDepthStencilState(&dsDesc, &myds); ?Does it look right Buckeye? ? ?
  17. terryeverlast

    Blending two images together.

    Ok. Ive been on blending two images together for awhile now and not getting any luck.   Will someone go to http://www.d3dcoder.net/d3d11.htm, download the SOURCE CODE SET I, and in "Chapter 9 Blending" is a blend project.   Make the water blend with another image. Blend the water with a grayscale image or any image you can using the OMSetBlendState   I need help on this. thank you
  18. terryeverlast

    Blending two images together.

    My blendFactor is {0.0f, 0.0f, 0.0f, 1.0f};   I did the opaque state with it now. Not blue anymore, just the normal first image crate withouth the second image.   How would you set the code up in the code below? for(UINT p = 0; p < techDesc.Passes; ++p) { md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Draw the box. XMMATRIX world = XMLoadFloat4x4(&mBoxWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMLoadFloat4x4(&mTexTransform)); Effects::BasicFX->SetMaterial(mBoxMat); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV); md3dImmediateContext->RSSetState(NoCullRS); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2); md3dImmediateContext->OMSetBlendState(mb2, blendFactor, 0xffffffff); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); }
  19. terryeverlast

    Blending two images together.

    Am I leaving out something?   md3dImmediateContext->OMSetBlendState(mb2, blendFactor, 0xffffffff);   Is making it blue.
  20. terryeverlast

    Blending two images together.

    Ok. I rendered the first image with no blend state. The wooden crate is the first image. The second image I converted to RGBA and put a blend on it.   This is what im getting     My code is for(UINT p = 0; p < techDesc.Passes; ++p) { md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Draw the box. XMMATRIX world = XMLoadFloat4x4(&mBoxWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMLoadFloat4x4(&mTexTransform)); Effects::BasicFX->SetMaterial(mBoxMat); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV); md3dImmediateContext->RSSetState(NoCullRS); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2); md3dImmediateContext->OMSetBlendState(mb2, blendFactor, 0xffffffff); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); } HR(mSwapChain->Present(0, 0)); and my blend code D3D11_BLEND_DESC myblend2 = { 0 }; myblend2.AlphaToCoverageEnable = false; myblend2.IndependentBlendEnable = false; myblend2.RenderTarget[0].BlendEnable = true; myblend2.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOp = D3D11_BLEND_OP_REV_SUBTRACT; myblend2.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; myblend2.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; myblend2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&myblend2, &mb2)); Why is it blue and not the subtracting the two images??
  21. terryeverlast

    Blending two images together.

    Ok..my code D3D11_BLEND_DESC transparentDesc = { 0 }; transparentDesc.AlphaToCoverageEnable = false; transparentDesc.IndependentBlendEnable = false; transparentDesc.RenderTarget[0].BlendEnable = false; transparentDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; transparentDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; transparentDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_SUBTRACT; transparentDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; transparentDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; transparentDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; transparentDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&transparentDesc, &TransparentBS)); D3D11_BLEND_DESC transparentDescS = { 0 }; transparentDescS.AlphaToCoverageEnable = false; transparentDescS.IndependentBlendEnable = false; transparentDescS.RenderTarget[0].BlendEnable = true; transparentDescS.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; transparentDescS.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; transparentDescS.RenderTarget[0].BlendOp = D3D11_BLEND_OP_REV_SUBTRACT; transparentDescS.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; transparentDescS.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; transparentDescS.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; transparentDescS.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&transparentDescS, &TransparentBS2)); still the image
  22. terryeverlast

    Blending two images together.

    Got a change but not the exact thing I need   here is what I got     I see the alpha with some brown from the bricks..but where is the bricks?   The image should be like   // Draw the box. world = XMLoadFloat4x4(&mBoxWorld); worldInvTranspose = MathHelper::InverseTranspose(world); worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMMatrixIdentity()); Effects::BasicFX->SetMaterial(mBoxMat); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV6); md3dImmediateContext->OMSetBlendState(TransparentBS, blendFactor, 0xffffffff); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV7); md3dImmediateContext->OMSetBlendState(TransparentBS2, blendFactor, 0xffffffff); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); here is my blend code D3D11_BLEND_DESC transparentDesc = { 0 }; transparentDesc.AlphaToCoverageEnable = false; transparentDesc.IndependentBlendEnable = false; transparentDesc.RenderTarget[0].BlendEnable = false; transparentDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; transparentDesc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; transparentDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_SUBTRACT; transparentDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; transparentDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; transparentDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; transparentDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&transparentDesc, &TransparentBS)); transparentDesc.RenderTarget[1].BlendEnable = true; transparentDesc.RenderTarget[1].SrcBlend = D3D11_BLEND_ONE; transparentDesc.RenderTarget[1].DestBlend = D3D11_BLEND_ONE; transparentDesc.RenderTarget[1].BlendOp = D3D11_BLEND_OP_SUBTRACT; transparentDesc.RenderTarget[1].SrcBlendAlpha = D3D11_BLEND_ONE; transparentDesc.RenderTarget[1].DestBlendAlpha = D3D11_BLEND_ZERO; transparentDesc.RenderTarget[1].BlendOpAlpha = D3D11_BLEND_OP_ADD; transparentDesc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; HR(md3dDevice->CreateBlendState(&transparentDesc, &TransparentBS2));
  23. terryeverlast

    Blending two images together.

    I really don't want to use the pixel shader to do this. I want to use the first option.(Multipass texturing) D3DX11_TECHNIQUE_DESC techDesc; activeTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Restore default blend state // Draw the box. world = XMLoadFloat4x4(&mBoxWorld); worldInvTranspose = MathHelper::InverseTranspose(world); worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetTexTransform(XMMatrixIdentity()); Effects::BasicFX->SetMaterial(mBoxMat); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV6); md3dImmediateContext->OMSetBlendState(TransparentBS, blendFactor, 0xffffffff); activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV7); activeTech->GetPassByIndex(p)->Apply(1, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff); } HR(mSwapChain->Present(0, 0)); } I tried that, but not working
  24. terryeverlast

    Blending two images together.

    I combined the brick with the vines with the tool "DirectX Texture Tool" and changed the surface format to "Four CC 8-bit DXT5"  and loaded the alpha onto the the texture.   This is right?
  25. terryeverlast

    Blending two images together.

    That blend makes the image transparent. The alpha(vines) is the transparent part.   I need something like this in the image.           One of my question is. Do I load the brick wall with that alpha into one image?   I loaded the brick wall as the rgb, and the vines as the alpha channel with the DxTex.exe.   My book says this.   Suppose that we want to Subtract the source pixels with the destination pixels. To do this, set the source blend factor to D3D11_BLEND_ONE, the destination blend factor to D3D11_BLEND_ONE, and the blend operator to D3D11_BLEND_OP_SUBTRACT.      
  • 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!