Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualgnomgrol

Posted 28 July 2012 - 04:32 AM

Thanks for the quick reply. I'll read over your article. Indexbuffer is shared already.
What do you mean by compressed textures? Using them in .jpg format?
You suggest to spilt the vertexbuffer, setting one only once (x + z), then pass a y-buffer every chunk?

I only set one set of textures once per frame for the terrain at the moment.

It seems to run smoother with smaller chunks, but I'm pretty sure thats only subjective, FPS are the same.
Here's the code for drawing:

// in terrain.cpp   ( called once per frame )
d3d11DevCon->VSSetShader(VS, 0, 0);
d3d11DevCon->PSSetShader(PS, 0, 0);

d3d11DevCon->OMSetBlendState(0, 0, 0xffffffff);

LightBufferType* dataPtr2;
D3D11_MAPPED_SUBRESOURCE mappedResource;
d3d11DevCon->Map(lightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
// Get a pointer to the data in the constant buffer.
dataPtr2 = (LightBufferType*)mappedResource.pData;
// Copy the lighting variables into the constant buffer.
dataPtr2->ambientColor = D3DXVECTOR4(0.3f, 0.3f, 0.3f, 1.0f); //Everythingcolor
dataPtr2->diffuseColor = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f); //Lightcolor
dataPtr2->lightDirection = D3DXVECTOR3(0.5f, -0.5f, 0.5f);
dataPtr2->padding = 0.0f; // Just Filler
// Unlock the constant buffer.
d3d11DevCon->Unmap(lightBuffer, 0);

// Finally set the light constant buffer in the pixel shader with the updated values.
d3d11DevCon->PSSetConstantBuffers(0, 1, &lightBuffer);
// For Texture
d3d11DevCon->PSSetShaderResources(0, 1, &slopeTexture);
d3d11DevCon->PSSetShaderResources(1, 1, &rockTexture);
d3d11DevCon->PSSetShaderResources(2, 1, &grassTexture);

d3d11DevCon->PSSetSamplers( 0, 1, &SamplerState );

d3d11DevCon->IASetInputLayout( vertLayout );
	d3d11DevCon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

d3d11DevCon->UpdateSubresource( cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0 );
d3d11DevCon->VSSetConstantBuffers( 0, 1, &cbPerObjectBuffer );

	d3d11DevCon->RSSetState(RSCullNormal);

int numVisChunks;
numVisChunks = 0;
for(int i=0;i<chunkList.size();i++){
  if(chunkList[i]->isVisible == true){
  chunkList[i]->Draw(d3d11DevCon);
  numVisChunks++;
  }
}

// chunk.cpp Draw()  ( called once per chunk )
d3d11DevCon->IASetIndexBuffer( indexBuffer, DXGI_FORMAT_R32_UINT, 0); // I need different indexBuffers for different LODs, right?
d3d11DevCon->IASetVertexBuffers( 0, 1, &vertexBuffer, &stride, &offset );
d3d11DevCon->DrawIndexed(numIndices, 0, 0 );


#2gnomgrol

Posted 28 July 2012 - 03:51 AM

Thanks for the quick reply. I'll read over your article. Indexbuffer is shared already.
What do you mean by compressed textures? Using them in .jpg format?
You suggest to spilt the vertexbuffer, setting one only once (x + z), then pass a y-buffer every chunk?

I only set one set of textures once per frame for the terrain at the moment.

It seems to run smoother with smaller chunks, but I'm pretty sure thats only subjective, FPS are the same.
Here's the code for drawing:

// in terrain.cpp
d3d11DevCon->VSSetShader(VS, 0, 0);
d3d11DevCon->PSSetShader(PS, 0, 0);

d3d11DevCon->OMSetBlendState(0, 0, 0xffffffff);

LightBufferType* dataPtr2;
D3D11_MAPPED_SUBRESOURCE mappedResource;
d3d11DevCon->Map(lightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
// Get a pointer to the data in the constant buffer.
dataPtr2 = (LightBufferType*)mappedResource.pData;
// Copy the lighting variables into the constant buffer.
dataPtr2->ambientColor = D3DXVECTOR4(0.3f, 0.3f, 0.3f, 1.0f); //Everythingcolor
dataPtr2->diffuseColor = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f); //Lightcolor
dataPtr2->lightDirection = D3DXVECTOR3(0.5f, -0.5f, 0.5f);
dataPtr2->padding = 0.0f; // Just Filler
// Unlock the constant buffer.
d3d11DevCon->Unmap(lightBuffer, 0);

// Finally set the light constant buffer in the pixel shader with the updated values.
d3d11DevCon->PSSetConstantBuffers(0, 1, &lightBuffer);
// For Texture
d3d11DevCon->PSSetShaderResources(0, 1, &slopeTexture);
d3d11DevCon->PSSetShaderResources(1, 1, &rockTexture);
d3d11DevCon->PSSetShaderResources(2, 1, &grassTexture);

d3d11DevCon->PSSetSamplers( 0, 1, &SamplerState );

d3d11DevCon->IASetInputLayout( vertLayout );
    d3d11DevCon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

d3d11DevCon->UpdateSubresource( cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0 );
d3d11DevCon->VSSetConstantBuffers( 0, 1, &cbPerObjectBuffer );

    d3d11DevCon->RSSetState(RSCullNormal);

int numVisChunks;
numVisChunks = 0;
for(int i=0;i<chunkList.size();i++){
  if(chunkList[i]->isVisible == true){
  chunkList[i]->Draw(d3d11DevCon);
  numVisChunks++;
  }
}

// chunk.cpp Draw():
d3d11DevCon->IASetIndexBuffer( indexBuffer, DXGI_FORMAT_R32_UINT, 0); // I need different indexBuffers for different LODs, right?
d3d11DevCon->IASetVertexBuffers( 0, 1, &vertexBuffer, &stride, &offset );
d3d11DevCon->DrawIndexed(numIndices, 0, 0 );


#1gnomgrol

Posted 28 July 2012 - 03:39 AM

Thanks for the quick reply. I'll read over your article. Indexbuffer is shared already.
What do you mean by compressed textures? Using them in .jpg format?
You suggest to spilt the vertexbuffer, setting one only once (x + z), then pass a y-buffer every chunk?

I only set one set of textures once per frame for the terrain at the moment.

PARTNERS