XNA 4.0 voxel map rendering, using noise techniques

Started by
45 comments, last by winsrp 12 years, 1 month ago
due to the complexity of the formulas that generate the landscape it seems inefficient to not store the position of the blocks in some sort of an array. In order to check coalitions for a single point i need to call 15 fractal formulas (so far), with several conditions in them, which would be a lot easier just to ask for the point under the array. So I'm storing the cubes now, I have managed to set a view distance that I seem comfortable with (and my memory too) peaking at around 500mb, I have more than room to spare with an array of 512*1024*512, which gives me from the center position at sea level, 256 blocks of view in every direction plus, 512 over my head, and I'm still running smoothly with v-sync at 60fps with no bumps, and generation for the initial map (the full 512*1024*512) only takes around 6 seconds so far, so I think I'll leave distances alone, and focus on adding terrain detail (I still haven't found a way to make overhangs, but I did found a way to do cliffs), and I think I have an idea to make the tree leafs procedural, but I still need to test it out a bit.

On the lighting department I think I'm stuck with the transparency issue I have, and doing Ambient Occlusion seems to need a lot of knowledge I still don't have, (read a lot about different techniques mostly SSAO) nor I have the basics to understand, so I'll try something more simple with a shadow map for my diffuse light (rendering transparency objects after it so I can cast shadows under water), and I'll use an inverted diffuse light to provide the light bounce effect.

I still need to learn about making a character out of blocks without using a model, and animating it.

If anyone can help me with any of those issues I have, I'll be really grateful.
Advertisement
ok transparency effect is fixed now, as I was drawing each land section I was also drawing each water section on top, which resulted in the transparency not working for the sections that were not loaded yet, so i just did all the terrain and then all the water after it, and it works wonders.

Still waiting for help on the character.
so after a month or so of experimentation I have found out about geometry shaders, that japro was talking about at the beginning, and I also learn how I cannot use it on XNA due to this being DX10 and XNA only supporting DX9... so, with that in mind, how can I get to use DX10 with C#/vb.net?

so, with that in mind, how can I get to use DX10 with C#/vb.net?

SlimDX.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

slimDX seem ok, but is sure could use a hell lot more examples.... its really hard for a newb to make it do something.
ok given the fact that the last example on the slimdx tutorials (yes third one, not many examples) is a corrupted zip file (at least that's what winrar says) then I had to figure it out a bit until finally... I managed to display the great yellow triangle...

I'm pasting the code I have here in vb.net (since there is no reference to vb.net anywhere)


Imports System
Imports System.Drawing
Imports SlimDX
Imports SlimDX.Windows
Imports SlimDX.DXGI
Imports SlimDX.Direct3D11
Imports SlimDX.D3DCompiler
Imports Device = SlimDX.Direct3D11.Device
Imports Resource = SlimDX.Direct3D11.Resource
Imports Buffer = SlimDX.Direct3D11.Buffer
Module test1
Private FormWindow As RenderForm
Private Device As Device
Private SwapChain As SwapChain
Private Context As DeviceContext
Private rendertarget As RenderTargetView
Private layout As InputLayout
Private effect As Effect
Private vertices As New DataStream(12 * 3, True, True)
Private vertexbuffer As Buffer
Sub Main()
Initialize()
Load()
'update + draw
MessagePump.Run(FormWindow, AddressOf MainLoop)
'Finalize
For Each item In ObjectTable.Objects
item.Dispose()
Next
End Sub
Private Sub Initialize()
FormWindow = New RenderForm("Test 1")
Dim description = New SwapChainDescription With _
{ _
.BufferCount = 1, _
.Usage = Usage.RenderTargetOutput, _
.OutputHandle = FormWindow.Handle, _
.IsWindowed = True, _
.ModeDescription = New ModeDescription(0, 0, New Rational(60, 1), Format.R8G8B8A8_UNorm), _
.SampleDescription = New SampleDescription(1, 0), _
.Flags = SwapChainFlags.AllowModeSwitch, _
.SwapEffect = SwapEffect.Discard _
}
AddHandler FormWindow.KeyDown, AddressOf HandleKeyDown
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, Device, SwapChain)
Using resourceTexture As Texture2D = Resource.FromSwapChain(Of Texture2D)(SwapChain, 0)
rendertarget = New RenderTargetView(Device, resourceTexture)
End Using
Context = Device.ImmediateContext
Dim viewport As Viewport = New Viewport(0.0F, 0.0F, FormWindow.ClientSize.Width, FormWindow.ClientSize.Height)
Context.OutputMerger.SetTargets(rendertarget)
Context.Rasterizer.SetViewports(viewport)
Using factory As Factory = SwapChain.GetParent(Of Factory)()
factory.SetWindowAssociation(FormWindow.Handle, WindowAssociationFlags.IgnoreAltEnter)
End Using
End Sub
Private Sub Load()
Dim bytecode As ShaderBytecode = ShaderBytecode.CompileFromFile("CodeFile1.fx", "Simple", "fx_5_0", ShaderFlags.EnableStrictness, EffectFlags.None)
effect = New Effect(Device, bytecode)
LoadVertices()
Dim elements As InputElement() = {New InputElement("POSITION", 0, Format.R32G32B32_Float, 0)}
layout = New InputLayout(Device, effect.GetTechniqueByName("Simple").GetPassByIndex(0).Description.Signature, elements)
vertexbuffer = New Buffer(Device, vertices, 12 * 3, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0)
End Sub
Private Sub LoadVertices()
vertices.Write(New Vector3(0.0F, 0.5F, 0.5F))
vertices.Write(New Vector3(0.5F, -0.5F, 0.5F))
vertices.Write(New Vector3(-0.5F, -0.5F, 0.5F))
vertices.Position = 0
End Sub
Private Sub MainLoop()
Update()
Draw()
End Sub
Private Sub Update()
End Sub
Private Sub Draw()
Context.ClearRenderTargetView(rendertarget, New Color4(Color.Aqua))
Context.InputAssembler.InputLayout = layout
Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList
Context.InputAssembler.SetVertexBuffers(0, New VertexBufferBinding(vertexbuffer, 12, 0))
Dim currentTechnique As EffectTechnique = effect.GetTechniqueByName("Simple")
For passIndex As Integer = 0 To currentTechnique.Description.PassCount - 1
Dim EPass As EffectPass = currentTechnique.GetPassByIndex(passIndex)
EPass.Apply(Context)
Context.Draw(3, 0)
Next
SwapChain.Present(0, PresentFlags.None)
End Sub
Private Sub HandleKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.Alt And e.KeyCode = Keys.Enter Then
SwapChain.IsFullScreen = Not SwapChain.IsFullScreen
End If
End Sub

End Module


and the simple Shader


float4 SimpleVS(float4 position : POSITION) : SV_POSITION
{
return position;
}

float4 SimplePS(float4 position : SV_POSITION) : SV_Target
{
return float4(1.0f, 1.0f, 0.0f, 1.0f);
}
technique11 Simple
{
pass P0
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, SimpleVS() ) );
SetPixelShader( CompileShader( ps_4_0, SimplePS() ) );
}
}
now, how can I get the gametime variable into my update like XNA had?

any ideas?

And how do i get to render text in the corner?... need my stats to work.

This topic is closed to new replies.

Advertisement