Previous topicNext topic

How do you make black as a solid color ?

Questions, comments, feedback, etc.
Post Reply
TanookiMonk
Posts: 131
Joined: Sat Sep 19, 2015 12:27 am

How do you make black as a solid color ?

Post by TanookiMonk »

How do you make black as a solid color ? So that the black color will not be transparent for this case :

I am placing a cube built from 6 square polygon to make a cube effect, what is the best way to acheive this ? as for now 1 of the polygon seems to always stay transparent ! I will post an example later !

Edit : my question wasnt clear enough
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: How do you make black as a solid color ?

Post by Magic »

If I had to guess, I'd say the problem you're encountering is with depth testing. You might want to look at the DepthTestExample sample project to see what I mean. Using the DepthTest module will probably make things look better :). It layers things based on their Z position instead of their input pin.
TanookiMonk
Posts: 131
Joined: Sat Sep 19, 2015 12:27 am

Re: How do you make black as a solid color ?

Post by TanookiMonk »

You were right about this but using depthtest cause really glitchy result ! I attached my example for better understanding.

Option 1 : Without using depthtest this will result some object to look like transparent

Option 2 : Using depthtest will look glitchy

Is there any other option available ? or maybe i am doing it wrong ?
Attachments
Problem Example.magic
(1.59 KiB) Downloaded 370 times
Sadler
Posts: 1145
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: How do you make black as a solid color ?

Post by Sadler »

When trying to recreate I also see something I wouldn't expect with DepthTest on polys.
Cube.magic
(1.95 KiB) Downloaded 433 times
Though it does give a nice sparkly effect when radially blurred.
Cube2.magic
(2 KiB) Downloaded 419 times
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: How do you make black as a solid color ?

Post by Magic »

Option 2 : Using depthtest will look glitchy
The problem here is a phenomenon known as "z-fighting". See https://en.wikipedia.org/wiki/Z-fighting. If two polygons occupy exactly the same position in space, the renderer doesn't know how to render them.

This can happen in pretty much any program that does 3D rendering. To help prevent it, fancy algorithms can be used, but the tradeoff is that the rendering won't be as fast.

An easy solution is to translate one of the polygons just a tiny little bit, for example, .0001 in the Z direction, so that it is in front of (or behind) the other one. Then the problem goes away :).
Though it does give a nice sparkly effect when radially blurred.
Hah, that's interesting. I'm not sure if I've ever seen it used as an intentional effect, but it can work I guess.
TanookiMonk
Posts: 131
Joined: Sat Sep 19, 2015 12:27 am

Re: How do you make black as a solid color ?

Post by TanookiMonk »

Eric wrote:
Option 2 : Using depthtest will look glitchy
The problem here is a phenomenon known as "z-fighting". See https://en.wikipedia.org/wiki/Z-fighting. If two polygons occupy exactly the same position in space, the renderer doesn't know how to render them.

This can happen in pretty much any program that does 3D rendering. To help prevent it, fancy algorithms can be used, but the tradeoff is that the rendering won't be as fast.

An easy solution is to translate one of the polygons just a tiny little bit, for example, .0001 in the Z direction, so that it is in front of (or behind) the other one. Then the problem goes away :).
Though it does give a nice sparkly effect when radially blurred.
Hah, that's interesting. I'm not sure if I've ever seen it used as an intentional effect, but it can work I guess.
Hey Eric ! This is just amazing ! This information should be widespread as this problem will for sure occur for other people tho !

Btw : this fixed everything and now opens new doors for me !
Sadler
Posts: 1145
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: How do you make black as a solid color ?

Post by Sadler »

I'm sure most folks could manage a cube on their own but with inspiration from Tanooki and expertise from Eric a little sharing is appropriate.
magic_cube_use.png
magic_cube_use.png (54.61 KiB) Viewed 6328 times
Cubes.magic
(2.67 KiB) Downloaded 355 times
This provides an opportunity for me to make a feature request. To use a shader as a square texture one must scale it. Better would be an option to set the render resolution (which might have been asked for before for different reasons) which would allow the effect to render at the correct aspect ratio. Especially prevalent when dealing with circular sources.
Magic
Site Admin
Posts: 3441
Joined: Wed Apr 09, 2014 9:28 pm

Re: How do you make black as a solid color ?

Post by Magic »

Hey Eric ! This is just amazing ! This information should be widespread as this problem will for sure occur for other people tho !

Btw : this fixed everything and now opens new doors for me !
Happy to help :)
Better would be an option to set the render resolution (which might have been asked for before for different reasons) which would allow the effect to render at the correct aspect ratio. Especially prevalent when dealing with circular sources.
That's what the Resolution module is for. It renders its input(s) at the specified resolution. It actually forces a temporary change in the resolution of the output (as opposed to rendering at the output resolution and then re-scaling), so if you specify a smaller resolution than the output, it will render faster. Cool eh?

For an example, you can open the Effects2DExamples sample project and check out the Resolution tab.

For your purpose you could do GLSLShader --> Resolution --> CUBE, and set the Resolution to 720x720 or something like that.
Sadler
Posts: 1145
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: How do you make black as a solid color ?

Post by Sadler »

Indeed. Thanks. Twas in the recesses of memory.
Post Reply