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 / [HLSL FX] Alpha/Colour Levels

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 21st Dec 2010 23:30
Hi, I would like to use a shader for blending and other pixels effects. But I'd like to control the alpha and colour levels outside of the shader.

I know you can do this for diffuse using vertexdata command (not sure if this is the best way for altering color, maybe memblocks?):


Not that sure on alpha. I've heard of using texture samples to control color/alpha but I never done that sort of stuff with a shaders yet. I got shaders up to point, like I can create a ton of effects on one object (one of my vids got mention in the newsletter a while back). But when it comes to using a single shader for tons of objects (3Di's (3D interface) in this case) with different params, that's where they lose me.

So any idea's guys?

Cheers for any help in advance

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Dec 2010 00:05
Quote: "But I'd like to control the alpha and colour levels outside of the shader"


Your snippet suggests that you want the same value of "diffuse" for each vertex. If that's the case why not have a float4 variable in the shader and assign it a value using set effect constant vector?

On the other hand the rest of your post suggests you want different colours for different objects but using just one shader. In that case a simple way is to texture each object with its own small image, e.g. 1x1 or 2x2 or 4x4, consisting of the colour you want. You might be able to set the alpha component in DBPro as well - by using one of IanM's rgba functions perhaps.

I would advise against trying to use the vertex diffuse component because that is awkward to implement correctly in DBPro in a shader.
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 23rd Dec 2010 09:39
correct me if I am wrong, but isn't this the basic functionality of the myriad terrain texture splatting shaders available? Like GG's or Dark Coder's, or heck, even one I made way way back?
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 27th Dec 2010 14:37
Holidays took me away sorry, hope everyone had a great Christmas

Quote: "On the other hand the rest of your post suggests you want different colours for different objects but using just one shader. In that case a simple way is to texture each object with its own small image, e.g. 1x1 or 2x2 or 4x4, consisting of the colour you want. You might be able to set the alpha component in DBPro as well - by using one of IanM's rgba functions perhaps."


I need the full range of colours to do fading stuff. And I couldn't get alpha to work with stock commands or IanM's (though I'm not sure which your referring too).

Quote: "I would advise against trying to use the vertex diffuse component because that is awkward to implement correctly in DBPro in a shader."


Is there a better way? I don't really know.

Quote: "correct me if I am wrong, but isn't this the basic functionality of the myriad terrain texture splatting shaders available? Like GG's or Dark Coder's, or heck, even one I made way way back?"


Where?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 2nd Jan 2011 00:16 Edited at: 2nd Jan 2011 00:17
Surprisingly this is harder than I thought... Any more input guy's?

Happy New Year Guys Btw

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 2nd Jan 2011 09:05
You could build the 1x1 images using Image Kit or IanM's plugin and draw to them directly though. Image Kit uses alpha, but quite frankly I thought IanM's MatrixUtils used it too...

Sven B

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Jan 2011 12:11
Quote: "but quite frankly I thought IanM's MatrixUtils used it too..."


Yes, as I said earlier, use IanM's rgba() function, etc.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 2nd Jan 2011 23:23
I still don't understand what you mean by the RBGA function, cause looking at it all it does is extract the alpha level from the RGB colour, so Alpha = RGBA ( Colour ). Thing is, what do you do with that, you still have to set the objects alpha and diffuse some how, so this is why i'm confused about the suggestion.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Jan 2011 02:06 Edited at: 3rd Jan 2011 02:06
I can only assume that you didn't bother to look in IanM's Help file:



I also said "etc". It can't be that hard to work it out surely?
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 3rd Jan 2011 04:13 Edited at: 3rd Jan 2011 04:20
Sorry, missed the 'etc' bit. Set Alpha seemed to do the trick, thanks GG and Sven to what you were hinting to

Though I had an issue with the 1x1 texture. 1x1 just made the object disappear, but 2x2+ and everything works fine. Now I'm not sure if this is because how the shader is set up, the code:



I'm wondering if taking the vertex shader out could cause issues...

Another thing is the performance, I didn't think it would affect it that much, but wow. Chuck just a 100 plains on with the shader and you've lost 75 percent of your performance. Hmm... that could end up being a hugh issue. Is this just because it's DBP everything is slow? well when it comes to shaders that is

Edit: I just remembered how some of the blending modes don't require setting alpha, so maybe that's why when I was using addictive blending try to alter the alpha did nothing since it's works off the diffuse.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 3rd Jan 2011 09:39
Quote: "addictive blending"


Lol

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 3rd Jan 2011 14:34
Hahaha... Additive Blending Sorry

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Jan 2011 22:35
Nah. Right first time. It is addictive.

At first sight your shader is just blending two textures so you might be able to use the blend mapping commands. When I've done that in the past I've found that blend mapping gives almost idential fps to the shader vesion. Haven't tested that on my higher spec machine though.

Not sure about your 1x1 vs 2x2 texture problem though. I recall Ric reported a while back that some GFX cards don't support 1x1 textures. In view of his report I usually use 4x4 images if I want a single colour and haven't noticed a problem.

Login to post a reply

Server time is: 2026-07-18 05:37:44
Your offset time is: 2026-07-18 05:37:44