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 / high resolution texturing

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Aug 2013 18:42 Edited at: 12th Aug 2013 19:06
It's been a while since I posted anything useful so here's a simple shader demo showing one way of achieving a high resolution texture for an object.

Ever noticed how when you get close to an object the object's surface seems to blur and eventually you just get one uniform colour? The purpose of the attached demo is to show one way of dramatically reducing this effect (it doesn't get rid of it at really small distances). The demo starts with the camera about 500 world units from the surface. Use the up/down keys to zoom in or out. You should still see plenty of detail right down to a distance of about two world units from the surface. The object disappears when you get closer than 1 unit because of the default camera range but you can change that if you like. The shader could be improved by replacing the hard-coded constants with variables - but I'll leave that for you to play with.

The crucial part of the shader is the following section of code:



What's happening is that the texture (one of The Slayer's wonderful free concrete textures in this case - Free Textures) is being sampled at several different LODs and the results are then simply multiplied together. The factor 2.684 is an arbitrary factor to prevent the final result becoming too dark - it needs to be calculated separately for each texture (and, ideally, separately for each colour component although I haven't done that here). The average colour of the source image is approximately RGB = (96,95,95) so I've brightened each multiplication by the factor 2.684 = 255/95.

You can see the default texturing by pressing the left key.

[Edit: added link for texture.]



Powered by Free Banners

Attachments

Login to view attachments
Kezzla
15
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 13th Aug 2013 14:29
That is really cool GG!

I like it a lot.

One of these days I am going to have to try and get my head around shaders.



Burn retina, burn!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Aug 2013 16:12
Thanks.

It works best with fairly random textures which don't have strongly defined features. I'm still tweaking it to widen the range of suitable textures so comments welcome.

Quote: "One of these days I am going to have to try and get my head around shaders."


I've been saying that about C++ for years.



Powered by Free Banners
Booma
15
Years of Service
User Offline
Joined: 29th Mar 2009
Location:
Posted: 23rd Aug 2013 14:42
@Green Gandalf

Cool!!! It is very useful for my rocks The camera floats very close to a surface, now the detailed textures aren't necessary to me Thanks!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2013 17:11
Thanks for the feedback.



Powered by Free Banners
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 23rd Aug 2013 17:53 Edited at: 23rd Aug 2013 17:57
This is very impressive.
Could this code be added to a Parallax Occlusion shader or does it only get applied as a separate shader?
Can you apply this shader with other shaders?
I am currently using a Parallax Occlusion shader on my models.
I am doing a high poly bake with textures using "XNormal".
This is the shader I am using which I altered for High Poly bakes.
My code changes might be wrong, still learning shaders.




[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Aug 2013 18:42
Quote: "What's happening is that the texture (one of The Slayer's wonderful free concrete textures in this case - Free Textures) is being sampled at several different LODs and the results are then simply multiplied together."


I see it, but I don't understand it.

Correct me if I'm wrong. The texture coordinates of the plain range from (0,0) to (1,1), meaning that In.UV in the following code will sample the texture within that range:



Given you've set up the sampler with these attributes:


Won't In.UV*x (where x is a natural number) wrap around to In.UV? I.e. In.UV*1 = In.UV*2 = In.UV*3 etc.

So you're effectively sampling the same value from the texture four extra times and multiplying them together? How am I supposed to understand this.

TheComet

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2013 20:13
@TheComet

Quote: "Won't In.UV*x (where x is a natural number) wrap around to In.UV? I.e. In.UV*1 = In.UV*2 = In.UV*3 etc."


Did you try some simple values to see how it works?

For example, suppose you start with In.UV = (0.1, 0.8). Then In.UV*3 = (0.1, 0.8) * 3 = (0.3, 2.4) = (0.3, 0.4) after applying the wrap. The point is that the extra detail is being applied by traversing the texture 3 times as fast so it is tiled over the original 3 times. Similarly, with wrapping, In.UV*5 will tile the texture 5 times and so on.

One change to this method would be to make sure you use a fairly random texture for the extra detail - in my example I used the same as the main source but that will give strange results for some source textures and you may get better results using a second texture. However, I was motivated by applications where I'm already using the max of 8 textures so I'm forced to reuse something - depending on your textures you may already be using one which is suitable. You would just need to amend the shader accordingly.

Quote: "How am I supposed to understand this."


By working through a simple example yourself, perhaps (as illustrated above)?

@Stab in the Dark software

Quote: "This is very impressive."


Thanks.

Quote: "Could this code be added to a Parallax Occlusion shader or does it only get applied as a separate shader?"


The basic idea could be added to almost any other existing shader. One possible application is to give things like skin more detail when you get close.

Is this the bit you're thinking of adding? If so I don't think that will give the effect you want if I've understood you correctly.



I'd be interested in helping out with this - but am busy with a blur shader on another thread at the moment (well I should be anyway ).



Powered by Free Banners
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Aug 2013 20:20
Quote: "Did you try some simple values to see how it works? "


The embarrassment I am feeling right now is unmatched.

Okay, so the extra detail comes from combining "faster" samples of the same image? That's a little cheeky, but it works.

TheComet

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2013 20:24
Quote: "The embarrassment I am feeling right now is unmatched."


I'm sure you're not alone. I'm glad you've got it now.

Quote: "That's a little cheeky, but it works."


Yes, I was surprised how effective that simple ploy could be. I'll be adding it to all my terrain shaders (when I remember ).



Powered by Free Banners
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 23rd Aug 2013 20:34 Edited at: 23rd Aug 2013 20:36
Quote: "That's a little cheeky, but it works."


If it looks good, it is good.

Sub-texturing need not be produced with the same image, and need not be the colour-map; the principle can be applied to normal maps as well; and the multiplication can feature various images underneath a consistent or 'manufactured' overlay. The texturing of textures.

This is what every DBP developer needs.

It resembles detail mapping but requires less effort.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2013 23:24
Yep.



Powered by Free Banners
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Sep 2013 16:15
Here's another version of the shader but with normal mapping as well this time. Same controls as before except additionally press and hold "r" key to rotate light. Fast machines will probably need to cap the sync rate to 60.



Powered by Free Banners

Attachments

Login to view attachments
Inflictive
14
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 30th Sep 2013 04:25
What's with the *= 2.684? Couldn't you just lerp(color1,color2,0.5)?

For textures with defined features, you would use a noise map sampler for all but the first tex2D()

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Sep 2013 13:10
Quote: "What's with the *= 2.684?"


That stops the overall texture becoming too dark. Since colour values are between 0 and 1 in a shader the multiplications tends overall to reduce the colour value so it needs to be brightened somewhat. The latest version uses the inverse of the overall average colour to do that per RGB component - the original value used a sort of combined average compromise. A default value would be something like 2 assuming average colour is about 0.5 (or 127.5 in byte terms).

Quote: "Couldn't you just lerp(color1,color2,0.5)?"


I decided not to use that because it would cause a serious loss of contrast - but I might have been wrong so I'll check and report back when I get the chance. Have you tried?

Quote: "For textures with defined features, you would use a noise map sampler for all but the first tex2D()"


Not quite sure what you mean but sounds good. Do you mean using UV coordinates sampled from a noise map for all except the first? If so then it might work.

I'm about to go on holiday for a couple of weeks so it might be a while before I can report back, but I intend to check out your suggestions. Thanks.



Powered by Free Banners

Login to post a reply

Server time is: 2024-04-26 18:25:26
Your offset time is: 2024-04-26 18:25:26