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 / Alter the Colour of a Shader Affected Object

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 29th Oct 2011 21:34
Basically I need to change the colour and alpha of an object that's affected by a shader, but not through the shader. I've gotten stuck on how to do this affectively and efficiently. So I ask you guys. Any ideas?

Cheers in advance
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 30th Oct 2011 01:21
Well you'd have to do it "through the shader" at some level since the shader completely determines the output colour of an object.

Why not make a variable in the shader which is the desired colour and then change that on the fly from DBPro with "set effect constant vector".

[b]
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Oct 2011 02:32
I need to use a single shader for multiple objects, like over a 1000 objects. Hence why I said not through the shader. Similar to Point Sprites where the color is set up via a memblock. I'm guessing there's a way to set up a shader to used whatever the vertex diffuse is. Or other methods I haven't thought of...
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 30th Oct 2011 03:21 Edited at: 30th Oct 2011 03:22
What about creating a diffuse texture to blend with the shader?

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Oct 2011 11:08
Then it's a question of how would you get every colour and alpha? Other than creating a 1 x 1 px render target to generate the diffuse texture using something like image kit to update the texture's color. It would work but to do it for every single active object required would be expensive.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 30th Oct 2011 13:18
Ah, I see what you mean now. Well one way is to generate a 1x1px image of the desired colour for each object using memblocks and texture that object with it. You can access the texture from a shader easily enough.

You could also do it through vertex diffuse but that would be even more wasteful, since you wouldn't be able to share vertexdata between objects and changing the colour would require you to go through every vertex on an object.

There may also be some way to get the current diffuse colour, but I'm not sure exactly how much information DBPro gives the shader.

[b]
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Oct 2011 14:40
Isn't this the kind of thing where having multiple techniques in the shader can help?

Have two techniques - one that calls a pixel shader without the colouring, and one that calls a pixel shader with the colouring. Then you can colour your object just by switching techique. The second pixel shader can use an extra texture to provide the extra colouring if you need different colours on several objects.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Oct 2011 15:02
Quote: "Other than creating a 1 x 1 px render target to generate the diffuse texture using something like image kit to update the texture's color. It would work but to do it for every single active object required would be expensive."


Would a 1x1 texture for each object really be that expensive?

Login to post a reply

Server time is: 2026-07-11 12:00:42
Your offset time is: 2026-07-11 12:00:42