Files
UmaViewer/Assets/Plugins/UnityGLTF/Runtime/Shaders/ShaderGraph/PBRHelpers.cginc
T
左右看 0d848e4d07 bug fix
2023-06-28 00:35:46 +08:00

120 lines
3.7 KiB
HLSL

#ifndef UNITY_DECLARE_OPAQUE_TEXTURE_INCLUDED_2
#define UNITY_DECLARE_OPAQUE_TEXTURE_INCLUDED_2
#ifdef SHADERGRAPH_PREVIEW
void SampleSceneColor2_float(float2 uv, float lod, out float3 color)
{
color = float3(1,1,1);
}
void SampleSceneColor2_half(half2 uv, half lod, out half3 color)
{
color = half3(1,1,1);
}
#else
// Needed to comment this out due to IN-4055 - can't build with this include being present here
// For code changes, comment this out so autocomplete etc. work, but remember to comment it again
// #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
// TODO figure out how we can differentiate between BiRP/URP/HDRP here
#define USE_CAMERA_OPAQUE
#if defined(USE_CAMERA_OPAQUE)
float4 _CameraOpaqueTexture_TexelSize;
TEXTURE2D_X(_CameraOpaqueTexture);
SAMPLER(sampler_CameraOpaqueTexture);
#endif
// for future use
// float applyIorToRoughness( const in float roughness, const in float ior ) {
// // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and
// // an IOR of 1.5 results in the default amount of microfacet refraction.
// return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
// }
void SampleSceneColor_float(float2 uv, float lod, out float3 color)
{
#define REQUIRE_OPAQUE_TEXTURE // seems we need to define this ourselves? HDSceneColorNode does that as well
#if defined(USE_CAMERA_OPAQUE)
color = SAMPLE_TEXTURE2D_X_LOD(_CameraOpaqueTexture, sampler_CameraOpaqueTexture, UnityStereoTransformScreenSpaceTex(uv), lod).rgb;
#else
// For HDRP, from HDSceneColorNode
#if defined(REQUIRE_OPAQUE_TEXTURE) && defined(_SURFACE_TYPE_TRANSPARENT) && defined(SHADERPASS) && (SHADERPASS != SHADERPASS_LIGHT_TRANSPORT) && (SHADERPASS != SHADERPASS_PATH_TRACING) && (SHADERPASS != SHADERPASS_RAYTRACING_VISIBILITY) && (SHADERPASS != SHADERPASS_RAYTRACING_FORWARD)
color = SampleCameraColor(uv, lod) * 1.0; // GetInverseCurrentExposureMultiplier()
#else
color = float3(0.0, 0.0, 0.0);
#endif
#endif
}
void SampleSceneColor_half(float2 uv, float lod, out float3 color)
{
SampleSceneColor_float(uv, lod, color);
}
#endif
void Refract_float(float3 v, float3 n, float ior, out float3 refractionVector)
{
refractionVector = refract( - v, normalize( n ), 1 / ior );
}
void Refract_half(half3 v, half3 n, half ior, out half3 refractionVector)
{
refractionVector = refract( - v, normalize( n ), 1 / ior );
}
inline half3 bump3y (half3 x, half3 yoffset)
{
float3 y = 1 - x * x;
y = saturate(y-yoffset);
return y;
}
void Spectral_float(float wavelength, out half3 color)
{
// Based on GPU Gems
// Optimised by Alan Zucconi
// w: [400, 700]
// x: [0, 1]
half x = ((wavelength - 400.0)/ 300.0) % 1.0;
const float3 c1 = float3(3.54585104, 2.93225262, 2.41593945);
const float3 x1 = float3(0.69549072, 0.49228336, 0.27699880);
const float3 y1 = float3(0.02312639, 0.15225084, 0.52607955);
const float3 c2 = float3(3.90307140, 3.21182957, 3.96587128);
const float3 x2 = float3(0.11748627, 0.86755042, 0.66077860);
const float3 y2 = float3(0.84897130, 0.88445281, 0.73949448);
color =
bump3y(c1 * (x - x1), y1) +
bump3y(c2 * (x - x2), y2) ;
}
#endif
void WorkaroundTilingOffset_float(UnityTexture2D Tex, float4 LegacyST, out float4 TilingOffset, out float4 TilingOffsetOther)
{
#if UNITY_VERSION >= 202120
TilingOffset = float4(1,1,0,0);
TilingOffsetOther = Tex.scaleTranslate.xyzw;
#else
TilingOffset = LegacyST;
TilingOffsetOther = LegacyST;
#endif
}
void WorkaroundTilingOffset_half(UnityTexture2D Tex, half4 LegacyST, out half4 TilingOffset, out half4 TilingOffsetOther)
{
#if UNITY_VERSION >= 202120
TilingOffset = half4(1,1,0,0);
TilingOffsetOther = Tex.scaleTranslate.xyzw;
#else
TilingOffset = LegacyST;
TilingOffsetOther = LegacyST;
#endif
}