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 / alpha shader - again

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 28th Oct 2011 22:31 Edited at: 28th Oct 2011 22:31


Watch the rings on the black hole carefully. See how they fade into existence on the outside, and then scroll into the middle? Is there a way to make a two layered texture on an object, where one is the alpha channel, and the other the color texture?

The way the rings work in the video is most likely with a texture like this:



Left is the alpha channel, and the right is the rings. The left texture is scrolled along the object, and the alpha channel stays where it is.

TheComet

revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 29th Oct 2011 07:31
Hi TheComet, I threw this demo together for you which I think is pretty close. It works in a similar manner to how you suggest, but with much friendlier images (straight lines instead of circles, but requires a special made object). What do you think?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Oct 2011 13:21 Edited at: 29th Oct 2011 13:22
Interesting question. I'd do it roughly as follows.

Texture the black hole with the two images - but make sure the object is contained well within the ring texture. Then gradually expand the UV coordinates from their centre values, i.e. (U,V)=(0.5,05). That will make the texture appear to shrink towards the centre. You then need to reset the amount of shrinkage each time a ring coincides with the position of the previous one and repeat the same procedure - you'll need to work out when that happens with a bit of math and simple experimentation. You should then get the impression of concentric rings continually shrinking towards the centre. I would calculate the amount of shrinkage within DBPro and pass it as a constant each sync to the shader. Should be simpler and more efficient to do it that way rather than in the shader.

Making the other objects distort as they fall into the black hole is another matter.

revenant chaos Nice demo - but I wouldn't do it that way. The simplicity of your method is that you don't need the maths to get the shrinking effect. The downside is, as you say, that you need a specially constructed object. My method should work with a simple plain.

I'm interested in seeing how this turns out.
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 22:46
Thought I'd better put my money where my mouth is.

Here's a demo of what I had in mind. I've included the program I used to create the ring texture. The alpha level is calculated in a rather ad hoc way in the shader - you could improve on that by incorporating it in the image and amending the shader accordingly. My level of laziness seems to be increasing these days.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 31st Oct 2011 21:06 Edited at: 31st Oct 2011 21:06
@ revenant chaos

Thanks for that, I remapped the texture to my object to fit your shader's demands, and it turns out incredibly pixelated:



The rings still scroll though...


@ Green Gandalf

I implemented your shader as well, but noticed you used a logarithmic function to generate the circles. Since my texture is linear, it isn't compatible. Would you mind sharing with me how you generated that texture?

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Oct 2011 22:40
Quote: "Would you mind sharing with me how you generated that texture?"


I thought I included the code for that as well. It was the "circles.dbpro" project. Have a look at the code and see if anything needs explaining further. Not sure now but I might have smoothed the texture a bit using Texture Maker.

My method needs a multiplicative rule because the texture is being shrunk by a fixed factor each sync - so outer rings need to be further apart than inner ones.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 31st Oct 2011 23:36 Edited at: 31st Oct 2011 23:36
Ah so it is, thanks

There's only one more problem left now... Above is how it looks without the shader, but as soon as I apply your shader, it becomes less transparent for some reason... The texture I use has an alpha channel if that is of any significance.



TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Nov 2011 01:48
Quote: "The texture I use has an alpha channel if that is of any significance."


That shouldn't affect the shader since that sets its own alpha value. Also, I can't reproduce your problem. Could you post a simple demo?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Nov 2011 08:14
Sure, I replaced the texture you used in your example with mine. [attached]

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Nov 2011 12:47
Your image is filled with blue between the rings so that gets added to the final colour. What effect did you want exactly?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Nov 2011 13:35 Edited at: 1st Nov 2011 13:36
In the last example I posted remove set object effect, delete the objects and color the backdrop black. For some reason the object then appears more transparent without the effect, and with it the space between the rings are filled. The effect I'm after is where the space between the rings aren't filled. Or am I doing something wrong?

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Nov 2011 15:03
Quote: "The effect I'm after is where the space between the rings aren't filled."


That's what I thought. Why have you filled the space between the rings with blue?

Anyway, I can simply edit the shader to use your alpha channel as well. The shader doesn't use it at the moment which is why you didn't get the effect with the shader. I guess that without the shader DBPro is using the alpha channel so you get the transparency effect.

I'll edit it now and post back soon.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Nov 2011 15:07
Here you go.

Just change this line:



to this:

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Nov 2011 19:00
Thanks GG, it finally works Here's a video demonstrating the effect. I hope I'm not giving away too much about my secret project



Still needs some work, but you get the basic idea

I know there's that "Learn to write shaders" thread and all of that, but how do you know the commands to use to write a shader? Is there a command list somewhere?

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Nov 2011 19:51
Quote: "but how do you know the commands to use to write a shader? Is there a command list somewhere?"


I usually refer to the MS DX9 SDK docs for things like that. It's available as a rather large free download from Microsoft and contains everything you need to know about DirectX plus various samples and tutorials.

Here's a typical link:

Microsoft DX SDK download

If you search the MS site you might find an earlier smaller version. If you just need documentation you can probably find that as well without having to download it. You could start from here:

HLSL intrinsic functions

The SDK is geared towards C++ programmers (which I'm not) but I still find the documentation indispensible even if it is indigestible at times.

You might be able to find some decent tutorials by searching for things like HLSL tutorials in Google.

Login to post a reply

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