leezer3 / OpenBVE

OpenBVE- A free train simulator
http://www.openbve-project.net
275 stars 52 forks source link

I want it to support objects that always face the camera. #980

Open ginga81 opened 8 months ago

ginga81 commented 8 months ago

I want you to watch this video. In ETS2 and TrainSimulator202x, by placing trees and grass so that they always face the camera in this way, it is possible to prepare many flat textures and express them realistically. I proposed this before, but it was not adopted, so I will propose it again. At Bve5, has been adopted by AtsEX. https://x.com/atF9045/status/1748724925899383233?s=20

adfriz commented 8 months ago

its looks like billboard effect. https://www.opengl-tutorial.org/intermediate-tutorials/billboards-particles/billboards/

that's very useful to make a foliage, although I'm curious where and how should we implement it for openbve, can this effect implemented using current available function formula or what?.

unfortunately i cant help you implement it, i cant write code at all.

leezer3 commented 8 months ago

Added two new functions: BillboardX and BillboardY These return the rotation angle required to billboard the object in the X and Y axis respectively.

[Object]
States = Tree.b3d
RotateXFunction = BillboardX
RotateYFunction = BillboardY

I don't really see any need to provide a Z-axis billboard unless someone has a specific need.

adfriz commented 8 months ago

Thanks, it works!

Top left using billboardY. Bottom using billboardX. Right side just the object.

https://github.com/leezer3/OpenBVE/assets/76892624/c2d25d3c-58b0-42f4-b016-ad173af6de79

although i don't know why the billboardX behave like that πŸ€”.

ginga81 commented 8 months ago

Thank you for implementing it! I prepared the following csv and animated object, and display ed them with ObjectViewer. I hopeed that it is rotating such as a green color's arrow's, but it doesn't appear at all. What's wrong.

rotate-tree.csv

CreateMeshBuilder
AddVertex,-2,0,0
AddVertex,-2,5,0
AddVertex,2,5,0
AddVertex,2,0,0

AddFace2, 0, 1, 2, 3
SetColor, 255, 255, 255, 255
LoadTexture, tree2023type10.png
SetTextureCoordinates, 0, 0, 1
SetTextureCoordinates, 1, 0, 0
SetTextureCoordinates, 2, 0.7760687470436096, 0
SetTextureCoordinates, 3, 0.7760687470436096, 1

rotate-tree.animated

[Object]
States = rotate-tree.csv
RotateYFunction = BillboardY

rotate

ginga81 commented 8 months ago

Additionally, if I use BillboardX, it will be displayed. However, the behavior didn't seem to be what I thought it would be, and it didn't work like in the previous video.

rotate-tree.animated

[Object]
States = rotate-tree.csv
RotateXFunction = BillboardX

https://github.com/leezer3/OpenBVE/assets/22734699/d3d21489-c840-47bc-8ea0-33cb6d57ca31

adfriz commented 8 months ago

I think i have noticed your problem @ginga81 There are a somewhat wrong axis calculation in the billboard effect.

If you use billboardY function the correct axis that should be looking at the camera is -Z not +X, -Z is the front facing of the object and +X is the right side of the object.

this is what happened to your tree object, the right side is always facing the camera not the front and because your object is flat the object will look like disappear but it isn't, the object is too thin to be displayed.

https://github.com/leezer3/OpenBVE/assets/76892624/1ec624c8-2e7b-4fdb-863a-3c6204f8a0ae

I think it's the same problem with the billboardY function too.

ginga81 commented 8 months ago

Ah! I see, that's because I was always facing the things in front and in the back! Thank you for the easy to understand video! The object is incredibly thin, so, we couldn't look. I rotate the object to Y axis, I can see it and works fine! However, we may need to explain how it works.

rotate-tree.csv

CreateMeshBuilder
AddVertex,0,0,-2
AddVertex,0,5,-2
AddVertex,0,5,2
AddVertex,0,0,2

AddFace2, 0, 1, 2, 3
SetColor, 255, 255, 255, 255
LoadTexture, tree2023type10.png
SetTextureCoordinates, 0, 0, 1
SetTextureCoordinates, 1, 0, 0
SetTextureCoordinates, 2, 0.7760687470436096, 0
SetTextureCoordinates, 3, 0.7760687470436096, 1

https://github.com/leezer3/OpenBVE/assets/22734699/429cfafc-d510-4ea8-bf4e-64d8f732db97 I can now create the tree expression I have wanted for a long time!

leezer3 commented 8 months ago

Will take a closer look when I get home. I was testing with a cube, which explains the difference probably....

leezer3 commented 8 months ago

OK, try the build from today. That seems wrong, but appears to produce the right results :/

adfriz commented 8 months ago

tried nightly builds OpenBVE-2024-01-23.

seems still wrong.

left is billboardX, right is billboardY.

https://github.com/leezer3/OpenBVE/assets/76892624/64d0b1fc-917f-4dd0-82d7-abba678f36ef

Here is the object is use test billboard.zip

ginga81 commented 8 months ago

I think BillboardX also working fine at the newest daily build. The axis around which BillboardX rotates is the red X. And this time, the "Back" face always rotates along the X axis and faces directly. To reproduce this, when we set the camera's X to always 0 and while maintaining the same distance from the center rotated camera like an orange, the "Back" face is already always facing directly.

However, when I enabled BillboardX and Y at the same time, I thought that the "Right" face that was displayed first would follow me no matter how I turned it, but I felt that the tracking was insufficient. I thought that maybe the Z axis was also needed.

I don't think this will be a problem if the specification is that only one of BillboardX or Y can be used.

BillboardX

leezer3 commented 8 months ago

I'll have to check and see exactly what's happening when X and Y are combined- Might be a rotation order issue, not sure without sitting down and thinking about it (this sort of math gets complex very quickly when there's rotation from the object, track position and camera into the mix.....)


The Z-axis can't be needed. Let me try to explain: You're moving a camera, which exists in 2D space within a 3D world.

If we take the 4 motion directions, these equate to the following: Up - positive Y Down - negative Y Left - negative X Right - positive X

(Let's assume you're rotating using a mouse- To create Z rotation, you'd need to physically lift the mouse from the desk)

ginga81 commented 8 months ago

We can do it with just the X and Y axes, is it! excuse me.

adfriz commented 8 months ago

the right side of the object that facing to the camera when using billboardY feels wrong to me, I think the correct one should be the object front side.

https://github.com/leezer3/OpenBVE/assets/76892624/aa40350c-99f4-40bb-b69c-a67ccdffb076

same problem also occurs when using billboardX, the back side that following camera not front side.

https://github.com/leezer3/OpenBVE/assets/76892624/82baecbf-3e06-4122-ab99-860159710ae9

the static one just a reference for what the original object orientation is (I just load the .obj file straight to object viewer).

object test : test3.zip


Honestly i don't know what the use case is for billboardX and billboardZ, for billboardY i know it very useful for a tree object or any object that need to always face the camera and rotate along Y axis.

ginga81 commented 7 months ago

https://github.com/leezer3/OpenBVE/releases/tag/1.9.2.6 I'm thinking of trying Billboard, but do I have to build it from source? I can't find built zip.

leezer3 commented 7 months ago

Try now, hadn't quite got that far this morning....

ginga81 commented 7 months ago

Thank you! I was able to download it! Have you not yet fix the behavior when using BillboardXY at the same time? I thought that the behavior was still different from what I expected. γƒ“γƒ«γƒœγƒΌγƒ‰θͺ¬ζ˜Ž3-1 γƒ“γƒ«γƒœγƒΌγƒ‰θͺ¬ζ˜Ž3-2

Kenny-Hui commented 7 months ago

Rotating Y by -90 deg should be closer to your result (Though will be inverted after the camera passes):

[object]
states = test2.obj

RotateXFunction = BillboardX
RotateYFunction = -(pi / 2) + BillboardY

https://github.com/leezer3/OpenBVE/assets/28094366/9e97bc73-2996-4177-83c8-2344c150840f

Also loading the cube obj file took 5 seconds here, and the duck freezing more than a minute to load, is that normal?

leezer3 commented 7 months ago

Sorry, meant to post again after thinking about it......

A billboard in both directions would probably need another function entirely to work without complications. (Maybe a [Billboard] section which supports no functions, and is a true billboard as you want?)

The basic trouble is that you're effectively applying a transform on the Z-camera axis twice with both billboards in action at once.

Whilst it would be possible to reverse this using the function (see KennyHui's above for an approximation, but I think it probably needs the result of the BillboardX to work 100%)


With regards to the obj files, that definitely doesn't sound normal. They're a bit slower, but a minute for the duck is way OTT. I'll take a look on Debian at some point.