Well it turns out I found my problem and have officially loaded my first fully texture mapped Quake III .BSP level in DirectX. Apparently having normals defined as part of your custom vertex but not having lighting enabled causes DX to puke when rendering textures.
Long story short, it's working and now I'm moving up to rendering full quake III levels like DM8 etc.
Thanks again for everyone's help, much appreciated. If anyone has any questions about this I'll be more than happy to help out with it and may look into turning it into a tutorial once I figure out lightmaps, brushes, etc.
Permafried-
Rendering Quake III BSP In DirectX
Glad to see you making progress.
I just finished getting most of my shader features implemented.
The only things which aren't working are environment mapping, sky boxes, deformed vertexes, and turblant textures.
I just finished getting most of my shader features implemented.
The only things which aren't working are environment mapping, sky boxes, deformed vertexes, and turblant textures.
Yzzid,
Wow you're miles ahead of me....I almost jumped outta my chair when I managed to get the level rendering fully texture mapped ^_^. I managed to get lightmaps somewhat working last nite, but think I have a few problems with how I'm building up the texture based on the information provided. All I do is create a blank texture using CreateTexture, then make a call to LockRect and loop through each pixel of the pBits and assign a colour to it 1 pixel at a time.
I'm going to experiment with this a little more tonite when I get home and hopefully can manage to solve this and move onto working with leaves, nodes and the PVS.
Permafried-
Wow you're miles ahead of me....I almost jumped outta my chair when I managed to get the level rendering fully texture mapped ^_^. I managed to get lightmaps somewhat working last nite, but think I have a few problems with how I'm building up the texture based on the information provided. All I do is create a blank texture using CreateTexture, then make a call to LockRect and loop through each pixel of the pBits and assign a colour to it 1 pixel at a time.
I'm going to experiment with this a little more tonite when I get home and hopefully can manage to solve this and move onto working with leaves, nodes and the PVS.
Permafried-
You must realize that I have been working on this for a few years.
It has taken me a while to understand everything.
One thing that has help immensely is that there is a rendering engine in the ShaderX book. That is what I am using as a reference right now. I highly recommend picking it up.
It has taken me a while to understand everything.
One thing that has help immensely is that there is a rendering engine in the ShaderX book. That is what I am using as a reference right now. I highly recommend picking it up.
I may have to look into getting a copy of that....I'm developing based on documentation on the Quake III BSP format from what is available online, and pieceing the rest of it together based on what I know about OpenGL, DirectX and C++ in general. For only working on the code for 4 days now or so I'm happy with the results, but I have a tight timeline as it's a school project.
It's supposed to run from September to December, but since I had the summer off as a co-op term I decided to work on it all summer instead, just so I can build the type of project I'm able to add to my portfolio after school, not this piece of junk threw it together as fast as possible just to get the mark ^_^.
If I run into anymore problems I'll keep adding to this thread, particularly since it may be of use to others in the community if they're interested in creating their own BSP parser/rendering engine. It still blows my mind that my texture coordinates are correct, even though the values that were output to the file are totally out of whack and shouldn't have worked in the first place, makes me wonder if they're in binary format, and if I were to convert them over to ASCII via conversion methods if I'd see the real values or not.
Permafried-
It's supposed to run from September to December, but since I had the summer off as a co-op term I decided to work on it all summer instead, just so I can build the type of project I'm able to add to my portfolio after school, not this piece of junk threw it together as fast as possible just to get the mark ^_^.
If I run into anymore problems I'll keep adding to this thread, particularly since it may be of use to others in the community if they're interested in creating their own BSP parser/rendering engine. It still blows my mind that my texture coordinates are correct, even though the values that were output to the file are totally out of whack and shouldn't have worked in the first place, makes me wonder if they're in binary format, and if I were to convert them over to ASCII via conversion methods if I'd see the real values or not.
Permafried-
Texture coordinates can be outside of the range of 0.0 to 1.0. If this is the case then the texture just repeats if the addressing mode is set to wrapping.
Hey,
Well I thought I had it down, but I seem to have problems with the creation of some of my lightmaps. It worked fine in a simple level which consisted of a cube with a ramp and a wooden platform, but now loading a larger level, I get a nice whack of purple in places and I'm not too sure why. I thought the code to create the lightmaps was working well....but maybe someone can spot an error:
Well I thought I had it down, but I seem to have problems with the creation of some of my lightmaps. It worked fine in a simple level which consisted of a cube with a ramp and a wooden platform, but now loading a larger level, I get a nice whack of purple in places and I'm not too sure why. I thought the code to create the lightmaps was working well....but maybe someone can spot an error:
for( int i = 0; i < m_pLevel->levelGetNumberOfLightmaps(); i++ ) { // create the texture at index i, we'll make this // dynamic so we can clear it out and re-write later D3DXCreateTexture( DXUTGetD3DDevice(), 128, 128, D3DX_DEFAULT, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &m_pLightmaps.m_d3dtTexture );<br><br> <span class="cpp-comment">// get the lightmap's surface descriptor</span><br> m_pLightmaps.m_d3dtTexture->GetSurfaceLevel( <span class="cpp-number">0</span>, &pLightmapSurface );<br><br> <span class="cpp-comment">// lock the texture's entire surface, this gets us</span><br> <span class="cpp-comment">// ready to begin writing out the pixel information</span><br> pLightmapSurface->LockRect( &rect, NULL, <span class="cpp-number">0</span> );<br><br> <span class="cpp-comment">// get the surface information in bit form, this will</span><br> <span class="cpp-comment">// allow us to write out the information pixel by pixel</span><br> pTextureSurface = <span class="cpp-keyword">static_cast</span><<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span>*>( rect.pBits );<br> dwBitsPerRow = rect.Pitch;<br><br> <span class="cpp-comment">// loop through all items in each row, Quake III</span><br> <span class="cpp-comment">// stores this information in 128 pixels</span><br> <span class="cpp-keyword">for</span>( <span class="cpp-keyword">int</span> x = <span class="cpp-number">0</span>; x < <span class="cpp-number">128</span>; x++ )<br> {<br> <span class="cpp-comment">// get the current index into the surface</span><br> DWORD dwIndex = x * dwBitsPerRow;<br><br> <span class="cpp-comment">// loop through all items in each column, Quake III</span><br> <span class="cpp-comment">// stores this information in 128 pixels as well</span><br> <span class="cpp-keyword">for</span>( <span class="cpp-keyword">int</span> y = <span class="cpp-number">0</span>; y < <span class="cpp-number">128</span>; y++ )<br> {<br> <span class="cpp-comment">// get the RGB elements out of the array, we need</span><br> <span class="cpp-comment">// to adjust the gamma so they're a little brighter</span><br> <span class="cpp-keyword">float</span> fRed = <span class="cpp-keyword">static_cast</span><<span class="cpp-keyword">float</span>>( m_pLevel->levelGetLightmapAtIndex( i )->ucImageBits[ x ][ y ][ <span class="cpp-number">2</span> ] );<br> <span class="cpp-keyword">float</span> fGreen = <span class="cpp-keyword">static_cast</span><<span class="cpp-keyword">float</span>>( m_pLevel->levelGetLightmapAtIndex( i )->ucImageBits[ x ][ y ][ <span class="cpp-number">1</span> ] );<br> <span class="cpp-keyword">float</span> fBlue = <span class="cpp-keyword">static_cast</span><<span class="cpp-keyword">float</span>>( m_pLevel->levelGetLightmapAtIndex( i )->ucImageBits[ x ][ y ][ <span class="cpp-number">0</span> ] );<br> <span class="cpp-keyword">float</span> fScale = <span class="cpp-number">1</span>.0f;<br><br> <span class="cpp-comment">// we'll brighten them up by a factor of 10, this will</span><br> <span class="cpp-comment">// still give a nice effect without blowing the user's eyes</span><br> fRed = fRed * ( <span class="cpp-number">10</span> / <span class="cpp-number">255</span>.0f );<br> fGreen = fGreen * ( <span class="cpp-number">10</span> / <span class="cpp-number">255</span>.0f );<br> fBlue = fBlue * ( <span class="cpp-number">10</span> / <span class="cpp-number">255</span>.0f );<br><br> <span class="cpp-comment">// check if the red went past the highest value</span><br> <span class="cpp-keyword">if</span>( fRed > <span class="cpp-number">1</span>.0f && ( ( <span class="cpp-number">1</span>.0f / fRed ) < <span class="cpp-number">1</span>.0f ) )<br> {<br> <span class="cpp-comment">// set the new scale</span><br> fScale = ( <span class="cpp-number">1</span>.0f / fRed );<br> }<br><br> <span class="cpp-comment">// check if the green went past the highest value</span><br> <span class="cpp-keyword">if</span>( fGreen > <span class="cpp-number">1</span>.0f && ( ( <span class="cpp-number">1</span>.0f / fGreen ) < <span class="cpp-number">1</span>.0f ) )<br> {<br> <span class="cpp-comment">// set the new scale</span><br> fScale = ( <span class="cpp-number">1</span>.0f / fGreen );<br> } <br><br> <span class="cpp-comment">// check if the blue went past the highest value</span><br> <span class="cpp-keyword">if</span>( fBlue > <span class="cpp-number">1</span>.0f && ( ( <span class="cpp-number">1</span>.0f / fBlue ) < <span class="cpp-number">1</span>.0f ) )<br> {<br> <span class="cpp-comment">// set the new scale</span><br> fScale = ( <span class="cpp-number">1</span>.0f / fBlue );<br> }<br><br> <span class="cpp-comment">// get the scale for this pixel</span><br> fScale *= <span class="cpp-number">255</span>.0f;<br><br> <span class="cpp-comment">// multiply all our pixel values by this scale</span><br> <span class="cpp-comment">// this will keep them constant but brighten them</span><br> fRed *= fScale;<br> fGreen *= fScale;<br> fBlue *= fScale;<br><br> <span class="cpp-comment">// setup the alpha information for all four bytes</span><br> pTextureSurface[ dwIndex + y * <span class="cpp-number">4</span> + <span class="cpp-number">0</span> ] = <span class="cpp-keyword">static_cast</span><<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span>>( fRed );<br> pTextureSurface[ dwIndex + y * <span class="cpp-number">4</span> + <span class="cpp-number">1</span> ] = <span class="cpp-keyword">static_cast</span><<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span>>( fGreen );<br> pTextureSurface[ dwIndex + y * <span class="cpp-number">4</span> + <span class="cpp-number">2</span> ] = <span class="cpp-keyword">static_cast</span><<span class="cpp-keyword">unsigned</span> <span class="cpp-keyword">char</span>>( fBlue );<br> pTextureSurface[ dwIndex + y * <span class="cpp-number">4</span> + <span class="cpp-number">3</span> ] = <span class="cpp-number">255</span>;<br> }<br> }<br><br></pre></div><!–ENDSCRIPT–><br><br>I'm going to continue investigating the problem in case this isn't it, but I can't really seem to find anywhere else where the problem might be arising from.<br><br>Permafried-
Your brightening method seems somewhat bizarre .. try using a power curve if you really need gamma correction. Also Q3 uses a gamma ramp where 0-128 is a linear or power ramp and 128-255 just is max, to be able to have intermediate blending results above 1.
Hey,
Thanks for the reply, I tried commenting out the code which handles gamma correction, and sure enough the ugly purple blotches disappeared so this seems to be the root of the problem. My ultimate goal would be to do this in hardware rather than through this algorithm but I'm still searching on how to accomplish this.
Anyone have any ideas on this, and if not, would anyone know of any good links explaning different means of apply gamma correction?
Thanks again everyone,
Permafried-
[Edited by - Permafried- on August 22, 2004 2:14:03 PM]
Thanks for the reply, I tried commenting out the code which handles gamma correction, and sure enough the ugly purple blotches disappeared so this seems to be the root of the problem. My ultimate goal would be to do this in hardware rather than through this algorithm but I'm still searching on how to accomplish this.
Anyone have any ideas on this, and if not, would anyone know of any good links explaning different means of apply gamma correction?
Thanks again everyone,
Permafried-
[Edited by - Permafried- on August 22, 2004 2:14:03 PM]
Hey hey, I am curious about what you have done, is there a way for you to write a follow up article or perhaps post what you have made ?? I am learning a lot of this stuff too trying to make sense of it all !
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement