Jump to content

  • Log In with Google      Sign In   
  • Create Account

Drakken255

Member Since 14 Oct 2010
Offline Last Active Aug 18 2013 04:44 PM

Topics I've Started

Optimizing Instancing Shader (Reducing Transfer Volume)

13 August 2013 - 03:21 PM

Hello all, long time since my last post.

 

I worked on a voxel engine about a year ago in XNA using hardware instancing of each cube's faces. While making it, I made a post here asking for advice (link below) on how to improve the framerate, as my code was incredibly inefficient, from doing too much unneeded update logic to simply drawing too much. During said discussion it has improved vastly, but had to put the project down without implementing the number 1 most important piece of advice I took from that post: reducing the volume of data about each instance. Following is a quote explaining how much I was using and how much I could have been using.

 

 

It sounds like your instance vertex format is something like this?


transform 16*4 -> 64 bytes
texcoord 2*4 -> 8 bytes
texcoord 2*4 -> 8 bytes
texcoord 2*4 -> 8 bytes
color 4*4 -> 16 bytes

As kalle_h mentioned, you should be able to reduce the color to 4 bytes. You can also use lower precision values for the texcoords. Using HalfVector2 for the texcoords will cut their size in half (or use the index menthod Kalle_h mentioned). These are simple changes to the vertex format, you don't need to change the shader.

For the transform, it sounds like you're passing a whole matrix? You actually only need to pass some of the matrix elements, and you can "reconstruct" the matrix in the shader. Certainly you could cut this down to 12 floats. If you only need translation, then you could cut it down to 3 floats. If you also need a uniform scale, that's only 1 more float. Rotation? Probably 4 more.

So, conservatively, you get have:
transform 12*4 -> 48 bytes
texcoord 2*2 -> 4 bytes
texcoord 2*2 -> 4 bytes
texcoord 2*2 -> 4 bytes
color 4*1 -> 4 bytes
TOTAL: 64 bytes

More aggressively, say you only need translation for your transform:
transform 3*4 -> 12 bytes
texcoord 2*2 -> 4 bytes
texcoord 2*2 -> 4 bytes
texcoord 2*2 -> 4 bytes
color 4*1 -> 4 bytes
TOTAL: 28 bytes

 

My goal is to take the last byte count down even further.

transform 3*4 -> 12 bytes

texcoord 1*2 -> 2 bytes
texcoord 1*2 -> 2 bytes
texcoord 1*2 -> 2 bytes
color 2*1 -> 2 bytes
TOTAL: 20 bytes

 

As the quote shows, I was indeed passing an entire matrix, when only the translation info was needed. I solved this easily enough by simply passing a Vector3 and rebuilding the world matrix in the shader.

 

Next, I want to take the next three variables (coordinates for a texture atlas, (base, overlay, and breaking)), and reduce them further than 2*2 down to a single 16 bit unsigned integer, which should allow ~65,536 different atlas coordinates. Problem is:

(1). I don't know how to turn an index into an x and a y int in HLSL code. I could do it in C# fine by just dividing the index by the number of pieces per row, storing the rounded down number as y, and subtracting the y * the number of pieces per row from the index to get x.

(2). HLSL has no 16-bit integer. Is it possible to still send a 16 bit int, but convert to a 32 bit int once it's there? Or am I just missing unlisted integral types?

 

Lastly, for my color, I only want to send 2 bytes. The first will represent red, green, and blue, while the second will represent transparency. How do I convert 2 bytes into 2 floats when the time comes?

 

All in all, I just need help in converting different data types back and forth to allow for the least needed bandwidth when I send my instance information.

 

For those of you that would like to view the original discussion, click this link: http://www.gamedev.net/topic/629247-face-instancing-dividing-draw-calls/

 

 

 

EDIT: I just realized that since I am instancing individual faces of each cube, I do also need rotation, so memory per instance will actually look like this:

transform 12*4 -> 48 bytes

texcoord 1*2 -> 2 bytes
texcoord 1*2 -> 2 bytes
texcoord 1*2 -> 2 bytes
color 2*1 -> 2 bytes
TOTAL: 56 bytes
 
What I don't understand is why I need to send an additional 6 bytes for a 3 axis rotation, or where in the matrix that data is, so I now also need help getting this cut down a bit.

Cross-Platform Web Browser Control for Winforms

15 November 2012 - 02:07 PM

Hello all,

I am trying to port my program, PatchCraft to Linux and Mac, but Mono doesn't have a WebBrowser control for OSX. The browser control is essential, so I can't remove it, and I'm having massive trouble finding any other working and documented library out there. The control doesn't even have to be capable of much; my pages have no more than text, hyperlinks, and an external stylesheet. The problem lies in the fact that either each library isn't well documented, or it only works for one or two of the three platforms. Ideally, the library I need would build into a single DLL to be shipped with PatchCraft that will wrap runtimes developed for each respective OS.

I've searched long and hard for a solution, but I am beginning to get very confused by it all and would very much appreciate a simple "step-by-step" guide on this. I must stress again that the library I need must work on Windows without Mono, and on both Linux and Mac WITH Mono, and not include 2 GB (exaggeration) worth of redists and natives that I myself must distribute.

On a side note, GeckoFX has failed me by working fine on Windows alone, but producing this exception (produced by custom handler) under Windows Mono:

An unhandled exception has occurred!
Message: xpcom
at (wrapper managed-to-native) Skybound.Gecko.Xpcom:NS_NewNativeLocalFile (Skybound.Gecko.nsACString,bool,object&)
at Skybound.Gecko.Xpcom.Initialize (System.String binDirectory) [0x00000] in <filename unknown>:0
at PatchCraft.Program.Begin (System.String[] args) [0x00000] in <filename unknown>:0

Any ideas?

Zip/Unzip Files without .NET 4.5: #ZipLib Not Working

20 October 2012 - 10:01 AM

Hello all,

I need to be able to zip and unzip files that are known to be named oddly, and my current method (SharpZipLib and a recursive zip/unzip wrapper) can't do it right. An example would be "aux.class" which is a reserved file name, so File won't write that. I've currently rigged a bit of a renaming system specifically for this file, but I dont like doing that sort of thing, it's just too messy and inefficient having to do special things for one file.

Next, I've noticed that even though the files now unzip and rezip, there is a difference between the original and the rezip. Currently, both the manually unzipped and the programmatically unzipped folders have the same size, but there is a difference of over 90KB between the original and the rezipped files, when done so programmatically. Any difference in zips is highly unacceptable since it's actually a JAR archive I'm messing with.

There is the possibility that I am missing something, so I'll give the benefit of the doubt and post my wrapper here:

Spoiler


If my code is correct, then I can't use SharpZipLib. I need something that can zip and unzip files accurately with no difference between the original and the rezip, no matter the file name, so I'm looking to use something else. Anyone have any ideas on what else to try?

UPDATE: I have switched over to DotNetZip and it does FAR better. The JAR (being Minecraft) actually runs now! The problem now is still that aux.class file. Now, when loading a map, the game will crash with "Incompatible magic value 0 in class file aux" or "ClassDefNotFound for aux" which obviously means it is corrupted somehow, but I just don't know what's going on with it. I have narrowed it down to the fact that done manually, the file will use 313 KB zipped, but after programmatical modification, the file will be only 8. 7-Zip strangely enough shows that each has the same unzipped file size...

Settings File and Compatibility

18 October 2012 - 11:06 AM

Hello all,

Bear in mind this is a bit difficult for me to explain.
I currently have a set of check boxes in my settings form and I might add more in later updates. I want to save these to a file in the general format of:

false
true
false
etc etc...

But what happens when an update adds a check box or two? I try to load the file's boolean values into them with:

string [] array = File.ReadAllLines(<FILE>);

checkboxOne.Checked = bool.Parse(array[0])
checkboxTwo.Checked = bool.Parse(array[1])
//etc etc...

But when it gets to the new check boxes, for which there is no line in the file, it will throw an IndexOutOfBoundsException because the file has x minus number-of-boxes-added lines and thus so does the array. Example:
5 old boxes, 3 new. the file and array count 5, so when the program reaches index 5 (the sixth and nonexistent line), exception.

Is there a better way to implement this to allow for a growing set of check boxes? Should I constantly check if the array length is less and resize as necessary?

[XNA] Model Renders Black

18 October 2012 - 08:59 AM

Hello all,

I am having a massive amount of trouble with a model and its texture showing up in XNA. I know it's not XNA because I am using a completely unmodified copy of the Skinned Model Sample to test it. Currently, it will render correctly in Blender, but will render black in XNA. I have already asked about this elsewhere in vain. Now out of frustration I am simply looking for someone to fix it for me. Credit will be given in my Minecraft tool called PatchCraft. The person that fixes it will be labeled in it as the sole creator of the model.

Screenshot of my problem (in PatchCraft):
Spoiler


Contact me if you would like to give it a try.

PARTNERS