Environment map reflections (fake)

Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
Darkcrafter
Posts: 586
Joined: Sat Sep 23, 2017 8:42 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

Environment map reflections (fake)

Post by Darkcrafter »

Code: Select all

Material material;

void SetupMaterial(inout Material material)
{

    vec2 texCoord = vTexCoord.st;

    material.Base = getTexel(texCoord);

	vec4 addEnv = texture(tex_envmap, (normalize(uCameraPos.xyz - pixelpos.xyz).xy));

	material.Base = (material.Base*0.7) + (addEnv*0.3);

}
GLDEFS implementation for a regular game texture:

Code: Select all

material texture "DEM1_5"
{
    Shader "shaders/EnvMapReflFake.gl"
	texture tex_envmap "Textures/Environments/Your_Environment_Map_Name.jpg"
}
GLDEFS implementation for a 3D model texture:

Code: Select all

material texture "Models/Floors/DEM1_5_On_My_Model.png"
{
    Shader "shaders/EnvMapReflFake.gl"
	texture tex_envmap "Textures/Environments/Your_Environment_Map_Name.jpg"
}


Here's a bit more advanced shader that also has an opacity mask to control reflections amount over a texture:

Code: Select all

Material material;

void SetupMaterial(inout Material material)
{

    vec2 texCoord = vTexCoord.st;

    material.Base = getTexel(texCoord);

	vec4 addEnv = texture(tex_envmap, (normalize(uCameraPos.xyz - pixelpos.xyz).xy));
        vec4 addEnvMask = texture(tex_envmap_mask, texCoord);

	material.Base = (material.Base * 0.64) + (addEnv * 0.7 * addEnvMask);
}
GLDEFS implementation for an effect with the opacity mask for reflections:

Code: Select all

material texture "Models/Floors/DEM1_5_On_My_Model.png"
{
    Shader "shaders/EnvMapReflFake.gl"
	texture tex_envmap "Textures/Environments/Your_Environment_Map_Name.jpg"
	texture tex_envmap_mask "Textures/Environments/Your_Environment_Map_Mask_Name.jpg"
}




The shader example, short test map, screenshot here
Last edited by Darkcrafter on Sat Dec 14, 2024 11:18 am, edited 2 times in total.
User avatar
DELTAtheDboi005
Posts: 219
Joined: Tue Apr 05, 2022 3:43 am
Preferred Pronouns: He/Him

Re: Environment map reflections (fake)

Post by DELTAtheDboi005 »

This looks quite nifty! if I use this, I'll be sure to credit you :)
User avatar
Darkcrafter
Posts: 586
Joined: Sat Sep 23, 2017 8:42 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support

Re: Environment map reflections (fake)

Post by Darkcrafter »

Thanks, later on I'll share a water shader which is also done in a similar way but with ripple distortions, maybe also derived from someone else (Marisa) shader pack.

https://imgur.com/a/XcyvY9I

Return to “Shaders”