   Artifact
  My application isn't doing much, but I can already see an artifact.All I do is render a unit size skybox, with the view matrix translated to the origin, and swizzle w to z.When I rotate my camera and quickly change directions I sometimes see a blue shape flash through my skybox. My background is blue, so it is showing through my skybox when it should never do so.Any speculation on what the cause and fix may be?   
  Hey,can you post the skybox code and the code that deals with transformations? Thanks   ;  The corners of the box are probably getting far clipped.The distance to the corner of the cube from the center is going to be greater than 1.0from the center of the cube:distance to side : 1distance to center of edge : sqrt(2)distance to corner : sqrt(3)   ;Quote:Original post by leet bixHey,can you post the skybox code and the code that deals with transformations? Thanks#include "SkyBox.h"// Common Lib Includes#include "StringUtil.h"#include "BaseException.h"// Standard Includes#include <vector>#include <string>using namespace common_lib_cpisz;//---------------------------------------------------------------------------SkyBox::SkyBox(ID3D10Device & device, TextureManager & textureManager, EffectManager & effectManager, InputLayoutManager & inputLayoutManager,const std::string & textureFileName_posX,const std::string & textureFileName_negX,const std::string & textureFileName_posY,const std::string & textureFileName_negY,const std::string & textureFileName_posZ,const std::string & textureFileName_negZ)   :   m_device(device),   m_effectManager(effectManager),   m_inputLayout(NULL){   BaseException exception("Not Set",  "SkyBox::SkyBox(ID3D10Device & device, TextureManager & textureManager, EffectManager & effectManager, InputLayoutManager & inputLayoutManager, const std::string & textureFileName_negX, const std::string & textureFileName_posX, const std::string & textureFileName_negY, const std::string & textureFileName_posY, const std::string & textureFileName_negZ, const std::string & textureFileName_posZ)",  "SkyBox.cpp");   // Create geometry to render   //   // Geometry will be inward facing quads that are renderable as triangle strips   std::vector<Position>   positions;   std::vector<TexCoord2D> texCoords;   // Pos Xpositions.push_back(Position(  1.0f, -1.0f,  1.0f )); texCoords.push_back(TexCoord2D( 0.0f, 1.0f ));positions.push_back(Position(  1.0f,  1.0f,  1.0f )); texCoords.push_back(TexCoord2D( 0.0f, 0.0f ));positions.push_back(Position(  1.0f, -1.0f, -1.0f )); texCoords.push_back(TexCoord2D( 1.0f, 1.0f ));positions.push_back(Position(  1.0f,  1.0f, -1.0f )); texCoords.push_back(TexCoord2D( 1.0f, 0.0f ));   // Neg Xpositions.push_back(Position( -1.0f, -1.0f, -1.0f )); texCoords.push_back(TexCoord2D( 0.0f, 1.0f ));positions.push_back(Position( -1.0f,  1.0f, -1.0f )); texCoords.push_back(TexCoord2D( 0.0f, 0.0f ));positions.push_back(Position( -1.0f, -1.0f,  1.0f )); texCoords.push_back(TexCoord2D( 1.0f, 1.0f ));positions.push_back(Position( -1.0f,  1.0f,  1.0f )); texCoords.push_back(TexCoord2D( 1.0f, 0.0f )); // Pos Ypositions.push_back(Position( -1.0f,  1.0f,  1.0f));  texCoords.push_back(TexCoord2D( 0.0f, 1.0f ));positions.push_back(Position( -1.0f,  1.0f, -1.0f));  texCoords.push_back(TexCoord2D( 0.0f, 0.0f ));positions.push_back(Position(  1.0f,  1.0f,  1.0f));  texCoords.push_back(TexCoord2D( 1.0f, 1.0f ));positions.push_back(Position(  1.0f,  1.0f, -1.0f));  texCoords.push_back(TexCoord2D( 1.0f, 0.0f ));// Neg Ypositions.push_back(Position( -1.0f, -1.0f, -1.0f));  texCoords.push_back(TexCoord2D( 0.0f, 1.0f ));positions.push_back(Position( -1.0f, -1.0f,  1.0f));  texCoords.push_back(TexCoord2D( 0.0f, 0.0f ));positions.push_back(Position(  1.0f, -1.0f, -1.0f));  texCoords.push_back(TexCoord2D( 1.0f, 1.0f ));positions.push_back(Position(  1.0f, -1.0f,  1.0f));  texCoords.push_back(TexCoord2D( 1.0f, 0.0f ));   // Pos Zpositions.push_back(Position( -1.0f, -1.0f,  1.0f )); texCoords.push_back(TexCoord2D( 0.0f, 1.0f ));positions.push_back(Position( -1.0f,  1.0f,  1.0f )); texCoords.push_back(TexCoord2D( 0.0f, 0.0f ));positions.push_back(Position(  1.0f, -1.0f,  1.0f )); texCoords.push_back(TexCoord2D( 1.0f, 1.0f ));positions.push_back(Position(  1.0f,  1.0f,  1.0f )); texCoords.push_back(TexCoord2D( 1.0f, 0.0f ));   // Neg Zpositions.push_back(Position(  1.0f, -1.0f, -1.0f )); texCoords.push_back(TexCoord2D( 0.0f, 1.0f ));positions.push_back(Position(  1.0f,  1.0f, -1.0f )); texCoords.push_back(TexCoord2D( 0.0f, 0.0f ));positions.push_back(Position( -1.0f, -1.0f, -1.0f )); texCoords.push_back(TexCoord2D( 1.0f, 1.0f ));positions.push_back(Position( -1.0f,  1.0f, -1.0f )); texCoords.push_back(TexCoord2D( 1.0f, 0.0f ));// Create Buffers   Buffer::SharedPtr bufPositions(new Buffer(device, POSITION, positions));   Buffer::SharedPtr bufTexCoords(new Buffer(device, TEXCOORD2D, texCoords));   m_buffers.push_back(bufPositions);   m_buffers.push_back(bufTexCoords);   // Remove extension from the texture filenames   RemoveExtFromFilename(textureFileName_posX, m_perSideTextureNames[0]);   RemoveExtFromFilename(textureFileName_negX, m_perSideTextureNames[1]);   RemoveExtFromFilename(textureFileName_posY, m_perSideTextureNames[2]);   RemoveExtFromFilename(textureFileName_negY, m_perSideTextureNames[3]);   RemoveExtFromFilename(textureFileName_posZ, m_perSideTextureNames[4]);   RemoveExtFromFilename(textureFileName_negZ, m_perSideTextureNames[5]); // Load the textures   try   { textureManager.CreateTextureFromFile(m_perSideTextureNames[0], textureFileName_posX); textureManager.CreateTextureFromFile(m_perSideTextureNames[1], textureFileName_negX);  textureManager.CreateTextureFromFile(m_perSideTextureNames[2], textureFileName_posY); textureManager.CreateTextureFromFile(m_perSideTextureNames[3], textureFileName_negY); textureManager.CreateTextureFromFile(m_perSideTextureNames[4], textureFileName_posZ); textureManager.CreateTextureFromFile(m_perSideTextureNames[5], textureFileName_negZ);   }   catch(BaseException & e)   { throw e;   }   // Load an effect to use   try   { effectManager.CreateChildEffect("skybox", "skybox.fx");   }   catch(BaseException & e)   { throw e;   }   // Create and store the input layout   Effect &    effect    = effectManager.GetChildEffect("skybox");   Technique & technique = effect.GetTechnique("RenderWith6Tex");   Pass & pass = technique.GetPass(0);   std::vector<InputElementDescription> inputElementDescs;   for(std::vector<Buffer::SharedPtr>::size_type i = 0; i < m_buffers.size(); ++i)   { std::vector<InputElementDescription> elementDesc; InputElementDescription::GetInputElementDesc(elementDesc, m_buffers->GetContentType(), 0, i, false); inputElementDescs.insert(inputElementDescs.end(), elementDesc.begin(), elementDesc.end());   }   m_inputLayout = inputLayoutManager.GetInputLayout(inputElementDescs, pass);   // Store the offsets for the buffers   for(unsigned i = 0; i < m_buffers.size(); ++i)   { m_offsets.push_back(0);   }   // Store the strides for the buffers   for(unsigned i = 0; i < m_buffers.size(); ++i)   { unsigned stride = GetStride(m_buffers->GetContentType()); m_strides.push_back(stride);   }}//---------------------------------------------------------------------------SkyBox::~SkyBox(){}//---------------------------------------------------------------------------void SkyBox::Render(){   Effect &    effect    = m_effectManager.GetChildEffect("skybox");   Technique & technique = effect.GetTechnique("RenderWith6Tex");   Pass & pass = technique.GetPass(0);   Material    material  = effect.GetMaterial();   // Get the current projection and view matrices   D3DXMATRIX origView;   D3DXMATRIX origProjection; m_effectManager.GetViewMatrix(origView);   m_effectManager.GetProjectionMatrix(origProjection);   // Create matrices for rendering the skybox   D3DXMATRIX newWorld;   D3DXMATRIX newView  = origView;   D3DXMATRIX newProjection = origProjection;   D3DXMatrixIdentity(&newWorld);   // Adjust the view matrix such that it has no translation   newView._41 = 0.0f;   newView._42 = 0.0f;   newView._43 = 0.0f;   // Adjust the perspective matrix such that the near and far clip are 2 units apart   float nearPlane = 0.01f;   float farPlane  = 2.0f;   float q    = farPlane / (farPlane - nearPlane);   newProjection._33 = q;   newProjection._43 = -q * nearPlane;    // Bind the matrices for rendering the skybox   effect.SetWorldMatrix(newWorld);   m_effectManager.SetViewMatrix(newView);   m_effectManager.SetProjectionMatrix(newProjection);   // Get the current depth stancil state   ID3D10DepthStencilState * origDepthStencilState;   UINT  stencilRef = 1; // TODO - I don't know what the heck this is! m_device.OMGetDepthStencilState(&origDepthStencilState, &stencilRef);    // Set a new depth stencil state with depth testing disabled   ID3D10DepthStencilState * newDepthStencilState = NULL;   D3D10_DEPTH_STENCIL_DESC  depthStencilDesc;   origDepthStencilState->GetDesc(&depthStencilDesc);   depthStencilDesc.DepthEnable    = true;   depthStencilDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;   depthStencilDesc.DepthFunc = D3D10_COMPARISON_LESS_EQUAL;   if( FAILED(m_device.CreateDepthStencilState(&depthStencilDesc, &newDepthStencilState)) )   { BaseException exception; exception.m_msg = "Failed to create D3D depth stencil state"; throw exception;   }   m_device.OMSetDepthStencilState(newDepthStencilState, stencilRef);   // Bind the input layout   m_device.IASetInputLayout(m_inputLayout);   // Bind the vertex buffers   //   // Since we are using shared pointers, we unfortunatly have to copy the D3D buffer interfaces they point to   // into a seperate vector to pass to D3D when we bind them std::vector<ID3D10Buffer *> vertexBuffers;   for(std::vector<Buffer::SharedPtr>::iterator it = m_buffers.begin(); it != m_buffers.end(); ++it)   { vertexBuffers.push_back((*it)->GetD3DBuffer());   }   m_device.IASetVertexBuffers(0, static_cast<UINT>(m_buffers.size()), &vertexBuffers[0], &m_strides[0], &m_offsets[0]); // Tell the input assembler how to assemble the vertices into primitives   m_device.IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);   // Draw one quad at a time   for( unsigned i = 0; i < 6; ++i )   { // Set the texture for this primitive material.SetTextureName("textureDiffuse", m_perSideTextureNames); effect.SetMaterial(material); // Apply pass pass.Apply(); // Render the face (one strip per face from the vertex buffer)  There are 2 primitives per face. m_device.Draw(4, i * 4);   }   // Restore the original view and projection matrices   m_effectManager.SetViewMatrix(origView);   m_effectManager.SetProjectionMatrix(origProjection); // Restore the original depth stencil state   m_device.OMSetDepthStencilState(origDepthStencilState, stencilRef);   origDepthStencilState->Release();   newDepthStencilState->Release();}//--------------------------------------------------------------------------------------// File: skybox.fx////--------------------------------------------------------------------------------------#include "EffectPool.fxh"matrix world : World;    // Not currently used, only here to comply with application requirementsTexture2D textureDiffuse;SamplerState samplerLinear{   Filter   = MIN_MAG_MIP_LINEAR;   AddressU = Clamp;   AddressV = Clamp;};//////// CONNECTOR DATA STRUCTURES ////////////* Data from application vertex buffer */struct VS_INPUT{   float4   position  : POSITION;   float2   uv   : TEXCOORD;};/* Data passed from vertex shader to pixel shader */struct PS_INPUT{   float4 position : SV_POSITION;   float2 uv  : TEXCOORD;};//--------------------------------------------------------------------------------------// Vertex Shader//--------------------------------------------------------------------------------------PS_INPUT VS( VS_INPUT input ){   PS_INPUT output = (PS_INPUT)0; // Transform the position   matrix viewProjection = mul(view, projection);   output.position = mul(input.position.xyz, viewProjection).xyww; // Copy the UV   output.uv = input.uv; return output;}//--------------------------------------------------------------------------------------// Pixel Shaders//--------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------// Simply shades an object at 100% opacity, with no lights or shadows//float4 PS( PS_INPUT input ) : SV_Target{// Sample the color   float4 finalColor = textureDiffuse.Sample(samplerLinear, input.uv);   finalColor.a = 1; return finalColor;}//--------------------------------------------------------------------------------------// Techniques//--------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------// Renders an object at 100% opacity, with no lights or shadows//technique10 RenderWith6Tex{    pass P0    {   SetVertexShader( CompileShader( vs_4_0, VS() ) );   SetGeometryShader( NULL );   SetPixelShader( CompileShader( ps_4_0, PS() ) );    }}Quote:Original post by ZonerThe corners of the box are probably getting far clipped.The distance to the corner of the cube from the center is going to be greater than 1.0from the center of the cube:distance to side : 1distance to center of edge : sqrt(2)distance to corner : sqrt(3)I turned depth testing off for the render. Any way it would still be clipped? I do have a scissor rect, but I think that is only width and height clipping?EDIT: Whoops, it was off, and then I had since turned it back on and forgot. So I guess the corners ARE getting clipped. How should I go about fixing that?I try to change the near and far clip on the projection matrix and it seems to have no effect.Should I just turn depth testing off and render the skybox first?[Edited by - brekehan on April 26, 2009 3:53:21 PM]