Jump to content
  • Advertisement

calvinsfu

Member
  • Content Count

    15
  • Joined

  • Last visited

Community Reputation

134 Neutral

About calvinsfu

  • Rank
    Member
  1. [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]What I'm trying to do is use the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)] [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]atlas[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)] to combine multiple terrain textures into one big [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)].[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]As you can see in the screenshot, the seams are clearly visible. and it gets worse when viewed from smaller angles. There are a few things I have tried.[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]Attempt 1:[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]In order to locate the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]problem[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)], I changed to a debug [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)] with no tiles and no [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)] [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]atlas[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]. Here's what I did.[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]when the uv calculation function was [/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]uv = worldPos.xz;[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]tex2D(_DiffuseTex_0, uv);[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]There is no seam.[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]After I changed the uv calculation function to[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]uv = frac(worldPos.xz);[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]tex2D(_DiffuseTex_0, uv);[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]the seams would show up. (one might suspect why I would make this change because I used frac() in the full version of my uv calculation. My thinking was that because the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)] UV expects values ranging from [0, 1] (both 0, 1 inclusive). But frac() only outputs to [0, 1) (0 inclusive, 1 exclusive). Another observation is that even though frac() only outputs to [0, 1), when the input uv has no fraction component, the result should be 0. And 0 should tell the sampler to sample the first row/column in the sub-texture. but the screenshot shows otherwise. The simplified version of my uv calculation is 'uv = baseUV + frac(uv); '[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]After searching the forum, it seems other people experienced this [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]problem[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)] and categorized it as texel bleeding in the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)] [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]atlas[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]' mipmaps. But after a few experiments, I still can not conclude it is a [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]problem [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]of mipmap. Here what I did.[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]Attempt 2:[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]I used 'Texture2D.PackTextures' in Unity to combine all the small terrain textures. According to the API documentation, it will merge their mipmaps as well. So I did. It seemed it did merge the textures and all of their mipmaps, but the outcome is exactly the same as before. [/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]Attempt 3:[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]One thing did work out was disabling the mipmap generation and the seams would go away.[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]So Attempt 1 tells me it might have something to do with the UV mapping; yet Attempt 2 is hinting that it has nothing to do with mipmap; and Attempt 3 tells me it does relate to the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(255, 235, 144)]problem[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)] of mipmap.[/background][/font] [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]Partial Shader Code:[/background][/font] [indent=1] /* the texture '_DiffuseTex_0' is the final merged texture that has the size 2048 x 2048. It contains 16 sub-textures with each being 512 x 512. There are 4 sub-textures in each row and a total of 4 rows. baseUV is the uv coordinate calculated based on the type of terrain type. e.g. (0,0) being the 1st terrain type, (0,0.25) being the 2nd terrain type, (0.75, 0.75) being the 16th terrain type.worldPos.xz is fed to the uv parameter. */ float4 GetDiffuseTex(float2 baseUV, float2 uv) { float correction = 1.0f/512.0f; float indent = 0.0f; uv /= _Repetition; // to scale the texture. uv = baseUV + (correction * indent + frac(uv) * (1 - indent *2* correction) ) *_TileSize; // Another test was using indentation to make it only sample from the inner portion of the sub-texture, // and it didn't help neither. //uv = (baseUV + frac(uv) *_TileSize); //uv = frac(uv); return tex2D(_DiffuseTex_0, uv); } [color=#111111][font=Helvetica, Arial, sans-serif][background=rgb(254, 254, 254)]So does anyone know how to resolve these seams? Thanks in advance![/background][/font]
  2. calvinsfu

    Shadow mapping tips?

    you may try orthogonal projection for rendering the shadow map. it simulates directional lights. also, use a 24bit or higher depth buffer. combined with PCF and right parameter settings, you will barely notice any aliasing.
  3. Hi guys! For my project I`m using the D3DX APIs to load .x files for mesh and animations. As requested by the animator, we are separating the mesh and animation data such that animation sets can be reused for different meshes that have the same skeleton structure. But it seems the resources on this topic are very rare. I tried to use ID3DXAnimationController::GetAnimationSet ID3DXAnimationController::RegisterAnimationSet but according the error message I can't add new animation sets. Some other options are to use RegisterAnimationOuput. but again, I can't find any example on how to use this API. Another solution I can think of is to cheat on D3DXAnimationController by replacing the skeleton matrices that are originally bound to the animation controller by the mesh that wants to reuse the animation. call AdvanceTime, then restore the matrices. But this method sounds to gimmicky and is prone to bugs in the long run. What do you think?
  4. calvinsfu

    Shadow Map issues

    shadow = max(step(realDistance, depthStoredInShadowMap.x), p); here in your pixel shader, it could be depthStoredInShadowMap.x + epsilon where epsilon is a very small number to account for floating point errors, like 0.000001f. tbh, if you just started to learn shadowmap why not learn from the DX sample. it's well commented and very easy to understand.
  5. So my understanding is that, if I load .x file with D3DXLoadMeshHierarchyFromX, this API automatically returns a handler to the ID3DXAnimationController object which is internally linked to the mesh. due to request, I need to separately load the mesh data and the animation data. that is, use the .x file to store mesh data and a custom format for animation data. I want to keep the .x mesh loader but rewrite the animation class. Is there any documentation/examples on ID3DXAnimationController? I'd assume I have to subclass this interface like what I did to ID3DXAllocateHierarchy. but I cant seem to find good resources on it. -Calvin
  6. by "so many instructions" do you mean the shader core can handle a lot more instructions in one pass? if I stuff all steps in one pass, wouldn't it slow down a lot because it breaks parallelism?
  7. Hi everyone, I have been reading Huges Hoppe's paper on geoclipmap. I'm still very confused about some details in implementation: in "coarser level", there are two triangles with five imaginary vertices at the middle of each edge. their height values should just be the average height values of the two vertices it is adjacent to. E.g. the height value of Q1 should be the average of P1 and P2. H(Q1) = ( H(P1) + H(P2) ) / 2 in "finer level", assume this grid in the finer ring has just moved into the position where the ring in the first pic was. let's further assume the quad is right on the edge of the finer ring. so the morph factor is zero, which means, to avoid popping artifacts, the actual height values of points Q1 - Q5 should be ignored. their height values are still calculated using H(Q1) = ( H(P1) + H(P2) ) / 2. As the vertices are further away from the edge of the ring, the morph factor increases. therefore, the final height will have some contribution from the sampled height value and some contribution from the calculated average height of the neighbouring vertices. So, this is what I can understand as far as vertex blending goes. Hoppe's paper proposed that we store the finer height value in the integer component of the height map, and the coarser height value in the decimal component. This way, we can avoid texture sampling multiple times in the vertex shader. Here is my question. Since we have to preprocess the height map, for each height value, how do I know which neighbouring pixel should I look for to calculate the average height? In this case, Q1 should be calculated from P1 and P2, Q2 is from P2 and P3, Q5 is from P1 and P3. additionally, the neighbouring pixels have different step size depending on the ring level. Am I missing something here?
  8. calvinsfu

    questions about geoclipmap

    Quote: -Every time you render the ring, each vertex need to sample the height from the heightmap. -if viewer was at (0,0) and move by 1.0 on x-axis, level 0 window is shifted by 1 and that's all. levels 1+ windows are Not shifted, but level 1 LShape location is changed. Remember that there is 4 locations for LShapes that depends on lower level ring position. So how would you update if the viewer keeps moving along the x axis when all rings are shifted right to be in the right-bottom(in which case, the L shapes are in the left-top I assume)?
  9. hi, I've been reading Hoppe's paper ( http://research.microsoft.com/~hoppe/gpugcm.pdf )on geoclipmap for some time. I still have some trouble understanding the mechanics. 1. the author splits each ring into 12 m*m blocks, 4 fixups and 1 L-shaped interior rim. I heard the L shape is needed for updating as the viewer moves on the terrain. Quote from Hoppe's paper, section 2.4 Update: Quote:As the viewer moves through the environment, each clipmap window translates within its pyramid level so as to remain centered about the viewer; thus, the window must be updated accordingly. Because viewer motion is coherent, generally only a small L-shaped region of the window needs to be incrementally processed each frame. Also, the relative motion of the viewer within the windows decreases exponentially at coarser levels, so coarse levels seldom require updating. We update the active clipmap levels in coarse-to-fine order. Recall that each clipmap level stores two textures: a single-channel floating-point elevation map, and a fourchannel, 8-bit-per-channel normal map. During the update step, we modify regions of these textures by rendering to them using a pixel shader. while I do understand how toroidal update on the heightmap works, but I don't see how the L-shaped interior rim comes into play. 2. A different paper( by Nick Brettell http://www.cosc.canterbury.ac.nz/research/reports/HonsReps/2005/hons_0502.pdf) described a derived technique that uses a simplified ring structure that has just 12 blocks. Does that mean it's not necessary to use Hoppe's ring structure? 3. Hoppe mentioned that the relative motion of the viewer within the windows decreases at coarser levels. I'm really confused. Because if the viewer moved 1.0 on the x-axis, all vertices on the coarsest level would have to resample the height from the heightmap because the window has shifted. Is something I'm missing still? any comment is appreciated. thank you. [Edited by - calvinsfu on August 8, 2008 1:02:14 PM]
  10. calvinsfu

    Precision in Shadow Mapping in DX10

    solved using 32bit depth buffer.
  11. I'm currently trying to render shadow with the most basic shadow mapping technique. There are several problems I've encountered. Can anyone post any thoughts on these? Thanks. 1: If I use position.z/position.w to calculate the depth value for each pixel and store them in a gray-scale texture, the depth precision is limited to 8-bit. 2: If I try to create the shader resource view for the 24 bit depth map that was automatically generated by DirectX , DirectX says the DXGI_FORMAT_D32_FLOAT format can't be bound to a shader input. I've attempted the following to try to solve the first method. using all 4 channels (RGBA) to store the depth value. but when it came down to encoding a 32 bit float into 4 8-bit color values, somehow all G,B,A are getting zeros by the following algorithm(debugged using PIX): PS_OUTPUT Output; float fDepth; fDepth = In.Depth; // In.Depth is calculated by z/w Output.RGBColor.r = fDepth; fDepth -= Output.RGBColor.r; // calculate the precision loss in 8-bit and 256-bit. e.g. fDepth = 0.123456, r = 0.123, fDepth = fDepth - r (fDepth now becomes 0.000456) Output.RGBColor.g = fDepth*256.0f; // amplify the loss and store it in g. fDepth = fDepth*256.0f - Output.RGBColor.g; Output.RGBColor.b= fDepth*256.0f; fDepth -= fDepth*256.0f - Output.RGBColor.b; Output.RGBColor.a= fDepth*256.0f; Is there something wrong with the algorithm? Also, is there a way to bind the depth-stencil buffer as a shader resource?
  12. can anyone shed light on the algorithms used in the shadow volume sample that come with dx9 sdk? it calculates the shadow mesh once for all. it seems it doesnt recalculate it when the light/dwarf position has changed, yet the shadow volume is still updated for each frame.
  13. while I'm attempting to make a shadow volume demo, I'm experimenting how the stencil buffer works. I think I have understood the concept but my code doesnt work. the basic algorithm: 1: render a terrain with the natural light on, 2: use the stencil technique to mask part of the terrain by drawing an object (which will be replaced by the shadow volume) on the terrain. 3: update the fragments of the terrain which are inside of the object with the shadow light on. the goal is to render a terrain with some part in shadow. void render_frame(void) { d3ddev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); d3ddev->Clear(0, NULL, D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); d3ddev->BeginScene(); // assume the #1 light is the natural light, #0 is the light used for drawing shadowed region. // *********************** pass 1 *********************** // pass 1 d3ddev->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS); d3ddev->SetRenderState(D3DRS_ZENABLE,TRUE); d3ddev->SetRenderState(D3DRS_STENCILENABLE,FALSE); d3ddev->SetRenderState(D3DRS_STENCILFUNC,D3DCMP_ALWAYS); d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE); d3ddev->LightEnable(1, TRUE); // turn on the normal light d3ddev->LightEnable(0, FALSE);// turn off the shadow light mesh_landscape->UpdateAll(); // update the matrices mesh_landscape->draw(); objects[0]->UpdateAll(); // draw some random object objects[0]->draw(); // *********************** shadow volume *********************** d3ddev->SetRenderState(D3DRS_STENCILENABLE,TRUE); d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE); // not bothering with light when drawing the shadow volume. d3ddev->SetRenderState(D3DRS_ZENABLE,TRUE); d3ddev->SetRenderState(D3DRS_ZFUNC,D3DCMP_LESS); d3ddev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); d3ddev->SetRenderState( D3DRS_COLORWRITEENABLE , FALSE); // turn off the color buffer. // stencil configurations d3ddev->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); // stencil test always passes objects[1]->UpdateAll(); d3ddev->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCR); d3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW); // render the front face of the shadow volume. objects[1]->draw(); // draw the front side of the shadow volume d3ddev->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_DECR); d3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW); // render the back of the shadow volume. objects[1]->draw();// draw the back side of the shadow volume. d3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW); // back to normal face culling. d3ddev->SetRenderState( D3DRS_COLORWRITEENABLE , 0xff); // turn the color buffer back on. // *********************** pass 2 *********************** // pass 2: draw the region that is covered by shadow. d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE); // turn the light back on, but only the shadow light source to draw the shadowed region. d3ddev->LightEnable(0, TRUE); // turn on the shadow light d3ddev->LightEnable(1, FALSE);// turn off the normal light d3ddev->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); // turn z-buffer write back on. d3ddev->SetRenderState(D3DRS_ZENABLE,TRUE); d3ddev->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL); // stencil configurations //d3ddev->SetRenderState(D3DRS_STENCILENABLE, TRUE); d3ddev->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_NOTEQUAL); // for this part even i change it to D3DCMP_NEVER everything still gets drawn d3ddev->SetRenderState(D3DRS_STENCILREF, 0x0); d3ddev->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP); d3ddev->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); d3ddev->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); // redraw the landscape mesh_landscape->draw(); /*************************** end *********************/ d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); return; } the result is the whole terrain mesh is redrawn in the second pass. it seems the stencil testing doesnt reject the pixels that have a zero value. I have spent a ridiculous amount of time on this already. I greatly appreciate it for reading this.
  14. calvinsfu

    question about LockVertexBuffer

    problem solved. thanks!
  15. When I use the vertices drawn from an existing model, the number of vertices is not 3 times the number of faces(triangles). how should I fix them such that I can use DrawPrimitive to reconstruct the mesh? thanks.
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!