Car simulation effects

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
aux
Posts: 10
Joined: Wed Aug 19, 2009 7:03 am
Location: Russia
Contact:

Car simulation effects

Post by aux »

Hi everyone.
I'm trying to make the cars in a game look more realistic. And I need your advice on what effects I need to apply to do that. I've tried 'Render To Texture' future with a material type EMT_REFLECTION_2_LAYER and a render-target-texture as the second layer, but it doesn't suit me because it looks normal only for black color while the yellow car chassis becomes green (when mixes when the sky color). You can see what I'm talking about on a screenshot (the chassis' color should be the same as the second car's rims):

Image

That's why I am thinking of using shaders. But the problem is that I dont know what shader I need, I've tried to search for shaders by guesswork, but what I found is mostly .fx files which, as I realized while reading this forum, are not supported by Irrlicht (are they?). And what about .hlsl files, I got working only one of them - 'Toon Shader By Blind Side'. That's the result (just a proof-pic, just if you are interested):

Image

So, the question is what should I apply to a car material to get its realistic looking? If you have a code of any good shader, I would be happy to use it in my project.

Thank you.
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

Blindside made a shader that was using a dual parabaloid rendering technique, and shaders to do realtime reflections and it was really nice...

I have been adapting and adjusting it over time, and i am just about finished fixing it (the render order is weird atm)

You can see it here :

http://irrlicht.sourceforge.net/phpBB2/ ... 766#202766

I will post this as soon as iv fixed it, or the non fixed one sooner if you cant wait :P should be later today sometime.
aux
Posts: 10
Joined: Wed Aug 19, 2009 7:03 am
Location: Russia
Contact:

Post by aux »

FuzzYspo0N, wow! You create incredible things! Looks great even non-fixed :)

Can't wait to try it out! But I'll better wait for a fixed version :D.
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

FuzzYspo0N wrote:Blindside made a shader that was using a dual parabaloid rendering technique, and shaders to do realtime reflections and it was really nice...

I have been adapting and adjusting it over time, and i am just about finished fixing it (the render order is weird atm)

You can see it here :

http://irrlicht.sourceforge.net/phpBB2/ ... 766#202766

I will post this as soon as iv fixed it, or the non fixed one sooner if you cant wait :P should be later today sometime.
That's great. I'm waiting for it too :D
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

Thanks guys, you can see the progress on my blog, its in my signature :P just fixing some irrlicht bugs and stuff, then some fixes on that.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

In the mean time, render monkey has an interesting example for rendering car paint, maybe you should check that out.
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

Yea and there have been many cool car paint shaders, i think some are on the wiki even?
aux
Posts: 10
Joined: Wed Aug 19, 2009 7:03 am
Location: Russia
Contact:

Post by aux »

Hm.. I seem to be missing something.
I had installed RenderMonkey special for car painting purpose before asking any questions here. But there were no .hlsl files in its folders as well as no exporter to .hlsl within the application. Generally speaking, it refuses to work with .hlsl at all.
Where is my mistake? Do I have to find a plugin? Or do I have to use a different format, not .hlsl? Or, maybe, I just have inappropriate version of RenderMonkey? Excuse me for these questions, but I am totally new to working with shaders, that is why I am asking for help.

P.S. FuzzYspo0N, your screenshots are so cool! Can't stop admiring them :)
lulzfish
Posts: 34
Joined: Sat Aug 15, 2009 8:19 pm

Post by lulzfish »

RenderMonkey only seems to work with GLSL and OpenGL.
Is the somber dream of the Grim Reaper a shade Darker Than Black?
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

No it supports many targets, including hlsl and glsl. Open the directX examples (ill take the car paint shader for this post) its here

\RenderMonkey 1.81\Examples\Dx9\Metal.rfx

This exmaple just happens to be PS 1.4 which is assembler, but is supported on many more systems so thats cool.

You save the code from that window to a .hlsl file (or any ext) and load it using irrlicht.

Open another example, like discoLighting and clicks the pass called "walls" , and expand it. Open the "Pixel Shader" node and you will see the hlsl is there. Thats where the code is in RM..
Mapping the inputs and outputs to irrlicht is a little trickier though.
aux
Posts: 10
Joined: Wed Aug 19, 2009 7:03 am
Location: Russia
Contact:

Post by aux »

Thank you people for devoting your time to my foolish questions :)

But by this moment i have faced some more issues i can't solve without your precious help.

First of all, i'd like to assure that i understand the following thing right:
If the input structure of a HLSL shader looks like

Code: Select all

struct VS_INPUT 
{ 
   float4 Position : POSITION0; 
   float2 Texcoord : TEXCOORD0; 
   float3 Normal :   NORMAL0; 
   float3 Binormal : BINORMAL0; 
   float3 Tangent :  TANGENT0; 
}; 
then i need to use a mesh created by using 'smgr->getMeshManipulator()->createMeshWithTangents(mesh);' in order to pass additional information to the shader, such as NORMAL, BINORMAL and TANGENT, is this right?

The second thing i'd like to get more clearly is how to pass textures to a shader. As far as i understand, Irrlicht refers textures which are set by '[ISceneNode*]->getMaterial(#).setTexture(level, texture)' function, and the shader recieves them by the use of "sampler2D [textureName]" instructions. But how does it 'understand' what sampler2D variable should point to a certain texture? (Heh, while writing this post i've tried to swap two sampler2D declarations in a shader hode and i got the result that the first texture goes to the second sampler2D (comparatively to the original shader code), and (of course) the second texture goes to the first sampler2D). Which means that the correspondence between Irrlicht textures and shader texture variables depends on the level of texture in Irrlicht and the order in which these variables are declared in a shader code.

And the last thing at the moment. I've used a shader that uses the above-mentioned input struct (look at she "Code:" section) and two textures: baseMap and bumpMap. Does anybody know what causes the unpleasant problem (i meen poignant change of colors on curves) shown in the following screenshot and is there any way to avoid it? (i used entirely black bumpMap in this example)

Image

I know that it is because of a 3D-model consists of polygons, but this car model seems to be converted properly, and loading original .3ds model gives even worse results, and i also know that this model was used in a certain game and looks good there.
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

Feel free to KEEP asking, thats the entire point of the community ;)

Also, in irrlicht you have different ways to pass the shader some textures.
The one way that i learnt was to do this :
int var1 = 0;

services->setPixelShaderConstant("diffuseMap", (float*)(&var1), 1);
That simply says, for the sampler2D diffuseMap, use texture slot 0 on the mesh.

If you change the var1 to 4, it will use material.setMaterialTexture(4, diffuseImage) will "pass the shader the fourth texture" by name.

For the other problem ,can you post the mesh on mediafire so i can take a look (or someone else) ?
aux
Posts: 10
Joined: Wed Aug 19, 2009 7:03 am
Location: Russia
Contact:

Post by aux »

Thank you, FuzzYspo0N :wink:

here is the mesh: http://psychoid.ru/aux/AstonMartinDB9.rar,
Please take a look when you'll have time

In the meanwhile, I have another question :)
I have examined some examples in RenderMonkey and read a little documentation about shaders. Everywhere is written that i should multiply a matrix by a vector to get right results.
But when i tried to load some samples in Irrlicht, they worked in a very strange way. It appeared that all what i needed to make them work correctly was to swap the matrix and the vector in the code, i.e. I've multiplied a vector by a matrix and everything worked. And it happens with each shader i try. Is there any explanation for this mystery?
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

There most definitely is. There are coordinate systems in 3d space, these fundamantals are extremely important to learn up front, before diving too far head first into shaders .Shaders rely heavily on the spaces and the transformations that objects and the world is in, so read those parts twice.

Also, i have grabbed the file and will be back online in about an hour to test it out :) it will be a cool test for the reflection i have been working on.
aux
Posts: 10
Joined: Wed Aug 19, 2009 7:03 am
Location: Russia
Contact:

Post by aux »

Oh.. yes, i was too lazy to read much documentation. I supposed i could make cool graphics without doing that. Obviosly, i was wrong :).
Actually, i wanted to save some time because there are plenty of ideas in my head concerning my project, but i planned to finish with shaders first before improving the physics world. But shaders seem to be a serious trouble.

FuzzYspo0N, i'm waiting for your cool screenshots with impatience ! :)
Post Reply