[2.1] Transparent Material Issues

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
DOS
Gnoblar
Posts: 19
Joined: Tue Oct 27, 2020 5:34 pm

[2.1] Transparent Material Issues

Post by DOS »

Hello,

I can't seem to get my transparent materials right. This is my material script:

Code: Select all

hlms Autoglas pbs
{
   ambient 0.37 0.37 0.37
   diffuse 0.37 0.37 0.37
   specular 0.05 0.05 0.05
   emissive 0.0 0.0 0.0
   
   depth_write off
   transparency_mode transparent
   roughness 0.1
}
I have also experimented with other parameters like depth_check, depth_func and scene_blend but my material (supposed to be the window of a car) always looks like this:

Image

I also have another material which is supposed to use the transparency from the texture alpha:

hlms Spruce pbs
{
cull_mode none
depth_write off
transparency_mode transparent
alpha_from_textures true
diffuse_map Fichte_Col_2K.dds
roughness 1.0
}

Here is the problem that the transparent parts still seem to reflect light at some angles which looks very weird:

Image

How can I make transparency work with my materials? Thanks in advance for any help.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Transparent Material Issues

Post by dark_sylinc »

Hi!

In the case of tree leaves though, it may be better to use alpha testing instead (and not transparency at all), which is order independent:
"transparent" mode is meant for materials like glass; and the user should probably have some knowledge of premultiplied alpha blending to take full advantage of it.

What you're looking for is probably "fade":

Code: Select all

transparency_mode fade
Which is good ol' regular alpha blending.

Code: Select all

alpha_test 0.5
For the case of the car glass, it looks like the alpha is set to maximum. Try:

Code: Select all

hlms Autoglas pbs
{
   // ambient 0.37 0.37 0.37 ambient is not used
   diffuse 0.37 0.37 0.37 // The value of diffuse when using transparent is important! Try other values
   specular 0.05 0.05 0.05
   
   depth_write off
   transparency_mode transparent
   transparency 0.5 // Play with this value
   roughness 0.05 // Try other values of roughness. This matters a lot for glass
}
Check the PbsMaterials sample and start hitting the '-' (minus) key which turns the spheres transparent
DOS
Gnoblar
Posts: 19
Joined: Tue Oct 27, 2020 5:34 pm

Re: [2.1] Transparent Material Issues

Post by DOS »

Hello,

thanks for your help, I was able to fix the glass, but I still have trouble with the tree.
Based on your suggestions, I changed the material to this:

Code: Select all

hlms Spruce pbs
{
   cull_mode none
   depth_write off
   transparency_mode fade
   alpha_test 1.0
   alpha_from_textures true
   diffuse_map Fichte_Col_2K.dds
   roughness 1.0
}
It's a bit better now but there are still 2 problems.
1) The white "smear" on the parts of the model where the directional light shines onto.
2) The order still doesn't seem to be correct because some parts are occluded by things on the other side (a bit hard to see from a screenshot, I have drawn a red circle around a part where the tree trunk is occluded by leafs on the other side of the model).

Image


EDIT: If it helps, I am trying to port this material from the old system, which displayed it correctly. Here is the old material:

Code: Select all

material  Spruce {
    receive_shadows on
    technique {
        pass Spruce {
            lighting off
            alpha_to_coverage off 
            colour_write on 
            cull_hardware none
            depth_check on 
            depth_func less_equal 
            depth_write on
            illumination_stage  
            light_clip_planes off 
            light_scissor off 
            normalise_normals off 
            polygon_mode solid 
            alpha_rejection greater_equal 128
            scene_blend_op add 
            shading gouraud 
            transparent_sorting on 
            texture_unit  {
                texture Fichte_Col_2K.dds 
                tex_address_mode wrap 
                scale 1.0 1.0 
                tex_coord_set 0 
                colour_op modulate 
            }
        }
    }
}
Last edited by DOS on Wed Oct 28, 2020 3:45 pm, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Transparent Material Issues

Post by dark_sylinc »

DOS wrote: Wed Oct 28, 2020 3:40 pm

Code: Select all

hlms Spruce pbs
{
   cull_mode none
   depth_write off
   transparency_mode fade
   alpha_test 1.0
   alpha_from_textures true
   diffuse_map Fichte_Col_2K.dds
   roughness 1.0
}
Hi!

Don't activate alpha test and fade at the same time, e.g. use

Code: Select all

hlms Spruce pbs
{
   // cull_mode none // More on this later
   alpha_test 0.5
   alpha_from_textures true
   diffuse_map Fichte_Col_2K.dds
   roughness 1.0
}
As for the smear thing, it sounds like a problem with fresnel. Try playing with "fresnel_coeff 0.1" , where the value can be in range [0; 1]

Additionally, use two-sided lighting. This can be enabled either via C++ or JSON materials (the simplified material syntax doesn't expose this setting). e.g.

Code: Select all

pbsDatablock->setTwoSidedLighting( true );
This will automatically set cull mode to none, and use proper lighting on the backface.
DOS
Gnoblar
Posts: 19
Joined: Tue Oct 27, 2020 5:34 pm

Re: [2.1] Transparent Material Issues

Post by DOS »

Hi,

thanks for your help but in the end the only thing that got rid of the white lines on the tree was to set the roughness to 0 (even very small values like 0.001 didn't help). fresnel_coeff and two sided lighting didn't seem to change anything regarding this issue.
User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Transparent Material Issues

Post by Crystal Hammer »

Okay I have a freaking problem with this too. I tried it with 2.1 some time ago, now I'm doing it again with 2.3, and this just does not work as it should (and it worked fine with Ogre 1.9).
My sources are here. Based on tutorial terrain. So I'm not making screens nor videos. :roll:

I'm using PBS materials and v2 meshes with LOD (made with new MeshTool and old StuntRally's 1.x stuff). I use GL3+.
I need no culling and no depth write. Texture has leaves with border having alpha, not drawn parts have alpha 0.
There are few issues here:

  • With no culling I get wrong order of triangles. E.g. if I look from top, order of drawing pine branches is wrong, random.
  • When I turn off depth write I see no shadows cast by trees and no self shadowing.
  • Plane as ground is okay, but when I show terrain it hides tress - Okay fixed this with item->setRenderQueueGroup for trees.
  • For parts having alpha 0 on texture, still fresnel, specular and such are being applied. Obviously with alpha 0 it should discard and don't do anything.
    This is less of a problem with specular 0 0 0 0 and fresnel_coeff 0.0, but not a solution.
    I saw alpha_test_cmp_func in shader and it gives <, while it should >. Because there is this weird glow otherwise with alpha_test (which I don't want anyway, I'm using transparent).

I guess this PBS works well with glass and all but for vegetation this is completely messed up for me right now, I can't get it to work.
It'd be great if you could fix it.
Seems for me way too hard to write own PBS implementation for this, I'd have to understand HLMS code a lot more. :cry:

Last edited by Crystal Hammer on Sun Feb 20, 2022 11:31 pm, edited 1 time in total.
User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Transparent Material Issues

Post by Crystal Hammer »

Okay my bad, it mostly works now.
So I need depth write and alpha_test greater 0.5 fixed the sign.

I think there is only 1 thing wrong I see. This glow around edges of branches, where alpha is close to test value I guess. It makes me see what is behind this tree:
Image
This wasn't in Ogre 1.9.
So I have now in pbs:

Code: Select all

hlms pine2norm pbs
{
  diffuse_map  pine_norm_gr1.png
  normal_map   pine_norm_norm.jpg
  fresnel_coeff 0.0
  roughness 0.2
  metalness 0.2

  //two_sided_lighting true  //?
  cull_mode none
  //depth_write off  // no shadows
  //transparency 0.5
  //transparency_mode transparent

  alpha_test greater 0.5
  //alpha_test_threshold 0.4
  alpha_from_textures true
}

This glow gets lesser with higher value e.g.: alpha_test greater 0.8, but it doesn't fix it completely and more of texture disappears this way.
Is there a way to fix this?

We had transparent for this tree in shiny syntax. Not sure what it did then.

Code: Select all

material pine_base
{
    parent base
    transparent true
    tree_wind true
    terrain_light_map true
    alpha_rejection greater 128

I have few new questions:

  • Why can't we setTwoSidedLighting in .material json?
  • How can I set textures to wrap in json?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Transparent Material Issues

Post by dark_sylinc »

I don't know what the blue glow is, at least not yet with the available info.

Crystal Hammer wrote: Sun Feb 20, 2022 11:25 pm

I have few new questions:

  • Why can't we setTwoSidedLighting in .material json?
  • How can I set textures to wrap in json?

This reminds me I should fix and merge the Docs PR!
In the meantime we have a JSON example with all available options.

Texture wrap is part of the sampler info:

Code: Select all

    "samplers" :
   {
        "unique_name" :
        {
            "u" : "wrap" "mirror" "clamp" "border",
            "v" : "wrap" "mirror" "clamp" "border",
            "w" : "wrap" "mirror" "clamp" "border",
        }
    },

Two sided lighting is simply "two_sided" : true

User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Transparent Material Issues

Post by Crystal Hammer »

OK. Thanks for info.
This glow is background color (sky) and (I think) it appears when alpha test has just passed, but it blends from background to texture.
I think it would just pass or discard, not blend. Or just blend between black or texture colour (behind alpha).
When I had previous issue: wrong alpha test (not greater) I could see through mountains in this glow, terrain wasn't there but further trees were. :D
Image

A few more questions for vegetation (if you don't mind :) ):

  • Is there a way to set "mesh view" LOD bias for camera so I could adjust in code how far I see quality trees?
  • Lets say I want to end at 70% LOD reduction and then after some distance make mesh disappear, is that possible somehow? If I end at 70% in MeshTool it will show them always even very far.
  • Or if I had impostors someday, e.g. 4 triangle meshes or 2 if they'd align to camera, then how would I made it work that those impostor meshes show after some distance and regular meshes hide?
  • BTW, a question for my road, for which I had 4 LOD levels too and made those meshes from code as ManualObjects. Can I make LOD meshses myself in code? I mean not by automatic reduction just by creating LOD level meshes myself.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Transparent Material Issues

Post by dark_sylinc »

Normally the glow looks like alpha blending is enabled with depth writes on and the terrain is being rendered after the trees.
However the material you posted, alpha blending is off.

The other thing I can think of is that the alpha threshold is not good enough and we're seeing ambient colouring (probably specular?) from areas that shouldn't be visible.

Is there a way to set "mesh view" LOD bias for camera so I could adjust in code how far I see quality trees?

Probably by modifying the CompositorPassSceneDef::mLodBias value.

Lets say I want to end at 70% LOD reduction and then after some distance make mesh disappear, is that possible somehow? If I end at 70% in MeshTool it will show them always even very far.

Use MovableObject::setRenderingDistance

Or if I had impostors someday, e.g. 4 triangle meshes or 2 if they'd align to camera, then how would I made it work that those impostor meshes show after some distance and regular meshes hide?

I don't think you can do this automatically. But you can consult getRenderingDistance to see the values from previous frame and manually do it.

BTW, a question for my road, for which I had 4 LOD levels too and made those meshes from code as ManualObjects. Can I make LOD meshses myself in code? I mean not by automatic reduction just by creating LOD level meshes myself.

Can you rephrase?

Cheers

User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Transparent Material Issues

Post by Crystal Hammer »

Thanks for answers.

dark_sylinc wrote: Mon Feb 21, 2022 1:29 am

BTW, a question for my road, for which I had 4 LOD levels too and made those meshes from code as ManualObjects. Can I make LOD meshses myself in code? I mean not by automatic reduction just by creating LOD level meshes myself.

Can you rephrase?

I mean my road meshes are created procedurally. I generate them in code, from spline. And I have steps (divisions) count parameters for quality. So I create 4 LODs that decrease quality.
Back in Ogre 1.9 I made just 4 meshes, and every frame I just did setVisible for 1 of 4 that I wanted to be visible, based on how close it is (best quality).
But with Ogre 2.3 maybe I could use mesh LOD system to do this for me? Question is can I specify meshes (vertices indices etc) myself manually for each LOD?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Transparent Material Issues

Post by dark_sylinc »

Ah yes!

You can create a Mesh with a single SubMesh (or more if you need multiple materials), then set each LOD to SubMesh::mVao[VpNormal].push_back( vaoLod );

You can have multiple Vaos share the same Vertex Buffer, or not. That's up to your needs.

The LOD distances go into Mesh::mLodValues (uh oh, I think it's not possible to alter mLodValues externally, that's an Ogre API bug).

User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Transparent Material Issues

Post by Crystal Hammer »

A closer look at this glow issue:
Image
I'm looking from ground up, first through close tree leaves, palm is after, and finally sky with clouds.
I should probably see dark leaves only, yet in alpha regions, close to leaves (big blobs) I see what is behind.
I think this region is 1pixel only and happens when alpha from texel is greater than 0.5 (set in material) until it's 1.0.
Maybe it is because depth is not written (but I didn't set to off)? Or triangles are not sorted? I see this when looking in any direction through any tree.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Transparent Material Issues

Post by dark_sylinc »

Could you upload a RenderDoc capture? (either GL or D3D11, but not Vulkan because Vulkan captures are specific to each GPU)

I could use that to inspect what's going on and from there diagnose what's going wrong.

User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Transparent Material Issues

Post by Crystal Hammer »

Okay, uploaded it here.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Transparent Material Issues

Post by dark_sylinc »

I took a quick look.

You have both alpha testing and alpha blending enabled. Turn off any kind of transparency. Only alpha testing should be left on.

Alpha testing enabled (right):

Alpha blending enabled (wrong):

Moreover, it's using TransparencyModes::Transparent mode, which is totally the wrong mode for vegetation (it's intended for glass like windows or cups of glasses)

User avatar
Crystal Hammer
Gnome
Posts: 317
Joined: Sat Jun 23, 2007 5:16 pm
x 77
Contact:

Re: [2.1] Transparent Material Issues

Post by Crystal Hammer »

Allright, I didn't know. So after I commented this line:
//alpha_from_textures true
the issue is now gone. Thanks for help.

Post Reply