Jump to content


Photo

Realistic car reflection in gamemaker


  • Please log in to reply
13 replies to this topic

#1 japjap

japjap

    GM-LINUX GM-PS4 user

  • New Member
  • 124 posts
  • Version:GM8

Posted 12 December 2011 - 09:21 PM

I have tried some but don’t even look half as good as this:
http://www.youtube.c...h?v=vBaOtLAyPCc
or
http://www.youtube.c...h?v=yz39F1rohNo
I have searched for gamemaker and found 0 tutorials and 0 samples.

Why realistic reflections on a car?
If you look at the car it is a simple ugly model. But with the reflection it looks pretty hot.

Finally what would be the best way to do a reflection on a car which is caused by little bit of mirroring the background and picking up the lights from the area?

Edited by japjap, 12 December 2011 - 09:22 PM.

  • 0

#2 YellowAfterlife

YellowAfterlife

    GMC Member

  • Global Moderators
  • 3493 posts
  • Version:GM:Studio

Posted 12 December 2011 - 09:34 PM

First, why Community forum? Wouldn't 3d questions forum do?

Second, this is next to impossible to achieve (with decent performance) with standard 3d.
It is relatively easy to achieve with 'enviroment map' shader (google it, in case of something), but that requires a DLL.
Spoiler
If you'd like to give up perfect portability for visuals, a shader dll is available in DLL's subforum. Quite searchable.

Edited by YellowAfterlife, 12 December 2011 - 09:34 PM.

  • 0

#3 japjap

japjap

    GM-LINUX GM-PS4 user

  • New Member
  • 124 posts
  • Version:GM8

Posted 13 December 2011 - 01:29 PM

this is next to impossible to achieve (with decent performance) with standard 3d

Thats what you also said regarding:
http://gmc.yoyogames.com/index.php?showtopic=526461&st=0&p=3874245&fromsearch=1&
Not only I manged to move the terrain but also added a system which allows you to move terrain after it is loaded. I am not saying that I am super ttalented. I only achieved this with not giving up. Indeed withouth the help of great programmers I would never do this.

You know I have sworn an oath to other comphetathors that I will make the best car sample without the use of any extension. I already done something which was prevoiusly impossible to achieve even with a DLL.

I believe with proper team work this will be done to in pure GML.

Edited by japjap, 13 December 2011 - 01:33 PM.

  • 0

#4 YellowAfterlife

YellowAfterlife

    GMC Member

  • Global Moderators
  • 3493 posts
  • Version:GM:Studio

Posted 13 December 2011 - 02:32 PM

this is next to impossible to achieve (with decent performance) with standard 3d

Thats what you also said regarding:
http://gmc.yoyogames.com/index.php?showtopic=526461&st=0&p=3874245&fromsearch=1&

Would you like to quote me saying that it is impossible? I do not quite like how you 'assign' wished activity to me, and then never provide a proof.
I have made a similar terrain system (targeting different version and purpose though) ~1.5 years ago (link).

Not only I manged to move the terrain but also added a system which allows you to move terrain after it is loaded. I am not saying that I am super ttalented. I only achieved this with not giving up. Indeed withouth the help of great programmers I would never do this.
You know I have sworn an oath to other comphetathors that I will make the best car sample without the use of any extension. I already done something which was prevoiusly impossible to achieve even with a DLL.

I believe with proper team work this will be done to in pure GML.

Please revise your point of view.
I understand that improving over existing technology seems like a large achievement to author, however in this case it is not.
Nothing is new under the sun.
The most easily recognisable (played by more than 30 000 people) game of this kind was made ~4 years ago:
http://sandbox.yoyogames.com/games/15027-swerve
(source is available too, in end of description)

And, if you'd like to know what is really new, and was never thought to be possible in GameMaker... look at his works.

Edit: on-topic, achieving (partially) enviroment reflection may be possible via smart planning and surfaces (rendering view into surface, then getting it mapped correctly, and applying transparency), so is a thing to check.

Edited by YellowAfterlife, 13 December 2011 - 02:35 PM.

  • 0

#5 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 13 December 2011 - 03:11 PM

I think you should focus on better models with better textures then adding reflections.

I mean, if you like to ONLY use GM then you pretty much got no other choice (at least that I can think of) then to render the world for each model surface onto a GM surface from a tweeked normal point of view.
Pretty much what YellowAfterlife just posted. :unsure:
(oh god... the amount of calculations...)
And I feel like that will be a challange for both you and the testing computer.

I'm not saying that you're an idiot for trying :rolleyes: I'm just saying that it might be really hard to achive.

Good luck anyways!

Edited by filulilus, 13 December 2011 - 03:14 PM.

  • 0

#6 japjap

japjap

    GM-LINUX GM-PS4 user

  • New Member
  • 124 posts
  • Version:GM8

Posted 13 December 2011 - 05:16 PM

Would you like to quote me saying that it is impossible? I do not quite like how you 'assign' wished activity to me, and then never provide a proof.

In the previous mission yellowafterlife said it does not support the code he did not said impossible. Are you happy now?

I dont like you when you discourage me.

Edit: on-topic, achieving (partially) environment reflection may be possible via smart planning and surfaces (rendering view into surface, then getting it mapped correctly, and applying transparency), so is a thing to check.

Thats more like it Yellowafterlife.

The most easily recognisable (played by more than 30 000 people) game of this kind was made ~4 years ago:

I mentioned the name of the original creator in the topic.30000 people played it but I am the only who decided to fix the bugs an I added a moveable terrain in it. Again with the help of our Lord and friends otherwise I am a noob who could never do this.


I'm not saying that you're an idiot for trying :rolleyes: I'm just saying that it might be really hard to achive.

Good luck anyways!

:lol: Thanks. Enough trolling guys. Now lets steam up our brains and achieve what other never done before in pure GML.


In gamemaker what you call shades could be achieved with a more simple trick then we think.
Convert the car in a mirror. But the mirrored view should be very dim so that you can see the full body texture and a bit of the mirrored view.

Or does anyone else know a better way?

Edited by japjap, 13 December 2011 - 05:17 PM.

  • 0

#7 Phantom107

Phantom107

    Engineer

  • GMC Member
  • 2593 posts
  • Version:GM:Studio

Posted 13 December 2011 - 08:32 PM

I didn't read any of the posts, sorry.

But in response to the original poster I can say this: unless you use a DLL (preferably GM OGRE) it's not possible to do this at a reasonable speed.

The way it's done in the 'real' way is cubemapping: GPU hardware maps a cubic image onto a 3d model, depending on the normals of that model. For realtime reflection, developers refresh that cubic image by using one or more render-to-texture camera. Unless you want 4 fps, I wouldn't recommend using native GM for this. (if you can even get it to work which I don't think is possible in this fashion)

Edited by Phantom107, 13 December 2011 - 08:32 PM.

  • 1

#8 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2438 posts
  • Version:GM:Studio

Posted 14 December 2011 - 12:09 AM

This is not exactly what you're asking for, but I just made a tiny example of how to make objects appear to be "shiny".
http://www.host-a.net/u/playway/shinyobject.zip
It first defines a light direction, then draws the object without texture to a surface. This makes it white where the light hits and black where it doesn't. In draw event I draw the surface on top of the normal view with a blend mode that removes the dark colours and only draws the lighter ones, giving the objects a shiny look. The model included is a random model I found on my harddrive, no idea who made it. Move the mouse to move the camera
True reflections on uneven surfaces would be immensely slow in game maker. Not only would you need a lot of surfaces, but you'd also have to render the scene once for each triangle
Posted Image

... look at his works.

Had to click a few times to make sure I followed the right link :P

Edited by TheSnidr, 14 December 2011 - 12:12 AM.

  • 2

#9 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 14 December 2011 - 07:16 AM

You can be pretty sure that it's damn hard to do if TheSnidr says it's hard to do.

If I would try this tho, I would use a model with a small amount of triangles and use two types of world rendering, one for the real world and one with a as small as possible amount of triangles since it's only a reflection and small details can't be seen.
And I guess I'd have to playaround with the view angle and aspect to make all the reflections fit in with eachother.
Well, well, just a few tips.

@TheSnidr: Awesome example! :woot:

Edited by filulilus, 14 December 2011 - 07:24 AM.

  • 2

#10 japjap

japjap

    GM-LINUX GM-PS4 user

  • New Member
  • 124 posts
  • Version:GM8

Posted 14 December 2011 - 01:42 PM

But in response to the original poster I can say this: unless you use a DLL (preferably GM OGRE) it's not possible to do this at a reasonable speed.
Unless you want 4 fps, I wouldn't recommend using native GM for this.

We are aware of gmogre.dll. Unfortunately we have to decline your offer because we are not interested in any extension or. Unfortunately we have to decline your offer because we are not interested in any extension or learning new languages. And we recommend you to upgrade your gm8 to the latest update which will give you 200-400 FPS.

This is not exactly what you're asking for, but I just made a tiny example of how to make objects appear to be "shiny".
http://www.host-a.net/u/playway/shinyobject.zip

This is 1\5 part of this mission. Well it is a beginning and a good idea.


You can be pretty sure that it's damn hard to do if TheSnidr says it's hard to do.

JF.K said in 1962
We choose to go to the moon as nation in this decade not because they are easy but haaard to do.

We choose to do shade reflections without a dll as a community because it is not easy to achieve but very hard.


I just noticed Snider title Faker.

Ramsfield said in 1965:
If we cant make it to the moon we will fake it moon

If we cant make it we shall fake it.
  • 1

#11 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 14 December 2011 - 02:18 PM

Hmmm, you could record a 360 degree view from the car and out then pick out the parts from the surface, not sure how this will look (defenatly not real) but at least it's a ide :sweat:

Edited by filulilus, 14 December 2011 - 02:19 PM.

  • 1

#12 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1589 posts
  • Version:GM8.1

Posted 14 December 2011 - 09:44 PM

We are aware of gmogre.dll. Unfortunately we have to decline your offer because we are not interested in any extension or. Unfortunately we have to decline your offer because we are not interested in any extension or learning new languages. And we recommend you to upgrade your gm8 to the latest update which will give you 200-400 FPS.

You misunderstand the problem then. The problem is that calculating the part of a texture to use for reflections is, while not too expensive for a shader, FAR too expensive to do in GM. (Even the latest GM8.1 version) Even if you solved the problem of the expensive computation times, drawing primitives in GM (no, you can't use a model because the texture coordinates change) is extremely slow, no matter what version you use.


This is not exactly what you're asking for, but I just made a tiny example of how to make objects appear to be "shiny".
http://www.host-a.net/u/playway/shinyobject.zip

This is 1\5 part of this mission. Well it is a beginning and a good idea.

What you want is full cube-mapped (or sphere-mapped) environment mapping, which is what we have been discussing.



You can be pretty sure that it's damn hard to do if TheSnidr says it's hard to do.

JF.K said in 1962
We choose to go to the moon as nation in this decade not because they are easy but haaard to do.

We choose to do shade reflections without a dll as a community because it is not easy to achieve but very hard.

We did not attempt to go to the moon in a horse-drawn carriage.

If we cant make it we shall fake it.

Computer graphics has always been about faking it. Your problem is that GM is unsuited to even the simplest methods of faking it.


Anyway, I've said my piece about your delusions, so here's something to make my contribution useful: (It's code to find spheremap uv coordinates given a point, a normal, and a camera)
//  get_spheremap_uv(x, y, z, nx, ny, nz, camera_x, camera_y, camera_z, up_x, up_y, up_z, camera_nx, camera_ny, camera_nz)

var normalSquared, dotProduct, reflection_x, reflection_y, reflection_z, left_x, left_y, left_z, up_x, up_y, up_z, front_x, front_y, front_z, inverseFront, inverseLeft, inverseReflection, uvLength, spheremap_w;

//  Prepare result for null case.
global.spheremap_u = 0.5;
global.spheremap_v = 0.5;
normalSquared = argument3 * argument3 + argument4 * argument4 + argument5 * argument5;
if (normalSquared == 0)  //  Null case (normal undefined)
    exit;
front_x = argument12;
front_y = argument13;
front_z = argument14;

left_x = front_y * argument11 - front_z * argument10;
left_y = front_z * argument9 - front_x * argument11;
left_z = front_x * argument10 - front_y * argument9;
if ((left_x == 0) && (left_y == 0) && (left_z == 0)) //  Null case. Left vector undefined
    exit;

//  If front and left are perpendicular, |up| = |left| * |front|.
up_x = front_y * left_z - front_z * left_y;
up_y = front_z * left_x - front_x * left_z;
up_z = front_x * left_y - front_y * left_x;

reflection_x = argument0 - argument6;
reflection_y = argument1 - argument7;
reflection_z = argument2 - argument8;
if (argument3 * reflection_x + argument4 * reflection_y + argument5 * reflection_z < 0) {
    dotProduct = 2 * (reflection_x * argument3 + reflection_y * argument4 + reflection_z * argument5) / normalSquared;
    reflection_x -= dotProduct * argument3;
    reflection_y -= dotProduct * argument4;
    reflection_z -= dotProduct * argument5;
}


global.spheremap_u = reflection_x * left_x + reflection_y * left_y + reflection_z * left_z;
global.spheremap_v = reflection_x * up_x + reflection_y * up_y + reflection_z * up_z;
if (global.spheremap_u != 0) or (global.spheremap_v != 0)   //  Transform from reflection to sphere position.
{
    inverseReflection = 1 / sqrt(reflection_x * reflection_x + reflection_y * reflection_y + reflection_z * reflection_z);
    inverseFront = 1 / sqrt(front_x * front_x + front_y * front_y + front_z * front_z); 
    inverseLeft = 1 / sqrt(left_x * left_x + left_y * left_y + left_z * left_z);
//  Half-angle identity: sin(a / 2) = sqrt(0.5 - cos(a) / 2)
    spheremap_w = (reflection_x * front_x + reflection_y * front_y + reflection_z * front_z) * inverseFront * inverseReflection;
    uvLength = inverseLeft * inverseReflection / sqrt(2 - 2 * spheremap_w);
    global.spheremap_u *= uvLength;
    global.spheremap_v *= uvLength * inverseFront;
}
global.spheremap_u = 0.5 + global.spheremap_u * 0.5;
global.spheremap_v = 0.5 + global.spheremap_v * 0.5;

  • 3

#13 japjap

japjap

    GM-LINUX GM-PS4 user

  • New Member
  • 124 posts
  • Version:GM8

Posted 16 December 2011 - 05:14 PM

//  get_spheremap_uv(x, y, z, nx, ny, nz, camera_x, camera_y, camera_z, up_x, up_y, up_z, camera_nx, camera_ny, camera_nz)

var normalSquared, dotProduct, reflection_x, reflection_y, reflection_z, left_x, left_y, left_z, up_x, up_y, up_z, front_x, front_y, front_z, inverseFront, inverseLeft, inverseReflection, uvLength, spheremap_w;

//  Prepare result for null case.
global.spheremap_u = 0.5;
global.spheremap_v = 0.5;
normalSquared = argument3 * argument3 + argument4 * argument4 + argument5 * argument5;
if (normalSquared == 0)  //  Null case (normal undefined)
    exit;
front_x = argument12;
front_y = argument13;
front_z = argument14;

left_x = front_y * argument11 - front_z * argument10;
left_y = front_z * argument9 - front_x * argument11;
left_z = front_x * argument10 - front_y * argument9;
if ((left_x == 0) && (left_y == 0) && (left_z == 0)) //  Null case. Left vector undefined
    exit;

//  If front and left are perpendicular, |up| = |left| * |front|.
up_x = front_y * left_z - front_z * left_y;
up_y = front_z * left_x - front_x * left_z;
up_z = front_x * left_y - front_y * left_x;

reflection_x = argument0 - argument6;
reflection_y = argument1 - argument7;
reflection_z = argument2 - argument8;
if (argument3 * reflection_x + argument4 * reflection_y + argument5 * reflection_z < 0) {
    dotProduct = 2 * (reflection_x * argument3 + reflection_y * argument4 + reflection_z * argument5) / normalSquared;
    reflection_x -= dotProduct * argument3;
    reflection_y -= dotProduct * argument4;
    reflection_z -= dotProduct * argument5;
}


global.spheremap_u = reflection_x * left_x + reflection_y * left_y + reflection_z * left_z;
global.spheremap_v = reflection_x * up_x + reflection_y * up_y + reflection_z * up_z;
if (global.spheremap_u != 0) or (global.spheremap_v != 0)   //  Transform from reflection to sphere position.
{
    inverseReflection = 1 / sqrt(reflection_x * reflection_x + reflection_y * reflection_y + reflection_z * reflection_z);
    inverseFront = 1 / sqrt(front_x * front_x + front_y * front_y + front_z * front_z); 
    inverseLeft = 1 / sqrt(left_x * left_x + left_y * left_y + left_z * left_z);
//  Half-angle identity: sin(a / 2) = sqrt(0.5 - cos(a) / 2)
    spheremap_w = (reflection_x * front_x + reflection_y * front_y + reflection_z * front_z) * inverseFront * inverseReflection;
    uvLength = inverseLeft * inverseReflection / sqrt(2 - 2 * spheremap_w);
    global.spheremap_u *= uvLength;
    global.spheremap_v *= uvLength * inverseFront;
}
global.spheremap_u = 0.5 + global.spheremap_u * 0.5;
global.spheremap_v = 0.5 + global.spheremap_v * 0.5;

Thanks but this belongs in fake reflections. We still have no real reflection sample.
  • 0

#14 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1589 posts
  • Version:GM8.1

Posted 16 December 2011 - 06:35 PM

Thanks but this belongs in fake reflections. We still have no real reflection sample.

Okay. So one of the best real-time reflection methods isn't good enough for you. You want raytracing. Enjoy your 1 fps (at sufficiently low resolution. I think you're going to have trouble with resolutions greater than 48x32)
  • 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users