Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

envMap automatic MIP level (HLSL Only) #154

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lighting/envMap.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ license:
*/

#ifndef SAMPLE_CUBE_FNC
// #define SAMPLE_CUBE_FNC(CUBEMAP, NORM, LOD) texCUBE(CUBEMAP, NORM)
#define SAMPLE_CUBE_FNC(CUBEMAP, NORM, LOD) texCUBElod(CUBEMAP, float4(NORM, LOD) )
//#define SAMPLE_CUBE_FNC(CUBEMAP, NORM, LOD) texCUBElod(CUBEMAP, float4(NORM, LOD) )
#define SAMPLE_CUBE_FNC(CUBEMAP, NORM, LOD) CUBEMAP.SampleLevel(sampler##CUBEMAP, NORM, LOD)
#endif

#ifndef ENVMAP_MAX_MIP_LEVEL
#if defined(ENVMAP_MAX_MIP_LEVEL) && !defined(UNITY_COMPILER_HLSL)
#define ENVMAP_MAX_MIP_LEVEL 3.0
#endif

Expand All @@ -39,6 +39,12 @@ float3 envMap(float3 _normal, float _roughness, float _metallic) {
return ENVMAP_FNC(_normal, _roughness, _metallic);

// Cubemap sampling
#elif defined(SCENE_CUBEMAP) && !defined(ENVMAP_MAX_MIP_LEVEL)
uint width, height, levels;
SCENE_CUBEMAP.GetDimensions(0, width, height, levels);
float lod = levels * _roughness;
return SAMPLE_CUBE_FNC( SCENE_CUBEMAP, _normal, lod).rgb;

#elif defined(SCENE_CUBEMAP)
float lod = ENVMAP_MAX_MIP_LEVEL * _roughness;
return SAMPLE_CUBE_FNC( SCENE_CUBEMAP, _normal, lod).rgb;
Expand Down
2 changes: 1 addition & 1 deletion lighting/fresnelReflection.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ float3 fresnelReflection(float3 R, float3 f0, float NoV) {
reflectColor = ENVMAP_FNC(R, 0.001, 0.001);

#elif defined(SCENE_CUBEMAP)
reflectColor = SAMPLE_CUBE_FNC( SCENE_CUBEMAP, R, ENVMAP_MAX_MIP_LEVEL).rgb;
reflectColor = envMap( R, 1.0 ).rgb;

#elif defined(SCENE_SH_ARRAY)
reflectColor = sphericalHarmonics(R);
Expand Down