weird stuff in Fresnel sample

Problems building or running the engine, queries about how to use features etc.
slapin
Bronze Sponsor
Bronze Sponsor
Posts: 148
Joined: Fri May 23, 2025 5:04 pm
x 5

weird stuff in Fresnel sample

Post by slapin »

Assuming the material:

Code: Select all

material Water/Below
{
        technique
        {
                pass
                {
                        ambient 1.0 1.0 1.0 1.0
                        diffuse 0.0 0.2 0.5 1.0
                        cull_hardware none
                        cull_software none
                        vertex_program_ref Water/water_vp
                        {
                        }
                        fragment_program_ref Water/water_fp
                        {
                        }
                        // Noise
                        texture_unit
                        {
                                // Perlin noise volume
                                texture waves2.png
                                // min / mag filtering, no mip
                                filtering linear linear none
                                tex_address_mode mirror
                        }
                        // Reflection
                        texture_unit
                        {
                                content_type compositor Fresnel reflection
                                tex_address_mode mirror
                        }
                        // Refraction
                        texture_unit
                        {
                                content_type compositor Fresnel refraction
                                tex_address_mode mirror
                        }
                }
        }
}

What this code does?

Code: Select all

        auto mat = Ogre::MaterialManager::getSingleton().getByName("Water/Above");
        mat->getTechnique(0)
                ->getPass(0)
                ->getTextureUnitState(0)
                ->setProjectiveTexturing(true, mCamera);

while printing

Code: Select all

std::cout << mat->getTechnique(0)
                ->getPass(0)
                ->getTextureUnitState(0)->getTextureName() << "\n";

prints "waves2.png"

rpgplayerrobin
Orc Shaman
Posts: 754
Joined: Wed Mar 18, 2009 3:03 am
x 421

Re: weird stuff in Fresnel sample

Post by rpgplayerrobin »

I guess your question is why projective texturing is used here?
In the older version of Ogre (1.12 for example), that projective texturing code is not used at all, and I see no reason to have to use that for the fresnel anyway.

Here is that older code:
viewtopic.php?p=554504#p554504

Also, it is a bit confusing that you share the Water/Below material, when Water/Above is the only one actually used in your code! :D
Projective texturing has nothing to do with the texture itself, it only changes the UV for it.

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 148
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: weird stuff in Fresnel sample

Post by slapin »

Above/Below materials now are the same...
My question is why projective texturing is used this way, i.e. only on 1 texture, and why it affects whole material.
I'm not against it per se as it might be very useful, but I see the usage as totally confusing :(

paroj
OGRE Team Member
OGRE Team Member
Posts: 2204
Joined: Sun Mar 30, 2014 2:51 pm
x 1188

Re: weird stuff in Fresnel sample

Post by paroj »

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 148
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: weird stuff in Fresnel sample

Post by slapin »

@paroj sorry, but it needs some explanation. Now I'm even more confused.

paroj
OGRE Team Member
OGRE Team Member
Posts: 2204
Joined: Sun Mar 30, 2014 2:51 pm
x 1188

Re: weird stuff in Fresnel sample

Post by paroj »

you need to generate uv coordinates for mapping the reflection texture onto the water plane. Using the main camera as a projector does that. The resulting matrix is passed to the shader.

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 148
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: weird stuff in Fresnel sample

Post by slapin »

Thanks!

rpgplayerrobin
Orc Shaman
Posts: 754
Joined: Wed Mar 18, 2009 3:03 am
x 421

Re: weird stuff in Fresnel sample

Post by rpgplayerrobin »

In that case that is the difference between the new and the old version, since the old version did the projection in the hlsl code instead:

Code: Select all

float4x4 scalemat = float4x4(0.5,   0,   0, 0.5, 
	                               0,-0.5,   0, 0.5,
								   0,   0, 0.5, 0.5,
								   0,   0,   0,   1);
	projectionCoord = mul(scalemat, oPos);
slapin
Bronze Sponsor
Bronze Sponsor
Posts: 148
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: weird stuff in Fresnel sample

Post by slapin »

My problem with this code is use of texture unit 0 (which is not even render target) and magic about how it works.
I avoided that and did via division by viewportSize.