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 Professional Discussion / Polygon random color

Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 1st Dec 2020 08:48
Hello there!
It sounds simple but I didn't get correct result yet.
I need all polys to be colored randomly by shader.
I try to create random color based on normals - seams like it is ok - but on flat surfaces ( where all normals are the same result color is also the same)

So, maybe there is a command in vertex shader like "get Poly Id" or something?
Derek Darkly
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 7th Dec 2020 19:39

Just a quick thought...
If you are randomizing from a seed based on the normals or vertex positions, perhaps try randomizing from timer() instead on the flat parts.
Send your parents to noisy sprite demo hell... enter the D-Zone
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 12th Dec 2020 10:56 Edited at: 12th Dec 2020 10:59

Here is what I have.
@Derek Darkly yes, this is exactly the way i did this.
It is good idea with timer, but i can't call time() inside vertex or pixel shader parts.Am I wrong?
Anyway the best way to create absolutely random and unique color is this:
1)use vertexdata
2)read vertex normals and write them to free UV channel (you have to use 2 of them or you can compress to 1 uv channel )
3)then set normals to colors which you want
4)SET OBJECT SMOOTHING 0 to prevent color smoothing and get crisp edges
5)in shader read UV data and use it as normals
I think that is very easiest way to create stylish low poly or flat shading look inside DBPro.
Project file is attached


Login to view attachments

Login to post a reply

Server time is: 2023-11-28 08:51:43
Your offset time is: 2023-11-28 08:51:43