Files
cocos4/editor/assets/chunks/common/texture/cubemap.chunk
T
2023-04-12 19:06:21 +08:00

62 lines
2.2 KiB
Plaintext

// for legacy only
#pragma extension([GL_OES_standard_derivatives, __VERSION__ < 110])
vec3 EnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {
#if CC_USE_IBL
// simulate GGX convolution
#if !CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING && !CC_IBL_CONVOLUTED
roughness = pow(roughness, 0.5);
#endif
//#todo: add GL400 calcmip
float mip = roughness * (mipCount - 1.0);
float delta = (dot(dFdx(R), dFdy(R))) * 1000.0;
float mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));
vec3 rotationDir = RotationVecFromAxisY(R.xyz, cc_surfaceTransform.z, cc_surfaceTransform.w);
vec4 biased = fragTextureLod(cc_environment, rotationDir, mip + mipBias);
vec4 filtered = texture(cc_environment, rotationDir);
#if CC_USE_IBL == IBL_RGBE
biased.rgb = unpackRGBE(biased);
filtered.rgb = unpackRGBE(filtered);
#else
biased.rgb = SRGBToLinear(biased.rgb);
filtered.rgb = SRGBToLinear(filtered.rgb);
#endif
return mix(biased.rgb, filtered.rgb, denoiseIntensity);
#else
return vec3(0.0, 0.0, 0.0);
#endif
}
vec3 EnvReflection(samplerCube tex, vec3 R, float roughness, float mipCount) {
// simulate GGX convolution
#if !CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING && !CC_IBL_CONVOLUTED
roughness = pow(roughness, 0.5);
#endif
vec3 rotationDir = RotationVecFromAxisY(R.xyz, cc_surfaceTransform.z, cc_surfaceTransform.w);
vec4 envmap = fragTextureLod(tex, rotationDir, roughness * (mipCount - 1.0));
#if CC_USE_IBL == IBL_RGBE
return unpackRGBE(envmap);
#else
return SRGBToLinear(envmap.rgb);
#endif
}
vec3 EnvReflectionOfReflectionProbe(samplerCube tex, vec3 R, float roughness, float mipCount, bool isRGBE) {
// simulate GGX convolution
#if !CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING && !CC_IBL_CONVOLUTED
roughness = pow(roughness, 0.5);
#endif
vec3 rotationDir = RotationVecFromAxisY(R.xyz, cc_surfaceTransform.z, cc_surfaceTransform.w);
vec4 envmap = fragTextureLod(tex, rotationDir, roughness * (mipCount - 1.0));
if (isRGBE)
return unpackRGBE(envmap);
else
return SRGBToLinear(envmap.rgb);
}