Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Scrolling a texture to face an object a programming challenge.

Author
Message
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Aug 2009 22:50
Imagine a ghosted object with a sunspot texture on it. Now I want to scroll it to face the sun at all times. I think it's possible, but probably a bit challenging.

Anybody fancy trying it, and posting the code?

Thanks for any attempts!

Pincho.

Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 10th Aug 2009 16:56
well, what do you mean by "scroll it to face the sun at all times?"

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 10th Aug 2009 17:31
Textures can be scrolled and used for reflections on glass from the sky for example. It looks really good on a ghosted object.

Here is an example....
I want to make a model of a planet. Then make a larger model of a planet, and ghost it, and that will make the planet atmosphere. On this atmosphere I could paint a white blob of light. DB Classic now allows you to scroll this texture around the planet. So it would be good if somebody could figure out a way so that the white blob always faces the sun object in my game. Then I can apply the same technique to my space ships as well. When they turn, the texture of the white blob remains facing the sun.

It is a Diffuse cheat, because diffuse requires high polygon objects, and this idea of mine will work on low polygon models.

Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 10th Aug 2009 18:01
hmm... why not try



or


?

that'll make sure that the white blob always faces the sun....

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 10th Aug 2009 18:15 Edited at: 10th Aug 2009 18:16
That would work on a planet. On a space ship, the shape of the ship is too complex to even rotate at all. It can probably only be done with a scrolling texture.

Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 10th Aug 2009 20:43
Quote: "On a space ship, the shape of the ship is too complex to even rotate at all."

You mean rotate the actual object?!

Oh, dang.........er.....*Looks for Latch*....Latch?

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th Aug 2009 22:22
aaah! I give up!
If the scroll texture didnt work in such a stupid way I might have been able to do this.

TGC Forum - converting error messages into sarcasm since 2002.
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 10th Aug 2009 22:39
And, there goes one of the three DBC Coding legends...... ...............................................................

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 10th Aug 2009 22:41
@Pincho

I think you may be after something like this:

Chrome Effect

Use mouse buttons to zoom in/out . Rotate with mouse movement.

Enjoy your day.
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 11th Aug 2009 03:05
Wow, latch, thats great!
The "texture 2" looks real.........Awsome.

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Aug 2009 03:48 Edited at: 11th Aug 2009 03:57
Quote: "@Pincho

I think you may be after something like this:

Chrome Effect

Use mouse buttons to zoom in/out . Rotate with mouse movement."


Thanks for the link, and also for showing part of what I mean, but that's what I do already, the problem is making the texture face an object at all times.

Somehow, I need to take an object position, and convert it into a different sort of maths. Some sort of extrapolation, conversion, distance, and direction.

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 11th Aug 2009 05:53
Quote: "It is a Diffuse cheat"

A specular cheat actually, the mention of diffuse had me wondering what you were trying to do a little but I think I understand.

You're right about the set object specular control not being as effective for low poly objects.

The trick here is really going to be the UV coordinates of your object. Rotating/scrolling the texture coordinates on one face isn't necessarily gonna rotate/scroll the UVs on another face so that it compliments the first face.

Hmmmm

A single plane textured with the reflection can be tilited and moved anywhere on the spaceship. Now expand that to a grid and texture the grid with the reflection.

The idea would be to shape the grid to the contours of the hull where ever the gird was moved. Pretty tricky, I'll have to think about that a little bit so for now, back to the single plane.

If you use Sparky's collision dll, you can cast a ray from the sun to the space ship. The point where the cast ray hits the space ship is the location to position the plane with the reflection on it. Still using sparky's, get the normal of the collision and point the plane towards the normal. The plane will then be alligned with the surface of the ship that is being hit and you should see the relfection.

I'm writing this as I'm thinking about it so I haven't tested it. But it makes sense in my brain. I'll try and put together an example.

Enjoy your day.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Aug 2009 15:06
Your idea sounds good, and is even lower poly than my original idea of doubling up the ship.

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 12th Aug 2009 00:10 Edited at: 12th Aug 2009 00:14
Ok, here's an example. It could use a little tweaking but seems to work. At the very least here is a way to cast a fake spot light!

The normal is 90 degrees to a face, so the plane will always try and be flat against a face, this can be a problem on a corner. Play with differnt shapes and positions and the size of the reflection to see if you can get the effect how you want it. You aren't limited to casting 1 ray. You could cast a series in a small area with multiple planes so that they strike multiple surfaces and you have multiple reflections. That would be more like the grid idea I was kicking around. Many small planes could, in theory, contour to the shape of the hull by using the collision normals from several ray casts.

In the example, the sun (sphere) is moving around the cylinder. The shpere's coordinates are calculated to x1#,y1# and z1# and it is positioned accordingly. The cylinder is at 0,0,0 so the ray is cast from x1#,y1#,z1# to 0.0,0.0,0.0 . Were the ray collides with the cylinder is where the plane is positioned. The collision generates a collision normal which is 90 degrees away from the face. Once the plane is positioned, it is pointed towards it's location + the collision normal.



Enjoy your day.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Aug 2009 10:08
Nice try, but it sticks out a bit, and overlayed ghosted objects create nasty double ghosts. But what I think you have created there is the x/y positions for the scrolling texture that I was looking for. I think you can get them from the projected plain, as it scrolls around it is acting like the scrolling texture would behave, which must somehow be convertible to an actual scrolling texture.

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Aug 2009 15:18 Edited at: 12th Aug 2009 15:27
I have it nearly working, but my math's isn't good enough to figure out how you use the Z properly with UV coordinates, and this code needs fixing a bit....

Can somebody have a play with this code please....

By the way.. I sphere mapped the model hoping that this is the best way to get the UV's to wrap around the object, and Cylinder mapping wouldn't work with a spaceship so this has to be a general mapping solution.

Attachments

Login to view attachments
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Aug 2009 16:57 Edited at: 12th Aug 2009 16:58
I can bodge it to get it to sort of work, but it's cheating...

The UV map doesn't seem right either.

Attachments

Login to view attachments
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Aug 2009 18:32 Edited at: 12th Aug 2009 18:49
Again bodged, but almost perfect. But I don't know why I am dividing by 76.5?

Don't worry about the spotlight being oval at the moment. I just need to squash the UV map a bit, and that's easy to do.

Attachments

Login to view attachments
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Aug 2009 20:14
Another version. Fixed the UV map, fixed the model which had a bad face.

the division of 76.5 is due to the scale of the model. Bigger models need a bigger division, so I need math's to figure that out now.

New Demo....

Attachments

Login to view attachments
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Aug 2009 00:47 Edited at: 13th Aug 2009 00:48
The UV map is extremely important for the ghosted object that will have the reflection as part of it's texture, you already know that. With that in mind, UV coordinates range from 0 to 1, where the divisions in between represent a percentage of the texture that is displayed on a face. So, if we think of the object as an entire UV map, a single revolution in terms of UV shoud be a scroll value of 1 in either the U direction or the V direction. In terms of degrees, that's 360. So each individual scroll has to be in the ratio of 1 UV / 360 degrees = 1/360 :

In the following example, notice how the white square ends up in the start position when sx and sy = 1 or any counting value of 1:



The object then becomes to figure out the angles that the sun is casting the ray at the ship. We can still approach it using Sparky's DLL. We can probably ignore the normals and just just the collision coordinates. We'd then have a dummy object that points from the center of the spaceship towards the collision coordinates. Once we've pointed the object, we can query the dummy object's y and x angles. We dived 1/y angle for the U scroll and we divide 1/x angle for the V scroll and that should be where the texture gets scrolled.

Try it out, and I'll try to put an example together as well. I only tested the first part, I haven't added it to using sparkys yet (I just thought of it as I was typing!)

[EDIT]
In fact, forget sparky's. Just point the dummy object from the center of the spaceship towards the sun and get the angles.

Enjoy your day.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Aug 2009 01:00 Edited at: 13th Aug 2009 01:12
It gets complicated for me. I have to read what you have written 6 times..lol!

So a UV map is divisible by an angle? That should make things a bit easier then. Although the Z still confuses me, as a spaceship can rotate as well as move around the sun, so the Z will swap places with the X, and Y sometimes. I'm not very good with angles.

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Aug 2009 03:00 Edited at: 13th Aug 2009 03:03
If what you were doing is working for you with sparky's, then stick with it. I'm just throwing ideas out there to try.

I did try and put together an example, and you are right, it got complicated real fast! The angles never want to behave the way you want them to! Darn angles!

Quote: "So a UV map is divisible by an angle"

Well, UV coordinates are mapped from 0,0 to 1,1 . All the points in between are a percentage of the texture. So if you scroll a UV texture .5,.5 then you are scrolling to the middle of it (50%,50%). So if you scroll 1,1 , then that just scrolls back to the start. If you scroll -.5,-.5 then you are scrolling the opposite direction, but still to the middle. -1,-1 is back to the start.

Angles, range from 0 to 360 degrees. So to go all the way back to start, a full circle, then you rotate the angle 360 degrees. If we want to scroll a texture so that the scroll increments are equal to angle increments, then each time we scroll the texture the equivalent of 1 degree, the U or V scroll value = 1/360 .

So, if we can come up with a generic formula that represents the angle(s) of your ships in relation to the angles of the sun, we can figure out how much to scroll the texture. That's what you've been after from the start, right?

Now if we can use the 1/360 in our figures, then converting the angles to UVs isn't the hard part. The hard part is finding the angles. POINT OBJECT doesn't seem to be good enough.

The UV map is very important. For example, if you used the default CUBE in DBC, there's no way you can scroll the reflection the correct way because each face of the cube has it's own complete UV map. In a 3D modeling program, you'd have to stretch the UVs so the whole object is mapped with a single texture. Then you can scroll it all around and it will stay in tact.

Anyway, it looks like your last demo was pretty close. I just don't understand where you are getting the numbers to divide by.

Enjoy your day.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Aug 2009 03:55 Edited at: 13th Aug 2009 04:01
Well the Uv's I'm pretty sure have to be a sphere map, which hopefully will work with any shape. When you sphere map a space ship it is impossible to paint, but we are not painting it, just sticking a white sphere on it, so we can just sphere map everything. The UV mapping program sorts out the shape for us, we end up with an odd looking squashed ship UV map, but at least the UV's all join up, and wrap around.

That last number to divide by is due I think to UV maps stretching when scaling. 100% will always divide by a different scale of UV spacing. The maths to find it must be model width + height / 100 or something like that. I'm not sure, I've just been tweaking the number until it works, and then trying to figure out what the number must mean. The division is not 100% accurate anyway, it's just a guess, and could slide off target after an hour of playing a game.

Login to post a reply

Server time is: 2024-05-09 04:04:43
Your offset time is: 2024-05-09 04:04:43