| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- Technique : base("ReflectionCubemapCommon") =
- {
- Language = "HLSL11";
- Pass =
- {
- Common =
- {
- float3 getDirFromCubeFace(uint cubeFace, float2 uv)
- {
- float3 dir;
- if(cubeFace == 0)
- dir = float3(1.0f, -uv.y, -uv.x);
- else if(cubeFace == 1)
- dir = float3(-1.0f, -uv.y, uv.x);
- else if(cubeFace == 2)
- dir = float3(uv.x, 1.0f, uv.y);
- else if(cubeFace == 3)
- dir = float3(uv.x, -1.0f, -uv.y);
- else if(cubeFace == 4)
- dir = float3(uv.x, -uv.y, 1.0f);
- else
- dir = float3(-uv.x, -uv.y, -1.0f);
-
- return dir;
- }
-
- /**
- * Calculates a mip level to sample from based on roughness value.
- *
- * @param roughness Roughness in range [0, 1]. Higher values yield more roughness.
- * @param numMips Total number of mip-map levels in the texture we'll be sampling from.
- * @return Index of the mipmap level to sample.
- */
- float mapRoughnessToMipLevel(float roughness, uint numMips)
- {
- // We use the following equation:
- // mipLevel = log10(roughness) / log10(dropPercent)
- //
- // Where dropPercent represent by what % to drop the roughness with each mip level.
- // We convert to log2 and a assume a drop percent value of 0.6. This gives us:
- // mipLevel = -1.35692 * log2(roughness);
-
- return max(0, numMips - 1 - (-1.35692 * log2(roughness)));
- }
-
- float mapMipLevelToRoughness(uint mipLevel)
- {
- // mapRoughnessToMipLevel() solved for roughness
- return 1.0f - exp2(-0.7369655941662063 * mipLevel);
- }
- };
- };
- };
- Technique : base("ReflectionCubemapCommon") =
- {
- Language = "GLSL";
- Pass =
- {
- Common =
- {
- vec3 getDirFromCubeFace(uint cubeFace, vec2 uv)
- {
- vec3 dir;
- if(cubeFace == 0)
- dir = vec3(1.0f, -uv.y, -uv.x);
- else if(cubeFace == 1)
- dir = vec3(-1.0f, -uv.y, uv.x);
- else if(cubeFace == 2)
- dir = vec3(uv.x, 1.0f, uv.y);
- else if(cubeFace == 3)
- dir = vec3(uv.x, -1.0f, -uv.y);
- else if(cubeFace == 4)
- dir = vec3(uv.x, -uv.y, 1.0f);
- else
- dir = vec3(-uv.x, -uv.y, -1.0f);
-
- return dir;
- }
- };
- };
- };
|