Game Development Community

Spline Road Material Problems

by Ronald J Nelson · in Torque Game Engine Advanced · 02/03/2009 (9:33 pm) · 46 replies

I have been working to make a spline or procedural road system use materials. So far I can get it to almost work perfectly when using Custom Materials that in my current example use the DiffuseBump shader. However I am having some initialization issues I am hoping someone can help me with. I am posting some screenshots, my rendering code, and my materials to show what I have done and to help illustrate my issue. Now I am doing my work for my game in TGEA 1.03 but having also been porting it to the newer versions for a later release and the problem is present in all versions.

First the starting issue is this:
i72.photobucket.com/albums/i192/DTDA/roadbug1.jpgi72.photobucket.com/albums/i192/DTDA/roadbug2.jpg
As you can see changing camera angles effects the problem.

When you look closely you can see that the shader is working.
i72.photobucket.com/albums/i192/DTDA/roadbug3.jpg
Now if I use spectator mode to run around the track and pass up and down through the object a couple of times the problem fixes itself.
i72.photobucket.com/albums/i192/DTDA/roadbug4.jpg

***CODE REMOVED***
I am sure this is probably something simple, but I am not seeing it yet. Also, I have tried this on multiple computers with different hardware and the problem is pretty consistent in all cases.
Page «Previous 1 2 3 Last »
#2
02/05/2009 (8:04 pm)
Possibly the texture uv repeat flags?
#3
02/05/2009 (8:47 pm)
OK I am going to go ahead and come right out and say I have no clue how to do that. I have been on hiatus for couple of months and am just trying to get back into this and I gotta admit, I forgot ALOT.

The only upside is I did manage to change out my code to just set a single shader so the standard material system would work. It didn't fix the bug though. So Tom, would you please elaborate?
#4
02/05/2009 (10:17 pm)
Using stock Torque materials is a good thing... we're doing that for a few things ourselves with a modified version of ShaderGen and Materials... but it should be possible with stock Torque as well.

You gotta setup the texture stages correctly... do a search thru the code for GFX->setTextureStageState, GFX->setSamplerState, and GFX->setRenderState. You should find examples of how to properly setup the device for rendering your geometry.

If you were on TGEA 1.7 or higher you could be using state blocks which are easier to deal with. In fact you can setup the stateblocks from script in 1.8... possibly 1.7 as well.
#5
02/06/2009 (6:20 am)
Why would adjusting the states through those methods have any effect on the camera angle changing what parts are rendering correctly? I only ask because I've already tried most of that.

Additionally, why is it that the method I mentioned above consistently makes it start working? I realize that it must bea GFXDevice setting I am missing because once I do that, it stays on and will continue to work until the machine the game is hosted on is restarted. Of course that is why initially I had begun to think my graphics card on my work machine was dying, but it does the same on several others.
#6
02/06/2009 (7:09 am)
if Camera Angle is part of the contributing factor, maybe there is something wrong with the generated geometry. Are you accidentally making coplanar faces or anything like that? It could be something as simple as z-fighting.
#7
02/06/2009 (11:46 am)
@Ron - It would help if you said... "Camera angle is affecting this". If your gonna give incomplete information on your problem then expect to not get a solution. :)

If camera angle is affecting it could be a transform... maybe projection. Are you using a matrix in C++ or HLSL to generate texture coords?
#8
02/06/2009 (1:16 pm)
Well Tom if you read the original post, I did. So there. ;)

Here is my most recent work. It does allow the use of stock materials now but has made no improvement to the original issue. Other than the fact that it is using a stock material in script now, everything else looks about the same outside of C++. As for your question Tom, a bit of both. I am feeding the SceneGraph data to initialize it and I input the projection information to the shader so HLSL can process it. Well just look at the following and I am sure you get what I am saying.

***Code Removed - Current Code above***
#10
02/08/2009 (12:28 am)
Well I have gone back and tried multiple things with the code using similar examples throughout the engine and still have had no success.
#11
02/09/2009 (2:34 pm)
OK has anyone seen a problem like this beofre on any other project? If so, did you find a solution? If you did, please share it. I am stumped.
#12
02/09/2009 (2:50 pm)
I'm with Jamie, I'd look really close at your geometry generation. Whenever I've had glitches like that, it's been because my buffer is too small and I'm overwriting memory. Or I'm not filling up the whole thing, and the card is rendering uninited stuff. Turn on the DirectX debug runtime and see if it complains about anything.
#13
02/09/2009 (4:53 pm)
Well you see I know its not the geometry. I have already used straight assign texture methods in TGEA and TGE for this instead of materials and it worked flawlessly. The issue with that is of course shaders and materials aren't being used to enhance the look.

So I am pretty positive the issue must be with the shader and material initialization. I must be missing something.
#14
02/09/2009 (8:58 pm)
Um never mind, I compared my work I did on Dan Keller's work to this one and found that you are indeed correct. My bufffer was only taking into account one portion of an equation rather than the sum. Thanks.
#15
02/10/2009 (10:17 am)
Cool, I'm glad you found it! As a general rule of thumb, if I ever say "it can't be that" I always double-check it anyways. ;)
#16
02/10/2009 (8:02 pm)
Well as much as I thought that was the solution, it was not. The way this code is processing it was actually much different from Dan Keller's code so the extra variables were are already a part of equation. I did have one small portion off by 1 but even that was not the solution to this problem.

I have tried just arbitrarily increasing and decreasing the buffer size with no success. No matter the setting(except in extreme cases that breaks it) the bug is still there. Now I did try some small changes that while they ddi break the material initialization and modulating process, they did in fact get rid of the bug. I even went back and did a simple set texture setup just to be sure, and yeah it works fine.

I am fairly convinced at this point it must be something I doing wrong with the material.
#17
02/10/2009 (11:28 pm)
D'oh. After taking another look at your second code snippet:

while(mEdgeMaterial->setupPass(sgData))
	{
		if (gClientSceneGraph->isReflectPass())
			GFX->setCullMode(GFXCullCW);
		else
			GFX->setCullMode(GFXCullCCW);

		ri->matInst = mEdgeMaterial;
		mRoadShader->shader->process();
		renderSides();
	}

Really should just look like this:

while(mEdgeMaterial->setupPass(sgData))
	{
		renderSides();
	}

With renderSides just pumping out geometry with drawprim calls. shader->process and cullflipping should be taken care of within setupPass and you shouldn't need to redo it.
#18
02/11/2009 (12:29 am)
Well Brian I would agree but this is where I have come to believe something is wrong with my setup. You see if I pull the setCullMode out of the loop or even remove it entirely, I get a crash for not having it set even if I have it set earlier in the code as shown above. Complete removal of any cull settings does the same.

Now if I move the material setting and shader processing code out of the loop this is what I get.

i72.photobucket.com/albums/i192/DTDA/roadshaderbug1.png
As you will notice the blacked out polys are gone but the thing is not modulating properly.
#19
02/11/2009 (12:04 pm)
You've definitely got some memory corruption if setting the cull mode avoids a crash. Having the cull mode unset, or set incorrectly should only affect what triangles the card decides to render. I'd leave it unset and start chasing down the crash.
#20
02/11/2009 (7:38 pm)
OK I figured the crash out. I needed to do the initial setting of course for my render states. The thing is that after you do one setupPass for a material you have to set up the states again because the process clears the states.

I have pulled everything out of the loop as you said, perhaps someone has an idea why it isn't iterating properly now? It is clear that the different materails are working fine because for the sections that are doing some form of rendering the materails are correct. Now what I can see is the shader is not being initialized properly. No idea why though.
Page «Previous 1 2 3 Last »