Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1] 2
  Print  
Author Topic: [how] Need for Speed Underground looking road  (Read 1150 times)
DarekRuman
Community Member
*
Posts: 101

game developer


WWW
« on: September 22, 2008, 07:16:37 AM »

Hi!

How to make reflection on road like in NFS Underground.



Notice that not all road is reflected - its some kind of patterned reflection.

How I can easly Wink make it in 6.5?
Logged

www.reddotgames.pl
tv6.3 tv6.5 developer
António Mateus
Community Member
*
Posts: 26


WWW
« Reply #1 on: September 22, 2008, 07:25:43 AM »

RenderSurface is the way to go, i think!
Logged
Lenn
Customers
Community Member
*****
Posts: 454

Ivan Miskelic


« Reply #2 on: September 22, 2008, 08:33:57 AM »

Cubemapping shader of some sort with a reflection map textured on the road (can be alpha channel).
Logged

Enzi
Community Member
*
Posts: 27


« Reply #3 on: September 22, 2008, 08:39:02 AM »

There's some work todo here.

First you need to render the scene with a little offset to get the reflection map. You can take the water tutorial for this perfectly from riemers.net .
Then the interesting part comes. There's definately a heavy blur on the map. One thing to take in mind is, to render the reflection map only on half resolution and then upscale it.

Next thing is a the specular map and a "static" reflaction alpha map where the intensity of the reflection is saved. For water you usually take the fresnel term. The reflection and refraction is dependent on the eye direction. In NFS you have asphalt and parts where the road is covered in rain, (I don't like the asphalt as it is in NFS btw.) so I would take a lookup map. It would work nearly the same way as the specular map. Maybe you can even take the specular map and just calculate the reflection. It's hard to see if there's a specular highlighting on a static image.
Logged
Lenn
Customers
Community Member
*****
Posts: 454

Ivan Miskelic


« Reply #4 on: September 22, 2008, 08:42:54 AM »

Yeah, in most cases the specular map is used as the reflection map. Specular IS, after all, a sort of reflected uniform light where we pretend the surface has max diffusuion of reflection. What we call "reflection" is in fact specular with minimum diffusion of reflection, if you look at it from another point of view. I haven't yet seen an impelementation of mapped reflection shader for tv3d but it shouldn't be hard to do.
Logged

AriusEso
Customers
Community Member
*****
Posts: 377

Esoteric


« Reply #5 on: September 22, 2008, 10:16:47 AM »

Don't use cubic reflection, planar reflection is more suited. I beleive Zak does this in one of his water samples if you're looking for some code to show you how.
Logged

DarekRuman
Community Member
*
Posts: 101

game developer


WWW
« Reply #6 on: September 23, 2008, 10:25:15 AM »

Thank you all for reply - i'm new in shaders and ... i think that all this road reflection is kind of hard stuff for me (i've just migrated from 6.3 where everything was so easy, no shaders - no problems)

I found reflection shader for my car body, but it wont work. In fx Composer 2.5 works fine but all i get in tv is this :



Shader code :

Code:
//Cubemaps are today's standards. Here's very simple example of vertex-based cubemap reflection.
//
//TEXTURE0 - base texture
//TEXTURE1 - cubemap reflection texture

//------------------------------------
float4x4 matWVP : WORLDVIEWPROJECTION;
float4x4 WorldIT : WORLDINVERSETRANSPOSE;
float4x4 World : WORLD;
float3 CAMERAPOS : CAMERAPOSITION;

float BLEND_FACTOR = 0.5;

//------------------------------------
struct vertexInput {
    float4 Position : POSITION;
    float3 Normal : NORMAL;
    float2 UV : TEXCOORD0;
};
struct vertexOutput {
    float4 HPosition : POSITION;
    float2 Coord : TEXCOORD0;
    float3 ReflectVector : TEXCOORD1;
};

//------------------------------------
texture diffuseTex : TEXTURE0;
sampler Sampler_Tex = sampler_state { Texture = (diffuseTex); };

texture reflectionTex : TEXTURE1;
sampler Sampler_Reflect = sampler_state { Texture = (reflectionTex); };

//------------------------------------
vertexOutput VS_Main(vertexInput IN)
{
    vertexOutput OUT;
    OUT.HPosition = mul(IN.Position, matWVP);
   
    float3 Normal = normalize(mul(IN.Normal, WorldIT).xyz);
    float3 View = normalize(mul(IN.Position, World) - float4(CAMERAPOS,1));
   
    OUT.ReflectVector = reflect(View, Normal);
   
    OUT.Coord = IN.UV;
    return OUT;
}

//------------------------------------
float4 PS_Main(vertexOutput IN) : COLOR0
{
float4 tex = tex2D(Sampler_Tex,IN.Coord);
float4 refl = texCUBE(Sampler_Reflect, IN.ReflectVector);

return float4( lerp(tex.rgb, refl.rgb, BLEND_FACTOR), tex.a);
}

//------------------------------------
technique cubemaps_rule
{
pass only
{
VertexShader = compile vs_1_1 VS_Main();
PixelShader  = compile ps_1_1 PS_Main();
}
}

Shader should reflect enviroment but only thing i get is transparent white color.

Screen from fx composer 2.5



My code :

Code:
  m_chassis := Scene.CreateMeshBuilder('mChassis');
  m_chassis.LoadTVM('Models\chassis.tvm', false, false);

  m_chassis.SetTextureEX(0,globals.GetTex('ChassisSTI'), 0);
  m_chassis.SetTextureEx(0, globals.GetTex('Windows'), 1);
  m_chassis.SetTexture(globals.GetTex('UnderCarriage'), 2);

  m_chassis.SetMaterial(matWindow, 1);
  m_chassis.SetMaterial(matVehicleBody,0);
  m_chassis.ComputeNormals();
  m_chassis.ComputeBoundings();
  m_chassis.SetMeshFormat(17);

  Shader := Scene.CreateShader('Reflection Shader');
  Shader.CreateFromEffectFile('reflection.fx');
  Shader.SetEffectParamTexture('diffuseTex',globals.GetTex('ChassisSTI'));
  Shader.SetEffectParamTexture('reflectionTex',globals.GetTex('ground'));
  m_chassis.SetShaderEx(Shader,true,0);

the same with box




I cannot see SetEffectParamTexture working - anything i set there - dont work.
« Last Edit: September 23, 2008, 10:29:52 AM by DarekRuman » Logged

www.reddotgames.pl
tv6.3 tv6.5 developer
AriusEso
Customers
Community Member
*****
Posts: 377

Esoteric


« Reply #7 on: September 23, 2008, 10:32:12 AM »

Reflection texture should be a cubemap.
Logged

DarekRuman
Community Member
*
Posts: 101

game developer


WWW
« Reply #8 on: September 23, 2008, 10:55:21 AM »

Reflection texture should be a cubemap.

I already tried this.

Init

Code:
  CMap := Scene.CreateCubeRenderSurface(512, true, TV_TEXTUREFORMAT_A8R8G8B8);

Code in render loop (outside tv.clear -> tv.rendertoscreen) :

Code:
  CMap.SetCubeMapProperties(true, m_chassis.GetPosition);
  for I := 0 to 5 do
  begin
    CMap.StartCubeRender(I, false);
      GroundMesh.Render;
    CMap.EndCubeRender(I);
  end;
  Shader.SetEffectParamTexture('reflectionTex',CMap.GetTexture);

dont change anything ...

Logged

www.reddotgames.pl
tv6.3 tv6.5 developer
MenDAKE
Community Member
*
Posts: 402


« Reply #9 on: September 23, 2008, 01:31:37 PM »

Just so I get this straight, are you trying to reflect your environment or just use a cubemap texture to give a cheap appearance of reflection?
Logged
DarekRuman
Community Member
*
Posts: 101

game developer


WWW
« Reply #10 on: September 23, 2008, 04:12:20 PM »

Just so I get this straight, are you trying to reflect your environment or just use a cubemap texture to give a cheap appearance of reflection?

Yes I want to reflect enviroment, mix it with base texture and apply on my car so i'm rendering cubemap and give this rendered cubmap as shader parameter - but it wont work.

Is this shader alright for TV?
Logged

www.reddotgames.pl
tv6.3 tv6.5 developer
MenDAKE
Community Member
*
Posts: 402


« Reply #11 on: September 23, 2008, 05:14:14 PM »

The shader looks right to me. It's been a while since I've worked directly with shaders, but it does look right at a glance. It's hard to say without seeing the rest of your code, but it seems to me that you're not creating a cubemap texture that reflects the world. it seems your cubmap texture only renders the ground, whereas it should render the sky, walls and other objects. Otherwise your ground will be reflecting ... uh ... the ground. Perhaps I'm not reading your code right, but that's the first thing that comes to mind.



Logged
DarekRuman
Community Member
*
Posts: 101

game developer


WWW
« Reply #12 on: September 24, 2008, 04:11:40 AM »

Hmm i'm still waiting for some help with this reflection shader.

I was experimenting with water reflection (build in in tv) and I achieved this :


I used 2 meshes - one for water reflection (no refraction, non shaking water type 2), and one for my "brick road".

It looks little glassy but - i'll try to make it look more realistic. And next question is - what should I do when my car change altitude ?

Code:
plane.dist = car.altitude
plane.normaln = car.slope.normal ?

Will it work in my racing game where city will have hills and valley?
Logged

www.reddotgames.pl
tv6.3 tv6.5 developer
WEst
Community Member
*
Posts: 813

Daniel Martinek


WWW
« Reply #13 on: September 24, 2008, 05:05:05 AM »

Code:
   
    float3 Normal = normalize(mul(IN.Normal, WorldIT).xyz);
    float3 View = normalize(mul(IN.Position, World) - float4(CAMERAPOS,1));
   
    OUT.ReflectVector = reflect(View, Normal);

I think this part in your car-shader is wrong. I'm not that experienced with shaders too, but why are you transforming the normal using the WorldIT Matrix, shouldn't you use the World-Matrix?
Logged

Greetings

Daniel Martinek
Lead Programmer
Roaming Nova Studios
DarekRuman
Community Member
*
Posts: 101

game developer


WWW
« Reply #14 on: September 24, 2008, 06:50:47 AM »

Code:
   
    float3 Normal = normalize(mul(IN.Normal, WorldIT).xyz);
    float3 View = normalize(mul(IN.Position, World) - float4(CAMERAPOS,1));
   
    OUT.ReflectVector = reflect(View, Normal);

I think this part in your car-shader is wrong. I'm not that experienced with shaders too, but why are you transforming the normal using the WorldIT Matrix, shouldn't you use the World-Matrix?

I've change it - no effect  Sad

In other hand - Got myself something like this :



its a water plane at the top of my road mesh. But when my car is changing rotation - plane is still at (0,-1,0) normal.
How can I get my car normal vector to apply on water surface?

Thanks for helping  Grin
Logged

www.reddotgames.pl
tv6.3 tv6.5 developer
jviper
Community Member
*
Posts: 1366

Discipline in training


« Reply #15 on: September 24, 2008, 01:15:01 PM »

Hopefully you know that you cannot use a water plane to apply reflections to the car. The water plane is to reflect along a single plane. It cannot replfect along multiple planes at once, which is what your car would need. You may have the same problem with a road that is not completely flat. But assuming your road is completely flat everywhere and stays on that same plane, you could create a plane from the verticies your road is made of and update the water plane with that.
Logged

JAbstract.....Don't just imagine, make it happen!
DarekRuman
Community Member
*
Posts: 101

game developer


WWW
« Reply #16 on: September 24, 2008, 01:34:28 PM »

You may have the same problem with a road that is not completely flat.

So i'm again at the beggining - i need a shader or tip to make my road reflect environment. Anyone would help?  Huh
Logged

www.reddotgames.pl
tv6.3 tv6.5 developer
jviper
Community Member
*
Posts: 1366

Discipline in training


« Reply #17 on: September 24, 2008, 01:59:06 PM »

Keep in mind, there is currently no way to do "general reflection" on any hardware. It does not exists yet in realtime (unless your using a raytracer, in which case DirectX is a vecter-based rasterizer and cannot be used). You have to fake it. This means rendering to a cubemap the entire environment. Also note that technically if you have multiple objects, you would have to render a cubemap for each of your objects at their positions, in order for this fake to even look convincing. And for Larger objects, like an entire city, you may be SOL. But keep in mind there may still be a way to fake it.

Sorry to disapoint, but this is a limitation with all hardware, currently. The reflections in all of the games you see, have found a way to fake it. But for you, I would suggest starting with the cubemap reflection.
Logged

JAbstract.....Don't just imagine, make it happen!
DarekRuman
Community Member
*
Posts: 101

game developer


WWW
« Reply #18 on: September 24, 2008, 05:55:54 PM »

You have to fake it. This means rendering to a cubemap the entire environment.

OK - I've got it - i've rendered enviroment to cubemap - what next? Smiley
Logged

www.reddotgames.pl
tv6.3 tv6.5 developer
Raine
Customers
Community Member
*****
Posts: 1189


« Reply #19 on: September 25, 2008, 02:46:22 AM »

I actually managed to get a "mirror" shader working from zak's Water shader. From there on you should have everything you need in order to make a super reflection Cheesy
Logged

Pages: [1] 2
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks