Jump to content

  • Log In with Google      Sign In   
  • Create Account

Hodgman

Member Since 14 Feb 2007
Offline Last Active Today, 05:09 AM

#5019341 Writing to the depth texture in a FBO

Posted by Hodgman on 08 January 2013 - 09:28 PM

You can use gl_FragDepth to write out your own depth-values instead of using the ones generated by the rasterizer.

 

n.b. this generally disables Hi-Z optimizations for that depth-buffer until the next clear, as the Hi-Z buffers are generally populated by the rasterizer (which is incorrect in the case where you've replaced it's depth values).




#5019285 Text editors that's optimized for 16:9 Laptops

Posted by Hodgman on 08 January 2013 - 06:33 PM

Picture trying to read a newspaper broadsheet if there was one column with all the text the width of the page.
The collected wisdom of the centuries is that the optimal column width is about 3 inches (7 cm), left justified, ragged right.

Picture trying to read C++ code if we formatted it as we do newspaper!

for ( int j = 0; j < Rasterizer::
g_width; ++j ) { for ( int y = 0;
y < Tile::g_tile_height; ++y )for
( int  x  =  0;  x   <   Tile::
g_tile_width; ++x ) { int idx = j
+Rasterizer::g_width; __m128i buf
  =  rast  .  m_tiles  [ idx ]  . 
m_frame_buffer[ y ]; unsigned int 
mask = ( ( unsigned int * ) ( &
buf ) ) [ x >> 5 ] ;  int  bit  = 
mask & ( 1 << (  x  &  31  ) )  ;
COLORREF col = bit ? RGB ( 255  ,
255 , 255 ) : 0 ;     g_data[ j * 
Tile::g_tile_width + 127 -  x   +
( Tile::g_tile_height + y )     *
g_info . bmiHeader . biWidth ]  =
( unsigned ) col ; } }

 
Not arguing for or against 80-columns here, but reading code is a very different activity to reading a newspaper or a novel, and code itself is a very different kind of content (closer to a mathematical theorem than prose), so conventional wisdom for laying out text is largely irrelevant.

Width only seems so excessive now because our monitors have given us so much of it, but they haven't given us so much that we can comfortably cut it in half

Works for me on my 2048*1152 monitor. Often with a 50/50 split, and sometimes with a 70/30 split if a file contains long lines.

if doing so requires you to lose your focus and take mental effort to interpret what you see (i.e. display big enough that you have to look down, lose your place, and find it again, or two views next to each other that take some practice to see them as a continuation of each other and reconcile the differences in indentation), then you may be better off just being able to seek faster and more efficiently

I used to use a 16:9 monitor rotated 90º to be a tall-screen for writing code, and another in regular landscape mode for playing the game on, because I found that "scrolling by looking" took less mental effort than actually scrolling, and I wouldn't lose my place as much wink.png

Speaking of text editors, what the hell is wrong with the forum text editor?

The staff are waiting on a patch from IPB (the forum software), as the last update has caused a lot of issues.




#5018764 Best Language for Cross-Platform Content Pipeline

Posted by Hodgman on 07 January 2013 - 04:00 PM

I use C# for that -- the huge standard library does all your directory/text/regex stuff, LuaInterface makes integrating with Lua amazingly simple (I use Lua to describe a lot of my input data), and calling external compilers, etc is easy.

I don't need it to be x-platform, as a lot of our other tools are Windows-only anyway. We compile resources for all platforms from a Windows development PC.
However Mono does make it portable if you need that, and the Mono/.NET runtime dependency doesnt bother me because only my devs need it, not my players/customers.


#5018486 Camera Zooming In and Out

Posted by Hodgman on 07 January 2013 - 01:15 AM

It was just an example of using intuitive values in degrees, you can animate them however you like, e.g.

 

inline float lerp( float a, float b, float f ) { return b*f + a*(1-f); }
float fovDegrees = lerp( regularFov, sniperFov, zoomFraction )

 

 

What is your maximum zoom value -- what fov value are you using as the 'maximum'? If you use an fov of 0, then you'd end up with an infinitely thin frustum with no area... but any value greater than 0 should work (and smaller than 180º...)

Can you post a picture of your "weird" textures?




#5018476 How to do in indie game

Posted by Hodgman on 07 January 2013 - 12:27 AM

If you are going to be operating a business (that sells products, etc), you will likely have to register your business with your government.




#5018454 Can you return a class member object as a pointer?

Posted by Hodgman on 06 January 2013 - 11:28 PM

Yes.

 

As a pointer:

a* GetA() {return &MyObject;}

MyB.GetA()->DoSomethingToMyObject();

 

or as a reference:

a& GetA(){return MyObject;}

MyB.GetA().DoSomethingToMyObject();




#5018383 Text editors that's optimized for 16:9 Laptops

Posted by Hodgman on 06 January 2013 - 07:41 PM

I use visual studio with a window layout like that, but with two different files open in the right/left panes (and traditional scrolling, instead of book-type).

I set all the "solution explorer" etc panes to auto-hide, and then right click on a file-tab and use "New Vertical Tab Group" to create the 2 panes. I also then right-click on the find-results and output panes and change them to "Tabbed documents" so that I can place them in these panes.

DLm8F.png

 

I've thought before that having the 1 file in both panes (scrolling in sync with each other) would be a good idea too wink.png but have never seen it. Maybe there's a VS plugin that can do it for me...

You can use "Window->New Window" to get two views of the same document, so you can view it in both the left/right panes, however, they don't scroll in sync with each other.




#5018373 Has Anyone Here Sold on Steam?

Posted by Hodgman on 06 January 2013 - 06:56 PM

I've not sold anything on steam, but:

 

1) In most countries, if you're selling anything at all, you need to register as a business. Here in Australia, the simplest way is to go to the taxation-office's website and fill in the form to register as an individual/sole-trader, which takes 5 minutes, and when you're done you've got a business number (and the obligation to submit tax information for that business).

 

2) Steam is a publisher. Traditionally, you've gotten in touch with them like you would any publisher, and made a pitch for them to sell your game for you.

All greenlight has done is changed the way you get in touch with them -- you've got to 'pass' the greenlight system before you can negotiate your publishing deal now.




#5018191 IDirect3DTexture9 vs LPDIRECT3DTEXTURE9

Posted by Hodgman on 06 January 2013 - 08:37 AM

I understand that LPDIRECT3DTEXTURE9 is just a IDirect3DTexture9*

Then to stop using LPDIRECT3DTEXTURE9, you just have to find-replace-in-files with IDirect3DTexture9* and you're done cool.png

does LPDIRECT3DTEXTURE9 have these?

There's no difference between LPDIRECT3DTEXTURE9 and IDirect3DTexture9*, so yes, they both have al the same stuff as each other.

I don't know what pass in for DWORD usage, D3DFORMAT format, D3DPOOL Pool?
Also there doesn't seem do be a file name parameter for IDirect3DTexture9 so how would I create a IDirect3DTexture9 from a file?

D3D is just a graphics API, it doesn't (and shouldn't!) know anything about file systems (D3DX is the helper layer to make writing simple programs easier, so it has file-system and image-format helpers). If you're not using D3DX to load your files, then you've got to load the file yourself, decode the file-format (PNG, BMP, etc) and generate an array of bytes that contain the pixel values, which you'll pass to CreateTexture. There's plenty of image loading libraries out there to help with the decoding steps (no need to write your own PNG/etc decoder).
 
For format, the most common will be D3DFMT_A8B8G8R8 -- the regular 32bpp format with red, green, blue and alpha channels. If you're loading a 24bpp image file, you'll have to convert it to 32bpp by adding an alpha channel to it.
 
For usage, most textures will use 0 (no flags).

If you want to write to it constantly from the CPU (for streaming video, etc), you'd use D3DUSAGE_DYNAMIC. If you want to draw to it using the GPU, you'd use D3DUSAGE_RENDERTARGET. If you're creating a depth-buffer texture (e.g. with format=D3DFMT_D24S8), you'd use D3DUSAGE_DEPTHSTENCIL.
 
For the pool, regular textures usually use D3DPOOL_MANAGED. Dynamic, render-target, and depth-buffer textures can't go in that pool though, so for them you'd use D3DPOOL_DEFAULT.




#5018173 Will i make it in game dev ?

Posted by Hodgman on 06 January 2013 - 07:30 AM

What's "the basic stuff"? Addition and subtraction? Algebra? Trigonometry? If you know them, then you've got more than enough to get started.

In regular "gameplay" programming, there isn't really that much complex math.

 

I specialize in 3D graphics, which has a lot more math than gameplay systems, and I was in a similar position -- I learnt most of my math skills "on the job" instead of in school.

In high-school I did "regular" math instead of the "advanced" class, and in university I did "business" math classes instead of "science/physics" ones.




#5018089 Which DirectX to Pick

Posted by Hodgman on 06 January 2013 - 12:12 AM

It's basically a choice between 9 and 11 these days.

If you want to support Windows XP then use 9, otherwise use 11.

 

DX11 has "feature levels" that allows you to use it in different ways, to support different types of hardware.

Dx11 set to use D3D_FEATURE_LEVEL_9_* supports D3D9/SM2 level hardware.

Dx11 set to use D3D_FEATURE_LEVEL_10_* supports D3D10/SM4 level hardware.

Dx11 set to use D3D_FEATURE_LEVEL_11_* supports D3D11/SM5 level hardware.

 

10/11 removed the fixed-function pipeline, so these days you need to learn how to write shaders in order to use them, so you could say they're more complicated.

However, you could also say they're simpler, because 9 always had 2 (or more) ways to do everything, due to it supporting both shaders and fixed-function...

 

I'm not sure if it's even possible to get an official SDK for DX8 and earlier from Microsoft any more.




#5017959 Skybox, render order and clipping thoughts

Posted by Hodgman on 05 January 2013 - 06:38 PM

The short version of the 'w' trick is -- the GPU computes each pixels depth buffer value as 'zbuf = pos.z / pos.w'.
So, if you set "z = w", then you get 'zbuf = w/w' or 'zbuf = 1'.

To explain what 'pos.w' is, is a bit harder. It's sometimes called the 'homogeneous coordinate' of the position.
To do our 3D perspective projections, it's easier to work in 4D space. In the vertex shader, we convert our euclidean position to a homogenous position by giving it a 4th (w) coordinate of 1. Our matrices then operate on these 4D values, producing a 4D position output. The GPU hardware automatically divides the position by its 'w' value per pixel, which is how we convert from homogenous coordinates back to euclidean coordinates.

All your other vertex-shader outputs (e.g. Texture coordinates) are also divided by 'pos.w' per pixel in order to achieve "perspective correct" interpolation. So, it's an important detail in 3D projection (and linear algebra) even if you don't understand it's meaning ;-)


#5017737 Passing bone matrices to shader

Posted by Hodgman on 05 January 2013 - 07:40 AM

is there a harm if it reads past the end of a vector, even if that data isn't used? Or is it undefined behaviour?

Yes it's harmful; it could crash your program. If you're lucky, nothing bad will happen (besides the extra bones containing garbage values), but it could crash depending on how the OS has decided to allocate your memory...

I got shader error if i pass it like this:

Ah, that must be an issue with the D3DX Effect framework -- I usually just use D3D shaders directly, and they allow you to send less data than the shader requires (with the unsent elements of the array containing garbage values).

In that case, just use vMat.resize(MAX_BONES) to avoid the error and also avoid the undefined behaviour wink.png




#5017734 Skybox, render order and clipping thoughts

Posted by Hodgman on 05 January 2013 - 07:33 AM

To make your sky geometry always appear to be at infinite depth, you can edit it's vertex shader so it outputs w as z.

e.g. right at the end, after computing the position: OUT.Position.z = OUT.Position.w;

 

@Columbo As Phantom said -- it's important to actually issue clear commands for the z-buffer on modern hardware. If you instead just clear it yourself by rendering distant objects, you'll basically be disabling the Hi-Z feature.




#5017730 Top of the line vs Old crap

Posted by Hodgman on 05 January 2013 - 07:22 AM

So, the real issue is that your logarithmic depth buffer isn't working (or your code to reconstruct position from depth isn't working), but somehow switching to DX 11.1 will solve this, which brings more issues? What's the theory behind the 11.1 fix?

 

To check if the issue is the logarithmic-depth code, or the reconstruct-position code, have you tried switching temporarily back to a 'standard' depth buffer and checking whether you can correctly reconstruct positions from it?

 

With your logarithmic depth values, are you computing them per-vertex or per-pixel?

 

Have you considered using a floating-point depth-buffer instead of a regular one with the logarithmic mapping? A 32-bit floating point buffer with near/far reversed gives better precision than a 24-bit logarithmic one anyway, with the down-side being that you lose your 8 bits of stencil buffer.






PARTNERS