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 Studio Chat / Object shader question. Triplanar? Cube mapping?

Author
Message
Divided
FPSC Reloaded TGC Backer
10
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 25th Oct 2023 10:43 Edited at: 26th Oct 2023 00:57
Howdy,

I'm building a level editor in AppGameKit tier 2 and I knew I'd run into this problem eventually but I'm not actually sure how to solve it.

Attached is a screenshot of the problem.

I have these tiles I can place around a grid. The problem is when a tile is rotated, so is the texture.

I think I need something called a Triplanar or Cube mapping shader to apply to the object so that the textures are using world space coordinates not UV coordinates.



I've attempted to code up one myself but found shaders to extremely difficult if you don't know what you're doing.

It would be nice if it were only applied to the top faces? Not sure if that's a thing but most of my tile objects have multiple textures/colours, and I only really need to apply the Triplanar mapping to "green part". (Second screenshot shows the different tiles)



Does anyone know how I might be able to achieve this?

Thanks!
Real programmers don't comment their code, because it should be written with readability in mind.

Attachments

Login to view attachments
Aidan
User Banned
Posted: 26th Oct 2023 13:00
I'm not sure about this one.

Maybe changed your image to not repeat on the edges is best bet


Think been like a chess board but having no repeated colours on two edges only and the other two edges having the alternate colour

Eg

Black ,/ white / black / white / black / white
white / black / white / black / white / black
Black ,/ white / black / white / black / white
white / black / white / black / white / black
Black / white / black / white / black / white
white / black / white / black / white / black

Something like that, saves messing around with cube mapping

Just an idea
Aidan
User Banned
Posted: 26th Oct 2023 16:42 Edited at: 26th Oct 2023 16:47
Hope this will be a good read for you

https://catlikecoding.com/unity/tutorials/advanced-rendering/triplanar-mapping/

Didn't realise you wanted to map an image with no UVs.
That's the basic concept of this kind of mapping


Ps. Sorry mods for the repeated threads
Divided
FPSC Reloaded TGC Backer
10
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 28th Oct 2023 09:44
Hey,

Yeah thanks for the idea. I did try write the shader but had a lot of AppGameKit specific compile issues I think. I was able to compile a version of my shader that sort of worked but the rotations were strange, maybe not taking into account the camera angle?
When I rotated an object it was still rotating at a slower speed to the object itself and then when I tried to apply it to objects that I placed around the grid their draw positions were way off and I don't understand why. Could be because the shader was using world coordinates?
Anyway, I'd share it but I ended up deleting it because it wasn't working and don't think I can remake it haha

My shader knowledge is terrible and not something i'm ready to deep dive and learn atm as I don't get a whole lot of time.

However, I took on the feedback to make the tiles sort of line up.

I ended up rotating the texture when the object is rotated which kind of has a similar effect (assuming the texture scale doesn't change) but it's more of a hack than the proper approach and it didn't really support a texture map of different colours/textures on a model with a single mesh.

If anyone has written a triplanar/cube map shader for agk I'd love to take a look and see if I can make it work.

Kind regards,
Blake
Real programmers don't comment their code, because it should be written with readability in mind.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 30th Oct 2023 16:51 Edited at: 30th Oct 2023 16:53
Here you go:



This is the un-revised Triplanar shader i used for my Marching cube world some time ago, as real UV mapping in such a generated world is quite hard(but possible).
Divided
FPSC Reloaded TGC Backer
10
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 2nd Nov 2023 23:04
Hey thanks Janbo,

I'll study the shader and see if I can get it to work for my example.

Very cool marching cubes program!

Real programmers don't comment their code, because it should be written with readability in mind.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 3rd Nov 2023 16:12
Seems to me you want Projection Mapping instead of Triplanar (which means 3 Axis projection. Overkill given you mention only needing the top. Now Shaders are quick straight forward once you understand /how/ they work on you or object/screen/object space.

By default most shaders pass the World Projection Transformed Vertex positions and the Texture (UV) space which will be static.
Now for projection mapping you'll want to pass a non transformed world space coordinate.

If you want to understand the basics of what is going on with the default projection search for my conversion of JavidXs software 3d renderer.
It's broken down into progressive steps to see how vertices are generated and converted to render correctly on-screen. It's a great primer for what world, object and projection mapping stem from.

When I have some free time I can draft a projection mapping shader... Been meaning to do one for lighting and decals anyway.

Login to post a reply

Server time is: 2024-05-02 17:12:46
Your offset time is: 2024-05-02 17:12:46