Skip to content

Commit

Permalink
Merge pull request #166 from shadielhajj/hlsl/sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciogonzalezvivo authored Jul 16, 2024
2 parents 110b569 + 6f0d775 commit be4bd83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lighting/envMap.hlsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#include "../sampler.hlsl"
#include "../math/powFast.hlsl"
#include "../color/tonemap.hlsl"

#include "fakeCube.hlsl"
#include "toShininess.hlsl"
Expand All @@ -22,8 +21,7 @@ license:
*/

#ifndef SAMPLE_CUBE_FNC
//#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)
#define SAMPLE_CUBE_FNC(CUBEMAP, NORM, LOD) CUBEMAP.SampleLevel(DEFAULT_SAMPLER_STATE, NORM, LOD)
#endif

#if defined(ENVMAP_MAX_MIP_LEVEL) && !defined(UNITY_COMPILER_HLSL)
Expand Down
36 changes: 31 additions & 5 deletions sampler.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,36 @@ license:
- Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0
- Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license
*/
#ifndef SAMPLER_FNC
#define SAMPLER_FNC(TEX, UV) tex2D(TEX, UV)
#endif

#ifndef SAMPLER_TYPE
#define SAMPLER_TYPE sampler2D
#if defined(__SHADER_TARGET_MAJOR) && __SHADER_TARGET_MAJOR < 4

#ifndef SAMPLER_FNC
#define SAMPLER_FNC(TEX, UV) tex2D(TEX, UV)
#endif

#ifndef SAMPLER_TYPE
#define SAMPLER_TYPE sampler2D
#endif

#else

// https://docs.unity3d.com/Manual/SL-SamplerStates.html
#ifndef DEFAULT_SAMPLER_STATE
#define DEFAULT_SAMPLER_STATE defaultLinearClampSampler
SamplerState DEFAULT_SAMPLER_STATE
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
#endif

#ifndef SAMPLER_FNC
#define SAMPLER_FNC(TEX, UV) TEX.Sample(DEFAULT_SAMPLER_STATE, UV)
#endif

#ifndef SAMPLER_TYPE
#define SAMPLER_TYPE Texture2D
#endif

#endif

0 comments on commit be4bd83

Please sign in to comment.