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.

AppGameKit Classic Chat / Inverting Normals on backfaces?

Author
Message
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd May 2019 01:00 Edited at: 22nd May 2019 01:04
I read elsewhere to create good foilage I need to invert the normal on backfaces.

Does anyone know how I could do this?

I don't even know where to start with this. Does it need to be done in the shader? Can it be done with memblocks?

edit: I know how to change normals, I just don't know how to detect if its a backface or not.

Thanks!
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd May 2019 01:05 Edited at: 22nd May 2019 01:07
Memblocks using SetMeshMemblockVertexNormal()

Although i don't see how that would help
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd May 2019 01:06
You got me before I edited. haha
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd May 2019 01:08
Backface points away from the camera so you will probably have to use the dreaded dot product
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd May 2019 01:12
Ok, thanks! At least its a start.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd May 2019 01:17
You can get the camera vector like so (You'll have to normalize it though)
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd May 2019 01:35
Thanks, again! I have a long ways to go to figuring it out, so I appreciate any help, haha
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd May 2019 01:46 Edited at: 22nd May 2019 01:48
Here are some vector commands (I think you only need the normalize command), AGK has a dot product command

Then i would just get the normal of the camera and the poly, apply the dot product, and (through experimentation) see what numbers come up when it's facing the camera and when it's pointing away

I still don't think it will help with leaves on a tree
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd May 2019 03:11 Edited at: 22nd May 2019 03:11
Oh, you don't think so?

My trees in AppGameKit look like total crap compared to other engines. I am not sure what is going behind the scenes to correct the issues. It seems like its mipmapping that is just making the leaves/stems vanish.

i am just willing to try anything at this point lol
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 22nd May 2019 10:32 Edited at: 22nd May 2019 10:33
It depends on what kind of mesh you are using.
If you build your mesh without indices so a triangle is created every third vertex, you either need to create the back of your foliage with actual poligons, which isnt recommended as you just created redundant data then, or you go and check the backface in the shader and alter the lighting calculation there without redundant mesh data.
You can also construct the mesh with indices and share vertices but that probably just messes up all the normals.
Thats the quick explanation, feel free to ask.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd May 2019 10:45
If your using AppGameKit plane objects to display your foliage on then you dont have to do anything at all! AppGameKit planes have a front face and a rear face both with correct normals meaning nothing needs to happen whatsoever. They just look right from any direction.

If you are loading in a model that only has one side (ie just a pair of triangles with normals facing in one direction) then you need to turn off backface culling (SetObjectCullmode()) and the lighting shader needs to take the absolute (abs()) of the lighting dot product to light the rear face correctly. You could just turn of the lighting for the foliage but all of it then appears at the same level which is unrealistic.




Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 23rd May 2019 23:43
Ah, good to know! Hopefully, better foliage is right around the corner, haha.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 26th May 2019 04:32 Edited at: 26th May 2019 14:22
I am still having a lot of trouble getting any tree to show up properly. I do not use AppGameKit planes. I am exporting from blender. The screen shot is a whooping 8k vertices, and still it looks like garbage.

Here is my shader code. I have tried everything to get the backfaces to show, but almost every angle is just ugly. Some angles show no leaves! The only way I can get a nice view is by forcing the normals to face the camera, but then the lighting is not natural.





Same tree different angle...




Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th May 2019 05:25
That light source appears to be inside the tree
Maybe try the following (without changing the normals)
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 26th May 2019 11:51 Edited at: 26th May 2019 12:02
Golelorn wrote: "Some angles show no leaves! "

Bengismo wrote: "If you are loading in a model that only has one side then you need to turn off backface culling (SetObjectCullmode(obj,0))"

As I said in a post above ^^

That command enables the backside of triangles to be drawn so even if leaf is facing away from the camera it will be drawn.

After that, its just a case of ensuring that lighting level on each leaf never drops below about 40% or so on any one leaf....using the absolute value of the lighting dot product and a min() operation gives a nice result in the shader.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 26th May 2019 14:20 Edited at: 26th May 2019 14:21
Ah! Duh. I misread that. Thanks for pointing it out again, and for the shader tips.

Login to post a reply

Server time is: 2024-04-19 18:12:45
Your offset time is: 2024-04-19 18:12:45