diff --git a/Assets/Filamented.meta b/Assets/Filamented.meta new file mode 100644 index 0000000..28ab602 --- /dev/null +++ b/Assets/Filamented.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f4b67dbe8e4f8d141aada22cb87a5d37 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/CrossStandardTest.mat b/Assets/Filamented/CrossStandardTest.mat new file mode 100644 index 0000000..b6c35e7 --- /dev/null +++ b/Assets/Filamented/CrossStandardTest.mat @@ -0,0 +1,106 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CrossStandardTest + m_Shader: {fileID: 4800000, guid: 9829e18681954944a8b25de9b080a0b6, type: 3} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 2800000, guid: 71df313bf94a79746a4688af6ae80017, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DFG: + m_Texture: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 2800000, guid: b582b17f0e346c24188b4e86cc8950b3, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 2800000, guid: 6f2555b25fa89524f9431086d0e2e8c7, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 2800000, guid: 0329f88e1a406644c97d0ec094ab70e2, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 2800000, guid: c3b93488fd8a11847ad12e8710e6866a, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RNM0: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RNM1: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RNM2: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _AlphaToMaskMode: 0 + - _Bakery: 0 + - _BakeryVertexLM: 0 + - _BumpScale: 1 + - _BumpShadowHardness: 50 + - _BumpShadowHeightScale: 0.2 + - _CullMode: 2 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _ExposureOcclusion: 0.2 + - _GlossMapScale: 1 + - _Glossiness: 1 + - _GlossyReflections: 1 + - _LTCGI: 0 + - _LightmapSpecular: 1 + - _LightmapSpecularMaxSmoothness: 1 + - _Metallic: 1 + - _Mode: 0 + - _NormalMapShadows: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + - _specularAntiAliasingThreshold: 0.25 + - _specularAntiAliasingVariance: 0.15 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 2.7921572, g: 2.729412, b: 2.227451, a: 1} diff --git a/Assets/Filamented/CrossStandardTest.mat.meta b/Assets/Filamented/CrossStandardTest.mat.meta new file mode 100644 index 0000000..4692344 --- /dev/null +++ b/Assets/Filamented/CrossStandardTest.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7e3e2734c20f8704986e4b44f7950257 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras.meta b/Assets/Filamented/Extras.meta new file mode 100644 index 0000000..ff6171e --- /dev/null +++ b/Assets/Filamented/Extras.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2a44cf144ddd0f148beb5007a7b636d8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedFractal.shader b/Assets/Filamented/Extras/FilamentedFractal.shader new file mode 100644 index 0000000..6f2b913 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedFractal.shader @@ -0,0 +1,347 @@ +/* +Filamented triplanar example. +*/ +Shader "Silent/Filamented Extras/Filamented Fractal Sampling" +{ + Properties + { + _Color("Color", Color) = (1,1,1,1) + _MainTex("Albedo", 2D) = "white" {} + [Space] + [NoScaleOffset][Normal] _BumpMap("Normal", 2D) = "bump" {} + _BumpScale("Normal Scale", Float) = 1 + [Space] + [NoScaleOffset]_MOESMap("MOES Map", 2D) = "white" {} + [NoScaleOffset]_MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _Emission("Emission Power", Float) = 0 + _EmissionColor("Emission Color", Color) = (1,1,1,1) + [Space] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + } + + CGINCLUDE + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + +//Samples at three scales, interpolating between them (with mipmapping) +float4 fractal_texture_mip(sampler2D tex, float2 uv, float depth) +{ + //Find the pixel level of detail + float LOD = log(depth); + //Round LOD down + float LOD_floor = floor(LOD); + //Compute the fract part for interpolating + float LOD_fract = LOD - LOD_floor; + + //Compute scaled uvs + float2 uv1 = uv / exp(LOD_floor - 1.0); + float2 uv2 = uv / exp(LOD_floor + 0.0); + float2 uv3 = uv / exp(LOD_floor + 1.0); + + //Compute continous derivitives + float2 dx = ddx(uv) / depth * exp(1.0); + float2 dy = ddy(uv) / depth * exp(1.0); + + //Sample at 3 scales + float4 tex0 = tex2Dgrad(tex, uv1, dx, dy); + float4 tex1 = tex2Dgrad(tex, uv2, dx, dy); + float4 tex2 = tex2Dgrad(tex, uv3, dx, dy); + + //Blend samples together + return (tex1 + lerp(tex0, tex2, LOD_fract)) * 0.5; +} + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs MyMaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_pos) +{ + float3x3 tangentToWorldOnly = float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz); + + float3 normal = mul ( float3( 0, 0, 1 ), tangentToWorldOnly ); + + float4 baseColor = 0; + fixed3 normalTangent = 0.0f; + float4 packedMap = 0; + + float depth = LinearEyeDepth(i_pos.z); + baseColor = fractal_texture_mip( _MainTex, i_tex, depth) * _Color; + normalTangent = UnpackScaleNormal(fractal_texture_mip( _BumpMap, i_tex, depth), _BumpScale); + packedMap = fractal_texture_mip( _MOESMap, i_tex, depth); + + half metallic = packedMap.x * _MetallicScale; + half occlusion = lerp(1, packedMap.y, _OcclusionScale); + half emissionMask = packedMap.z; + half smoothness = packedMap.w * _SmoothnessScale; + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = normalTangent; + material.emissive.rgb = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, i.pos); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, i.pos); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + + #pragma shader_feature_local _LIGHTMAPSPECULAR + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDCG + } + + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + // Meta not implemented + UsePass "Standard/META" + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedFractal.shader.meta b/Assets/Filamented/Extras/FilamentedFractal.shader.meta new file mode 100644 index 0000000..b90a213 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedFractal.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: 9dabe5d8b925aff4a8ce5e93b20bd940 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedGlinty.shader b/Assets/Filamented/Extras/FilamentedGlinty.shader new file mode 100644 index 0000000..beef4ce --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedGlinty.shader @@ -0,0 +1,397 @@ +Shader "Silent/Filamented Extras/Filamented Glinty" +{ + Properties + { + [CheckDFGTexture] + [ScaleOffset][SingleLine(_Color)]_MainTex("Albedo", 2D) = "white" {} + [HideInInspector]_Color("Color", Color) = (1,1,1,1) + [Space] + [SingleLine(_BumpScale)][Normal] _BumpMap("Normal", 2D) = "bump" {} + [HideInInspector]_BumpScale("Normal Scale", Float) = 1 + [Space] + [SingleLine]_MOESMap("MOES Map", 2D) = "white" {} + [Space] + _MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _Emission("Emission Power", Float) = 0 + _EmissionColor("Emission Color", Color) = (1,1,1,1) + [Header(Glint Properties)][Space] + _SpecularGlintSize("Glint Size", Range(0, 1)) = 0.5 + _SpecularGlintDensity("Glint Density", Range(0, 1)) = 0.5 + [Header(Clear Coat Properties)][Space] + [Toggle(_USE_CLEARCOAT)]_ClearCoatMode("Clear Coat", Float) = 0 + [IfDef(_USE_CLEARCOAT)][SingleLine]_ClearCoatMap("Clear Coat Map (R: Intensity, G: Roughness)", 2D) = "white" {} + [IfDef(_USE_CLEARCOAT)]_ClearCoat("Clear Coat Intensity", Range(0, 1)) = 0.0 + [IfDef(_USE_CLEARCOAT)]_ClearCoatRoughness("Clear Coat Roughness", Range(0, 1)) = 0.0 + [Header(System Settings)][Space] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + [Toggle(_ALPHATEST_ON)]_AtoCmode("Cutout Transparency", Float) = 0 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + } + + HLSLINCLUDE + #define fixed half + #define fixed2 half2 + #define fixed3 half3 + #define fixed4 half4 + ENDHLSL + + HLSLINCLUDE + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + #if defined(_USE_CLEARCOAT) + #define MATERIAL_HAS_CLEAR_COAT + #endif + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define MATERIAL_HAS_GLINT + // If this is set, the material will support glint specular. + // Not compatible with cloth/anisotropy. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDHLSL + + HLSLINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + + uniform half _SpecularGlintSize; + uniform half _SpecularGlintDensity; + + #if defined(_USE_CLEARCOAT) + uniform sampler2D _ClearCoatMap; + uniform half _ClearCoat; + uniform half _ClearCoatRoughness; + #endif + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs MyMaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_posWorld) +{ + half4 baseColor = tex2D (_MainTex, i_tex.xy) * _Color; + half4 packedMap = tex2D (_MOESMap, i_tex.xy); + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, i_tex.xy), _BumpScale); + + half metallic = packedMap.x * _MetallicScale; + half occlusion = lerp(1, packedMap.y, _OcclusionScale); + half emissionMask = packedMap.z; + half smoothness = packedMap.w * _SmoothnessScale; + + half internal_glint_alpha = lerp(0.001, 0.1, _SpecularGlintSize * _SpecularGlintSize); + half internal_density = pow(10.0, lerp(3.0, 9.0, _SpecularGlintDensity)); + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = normalTangent; + material.emissive.rgb = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + + material.uv = i_tex.xy; + material.glintAlpha = internal_glint_alpha; + material.glintDensity = internal_density; + + #if defined(_USE_CLEARCOAT) + half4 ccMap = tex2D(_ClearCoatMap, i_tex.xy); + material.clearCoat = ccMap.r * _ClearCoat; + material.clearCoatRoughness = ccMap.g * _ClearCoatRoughness; + #endif + + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDHLSL + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + AlphaToMask [_AtoCmode] + + HLSLPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma shader_feature_local_fragment _ _USE_CLEARCOAT + + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDHLSL + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + AlphaToMask [_AtoCmode] + + HLSLPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + + #pragma shader_feature_local_fragment _ _USE_CLEARCOAT + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDHLSL + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + + HLSLPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDHLSL + } + + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + Pass + { + Name "META" + Tags {"LightMode"="Meta"} + Cull Off + HLSLPROGRAM + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardMeta.cginc" + + #define META_PASS + + float4 frag_meta2 (v2f_meta i): SV_Target + { + MaterialInputs material = SETUP_BRDF_INPUT (i.uv); + // Note: If your MaterialSetup needs vertex normals, you might want to use a custom vert_meta which passes them through. + float4 dummy[3]; dummy[0] = 1.0; dummy[1] = 0.0; dummy[2] = 0.0; + material = MyMaterialSetup(i.uv, 0, 0, dummy, 0); + + PixelParams pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + + UnityMetaInput o; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); + + #ifdef EDITOR_VISUALIZATION + o.Albedo = pixel.diffuseColor; + o.VizUV = i.vizUV; + o.LightCoord = i.lightCoord; + #else + o.Albedo = UnityLightmappingAlbedo (pixel.diffuseColor, pixel.f0, 1-pixel.perceptualRoughness); + #endif + o.SpecularColor = pixel.f0; + o.Emission = material.emissive; + + return UnityMetaFragment(o); + } + + #pragma vertex vert_meta + #pragma fragment frag_meta2 + #pragma shader_feature _EMISSION + #pragma shader_feature _METALLICGLOSSMAP + #pragma shader_feature ___ _DETAIL_MULX2 + ENDHLSL + } + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedGlinty.shader.meta b/Assets/Filamented/Extras/FilamentedGlinty.shader.meta new file mode 100644 index 0000000..2ca488b --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedGlinty.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: f0a1aea00313d7046ac9e997ca48e8b0 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedMirrorTemplate.shader b/Assets/Filamented/Extras/FilamentedMirrorTemplate.shader new file mode 100644 index 0000000..929dc82 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedMirrorTemplate.shader @@ -0,0 +1,468 @@ +Shader "Silent/Filamented Mirror Template" +{ + Properties + { + [CheckDFGTexture] + [BlendModeSelector(_SrcBlend, _DstBlend, _CustomRenderQueue, _ZWrite, _AtoCmode)] _Mode ("__mode", Float) = 0.0 + [HeaderEx(Base Material)] + [ScaleOffset][SingleLine(_Color)]_MainTex("Albedo", 2D) = "white" {} + [HideInInspector]_Color("Color", Color) = (1,1,1,1) + [SingleLine(_BumpScale)][Normal] _BumpMap("Normal", 2D) = "bump" {} + [HideInInspector]_BumpScale("Normal Scale", Float) = 1 + [SingleLine]_MOESMap("MOES Map", 2D) = "white" {} + [Space] + _MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _Emission("Emission Power", Float) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _EmissionColor("Emission Tint", Color) = (1,1,1,1) + [Space] + [HeaderEx(Details)] + _DetailBlendWeight("Blend Weight", Range(0, 1)) = 1 + [HideInInspector][Enum(Multiply2x, 0, Multiply, 1, Additive, 2, AlphaBlend, 3)]_DetailBlendMode("Blend Mode", Float) = 0.0 + [ScaleOffset][SingleLine(_DetailBlendMode)]_MainTexDetail("Albedo Detail", 2D) = "gray" {} + [SingleLine(_BumpScaleDetail)][Normal] _BumpMapDetail("Normal Detail", 2D) = "bump" {} + [HideInInspector]_BumpScaleDetail("Normal Detail Scale", Float) = 1 + [SingleLine]_MOESMapDetail("MOES Map Detail", 2D) = "white" {} + [Space] + [Toggle(_DTRIPLANAR)]_UseDTriplanar("Triplanar Detail", Float) = 0.0 + _TriplanarSharp("Blending Sharpness", Range(1, 10)) = 3 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0x ("X Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0y ("Y Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0z ("X Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0x ("X Axis Offset", float) = 0 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0y ("Y Axis Offset", float) = 0 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0z ("X Axis Offset", float) = 0 + [Space] + [HeaderEx(System)] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + // Blending state + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _CustomRenderQueue ("__rq", Float) = 1.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + [HideInInspector] _AtoCmode("__atoc", Float) = 0 + + [HideInInspector] _ReflectionTex0("", 2D) = "white" {} + [HideInInspector] _ReflectionTex1("", 2D) = "white" {} + } + + CustomEditor "Silent.FilamentedExtras.Unity.FilamentedExtrasInspector" + + CGINCLUDE + #pragma multi_compile_local _ _DTRIPLANAR + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + + #define MIRROR_REFLECTION + // If this is set, the mirror reflection will be used. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + + uniform sampler2D _MainTexDetail; + uniform sampler2D _MOESMapDetail; + uniform sampler2D _BumpMapDetail; + uniform half _BumpScaleDetail; + uniform half _DetailBlendMode; + uniform half _DetailBlendWeight; + uniform half4 _MainTexDetail_ST; + + #ifdef _DTRIPLANAR + uniform half _TriplanarTiles0x; + uniform half _TriplanarTiles0y; + uniform half _TriplanarTiles0z; + uniform half _TriplanarOffset0x; + uniform half _TriplanarOffset0y; + uniform half _TriplanarOffset0z; + uniform half _TriplanarSharp; + #endif + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + +float4 boxmap(sampler2D tex, float3 p, float3 n, float k ) +{ + // grab coord derivatives for texturing + float3 dpdx = ddx(p); + float3 dpdy = ddy(p); + + float3 m = pow( abs(n), k ); + + // project+fetch + float4 x = 0.0; + if (m.x > 0) x = tex2Dgrad( tex, p.zy, dpdx.zy, dpdy.zy ); + float4 y = 0.0; + if (m.y > 0) y = tex2Dgrad( tex, p.zx, dpdx.zx, dpdy.zx ); + float4 z = 0.0; + if (m.z > 0) z = tex2Dgrad( tex, p.xy, dpdx.xy, dpdy.xy ); + + // and blend + return (x*m.x + y*m.y + z*m.z) / (m.x + m.y + m.z); +} + +float3 applyDetailBlendMode(int blendOp, half3 a, half3 b, half t) +{ + switch(blendOp) + { + default: + case 0: // Multiply 2x + return a * LerpWhiteTo (b * unity_ColorSpaceDouble.rgb, t); + case 1: // Multiply + return a * LerpWhiteTo (b, t); + case 2: // Additive + return a + b * t; + case 3: // Alpha Blend + return lerp(a, b, t); + } +} + +float3 RNMBlendUnpacked(float3 n1, float3 n2) +{ + n1 += float3( 0, 0, 1); + n2 *= float3(-1, -1, 1); + return n1*dot(n1, n2)/n1.z - n2; +} + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs MyMaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_posWorld) +{ + half4 baseColor = tex2D (_MainTex, i_tex.xy) * _Color; + half4 packedMap = tex2D (_MOESMap, i_tex.xy); + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, i_tex.xy), _BumpScale); + + half metallic = packedMap.x * _MetallicScale; + half occlusion = lerp(1, packedMap.y, _OcclusionScale); + half emissionMask = packedMap.z; + half smoothness = packedMap.w * _SmoothnessScale; + + #if defined(_DTRIPLANAR) + float triSharp = _TriplanarSharp; + float3 triPosition = i_posWorld * float3(_TriplanarTiles0x, _TriplanarTiles0y, _TriplanarTiles0z) + + float3(_TriplanarOffset0x, _TriplanarOffset0y, _TriplanarOffset0z); + half4 baseColorDetail = boxmap (_MainTexDetail, triPosition, tangentToWorld[2], triSharp); + half4 packedMapDetail = boxmap (_MOESMapDetail, triPosition, tangentToWorld[2], triSharp); + half3 normalTangentDetail = UnpackScaleNormal(boxmap (_BumpMapDetail, triPosition, tangentToWorld[2], triSharp), _BumpScaleDetail); + #else + float2 dUV = i_tex.xy * _MainTexDetail_ST.xy + _MainTexDetail_ST.zw; + half4 baseColorDetail = tex2D (_MainTexDetail, dUV); + half4 packedMapDetail = tex2D (_MOESMapDetail, dUV); + half3 normalTangentDetail = UnpackScaleNormal(tex2D (_BumpMapDetail, dUV), _BumpScaleDetail); + #endif + + baseColor.rgb = applyDetailBlendMode(_DetailBlendMode, baseColor, baseColorDetail, _DetailBlendWeight); + + normalTangent = lerp(normalTangent, RNMBlendUnpacked(normalTangent, normalTangentDetail), _DetailBlendWeight); + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = normalTangent; + material.emissive.rgb = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + AlphaToMask [_AtoCmode] + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + AlphaToMask [_AtoCmode] + Blend One [_DstBlend] + ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + AlphaToMask Off + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDCG + } + + Pass + { + Name "META" + Tags {"LightMode"="Meta"} + Cull Off + CGPROGRAM + + #define REQUIRE_META_WORLDPOS + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardMeta.cginc" + + #define META_PASS + + float4 frag_meta2 (v2f_meta i): SV_Target + { + MaterialInputs material = SETUP_BRDF_INPUT (i.uv); + float4 dummy[3]; dummy[0] = 1; dummy[1] = 0; dummy[2] = 0; + material = MyMaterialSetup (i.uv, 0, 0, dummy, i.worldPos); + + PixelParams pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + + UnityMetaInput o; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); + + #ifdef EDITOR_VISUALIZATION + o.Albedo = pixel.diffuseColor; + o.VizUV = i.vizUV; + o.LightCoord = i.lightCoord; + #else + o.Albedo = UnityLightmappingAlbedo (pixel.diffuseColor, pixel.f0, 1-pixel.perceptualRoughness); + #endif + o.SpecularColor = pixel.f0; + o.Emission = material.emissive; + + return UnityMetaFragment(o); + } + + #pragma vertex vert_meta + #pragma fragment frag_meta2 + #pragma shader_feature _EMISSION + #pragma shader_feature _METALLICGLOSSMAP + #pragma shader_feature ___ _DETAIL_MULX2 + ENDCG + } + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedMirrorTemplate.shader.meta b/Assets/Filamented/Extras/FilamentedMirrorTemplate.shader.meta new file mode 100644 index 0000000..bdeaddb --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedMirrorTemplate.shader.meta @@ -0,0 +1,21 @@ +fileFormatVersion: 2 +guid: 870896c71151de24eb10da376e8cb502 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + - _MainTexDetail: {instanceID: 0} + - _BumpMapDetail: {instanceID: 0} + - _MOESMapDetail: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + - _ReflectionTex0: {instanceID: 0} + - _ReflectionTex1: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedPaintingCanvas.shader b/Assets/Filamented/Extras/FilamentedPaintingCanvas.shader new file mode 100644 index 0000000..48fcdfc --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedPaintingCanvas.shader @@ -0,0 +1,389 @@ +// A shader for displaying artwork in high quality, as though it +// were printed or painted onto a canvas. +Shader "Silent/Filamented Extras/Painting Canvas" +{ + Properties + { + _MainTex("Main Texture", 2D) = "white" {} + [Space] + [NoScaleOffset][Normal] _BumpMap("Canvas Pattern Normal", 2D) = "bump" {} + _BumpSize("Pattern Scale", Float) = 1 + _BumpScale("Pattern Intensity", Float) = 1 + _BumpScaleWarp("Main Texture Canvas Intensity", Float) = 1 + [Space] + [NoScaleOffset]_MOESMap("Canvas MOES Map", 2D) = "white" {} + _MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _Emission("Emission Power", Float) = 0 + _EmissionColor("Emission Color", Color) = (1,1,1,1) + [Space] + [Header(System)] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + [Toggle(_ALPHATEST_ON)]_AtoCmode("Cutout Transparency", Float) = 0 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + } + + CGINCLUDE + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + + uniform float4 _MainTex_TexelSize; + + uniform half _BumpSize; + uniform half _BumpScaleWarp; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + +float4 bicubicFilter(sampler2D inTex, float2 texcoord, float4 texscale) +{ + //#if _BICUBIC + texcoord *= texscale.zw; + float fx = frac(texcoord.x); + float fy = frac(texcoord.y); + texcoord.x -= fx; + texcoord.y -= fy; + + float4 xcubic = cubic(fx); + float4 ycubic = cubic(fy); + + float4 c = float4(texcoord.x - 0.5, texcoord.x + 1.5, texcoord.y - 0.5, texcoord.y + 1.5); + float4 s = float4(xcubic.x + xcubic.y, xcubic.z + xcubic.w, ycubic.x + ycubic.y, ycubic.z + ycubic.w); + float4 offset = c + float4(xcubic.y, xcubic.w, ycubic.y, ycubic.w) / s; + + float4 sample0 = tex2D(inTex, float2(offset.x, offset.z) * texscale.xy); + float4 sample1 = tex2D(inTex, float2(offset.y, offset.z) * texscale.xy); + float4 sample2 = tex2D(inTex, float2(offset.x, offset.w) * texscale.xy); + float4 sample3 = tex2D(inTex, float2(offset.y, offset.w) * texscale.xy); + + float sx = s.x / (s.x + s.y); + float sy = s.z / (s.z + s.w); + + return lerp( + lerp(sample3, sample2, sx), + lerp(sample1, sample0, sx), sy); + //#else + return tex2D(inTex, texcoord); + //#endif +} + +// https://iquilezles.org/www/articles/biplanar/biplanar.htm +// "p" point being textured +// "n" surface normal at "p" +// "k" controls the sharpness of the blending in the transitions areas +// "s" texture sampler +float4 biplanar( sampler2D sam, float3 p, float3 n, float k ) +{ + // grab coord derivatives for texturing + float3 dpdx = ddx(p); + float3 dpdy = ddy(p); + n = abs(n); + + // determine major axis (in x; yz are following axis) + int3 ma = (n.x>n.y && n.x>n.z) ? int3(0,1,2) : + (n.y>n.z) ? int3(1,2,0) : + int3(2,0,1) ; + // determine minor axis (in x; yz are following axis) + int3 mi = (n.x 0); + float rotateOffset = _RotationOffsetByWorldPos * hash13(mul(unity_ObjectToWorld, float4(0, 0, 0, 1.0))); + + if (shouldRotate) + { + float rotateFactor = frac(_RotateSpeed * _Time.y + rotateOffset) * UNITY_PI * 2.0; + v.vertex.xyz = mul(v.vertex.xyz - _RotationOffset, AngleAxis3x3(rotateFactor, _RotationAxis)) + _RotationOffset; + v.normal.xyz = mul(v.normal.xyz, AngleAxis3x3(rotateFactor, _RotationAxis)); + #ifdef _TANGENT_TO_WORLD + v.tangent.xyz = mul(v.tangent.xyz, AngleAxis3x3(rotateFactor, _RotationAxis)); + #endif + } +} + +#ifndef UNITY_PASS_SHADOWCASTER + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + + VertexOutputForwardBase vertBase (VertexInput v) { VertexCommon(v); return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { VertexCommon(v); return vertForwardAdd(v); } + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs MyMaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_posWorld) +{ + half4 baseColor = tex2D (_MainTex, i_tex.xy) * _Color; + half4 packedMap = tex2D (_MOESMap, i_tex.xy); + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, i_tex.xy), _BumpScale); + + half metallic = packedMap.x * _MetallicScale; + half occlusion = lerp(1, packedMap.y, _OcclusionScale); + half emissionMask = packedMap.z; + half smoothness = packedMap.w * _SmoothnessScale; + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = normalTangent; + material.emissive.rgb = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + AlphaToMask [_AtoCmode] + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + + #pragma shader_feature_local _LIGHTMAPSPECULAR + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + AlphaToMask [_AtoCmode] + Blend One [_DstBlend] + ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + AlphaToMask Off + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCasterLocal + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + // We use Unity's shadowcaster as a base, but unfortunately it's complicated to work with. + void vertShadowCasterLocal (VertexInput v + , out float4 opos : SV_POSITION + #ifdef UNITY_STANDARD_USE_SHADOW_OUTPUT_STRUCT + , out VertexOutputShadowCaster o + #endif + #ifdef UNITY_STANDARD_USE_STEREO_SHADOW_OUTPUT_STRUCT + , out VertexOutputStereoShadowCaster os + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(v); + #ifdef UNITY_STANDARD_USE_STEREO_SHADOW_OUTPUT_STRUCT + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(os); + #endif + VertexCommon(v); + TRANSFER_SHADOW_CASTER_NOPOS(o,opos) + #if defined(UNITY_STANDARD_USE_SHADOW_UVS) + o.tex = TRANSFORM_TEX(v.uv0, _MainTex); + + #ifdef _PARALLAXMAP + TANGENT_SPACE_ROTATION; + o.viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex)); + #endif + #endif + } + + ENDCG + } + + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + // Meta not implemented + UsePass "Standard/META" + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedSimpleRotation.shader.meta b/Assets/Filamented/Extras/FilamentedSimpleRotation.shader.meta new file mode 100644 index 0000000..0363f76 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedSimpleRotation.shader.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: bb6f3dbf7de087b41886f3805bfaf97b +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedTemplate.shader b/Assets/Filamented/Extras/FilamentedTemplate.shader new file mode 100644 index 0000000..0451a1b --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplate.shader @@ -0,0 +1,359 @@ +/* +Filamented example template. +This is a template of how to use Filamented to make a simple shader +that passes its own properties through to Filament, in a manner +similar to a Unity surface shader - but with less jank. + +Instead of reading multiple seperate maps, it just asks for +an albedo map, a normal map, and a MOES map. +*/ +Shader "Silent/Filamented Extras/Filamented Template" +{ + Properties + { + _MainTex("Albedo", 2D) = "white" {} + [Normal] _BumpMap("Normal", 2D) = "bump" {} + _BumpScale("Normal Scale", Float) = 1 + [Space] + _MOESMap("MOES Map", 2D) = "white" {} + _MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _Emission("Emission Power", Float) = 0 + _EmissionColor("Emission Color", Color) = (1,1,1,1) + [Space] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + [Toggle(_ALPHATEST_ON)]_AtoCmode("Cutout Transparency", Float) = 0 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + } + + CGINCLUDE + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs MyMaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_posWorld) +{ + half4 baseColor = tex2D (_MainTex, i_tex.xy); + half4 packedMap = tex2D (_MOESMap, i_tex.xy); + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, i_tex.xy), _BumpScale); + + half metallic = packedMap.x * _MetallicScale; + half occlusion = lerp(1, packedMap.y, _OcclusionScale); + half emissionMask = packedMap.z; + half smoothness = packedMap.w * _SmoothnessScale; + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = normalTangent; + material.emissive.rgb = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + AlphaToMask [_AtoCmode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + AlphaToMask [_AtoCmode] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDCG + } + + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + Pass + { + Name "META" + Tags {"LightMode"="Meta"} + Cull Off + CGPROGRAM + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardMeta.cginc" + + #define META_PASS + + float4 frag_meta2 (v2f_meta i): SV_Target + { + MaterialInputs material = SETUP_BRDF_INPUT (i.uv); + // Note: If your MaterialSetup needs vertex normals, you might want to use a custom vert_meta which passes them through. + float4 dummy[3]; dummy[0] = 1.0; dummy[1] = 0.0; dummy[2] = 0.0; + material = MyMaterialSetup(i.uv, 0, 0, dummy, 0); + + PixelParams pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + + UnityMetaInput o; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); + + #ifdef EDITOR_VISUALIZATION + o.Albedo = pixel.diffuseColor; + o.VizUV = i.vizUV; + o.LightCoord = i.lightCoord; + #else + o.Albedo = UnityLightmappingAlbedo (pixel.diffuseColor, pixel.f0, 1-pixel.perceptualRoughness); + #endif + o.SpecularColor = pixel.f0; + o.Emission = material.emissive; + + return UnityMetaFragment(o); + } + + #pragma vertex vert_meta + #pragma fragment frag_meta2 + #pragma shader_feature _EMISSION + #pragma shader_feature _METALLICGLOSSMAP + #pragma shader_feature ___ _DETAIL_MULX2 + ENDCG + } + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedTemplate.shader.meta b/Assets/Filamented/Extras/FilamentedTemplate.shader.meta new file mode 100644 index 0000000..51c38ec --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplate.shader.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 88e4dbdb6ade3b14da90a528eaec41f5 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedTemplateDetails.shader b/Assets/Filamented/Extras/FilamentedTemplateDetails.shader new file mode 100644 index 0000000..382508a --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplateDetails.shader @@ -0,0 +1,465 @@ +/* +Filamented example template. +*/ +Shader "Silent/Filamented Extras/Filamented Details Template" +{ + Properties + { + [CheckDFGTexture] + [BlendModeSelector(_SrcBlend, _DstBlend, _CustomRenderQueue, _ZWrite, _AtoCmode)] _Mode ("__mode", Float) = 0.0 + [HeaderEx(Base Material)] + [ScaleOffset][SingleLine(_Color)]_MainTex("Albedo", 2D) = "white" {} + [HideInInspector]_Color("Color", Color) = (1,1,1,1) + [SingleLine(_BumpScale)][Normal] _BumpMap("Normal", 2D) = "bump" {} + [HideInInspector]_BumpScale("Normal Scale", Float) = 1 + [SingleLine]_MOESMap("MOES Map", 2D) = "white" {} + [Space] + _MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _Emission("Emission Power", Float) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _EmissionColor("Emission Tint", Color) = (1,1,1,1) + [Space] + [HeaderEx(Details)] + _DetailBlendWeight("Blend Weight", Range(0, 1)) = 1 + [HideInInspector][Enum(Multiply2x, 0, Multiply, 1, Additive, 2, AlphaBlend, 3)]_DetailBlendMode("Blend Mode", Float) = 0.0 + [ScaleOffset][SingleLine(_DetailBlendMode)]_MainTexDetail("Albedo Detail", 2D) = "gray" {} + [SingleLine(_BumpScaleDetail)][Normal] _BumpMapDetail("Normal Detail", 2D) = "bump" {} + [HideInInspector]_BumpScaleDetail("Normal Detail Scale", Float) = 1 + [SingleLine]_MOESMapDetail("MOES Map Detail", 2D) = "white" {} + [Space] + [Toggle(_DTRIPLANAR)]_UseDTriplanar("Triplanar Detail", Float) = 0.0 + _TriplanarSharp("Blending Sharpness", Range(1, 10)) = 3 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0x ("X Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0y ("Y Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0z ("X Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0x ("X Axis Offset", float) = 0 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0y ("Y Axis Offset", float) = 0 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0z ("X Axis Offset", float) = 0 + [Space] + [HeaderEx(System)] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + // Blending state + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _CustomRenderQueue ("__rq", Float) = 1.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + [HideInInspector] _AtoCmode("__atoc", Float) = 0 + } + + CustomEditor "Silent.FilamentedExtras.Unity.FilamentedExtrasInspector" + + CGINCLUDE + #pragma multi_compile_local _ _DTRIPLANAR + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + + uniform sampler2D _MainTexDetail; + uniform sampler2D _MOESMapDetail; + uniform sampler2D _BumpMapDetail; + uniform half _BumpScaleDetail; + uniform half _DetailBlendMode; + uniform half _DetailBlendWeight; + uniform half4 _MainTexDetail_ST; + + #ifdef _DTRIPLANAR + uniform half _TriplanarTiles0x; + uniform half _TriplanarTiles0y; + uniform half _TriplanarTiles0z; + uniform half _TriplanarOffset0x; + uniform half _TriplanarOffset0y; + uniform half _TriplanarOffset0z; + uniform half _TriplanarSharp; + #endif + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + +float4 boxmap(sampler2D tex, float3 p, float3 n, float k ) +{ + // grab coord derivatives for texturing + float3 dpdx = ddx(p); + float3 dpdy = ddy(p); + + float3 m = pow( abs(n), k ); + + // project+fetch + float4 x = 0.0; + if (m.x > 0) x = tex2Dgrad( tex, p.zy, dpdx.zy, dpdy.zy ); + float4 y = 0.0; + if (m.y > 0) y = tex2Dgrad( tex, p.zx, dpdx.zx, dpdy.zx ); + float4 z = 0.0; + if (m.z > 0) z = tex2Dgrad( tex, p.xy, dpdx.xy, dpdy.xy ); + + // and blend + return (x*m.x + y*m.y + z*m.z) / (m.x + m.y + m.z); +} + +float3 applyDetailBlendMode(int blendOp, half3 a, half3 b, half t) +{ + switch(blendOp) + { + default: + case 0: // Multiply 2x + return a * LerpWhiteTo (b * unity_ColorSpaceDouble.rgb, t); + case 1: // Multiply + return a * LerpWhiteTo (b, t); + case 2: // Additive + return a + b * t; + case 3: // Alpha Blend + return lerp(a, b, t); + } +} + +float3 RNMBlendUnpacked(float3 n1, float3 n2) +{ + n1 += float3( 0, 0, 1); + n2 *= float3(-1, -1, 1); + return n1*dot(n1, n2)/n1.z - n2; +} + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs MyMaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_posWorld) +{ + half4 baseColor = tex2D (_MainTex, i_tex.xy) * _Color; + half4 packedMap = tex2D (_MOESMap, i_tex.xy); + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, i_tex.xy), _BumpScale); + + half metallic = packedMap.x * _MetallicScale; + half occlusion = lerp(1, packedMap.y, _OcclusionScale); + half emissionMask = packedMap.z; + half smoothness = packedMap.w * _SmoothnessScale; + + #if defined(_DTRIPLANAR) + float triSharp = _TriplanarSharp; + float3 triPosition = i_posWorld * float3(_TriplanarTiles0x, _TriplanarTiles0y, _TriplanarTiles0z) + + float3(_TriplanarOffset0x, _TriplanarOffset0y, _TriplanarOffset0z); + half4 baseColorDetail = boxmap (_MainTexDetail, triPosition, tangentToWorld[2], triSharp); + half4 packedMapDetail = boxmap (_MOESMapDetail, triPosition, tangentToWorld[2], triSharp); + half3 normalTangentDetail = UnpackScaleNormal(boxmap (_BumpMapDetail, triPosition, tangentToWorld[2], triSharp), _BumpScaleDetail); + #else + float2 dUV = i_tex.xy * _MainTexDetail_ST.xy + _MainTexDetail_ST.zw; + half4 baseColorDetail = tex2D (_MainTexDetail, dUV); + half4 packedMapDetail = tex2D (_MOESMapDetail, dUV); + half3 normalTangentDetail = UnpackScaleNormal(tex2D (_BumpMapDetail, dUV), _BumpScaleDetail); + #endif + + baseColor.rgb = applyDetailBlendMode(_DetailBlendMode, baseColor, baseColorDetail, _DetailBlendWeight); + + normalTangent = lerp(normalTangent, RNMBlendUnpacked(normalTangent, normalTangentDetail), _DetailBlendWeight); + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = normalTangent; + material.emissive.rgb = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + AlphaToMask [_AtoCmode] + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + AlphaToMask [_AtoCmode] + Blend One [_DstBlend] + ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + AlphaToMask Off + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDCG + } + + Pass + { + Name "META" + Tags {"LightMode"="Meta"} + Cull Off + CGPROGRAM + + #define REQUIRE_META_WORLDPOS + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardMeta.cginc" + + #define META_PASS + + float4 frag_meta2 (v2f_meta i): SV_Target + { + MaterialInputs material = SETUP_BRDF_INPUT (i.uv); + float4 dummy[3]; dummy[0] = 1; dummy[1] = 0; dummy[2] = 0; + material = MyMaterialSetup (i.uv, 0, 0, dummy, i.worldPos); + + PixelParams pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + + UnityMetaInput o; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); + + #ifdef EDITOR_VISUALIZATION + o.Albedo = pixel.diffuseColor; + o.VizUV = i.vizUV; + o.LightCoord = i.lightCoord; + #else + o.Albedo = UnityLightmappingAlbedo (pixel.diffuseColor, pixel.f0, 1-pixel.perceptualRoughness); + #endif + o.SpecularColor = pixel.f0; + o.Emission = material.emissive; + + return UnityMetaFragment(o); + } + + #pragma vertex vert_meta + #pragma fragment frag_meta2 + #pragma shader_feature _EMISSION + #pragma shader_feature _METALLICGLOSSMAP + #pragma shader_feature ___ _DETAIL_MULX2 + ENDCG + } + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedTemplateDetails.shader.meta b/Assets/Filamented/Extras/FilamentedTemplateDetails.shader.meta new file mode 100644 index 0000000..2b764df --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplateDetails.shader.meta @@ -0,0 +1,19 @@ +fileFormatVersion: 2 +guid: fdde3e81293f3dd4f9d7c390d4b95a5a +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + - _MainTexDetail: {instanceID: 0} + - _BumpMapDetail: {instanceID: 0} + - _MOESMapDetail: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedTemplateRefraction.shader b/Assets/Filamented/Extras/FilamentedTemplateRefraction.shader new file mode 100644 index 0000000..469532f --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplateRefraction.shader @@ -0,0 +1,349 @@ +/* +Filamented example template. +This is a template of how to use Filamented to make a simple shader +that passes its own properties through to Filament, in a manner +similar to a Unity surface shader - but with less jank. + +Instead of reading multiple seperate maps, it just asks for +an albedo map, a normal map, and a MOES map. +*/ +Shader "Silent/Filamented Extras/Filamented Refraction" +{ + Properties + { + _MainTex("Albedo", 2D) = "white" {} + [Normal] _BumpMap("Normal", 2D) = "bump" {} + _BumpScale("Normal Scale", Float) = 1 + [Space] + _MOESMap("MOES Map", 2D) = "white" {} + _MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _Emission("Emission Power", Float) = 0 + _EmissionColor("Emission Color", Color) = (1,1,1,1) + [Space] + _Transmission("Transmission", Range(0, 1)) = 1.0 + _Absorption("Absorbtion", Color) = (0, 0, 0, 0) + _IOR("IOR", Float) = 1.5 + [Space] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + } + + CGINCLUDE + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define HAS_REFRACTION + // If this is defined, the material supports refraction. + + #define MATERIAL_HAS_TRANSMISSION + #define MATERIAL_HAS_ABSORPTION + #define MATERIAL_HAS_THICKNESS + #define MATERIAL_HAS_IOR + // These properties are controls for the refraction effect. + + // REFRACTION_TYPE REFRACTION_TYPE_THIN + // MATERIAL_HAS_MICRO_THICKNESS + // Micro thickness is only supported for thin refraction. + + // REFRACTION_MODE REFRACTION_MODE_SCREEN + // Set to use the screen as a refraction source, which is typically very expensive. + + // REFRACTION_SOURCE _GrabPassRefraction + // REFRACTION_MULTIPLIER 1.0 + // If screen refractions are enabled, you'll need to set these as well. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + + // Refraction-specific settings + uniform half _Transmission; + uniform half3 _Absorption; + uniform half _IOR; + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs MyMaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_posWorld) +{ + half4 baseColor = tex2D (_MainTex, i_tex.xy); + half4 packedMap = tex2D (_MOESMap, i_tex.xy); + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, i_tex.xy), _BumpScale); + + half metallic = packedMap.x * _MetallicScale; + half occlusion = lerp(1, packedMap.y, _OcclusionScale); + half emissionMask = packedMap.z; + half smoothness = packedMap.w * _SmoothnessScale; + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = normalTangent; + material.emissive.rgb = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + + + material.transmission = _Transmission; + material.absorption = _Absorption; + material.ior = _IOR; + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i)); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDCG + } + + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + // Meta not implemented + UsePass "Standard/META" + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedTemplateRefraction.shader.meta b/Assets/Filamented/Extras/FilamentedTemplateRefraction.shader.meta new file mode 100644 index 0000000..a0bc04e --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplateRefraction.shader.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 15d843c037dba3d44b1241383a0caf43 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedTemplateSelector.shader b/Assets/Filamented/Extras/FilamentedTemplateSelector.shader new file mode 100644 index 0000000..f7fc7dc --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplateSelector.shader @@ -0,0 +1,740 @@ +/* +Filamented example template. +*/ +Shader "Silent/Filamented Extras/Filamented Selector" +{ + Properties + { + [CheckDFGTexture] + [BlendModeSelector(_SrcBlend, _DstBlend, _CustomRenderQueue, _ZWrite, _AtoCmode)] _Mode ("__mode", Float) = 0.0 + [KeywordEnum(Standard,Cloth,Anisotropy,Glint,Subsurface)]_Shading("Shading Type", Float) = 0 + [HeaderEx(Base Material)] + [ScaleOffset][SingleLine(_Color)]_MainTex("Albedo", 2D) = "white" {} + [HideInInspector]_Color("Color", Color) = (1,1,1,1) + [SingleLine(_BumpScale)][Normal] _BumpMap("Normal", 2D) = "bump" {} + [HideInInspector]_BumpScale("Normal Scale", Float) = 1 + [Space] + [SingleLine]_MOESMap("Property Map", 2D) = "white" {} + [Space] + [Enum(Red, 0, Green, 1, Blue, 2, Alpha, 3)]_MetallicSelect("Metallic Channel", Range(0, 3)) = 0 + _MetallicScale("Metallic Scale", Range( 0 , 1)) = 0 + [Space] + [Enum(Red, 0, Green, 1, Blue, 2, Alpha, 3)]_SmoothnessSelect("Smoothness Channel", Range(0, 3)) = 3 + [Enum(Smoothness, 0, Roughness, 1)]_SmoothnessMode("Smoothness Mode", Float) = 0 + _SmoothnessScale("Smoothness Scale", Range( 0 , 1)) = 0 + [Space] + [Enum(Red, 0, Green, 1, Blue, 2, Alpha, 3)]_OcclusionSelect("Occlusion Channel", Range(0, 3)) = 1 + _OcclusionScale("Occlusion Scale", Range( 0 , 1)) = 0 + [Space] + [Enum(Red, 0, Green, 1, Blue, 2, Alpha, 3)]_EmissionSelect("Emission Mask Channel", Range(0, 3)) = 2 + _Emission("Emission Power", Float) = 0 + _EmissionColor("Emission Tint", Color) = (1,1,1,1) + _EmissionFluro("Emission Edge Fade Intensity", Range(0, 1)) = 0.0 + [Space] + [IfDef(_SHADING_ANISOTROPY)][HeaderEx(Anisotropy Properties)] + _Anisotropy("Anisotropy", Range(-1, 1)) = 0.5 + [IfDef(_SHADING_ANISOTROPY)][Normal][SingleLine] + _AnisotropyDirectionMap("Direction Map", 2D) = "bump" {} + [IfDef(_SHADING_GLINT)][HeaderEx(Glint Properties)] + _SpecularGlintSize("Glint Size", Range(0, 1)) = 0.5 + [IfDef(_SHADING_GLINT)] + _SpecularGlintDensity("Glint Density", Range(0, 1)) = 0.5 + [IfDef(_SHADING_SUBSURFACE)][HeaderEx(Subsurface Properties)] + [SingleLine][NoScaleOffset]_ThicknessMap("Thickness Map", 2D) = "white" {} + [IfDef(_SHADING_SUBSURFACE)]_ThicknessScale("Thickness", Range(0, 1)) = 0.5 + [IfDef(_SHADING_SUBSURFACE)]_SubsurfacePower("Subsurface Power", Float) = 12.234 + [IfDef(_SHADING_SUBSURFACE,_SHADING_CLOTH)]_SubsurfaceColor("Subsurface Color", Color) = (1.0, 1.0, 1.0, 1.0) + [IfDef(_SHADING_SUBSURFACE,_SHADING_CLOTH)][ToggleUI]_AutoSubsurfaceColor("Subsurface Colour from Albedo", Float) = 1 + [Space] + [HeaderEx(Emission Texture)] + [NoScaleOffset][SetKeywordSingleLine(_ADD_EMISSION)]_EmissionMap("Emission Map", 2D) = "black" {} + _EmissionMapPower("Emission Map Intensity", Float) = 1.0 + [Space] + [HeaderEx(Detail Mapping)] + _DetailBlendWeight("Blend Weight", Range(0, 1)) = 1 + [HideInInspector][Enum(Multiply2x, 0, Multiply, 1, Additive, 2, AlphaBlend, 3)]_DetailBlendMode("Blend Mode", Float) = 0.0 + [ScaleOffset][SingleLine(_DetailBlendMode)]_MainTexDetail("Albedo Detail", 2D) = "gray" {} + [SingleLine(_BumpScaleDetail)][Normal] _BumpMapDetail("Normal Detail", 2D) = "bump" {} + [HideInInspector]_BumpScaleDetail("Normal Detail Scale", Float) = 1 + [SingleLine]_MOESMapDetail("Property Map Detail", 2D) = "white" {} + [Space] + [Toggle(_DTRIPLANAR)]_UseDTriplanar("Triplanar Detail", Float) = 0.0 + [IfDef(_DTRIPLANAR)]_TriplanarSharp("Blending Sharpness", Range(1, 10)) = 3 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0x ("X Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0y ("Y Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarTiles0z ("X Axis Tiling", float) = 1 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0x ("X Axis Offset", float) = 0 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0y ("Y Axis Offset", float) = 0 + [IfDef(_DTRIPLANAR)]_TriplanarOffset0z ("X Axis Offset", float) = 0 + [Space] + [HeaderEx(Complex Material)] + [IfNDef(_SHADING_SUBSURFACE,_SHADING_CLOTH,_SHADING_SUBSURFACE)][SingleLine]_IridescenceRamp("Specular Iridescence Ramp", 2D) = "white" {} + [IfNDef(_SHADING_SUBSURFACE,_SHADING_CLOTH,_SHADING_SUBSURFACE)]_IridescenceAmount("Iridescence Amount", Range(0, 1)) = 0 + [Space] + [SingleLine]_WetnessMap("Wetness Mask (R)", 2D) = "white" {} + _WetnessAmount("Wetness Amount", Range(0, 1)) = 0.0 + [Space] + [Toggle(_USE_CLEARCOAT)]_ClearCoatMode("Clear Coat", Float) = 0 + [IfDef(_USE_CLEARCOAT)][SingleLine]_ClearCoatMap("Clear Coat Map (R: Intensity, G: Roughness)", 2D) = "white" {} + [IfDef(_USE_CLEARCOAT)]_ClearCoat("Clear Coat Intensity", Range(0, 1)) = 0.0 + [IfDef(_USE_CLEARCOAT)]_ClearCoatRoughness("Clear Coat Roughness", Range(0, 1)) = 0.0 + [Space] + [IfNDef(_SHADING_SUBSURFACE,_SHADING_CLOTH)][Toggle(_USE_SHEEN)]_SheenMode("Sheen", Float) = 0 + [IfNDef(_SHADING_SUBSURFACE,_SHADING_CLOTH)][IfDef(_USE_SHEEN)][SingleLine]_SheenMap("Sheen Map (R: Intensity, G: Roughness)", 2D) = "white" {} + [IfNDef(_SHADING_SUBSURFACE,_SHADING_CLOTH)][IfDef(_USE_SHEEN)]_SheenColor("Sheen Color", Color) = (1.0, 1.0, 1.0, 1.0) + [IfNDef(_SHADING_SUBSURFACE,_SHADING_CLOTH)][IfDef(_USE_SHEEN)][ToggleUI]_AutoSheenColor("Sheen Colour from Albedo", Float) = 1 + [IfNDef(_SHADING_SUBSURFACE,_SHADING_CLOTH)][IfDef(_USE_SHEEN)]_SheenRoughness("Sheen Roughness", Range(0, 1)) = 0.8 + [Space] + [HeaderEx(System)] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + [IfDef(_LIGHTMAPSPECULAR)]_LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + + // Blending state + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _CustomRenderQueue ("__rq", Float) = 1.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + [HideInInspector] _AtoCmode("__atoc", Float) = 0 + } + + CustomEditor "Silent.FilamentedExtras.Unity.FilamentedExtrasInspector" + + CGINCLUDE + #pragma shader_feature_local_fragment _ _DTRIPLANAR + #pragma shader_feature_local_fragment _ _ADD_EMISSION + #pragma shader_feature_local_fragment _SHADING_STANDARD _SHADING_CLOTH _SHADING_ANISOTROPY _SHADING_GLINT _SHADING_SUBSURFACE + #pragma shader_feature_local_fragment _ _USE_CLEARCOAT + #pragma shader_feature_local_fragment _ _USE_SHEEN + + #pragma skip_variants _METALLICGLOSSMAP _NORMALMAP _EMISSION + + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + #if defined(_SHADING_CLOTH) + #define SHADING_MODEL_CLOTH + #define MATERIAL_HAS_SUBSURFACE_COLOR + #undef _USE_SHEEN // Not supported. + #endif + + #if defined(_SHADING_ANISOTROPY) + #define MATERIAL_HAS_ANISOTROPY + #endif + + #if defined(_SHADING_GLINT) + #define MATERIAL_HAS_GLINT + #endif + + #if defined(_SHADING_SUBSURFACE) + #define SHADING_MODEL_SUBSURFACE + #undef _USE_SHEEN // Not supported. + #endif + + #if defined(_USE_CLEARCOAT) + #define MATERIAL_HAS_CLEAR_COAT + #endif + + #if defined(_USE_SHEEN) + #define MATERIAL_HAS_SHEEN_COLOR + #endif + + #if defined(_SHADING_STANDARD) || defined(_SHADING_ANISOTROPY) || defined(_SHADING_GLINT) + #define SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + // This is used to control the specular colour for iridescence. + // However, it is not supported for cloth or subsurface shading. + #endif + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + + uniform half _MetallicSelect; + uniform half _SmoothnessSelect; + uniform half _SmoothnessMode; + uniform half _OcclusionSelect; + uniform half _EmissionSelect; + + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + uniform half _EmissionFluro; + + uniform sampler2D _MainTexDetail; + uniform sampler2D _MOESMapDetail; + uniform sampler2D _BumpMapDetail; + uniform half _BumpScaleDetail; + uniform half _DetailBlendMode; + uniform half _DetailBlendWeight; + uniform half4 _MainTexDetail_ST; + + #ifdef _DTRIPLANAR + uniform half _TriplanarTiles0x; + uniform half _TriplanarTiles0y; + uniform half _TriplanarTiles0z; + uniform half _TriplanarOffset0x; + uniform half _TriplanarOffset0y; + uniform half _TriplanarOffset0z; + uniform half _TriplanarSharp; + #endif + + #ifdef _ADD_EMISSION + //uniform sampler2D _EmissionMap; + uniform half _EmissionMapPower; + #endif + + #ifdef _SHADING_ANISOTROPY + uniform half _Anisotropy; + uniform sampler2D _AnisotropyDirectionMap; + #endif + + #ifdef _SHADING_GLINT + uniform half _SpecularGlintSize; + uniform half _SpecularGlintDensity; + #endif + + #ifdef _SHADING_SUBSURFACE + uniform sampler2D _ThicknessMap; + uniform half _ThicknessScale; + uniform half _SubsurfacePower; + uniform half4 _SubsurfaceColor; + uniform half _AutoSubsurfaceColor; + #endif + + #ifdef _SHADING_CLOTH + uniform half4 _SubsurfaceColor; + uniform half _AutoSubsurfaceColor; + #endif + + uniform sampler2D _IridescenceRamp; + uniform half4 _IridescenceRamp_TexelSize; + uniform half _IridescenceAmount; + + uniform sampler2D _WetnessMap; + uniform half _WetnessAmount; + + #if defined(_USE_CLEARCOAT) + uniform sampler2D _ClearCoatMap; + uniform half _ClearCoat; + uniform half _ClearCoatRoughness; + #endif + + #if defined(_USE_SHEEN) + uniform sampler2D _SheenMap; + uniform half4 _SheenColor; + uniform half _SheenRoughness; + uniform half _AutoSheenColor; + #endif + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + +float4 boxmap(sampler2D tex, float3 p, float3 n, float k ) +{ + // grab coord derivatives for texturing + float3 dpdx = ddx(p); + float3 dpdy = ddy(p); + + float3 m = pow( abs(n), k ); + + // project+fetch + float4 x = 0.0; + if (m.x > 0) x = tex2Dgrad( tex, p.zy, dpdx.zy, dpdy.zy ); + float4 y = 0.0; + if (m.y > 0) y = tex2Dgrad( tex, p.zx, dpdx.zx, dpdy.zx ); + float4 z = 0.0; + if (m.z > 0) z = tex2Dgrad( tex, p.xy, dpdx.xy, dpdy.xy ); + + // and blend + return (x*m.x + y*m.y + z*m.z) / (m.x + m.y + m.z); +} + +float3 applyDetailBlendMode(int blendOp, half3 a, half3 b, half t) +{ + switch(blendOp) + { + default: + case 0: // Multiply 2x + return a * LerpWhiteTo (b * unity_ColorSpaceDouble.rgb, t); + case 1: // Multiply + return a * LerpWhiteTo (b, t); + case 2: // Additive + return a + b * t; + case 3: // Alpha Blend + return lerp(a, b, t); + } +} + +float3 RNMBlendUnpacked(float3 n1, float3 n2) +{ + n1 += float3( 0, 0, 1); + n2 *= float3(-1, -1, 1); + return n1*dot(n1, n2)/n1.z - n2; +} + +inline float EmissionFluro(float NdotV) +{ + float fluroBase = saturate(pow(NdotV, 2)); + return lerp(1.0 - _EmissionFluro, 1.0, fluroBase); +} + +half4 SampleIridescence(half NoV, half rampID) +{ + if (any(_IridescenceRamp_TexelSize.zw > 6.0)) + { + half rampIDUV = (1.0 - (floor(rampID * _IridescenceRamp_TexelSize.w) + 0.5) * _IridescenceRamp_TexelSize.y); + half2 rampUV = float2(NoV, rampIDUV); + return tex2D(_IridescenceRamp, rampUV); + } + return 1.0; +} + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs MyMaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, + float4 tangentToWorld[3], float3 i_posWorld) +{ + half4 baseColor = tex2D (_MainTex, i_tex.xy) * _Color; + half4 packedMap = tex2D (_MOESMap, i_tex.xy); + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, i_tex.xy), _BumpScale); + + #if defined(_DTRIPLANAR) + float triSharp = _TriplanarSharp; + float3 triPosition = i_posWorld * float3(_TriplanarTiles0x, _TriplanarTiles0y, _TriplanarTiles0z) + + float3(_TriplanarOffset0x, _TriplanarOffset0y, _TriplanarOffset0z); + half4 baseColorDetail = boxmap (_MainTexDetail, triPosition, tangentToWorld[2], triSharp); + half4 packedMapDetail = boxmap (_MOESMapDetail, triPosition, tangentToWorld[2], triSharp); + half3 normalTangentDetail = UnpackScaleNormal(boxmap (_BumpMapDetail, triPosition, tangentToWorld[2], triSharp), _BumpScaleDetail); + #else + float2 dUV = i_tex.xy * _MainTexDetail_ST.xy + _MainTexDetail_ST.zw; + half4 baseColorDetail = tex2D (_MainTexDetail, dUV); + half4 packedMapDetail = tex2D (_MOESMapDetail, dUV); + half3 normalTangentDetail = UnpackScaleNormal(tex2D (_BumpMapDetail, dUV), _BumpScaleDetail); + #endif + + baseColor.rgb = applyDetailBlendMode(_DetailBlendMode, baseColor, baseColorDetail, _DetailBlendWeight); + normalTangent = lerp(normalTangent, RNMBlendUnpacked(normalTangent, normalTangentDetail), _DetailBlendWeight); + packedMap = lerp(packedMap, packedMap * packedMapDetail, saturate(_DetailBlendWeight)); + + half metallic = packedMap[_MetallicSelect] * _MetallicScale; + half occlusion = lerp(1, packedMap[_OcclusionSelect], _OcclusionScale); + half emissionMask = packedMap[_EmissionSelect]; + half smoothness = packedMap[_SmoothnessSelect] * _SmoothnessScale; + + smoothness = (_SmoothnessMode == 0) ? smoothness : 1.0 - smoothness; + + half3 emission = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + + #if defined(_ADD_EMISSION) + half4 emissionMap = tex2D (_EmissionMap, i_tex.xy); + emission += emissionMap * _EmissionMapPower; + #endif + + half anisotropy; half3 anisotropyDir; + #if defined(_SHADING_ANISOTROPY) + anisotropy = _Anisotropy; + anisotropyDir = UnpackNormal(tex2D(_AnisotropyDirectionMap, i_tex.xy)); + #endif + + half clearCoat, clearCoatRoughness; + #if defined(_USE_CLEARCOAT) + half4 ccMap = tex2D(_ClearCoatMap, i_tex.xy); + clearCoat = ccMap.r * _ClearCoat; + clearCoatRoughness = ccMap.g * _ClearCoatRoughness; + #endif + + // In Cloth mode, use metalness for sheen. + half3 sheenColor = lerp(baseColor*baseColor, sqrt(baseColor), metallic); + half sheenRoughness = 1.0h; + + #if defined(_USE_SHEEN) + if (_AutoSheenColor != 0) + sheenColor = 1.0h; + + half4 sheenMap = tex2D(_SheenMap, i_tex.xy); + sheenColor = sheenColor * _SheenColor.rgb * sheenMap.r; + sheenRoughness = _SheenRoughness * sheenMap.g; + #endif + + if (_WetnessAmount > 0) + { + half wetness = tex2D(_WetnessMap, i_tex.xy).r * _WetnessAmount; + half porosity = saturate((1.0 - metallic) * (1.0 - smoothness)); + half waterDarken = wetness * porosity; + + // Darken and slightly saturate porous surfaces + baseColor.rgb = lerp(baseColor.rgb, baseColor.rgb * baseColor.rgb, waterDarken * 0.5); + baseColor.rgb *= lerp(1.0, 0.2, waterDarken); + normalTangent = lerp(normalTangent, half3(0, 0, 1), wetness); + smoothness = lerp(smoothness, 0.95, wetness); + + anisotropy = lerp(anisotropy, 0.0, wetness); + anisotropyDir = lerp(anisotropyDir, half3(0, 0, 1), wetness); + + clearCoat = lerp(clearCoat, 1.0, wetness); + clearCoatRoughness = lerp(clearCoatRoughness, 0.05, wetness); + } + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + + #if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + material.baseColor = baseColor; + material.specularColor = baseColor * metallic; + material.glossiness = smoothness; + #else + material.baseColor = baseColor; + #if defined(SHADING_MODEL_CLOTH) + material.sheenColor = lerp(baseColor*baseColor, sqrt(baseColor), metallic); + #else + material.metallic = metallic; + #endif + material.roughness = computeRoughnessFromGlossiness(smoothness); + #endif + + material.normal = normalTangent; + material.emissive.rgb = emission; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + + #if defined(_SHADING_ANISOTROPY) + material.anisotropy = anisotropy; + material.anisotropyDirection = anisotropyDir; + #endif + + #if defined(_SHADING_GLINT) + half internal_glint_alpha = lerp(0.001, 0.1, _SpecularGlintSize * _SpecularGlintSize); + half internal_density = pow(10.0, lerp(3.0, 9.0, _SpecularGlintDensity)); + + material.uv = i_tex.xy; + material.glintAlpha = internal_glint_alpha; + material.glintDensity = internal_density; + #endif + + #if defined(_SHADING_SUBSURFACE) || defined(_SHADING_CLOTH) + half3 subsurfaceColor = 1.0h; + if (_AutoSubsurfaceColor != 0) + subsurfaceColor = lerp(baseColor*baseColor, sqrt(baseColor), metallic); + material.subsurfaceColor = subsurfaceColor * _SubsurfaceColor.rgb; + #endif + + #if defined(_SHADING_SUBSURFACE) + material.thickness = tex2D(_ThicknessMap, i_tex.xy).r * _ThicknessScale; + material.subsurfacePower = _SubsurfacePower; + #endif + + #if defined(_USE_CLEARCOAT) + material.clearCoat = clearCoat; + material.clearCoatRoughness = clearCoatRoughness; + #endif + + #if defined(_USE_SHEEN) && !defined(SHADING_MODEL_CLOTH) + material.sheenColor = sheenColor; + material.sheenRoughness = sheenRoughness; + #endif + + return material; +} + +inline void applyIridescence(const ShadingParams shading, inout MaterialInputs material) +{ + #if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + if (_IridescenceAmount > 0) + { + + half4 specIridescence = lerp(half4(1.0.xxx, 0.0), SampleIridescence(shading.NoV, 0), _IridescenceAmount); + material.specularColor *= specIridescence.rgb; + } + #endif +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i, bool facing) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS(i)); + + prepareMaterial(shading, material); + + material.emissive *= EmissionFluro(shading.NoV); + + applyIridescence(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i, bool facing) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + MyMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i)); + + prepareMaterial(shading, material); + + applyIridescence(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i, bool f : SV_IsFrontFace) : SV_Target + { return fragForwardBaseTemplate(i, f); } +half4 fragAdd (VertexOutputForwardAdd i, bool f : SV_IsFrontFace) : SV_Target + { return fragForwardAddTemplate(i, f); } + + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + AlphaToMask [_AtoCmode] + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local_fragment _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local_fragment _ _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local_fragment _ _GLOSSYREFLECTIONS_OFF + + #pragma shader_feature_local_fragment _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local_fragment _LTCGI + #pragma shader_feature_local_fragment _VRCLV + #pragma shader_feature_local_fragment _LIGHTMAPSPECULAR + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + AlphaToMask [_AtoCmode] + //Blend One [_DstBlend] + //ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local_fragment _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + AlphaToMask Off + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + // Must be in vertex stage to pass UVs. + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDCG + } + + Pass + { + Name "META" + Tags {"LightMode"="Meta"} + Cull Off + CGPROGRAM + + #define REQUIRE_META_WORLDPOS + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardMeta.cginc" + + #define META_PASS + + float4 frag_meta2 (v2f_meta i): SV_Target + { + MaterialInputs material = SETUP_BRDF_INPUT (i.uv); + float4 dummy[3]; dummy[0] = 1; dummy[1] = 0; dummy[2] = i.worldPos; + material = MyMaterialSetup (i.uv, 0, 0, dummy, i.worldPos); + + PixelParams pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + + UnityMetaInput o; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); + + #ifdef EDITOR_VISUALIZATION + o.Albedo = pixel.diffuseColor; + o.VizUV = i.vizUV; + o.LightCoord = i.lightCoord; + #else + o.Albedo = UnityLightmappingAlbedo (pixel.diffuseColor, pixel.f0, 1-pixel.perceptualRoughness); + #endif + o.SpecularColor = pixel.f0; + o.Emission = material.emissive; + + return UnityMetaFragment(o); + } + + #pragma vertex vert_meta + #pragma fragment frag_meta2 + ENDCG + } + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedTemplateSelector.shader.meta b/Assets/Filamented/Extras/FilamentedTemplateSelector.shader.meta new file mode 100644 index 0000000..b5d1a01 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplateSelector.shader.meta @@ -0,0 +1,20 @@ +fileFormatVersion: 2 +guid: 5835b3b76534b964c8b4b6f41edd479f +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + - _EmissionMap: {instanceID: 0} + - _MainTexDetail: {instanceID: 0} + - _BumpMapDetail: {instanceID: 0} + - _MOESMapDetail: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedTemplateVertexColor.shader b/Assets/Filamented/Extras/FilamentedTemplateVertexColor.shader new file mode 100644 index 0000000..3540760 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplateVertexColor.shader @@ -0,0 +1,371 @@ +/* +Filamented example template. +This is a template of how to use Filamented to make a simple shader +that passes its own properties through to Filament, in a manner +similar to a Unity surface shader - but with less jank. + +Instead of reading multiple seperate maps, it just asks for +an albedo map, a normal map, and a MOES map. +This version adds vertex colours, and also shows some examples of +how to use the custom material editor from Filamented Extras. +*/ +Shader "Silent/Filamented Template (Vertex Color)" +{ + Properties + { + [CheckDFGTexture] + [SingleLine]_MainTex("Albedo", 2D) = "white" {} + _VertexColourScale("Vertex Colour Intensity", Range(0, 1)) = 1.0 + [Space] + [SingleLine(_BumpScale)][Normal] _BumpMap("Normal", 2D) = "bump" {} + [HideInInspector]_BumpScale("Normal Scale", Float) = 1 + [Space] + [SingleLine]_MOESMap("MOES Map", 2D) = "white" {} + _MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _Emission("Emission Power", Float) = 0 + _EmissionColor("Emission Color", Color) = (1,1,1,1) + [Space] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + [Toggle(_ALPHATEST_ON)]_AtoCmode("Cutout Transparency", Float) = 0 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + } + + CustomEditor "Silent.FilamentedExtras.Unity.FilamentedExtrasInspector" + + CGINCLUDE + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + #define HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + uniform half _VertexColourScale; + // uniform half3 _EmissionColor; + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs VCMaterialSetup (inout float4 i_tex, float3 i_eyeVec, + half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_posWorld, float4 i_color) +{ + half4 baseColor = tex2D (_MainTex, i_tex.xy); + half4 packedMap = tex2D (_MOESMap, i_tex.xy); + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, i_tex.xy), _BumpScale); + + half metallic = packedMap.x * _MetallicScale; + half occlusion = lerp(1, packedMap.y, _OcclusionScale); + half emissionMask = packedMap.z; + half smoothness = packedMap.w * _SmoothnessScale; + + baseColor.rgb = lerp(baseColor, baseColor * i_color, _VertexColourScale); + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = normalTangent; + material.emissive.rgb = baseColor.rgb * emissionMask * _Emission * _EmissionColor; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + VCMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, + IN_WORLDPOS(i), i.color); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + VCMaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, + IN_WORLDPOS_FWDADD(i), i.color); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + AlphaToMask [_AtoCmode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + AlphaToMask [_AtoCmode] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDCG + } + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + Pass + { + Name "META" + Tags {"LightMode"="Meta"} + Cull Off + CGPROGRAM + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardMeta.cginc" + + #define META_PASS + + float4 frag_meta2 (v2f_meta i): SV_Target + { + MaterialInputs material = SETUP_BRDF_INPUT (i.uv); + // Note: If your MaterialSetup needs vertex normals, you might want to use a custom vert_meta which passes them through. + float4 dummy[3]; dummy[0] = 1.0; dummy[1] = 0.0; dummy[2] = 0.0; + material = MyMaterialSetup(i.uv, 0, 0, dummy, 0, i.color); + + PixelParams pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + + UnityMetaInput o; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); + + #ifdef EDITOR_VISUALIZATION + o.Albedo = pixel.diffuseColor; + o.VizUV = i.vizUV; + o.LightCoord = i.lightCoord; + #else + o.Albedo = UnityLightmappingAlbedo (pixel.diffuseColor, pixel.f0, 1-pixel.perceptualRoughness); + #endif + o.SpecularColor = pixel.f0; + o.Emission = material.emissive; + + return UnityMetaFragment(o); + } + + #pragma vertex vert_meta + #pragma fragment frag_meta2 + #pragma shader_feature _EMISSION + #pragma shader_feature _METALLICGLOSSMAP + #pragma shader_feature ___ _DETAIL_MULX2 + ENDCG + } + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedTemplateVertexColor.shader.meta b/Assets/Filamented/Extras/FilamentedTemplateVertexColor.shader.meta new file mode 100644 index 0000000..b1b1e24 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTemplateVertexColor.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: 9d2eaba013d66c24a9b2e5e3bc2cb259 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedTextureBlending.shader b/Assets/Filamented/Extras/FilamentedTextureBlending.shader new file mode 100644 index 0000000..06b7aa3 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTextureBlending.shader @@ -0,0 +1,722 @@ +/* +Filamented texture blending sample. +This is designed to be used as-is in existing projects, but +experienced users may wish to modify how the shader functions. +*/ +Shader "Silent/Filamented Extras/Texture Blending Filamented" +{ + Properties + { + [CheckDFGTexture] + [BlendModeSelector(_SrcBlend, _DstBlend, _CustomRenderQueue, _ZWrite, _AtoCmode)] _Mode ("__mode", Float) = 0.0 + + [HeaderEx(Base Settings)] + [Enum(UV0,0,UV1,1,UV2,2,UV3,3)] _UVSec ("UV for Splat Map", Float) = 0 + [SetKeyword(_SPLATMAP)]_MainTex("Splat Map (Optional) and Texture Scale", 2D) = "black" {} + [ToggleUI]_WeightFromDirection("World-Space XYZ to Vertex Colour RGB", Float) = 0 + + [HeaderEx(Base Color)] + [ScaleOffset][SingleLine(_ColorA)]_MainTexA ("Albedo (RGB)", 2D) = "white" {} + [HideInInspector]_ColorA("Color", Color) = (1,1,1,1) + [SingleLine(_BumpScaleA)][Normal]_BumpMapA ("Normal Map (XYZ)", 2D) = "bump" {} + [HideInInspector]_BumpScaleA("Normal Scale", Float) = 1 + [SingleLine(_PropertiesA)]_MaskMapA ("Mask (MOES)", 2D) = "green" {} + [HideInInspector]_PropertiesA("MOES Scale", Vector) = (0.0, 0.0, 0.0, 1.0) + + [HeaderEx(Vertex Color R)] + [ScaleOffset][SingleLine(_ColorR)]_MainTexR ("Albedo (RGB)", 2D) = "white" {} + [HideInInspector]_ColorR("Color", Color) = (1,1,1,1) + [SingleLine(_BumpScaleR)][Normal]_BumpMapR ("Normal Map (XYZ)", 2D) = "bump" {} + [HideInInspector]_BumpScaleR("Normal Scale", Float) = 1 + [SingleLine(_PropertiesR)]_MaskMapR ("Mask (MOES)", 2D) = "green" {} + [HideInInspector]_PropertiesR("MOES Scale", Vector) = (0.0, 0.0, 0.0, 1.0) + + [HeaderEx(Vertex Color G)] + [ScaleOffset][SingleLine(_ColorG)]_MainTexG ("Albedo (RGB)", 2D) = "white" {} + [HideInInspector]_ColorG("Color", Color) = (1,1,1,1) + [SingleLine(_BumpScaleG)][Normal]_BumpMapG ("Normal Map (XYZ)", 2D) = "bump" {} + [HideInInspector]_BumpScaleG("Normal Scale", Float) = 1 + [SingleLine(_PropertiesG)]_MaskMapG ("Mask (MOES)", 2D) = "green" {} + [HideInInspector]_PropertiesG("MOES Scale", Vector) = (0.0, 0.0, 0.0, 1.0) + + [HeaderEx(Vertex Color B)] + [ScaleOffset][SingleLine(_ColorB)]_MainTexB ("Albedo (RGB)", 2D) = "white" {} + [HideInInspector]_ColorB("Color", Color) = (1,1,1,1) + [SingleLine(_BumpScaleB)][Normal]_BumpMapB ("Normal Map (XYZ)", 2D) = "bump" {} + [HideInInspector]_BumpScaleB("Normal Scale", Float) = 1 + [SingleLine(_PropertiesB)]_MaskMapB ("Mask (MOES)", 2D) = "green" {} + [HideInInspector]_PropertiesB("MOES Scale", Vector) = (0.0, 0.0, 0.0, 1.0) + + [HeaderEx(Texture Blending Settings)] + [ScaleOffset][SingleLine]_BlendMask ("Texture Blending Offset (R)", 2D) = "grey" {} + _MaskStr("Blending Mask Power (per-channel)", Vector) = (1.0, 1.0, 1.0, 1.0) + [Toggle(_DEBUG_VIEWWEIGHTS)]_DebugViewBlendingWeights("Debug View for Blend Weights", Float ) = 0.0 + + [Space] + [HeaderEx(Sampling Settings)] + [Toggle(_STOCHASTIC)]_UseStochastic("Stochastic Sampling", Float) = 0.0 + [Space] + [Toggle(_TRIPLANAR)]_UseTriplanar("Triplanar Sampling", Float) = 0.0 + [IfDef(_TRIPLANAR)]_UVTransform0("Triplanar UV Transform X", Vector) = (1, 0, 0, 0) + [IfDef(_TRIPLANAR)]_UVTransform1("Triplanar UV Transform Y", Vector) = (0, 1, 0, 0) + [IfDef(_TRIPLANAR)]_UVTransform2("Triplanar UV Transform Z", Vector) = (0, 0, 1, 0) + + [HeaderEx(Filamented Settings)] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + + [Space] + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + // Blending state + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _CustomRenderQueue ("__rq", Float) = 1.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + [HideInInspector] _AtoCmode("__atoc", Float) = 0 + } + + CustomEditor "Silent.FilamentedExtras.Unity.FilamentedExtrasInspector" + + CGINCLUDE + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + #define HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define HAS_ATTRIBUTE_UV2 + #define HAS_ATTRIBUTE_UV3 + // If this is not defined, secondary UVs will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + // UNITY_SHADER_NO_UPGRADE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + #include "Packages/s-ilent.filamented/Filamented/SharedSamplingLib.hlsl" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. + + TEXTURE2D(_MainTexR); TEXTURE2D(_MainTexG); TEXTURE2D(_MainTexB); TEXTURE2D(_MainTexA); + TEXTURE2D(_BumpMapR); TEXTURE2D(_BumpMapG); TEXTURE2D(_BumpMapB); TEXTURE2D(_BumpMapA); + TEXTURE2D(_MaskMapR); TEXTURE2D(_MaskMapG); TEXTURE2D(_MaskMapB); TEXTURE2D(_MaskMapA); + + SAMPLER(sampler_MainTexR); + SAMPLER(sampler_BumpMapR); + SAMPLER(sampler_MaskMapR); + + float4 _MainTexR_ST; float4 _MainTexG_ST; float4 _MainTexB_ST; float4 _MainTexA_ST; + + float4 _ColorR; float4 _ColorG; float4 _ColorB; float4 _ColorA; + float _BumpScaleR; float _BumpScaleG; float _BumpScaleB; float _BumpScaleA; + + float4 _PropertiesR; float4 _PropertiesG; float4 _PropertiesB; float4 _PropertiesA; + + uniform half4 _UVTransform0; + uniform half4 _UVTransform1; + uniform half4 _UVTransform2; + + TEXTURE2D(_BlendMask); SAMPLER(sampler_BlendMask); + float4 _BlendMask_ST; + float4 _MaskStr; + + half _WeightFromDirection; + +VertexOutputForwardBase vertBase (VertexInput v) + { + VertexOutputForwardBase o; + o = vertForwardBase(v); + o.tex.zw = TRANSFORM_TEX(((_UVSec == 0) ? v.uv0 : v.uv1), _MainTex); + #if defined(HAS_ATTRIBUTE_UV2) + o.tex.zw = TRANSFORM_TEX(((_UVSec == 2) ? v.uv2 : o.tex.zw), _MainTex); + #endif + #if defined(HAS_ATTRIBUTE_UV3) + o.tex.zw = TRANSFORM_TEX(((_UVSec == 3) ? v.uv3 : o.tex.zw), _MainTex); + #endif + return o; + } + +VertexOutputForwardAdd vertAdd (VertexInput v) + { + VertexOutputForwardAdd o; + o = vertForwardAdd(v); + o.tex.zw = TRANSFORM_TEX(((_UVSec == 0) ? v.uv0 : v.uv1), _MainTex); + #if defined(HAS_ATTRIBUTE_UV2) + o.tex.zw = TRANSFORM_TEX(((_UVSec == 2) ? v.uv2 : o.tex.zw), _MainTex); + #endif + #if defined(HAS_ATTRIBUTE_UV3) + o.tex.zw = TRANSFORM_TEX(((_UVSec == 3) ? v.uv3 : o.tex.zw), _MainTex); + #endif + return o; + } + + +//hash for randomness +float2 hash2D2D(float2 s) +{ + //magic numbers + return frac(sin(fmod(float2(dot(s, float2(127.1, 311.7)), dot(s, float2(269.5, 183.3))), 3.14159)) * 43758.5453); +} + +//stochastic sampling +float4 tex2DStochastic(TEXTURE2D_PARAM(tex, smp), float2 UV) +{ + //triangle vertices and blend weights + //BW_vx[0...2].xyz = triangle verts + //BW_vx[3].xy = blend weights (z is unused) + float4x3 BW_vx; + + //uv transformed into triangular grid space with UV scaled by approximation of 2*sqrt(3) + float2 skewUV = mul(float2x2 (1.0, 0.0, -0.57735027, 1.15470054), UV * 3.464); + + //vertex IDs and barycentric coords + float2 vxID = float2 (floor(skewUV)); + float3 barry = float3 (frac(skewUV), 0); + barry.z = 1.0 - barry.x - barry.y; + + BW_vx = ((barry.z > 0) ? + float4x3(float3(vxID, 0), float3(vxID + float2(0, 1), 0), float3(vxID + float2(1, 0), 0), barry.zyx) : + float4x3(float3(vxID + float2 (1, 1), 0), float3(vxID + float2 (1, 0), 0), float3(vxID + float2 (0, 1), 0), float3(-barry.z, 1.0 - barry.y, 1.0 - barry.x))); + + //calculate derivatives to avoid triangular grid artifacts + float2 dx = ddx(UV); + float2 dy = ddy(UV); + + //blend samples with calculated weights + return mul(SAMPLE_TEXTURE2D_GRAD(tex, smp, UV + hash2D2D(BW_vx[0].xy), dx, dy), BW_vx[3].x) + + mul(SAMPLE_TEXTURE2D_GRAD(tex, smp, UV + hash2D2D(BW_vx[1].xy), dx, dy), BW_vx[3].y) + + mul(SAMPLE_TEXTURE2D_GRAD(tex, smp, UV + hash2D2D(BW_vx[2].xy), dx, dy), BW_vx[3].z); +} + +// Typical triplanar mapping -- has less visual artifacts than biplanar. +// Artifacts stand out because this is a material shader for things like +// terrain which cover a large portion of the screen. +float4 boxmap( TEXTURE2D_PARAM(tex, smp), float3 p, float3 n, float k ) +{ + // grab coord derivatives for texturing + float3 dpdx = ddx(p); + float3 dpdy = ddy(p); + + float3 m = pow( abs(n), k ); + + // project+fetch + float4 x = 0.0; + if (m.x > 0) x = SAMPLE_TEXTURE2D_GRAD( tex, smp, p.zy, dpdx.zy, dpdy.zy ); + float4 y = 0.0; + if (m.y > 0) y = SAMPLE_TEXTURE2D_GRAD( tex, smp, p.zx, dpdx.zx, dpdy.zx ); + float4 z = 0.0; + if (m.z > 0) z = SAMPLE_TEXTURE2D_GRAD( tex, smp, p.xy, dpdx.xy, dpdy.xy ); + + // and blend + return (x*m.x + y*m.y + z*m.z) / (m.x + m.y + m.z); +} + +float4 tex2DStochasticBoxmap(TEXTURE2D_PARAM(tex, smp), float3 p, float3 n, float k) +{ + // Stochastic sampling + float4x3 BW_vx; + float3 m = pow( abs(n), k ); + float2 skewUV = mul(float2x2 (1.0, 0.0, -0.57735027, 1.15470054), (p.xy * m.x + p.yz * m.y + p.zx * m.z) * 3.464); + float2 vxID = float2 (floor(skewUV)); + float3 barry = float3 (frac(skewUV), 0); + barry.z = 1.0 - barry.x - barry.y; + + BW_vx = ((barry.z > 0) ? + float4x3(float3(vxID, 0), float3(vxID + float2(0, 1), 0), float3(vxID + float2(1, 0), 0), barry.zyx) : + float4x3(float3(vxID + float2 (1, 1), 0), float3(vxID + float2 (1, 0), 0), float3(vxID + float2 (0, 1), 0), float3(-barry.z, 1.0 - barry.y, 1.0 - barry.x))); + + // Box mapping + float3 dpdx = ddx(p); + float3 dpdy = ddy(p); + + // Blend samples with calculated weights + return ((m.x > 0 ? mul(SAMPLE_TEXTURE2D_GRAD(tex, smp, p.zy + hash2D2D(BW_vx[0].xy), dpdx.zy, dpdy.zy), BW_vx[3].x) : 0) + + (m.y > 0 ? mul(SAMPLE_TEXTURE2D_GRAD(tex, smp, p.zx + hash2D2D(BW_vx[1].xy), dpdx.zx, dpdy.zx), BW_vx[3].y) : 0) + + (m.z > 0 ? mul(SAMPLE_TEXTURE2D_GRAD(tex, smp, p.xy + hash2D2D(BW_vx[2].xy), dpdx.xy, dpdy.xy), BW_vx[3].z) : 0)) / (m.x + m.y + m.z); +} + + +float3 RNMBlendUnpacked(float3 n1, float3 n2) +{ + n1 += float3( 0, 0, 1); + n2 *= float3(-1, -1, 1); + return n1*dot(n1, n2)/n1.z - n2; +} + +float3 PDNormalBlend(float3 n1, float3 n2, float alpha) +{ + float2 pd1 = n1.xy / n1.z; + float2 pd2 = n2.xy / n2.z; + float2 pd_interpolated = lerp(pd1, pd2, alpha); + return normalize(float3(pd_interpolated, 1.0)); +} + +void addLayer(float weight, float2 uv, float4 uv_ST, + TEXTURE2D_PARAM(tex_A, smp_A), inout float4 albedoAlpha, float4 tint, + TEXTURE2D_PARAM(tex_N, smp_N), inout float3 normal, float scale, + TEXTURE2D_PARAM(tex_M, smp_M), inout float4 props, + inout float4 maskProps) +{ + if (weight > 0) + { + uv = uv * uv_ST.xy + uv_ST.zw; + + #if defined(_STOCHASTIC) + float4 thisBasemap = tex2DStochastic(tex_A, smp_A, uv); + float3 thisNormal = UnpackScaleNormal(tex2DStochastic(tex_N, smp_N, uv), weight * scale); + float4 thisProps = tex2DStochastic(tex_M, smp_M, uv); + #else + float4 thisBasemap = SAMPLE_TEXTURE2D(tex_A, smp_A, uv); + float3 thisNormal = UnpackScaleNormal(SAMPLE_TEXTURE2D(tex_N, smp_N, uv), weight * scale); + float4 thisProps = SAMPLE_TEXTURE2D(tex_M, smp_M, uv); + #endif + + thisBasemap *= tint; + + thisProps.rba *= maskProps.rba; // metallic, emission, smoothness + thisProps.g = lerp(1, thisProps.g, maskProps.g); // occlusion + + #if 0 + albedoAlpha = albedoAlpha + thisBasemap * weight; + normal = RNMBlendUnpacked(thisNormal, normal); + props = props + thisProps * weight; + #else + albedoAlpha = lerp(albedoAlpha, thisBasemap, weight); + normal = lerp(normal, thisNormal, weight); + props = lerp(props, thisProps, weight); + #endif + } +} + +void addLayerTriplanar(float weight, float3 p, float3 n, float4 uv_ST, + TEXTURE2D_PARAM(tex_A, smp_A), inout float4 albedoAlpha, float4 tint, + TEXTURE2D_PARAM(tex_N, smp_N), inout float3 normal, float scale, + TEXTURE2D_PARAM(tex_M, smp_M), inout float4 props, + inout float4 maskProps) +{ + const float tightness = 6.0; + if (weight > 0.01) + { + p = p * uv_ST.xyx + uv_ST.zwz; + + #if defined(_STOCHASTIC) + float4 thisBasemap = tex2DStochasticBoxmap(TEXTURE2D_ARGS(tex_A, smp_A), p, n, tightness); + float3 thisNormal = UnpackScaleNormal(tex2DStochasticBoxmap(TEXTURE2D_ARGS(tex_N, smp_N), p, n, tightness), weight * scale); + float4 thisProps = tex2DStochasticBoxmap(TEXTURE2D_ARGS(tex_M, smp_M), p, n, tightness); + #else + float4 thisBasemap = boxmap(TEXTURE2D_ARGS(tex_A, smp_A), p, n, tightness); + float3 thisNormal = UnpackScaleNormal(boxmap(TEXTURE2D_ARGS(tex_N, smp_N), p, n, tightness), weight * scale); + float4 thisProps = boxmap(TEXTURE2D_ARGS(tex_M, smp_M), p, n, tightness); + #endif + + thisBasemap *= tint; + + thisProps.rba *= maskProps.rba; // metallic, emission, smoothness + thisProps.g = lerp(1, thisProps.g, maskProps.g); // occlusion + + #if 0 + albedoAlpha = albedoAlpha + thisBasemap * weight; + normal = RNMBlendUnpacked(thisNormal, normal); + props = props + thisProps * weight; + #else + albedoAlpha = lerp(albedoAlpha, thisBasemap, weight); + normal = lerp(normal, thisNormal, weight); + props = lerp(props, thisProps, weight); + #endif + } +} + + // The material function itself! You can alter the code below to add extra properties. +inline MaterialInputs BlendedMaterialSetup (inout float4 i_tex, float4 tangentToWorld[3], + float3 i_posWorld, float4 i_color) +{ + // Blend weights in vertex colours + fixed3 weights = i_color; + #if defined(_SPLATMAP) + // Blend weights in splat map + weights = tex2D (_MainTex, i_tex.zw); + #endif + + float3x3 tangentToWorldOnly = float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz); + float3 worldNormalT = mul ( float3( 0, 0, 1 ), tangentToWorldOnly ); + float3 worldPosT = float3( + dot(float4(i_posWorld.xyz, 1), _UVTransform0), + dot(float4(i_posWorld.xyz, 1), _UVTransform1), + dot(float4(i_posWorld.xyz, 1), _UVTransform2) + ); + + if (_WeightFromDirection) + { + weights = (abs(worldNormalT)); + } + +#if defined(_TRIPLANAR) + float4 blendMod = boxmap(TEXTURE2D_ARGS(_BlendMask, sampler_BlendMask), + worldPosT * _BlendMask_ST.xyx + _BlendMask_ST.zwz, worldNormalT, 1.0).r; +#else + float4 blendMod = SAMPLE_TEXTURE2D(_BlendMask, sampler_BlendMask, + i_tex.xy * _BlendMask_ST.xy + _BlendMask_ST.zw).r; +#endif + + weights = saturate( pow(((blendMod*weights)*4) + (weights*2), _MaskStr) ); + + float baseLayerWeight = 1.0 - saturate(dot(weights, 1.0)); + +#if defined(_DEBUG_VIEWWEIGHTS) + MaterialInputs debugView = (MaterialInputs)0; + initMaterial(debugView); + debugView.baseColor = 0.0; + debugView.emissive = float4(weights, 1.0); + debugView.emissive.a = 1.0; + return debugView; +#endif + + float4 c = 0; + float3 n = float3(0.0, 0.0, 1.0); + float4 m = 0; + +#if defined(_TRIPLANAR) + addLayerTriplanar(baseLayerWeight, worldPosT, worldNormalT, _MainTexA_ST, + TEXTURE2D_ARGS(_MainTexA, sampler_MainTexR), c, _ColorA, + TEXTURE2D_ARGS(_BumpMapA, sampler_BumpMapR), n, _BumpScaleA, + TEXTURE2D_ARGS(_MaskMapA, sampler_MaskMapR), m, + _PropertiesA); + addLayerTriplanar(weights.r, worldPosT, worldNormalT, _MainTexR_ST, + TEXTURE2D_ARGS(_MainTexR, sampler_MainTexR), c, _ColorR, + TEXTURE2D_ARGS(_BumpMapR, sampler_BumpMapR), n, _BumpScaleR, + TEXTURE2D_ARGS(_MaskMapR, sampler_MaskMapR), m, + _PropertiesR); + addLayerTriplanar(weights.g, worldPosT, worldNormalT, _MainTexG_ST, + TEXTURE2D_ARGS(_MainTexG, sampler_MainTexR), c, _ColorG, + TEXTURE2D_ARGS(_BumpMapG, sampler_BumpMapR), n, _BumpScaleG, + TEXTURE2D_ARGS(_MaskMapG, sampler_MaskMapR), m, + _PropertiesG); + addLayerTriplanar(weights.b, worldPosT, worldNormalT, _MainTexB_ST, + TEXTURE2D_ARGS(_MainTexB, sampler_MainTexR), c, _ColorB, + TEXTURE2D_ARGS(_BumpMapB, sampler_BumpMapR), n, _BumpScaleB, + TEXTURE2D_ARGS(_MaskMapB, sampler_MaskMapR), m, + _PropertiesB); +#else + addLayer(baseLayerWeight, i_tex.xy, _MainTexA_ST, + TEXTURE2D_ARGS(_MainTexA, sampler_MainTexR), c, _ColorA, + TEXTURE2D_ARGS(_BumpMapA, sampler_BumpMapR), n, _BumpScaleA, + TEXTURE2D_ARGS(_MaskMapA, sampler_MaskMapR), m, + _PropertiesA); + addLayer(weights.r, i_tex.xy, _MainTexR_ST, + TEXTURE2D_ARGS(_MainTexR, sampler_MainTexR), c, _ColorR, + TEXTURE2D_ARGS(_BumpMapR, sampler_BumpMapR), n, _BumpScaleR, + TEXTURE2D_ARGS(_MaskMapR, sampler_MaskMapR), m, + _PropertiesR); + addLayer(weights.g, i_tex.xy, _MainTexG_ST, + TEXTURE2D_ARGS(_MainTexG, sampler_MainTexR), c, _ColorG, + TEXTURE2D_ARGS(_BumpMapG, sampler_BumpMapR), n, _BumpScaleG, + TEXTURE2D_ARGS(_MaskMapG, sampler_MaskMapR), m, + _PropertiesG); + addLayer(weights.b, i_tex.xy, _MainTexB_ST, + TEXTURE2D_ARGS(_MainTexB, sampler_MainTexR), c, _ColorB, + TEXTURE2D_ARGS(_BumpMapB, sampler_BumpMapR), n, _BumpScaleB, + TEXTURE2D_ARGS(_MaskMapB, sampler_MaskMapR), m, + _PropertiesB); +#endif + + half metallic = m.x; + half occlusion = m.y; + half emissionMask = m.z; + half smoothness = m.w; + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = c; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + material.normal = n; + material.emissive.rgb = c.rgb * emissionMask; + material.emissive.a = 1.0; + material.ambientOcclusion = occlusion; + return material; +} + +half4 fragForwardBaseTemplate (VertexOutputForwardBase i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + // Your material setup goes here. + MaterialInputs material = + BlendedMaterialSetup(i.tex, i.tangentToWorldAndPackedData, IN_WORLDPOS(i), i.color); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardAddTemplate (VertexOutputForwardAdd i) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position); + + // Your material setup goes here. + MaterialInputs material = + BlendedMaterialSetup(i.tex,i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i), i.color); + + prepareMaterial(shading, material); + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseTemplate(i); } +half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddTemplate(i); } + #endif + + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Cull [_CullMode] + AlphaToMask [_AtoCmode] + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 5.0 + + // ------------------------------------- + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _LIGHTMAPSPECULAR + + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + #pragma shader_feature_local _SPLATMAP + #pragma shader_feature_local _TRIPLANAR + #pragma shader_feature_local _STOCHASTIC + + #pragma shader_feature_local _DEBUG_VIEWWEIGHTS + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest Equal + Cull [_CullMode] + AlphaToMask [_AtoCmode] + //Blend One [_DstBlend] + //ZWrite [_ZWrite] + + CGPROGRAM + #pragma target 5.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _SPLATMAP + #pragma shader_feature_local _TRIPLANAR + #pragma shader_feature_local _STOCHASTIC + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + + ENDCG + } + + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + Cull [_CullMode] + AlphaToMask Off + + CGPROGRAM + #pragma target 5.0 + + // ------------------------------------- + + #ifndef UNITY_PASS_SHADOWCASTER + #define UNITY_PASS_SHADOWCASTER + #endif + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc" + + ENDCG + } + + Pass + { + Name "META" + Tags {"LightMode"="Meta"} + Cull Off + AlphaToMask Off + CGPROGRAM + + #define REQUIRE_META_WORLDPOS + + #include "Packages/s-ilent.filamented/Filamented/UnityStandardMeta.cginc" + + #define META_PASS + + float4 frag_meta2 (v2f_meta i): SV_Target + { + MaterialInputs material = SETUP_BRDF_INPUT (i.uv); + float4 dummy[3]; dummy[0] = 1; dummy[1] = 0; dummy[2] = 0; + material = BlendedMaterialSetup(i.uv, dummy, i.worldPos, i.color); + + PixelParams pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + + UnityMetaInput o; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); + + #ifdef EDITOR_VISUALIZATION + o.Albedo = pixel.diffuseColor; + o.VizUV = i.vizUV; + o.LightCoord = i.lightCoord; + #else + o.Albedo = UnityLightmappingAlbedo (pixel.diffuseColor, pixel.f0, 1-pixel.perceptualRoughness); + #endif + o.SpecularColor = pixel.f0; + o.Emission = material.emissive; + + return UnityMetaFragment(o); + } + + #pragma vertex vert_meta + #pragma fragment frag_meta2 + #pragma shader_feature _EMISSION + #pragma shader_feature _METALLICGLOSSMAP + #pragma shader_feature ___ _DETAIL_MULX2 + ENDCG + } + + } + + FallBack "VertexLit" +} diff --git a/Assets/Filamented/Extras/FilamentedTextureBlending.shader.meta b/Assets/Filamented/Extras/FilamentedTextureBlending.shader.meta new file mode 100644 index 0000000..a709110 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTextureBlending.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: bba5baa3e3ab1e1408b673307df0108e +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _MOESMap: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Extras/FilamentedTriplanar.shader b/Assets/Filamented/Extras/FilamentedTriplanar.shader new file mode 100644 index 0000000..47de406 --- /dev/null +++ b/Assets/Filamented/Extras/FilamentedTriplanar.shader @@ -0,0 +1,432 @@ +/* +Filamented triplanar example. +*/ +Shader "Silent/Filamented Extras/Simple Triplanar Filamented" +{ + Properties + { + [CheckDFGTexture] + [BlendModeSelector(_SrcBlend, _DstBlend, _CustomRenderQueue, _ZWrite, _AtoCmode)] _Mode ("__mode", Float) = 0.0 + [HeaderEx(Base Material)] + [SingleLine(_Color)]_MainTex("Albedo", 2D) = "white" {} + [HideInInspector]_Color("Color", Color) = (1,1,1,1) + [SingleLine(_BumpScale)][Normal] _BumpMap("Normal", 2D) = "bump" {} + [HideInInspector]_BumpScale("Normal Scale", Float) = 1 + [SingleLine]_MOESMap("MOES Map", 2D) = "white" {} + [Space] + _MetallicScale("Metallic", Range( 0 , 1)) = 0 + _OcclusionScale("Occlusion", Range( 0 , 1)) = 0 + _Emission("Emission Power", Float) = 0 + _SmoothnessScale("Smoothness", Range( 0 , 1)) = 0 + [Space] + _EmissionColor("Emission Tint", Color) = (1,1,1,1) + [Space] + [HeaderEx(Texture Transform)] + _UVTransform0("UV Transform X", Vector) = (1, 0, 0, 0) + _UVTransform1("UV Transform Y", Vector) = (0, 1, 0, 0) + _UVTransform2("UV Transform Z", Vector) = (0, 0, 1, 0) + [HeaderEx(System)] + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 1 + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [HideInInspector]_RNM0("RNM0", 2D) = "black" {} + [HideInInspector]_RNM1("RNM1", 2D) = "black" {} + [HideInInspector]_RNM2("RNM2", 2D) = "black" {} + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + [Space] + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + // Blending state + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _CustomRenderQueue ("__rq", Float) = 1.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + [HideInInspector] _AtoCmode("__atoc", Float) = 0 + } + + CustomEditor "Silent.FilamentedExtras.Unity.FilamentedExtrasInspector" + + CGINCLUDE + // First, setup what Filamented does. + // Filamented's behaviour is decided by the shading model and what material properties are defined. + // These are listed in FilamentMaterialInputs. + // You can set up and use anything in the initMaterials function. + + // SHADING_MODEL_SPECULAR_GLOSSINESS + // If this is not defined, the material will default to metallic/roughness workflow. + + #define MATERIAL_HAS_NORMAL + // If this is not defined, normal maps won't be enabled. + + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // If this is not defined, occlusion won't be taken into account + + #define MATERIAL_HAS_EMISSIVE + // If this is not defined, emission won't be taken into account + + // MATERIAL_HAS_ANISOTROPY + // If this is set, the material will support anisotropy. + + // MATERIAL_HAS_CLEAR_COAT + // If this is set, the material will support clear coat. + + // HAS_ATTRIBUTE_COLOR + // If this is not defined, vertex colour will not be available. + + #define USE_DFG_LUT + // Whether to use the lookup texture for specular reflection calculation. + // Requires a shader property _DFG to be present and filled. + ENDCG + + CGINCLUDE + #ifndef UNITY_PASS_SHADOWCASTER + + // Include common files. These will include the other files as needed. + #include "Packages/s-ilent.filamented/Filamented/UnityLightingCommon.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardInput.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardConfig.cginc" + #include "Packages/s-ilent.filamented/Filamented/UnityStandardCore.cginc" + // Note: Unfortunately, Input is still needed due to some interdependancies with other Unity files. + // This means that some properties will always be defined, even if they aren't used. + // In practise, this won't affect the final compilation, but it means you'll need to watch out for the names + // of some common parameters. In this case, only MOESMap and some other properties are defined here because + // they are already defined in Input. + + // uniform sampler2D _MainTex; + // uniform sampler2D _BumpMap; + uniform sampler2D _MOESMap; + // uniform half _BumpScale; + uniform half _MetallicScale; + uniform half _OcclusionScale; + uniform half _SmoothnessScale; + uniform half _Emission; + // uniform half3 _EmissionColor; + uniform half4 _UVTransform0; + uniform half4 _UVTransform1; + uniform half4 _UVTransform2; + + // Vertex functions are called from UnityStandardCore. + // You can alter values here, or copy the function in and modify it. + VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } + VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } + +// https://iquilezles.org/www/articles/biplanar/biplanar.htm +// "p" point being textured +// "n" surface normal at "p" +// "k" controls the sharpness of the blending in the transitions areas +// "s" texture sampler +float4 biplanar( sampler2D sam, float3 p, float3 n, float k ) +{ + // grab coord derivatives for texturing + float3 dpdx = ddx(p); + float3 dpdy = ddy(p); + n = abs(n); + + // determine major axis (in x; yz are following axis) + int3 ma = (n.x>n.y && n.x>n.z) ? int3(0,1,2) : + (n.y>n.z) ? int3(1,2,0) : + int3(2,0,1) ; + // determine minor axis (in x; yz are following axis) + int3 mi = (n.x 0 in fp16 + return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI); +} + +half V_SmithGGXCorrelated(half roughness, half NoV, half NoL) { + // Heitz 2014, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs" + half a2 = roughness * roughness; + // TODO: lambdaV can be pre-computed for all the lights, it should be moved out of this function + half lambdaV = NoL * sqrt((NoV - a2 * NoV) * NoV + a2); + half lambdaL = NoV * sqrt((NoL - a2 * NoL) * NoL + a2); + // 0.0000077 = nextafter(0.5 / MEDIUMP_FLT_MAX, 1.0) in fp16, so we don't overflow + half v = PREVENT_DIV0(0.5, lambdaV + lambdaL, 0.0000077); + // a2=0 => v = 1 / 4*NoL*NoV => min=1/4, max=+inf + // a2=1 => v = 1 / 2*(NoL+NoV) => min=1/4, max=+inf + return v; +} + +half V_SmithGGXCorrelated_Fast(half roughness, half NoV, half NoL) { + // Hammon 2017, "PBR Diffuse Lighting for GGX+Smith Microsurfaces" + // 0.0000077 = nextafter(0.5 / MEDIUMP_FLT_MAX, 1.0) in fp16, so we don't overflow + half v = PREVENT_DIV0(0.5, lerp(2.0 * NoL * NoV, NoL + NoV, roughness), 0.0000077); + return v; +} + +half V_SmithGGXCorrelated_Anisotropic(half at, half ab, half ToV, half BoV, + half ToL, half BoL, half NoV, half NoL) { + // Heitz 2014, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs" + // TODO: lambdaV can be pre-computed for all the lights, it should be moved out of this function + half lambdaV = NoL * length(half3(at * ToV, ab * BoV, NoV)); + half lambdaL = NoV * length(half3(at * ToL, ab * BoL, NoL)); + // 0.0000077 = nextafter(0.5 / MEDIUMP_FLT_MAX, 1.0) in fp16, so we don't overflow + half v = PREVENT_DIV0(0.5, lambdaV + lambdaL, 0.0000077); + return v; +} + +half V_Kelemen(half LoH) { + // Kelemen 2001, "A Microfacet Based Coupled Specular-Matte BRDF Model with Importance Sampling" + // 0.0000039 = nextafter(0.25 / MEDIUMP_FLT_MAX, 1.0) in fp16, so we don't overflow + return PREVENT_DIV0(0.25, LoH * LoH, 0.0000039); +} + +half V_Neubelt(half NoV, half NoL) { + // Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886" + // 0.00001532 = nextafter(1.0 / MEDIUMP_FLT_MAX, 1.0) in fp16, so we don't overflow + return PREVENT_DIV0(1.0, 4.0 * (NoL + NoV - NoL * NoV), 0.00001532); +} + +half3 F_Schlick(const half3 f0, half f90, half VoH) { + // Schlick 1994, "An Inexpensive BRDF Model for Physically-Based Rendering" + return f0 + (f90 - f0) * pow5(1.0 - VoH); +} + +half3 F_Schlick(const half3 f0, half VoH) { + half f = pow(1.0 - VoH, 5.0); + return f + f0 * (1.0 - f); +} + +half F_Schlick(half f0, half f90, half VoH) { + return f0 + (f90 - f0) * pow5(1.0 - VoH); +} + +//------------------------------------------------------------------------------ +// Specular BRDF dispatch +//------------------------------------------------------------------------------ + +half distribution(half roughness, half NoH, half3 NxH, const half3 h) { +#if BRDF_SPECULAR_D == SPECULAR_D_GGX + return D_GGX(roughness, NoH, NxH, h); +#endif +} + +half visibility(half roughness, half NoV, half NoL) { +#if BRDF_SPECULAR_V == SPECULAR_V_SMITH_GGX + return V_SmithGGXCorrelated(roughness, NoV, NoL); +#elif BRDF_SPECULAR_V == SPECULAR_V_SMITH_GGX_FAST + return V_SmithGGXCorrelated_Fast(roughness, NoV, NoL); +#endif +} + +half3 fresnel(const half3 f0, half LoH) { +#if BRDF_SPECULAR_F == SPECULAR_F_SCHLICK +#if FILAMENT_QUALITY == FILAMENT_QUALITY_LOW + return F_Schlick(f0, LoH); // f90 = 1.0 +#else + half f90 = saturate(dot(f0, (50.0 * 0.33))); + return F_Schlick(f0, f90, LoH); +#endif +#endif +} + +half3 fresnel(const half3 f0, const half f90, half LoH) { +#if BRDF_SPECULAR_F == SPECULAR_F_SCHLICK + return F_Schlick(f0, f90, LoH); +#endif +} + +half distributionAnisotropic(half at, half ab, half ToH, half BoH, half NoH) { +#if BRDF_ANISOTROPIC_D == SPECULAR_D_GGX_ANISOTROPIC + return D_GGX_Anisotropic(at, ab, ToH, BoH, NoH); +#endif +} + +half visibilityAnisotropic(half roughness, half at, half ab, + half ToV, half BoV, half ToL, half BoL, half NoV, half NoL) { +#if BRDF_ANISOTROPIC_V == SPECULAR_V_SMITH_GGX + return V_SmithGGXCorrelated(roughness, NoV, NoL); +#elif BRDF_ANISOTROPIC_V == SPECULAR_V_GGX_ANISOTROPIC + return V_SmithGGXCorrelated_Anisotropic(at, ab, ToV, BoV, ToL, BoL, NoV, NoL); +#endif +} + +half distributionClearCoat(half roughness, half NoH, half3 NxH, const half3 h) { +#if BRDF_CLEAR_COAT_D == SPECULAR_D_GGX + return D_GGX(roughness, NoH, NxH, h); +#endif +} + +half visibilityClearCoat(half LoH) { +#if BRDF_CLEAR_COAT_V == SPECULAR_V_KELEMEN + return V_Kelemen(LoH); +#endif +} + +half distributionCloth(half roughness, half NoH) { +#if BRDF_CLOTH_D == SPECULAR_D_CHARLIE + return D_Charlie(roughness, NoH); +#endif +} + +half visibilityCloth(half NoV, half NoL) { +#if BRDF_CLOTH_V == SPECULAR_V_NEUBELT + return V_Neubelt(NoV, NoL); +#endif +} + +//------------------------------------------------------------------------------ +// Diffuse BRDF implementations +//------------------------------------------------------------------------------ + +half Fd_Lambert() { + return 1.0 / PI; +} + +half Fd_Burley(half roughness, half NoV, half NoL, half LoH) { + // Burley 2012, "Physically-Based Shading at Disney" + half f90 = 0.5 + 2.0 * roughness * LoH * LoH; + half lightScatter = F_Schlick(1.0, f90, NoL); + half viewScatter = F_Schlick(1.0, f90, NoV); + return lightScatter * viewScatter * (1.0 / PI); +} + +// Energy conserving wrap diffuse term, does *not* include the divide by pi +half Fd_Wrap(half NoL, half w) { + return saturate((NoL + w) / sq(1.0 + w)); +} + +//------------------------------------------------------------------------------ +// Diffuse BRDF dispatch +//------------------------------------------------------------------------------ + +half diffuse(half roughness, half NoV, half NoL, half LoH) { +#if BRDF_DIFFUSE == DIFFUSE_LAMBERT + return Fd_Lambert(); +#elif BRDF_DIFFUSE == DIFFUSE_BURLEY + return Fd_Burley(roughness, NoV, NoL, LoH); +#endif +} + +#endif // FILAMENT_BRDF_INCLUDED diff --git a/Assets/Filamented/FilamentBRDF.cginc.meta b/Assets/Filamented/FilamentBRDF.cginc.meta new file mode 100644 index 0000000..d9693d7 --- /dev/null +++ b/Assets/Filamented/FilamentBRDF.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 68dc287072e9d5a439cd6b82033899d6 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentCommonDithering.cginc b/Assets/Filamented/FilamentCommonDithering.cginc new file mode 100644 index 0000000..477c745 --- /dev/null +++ b/Assets/Filamented/FilamentCommonDithering.cginc @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +// Dithering configuration +//------------------------------------------------------------------------------ + +// Dithering operators +#define DITHERING_NONE 0 +#define DITHERING_INTERLEAVED_NOISE 1 +#define DITHERING_VLACHOS 2 +#define DITHERING_TRIANGLE_NOISE 3 +#define DITHERING_TRIANGLE_NOISE_RGB 4 + +#define DITHERING_OPERATOR DITHERING_TRIANGLE_NOISE + +//------------------------------------------------------------------------------ +// Noise +//------------------------------------------------------------------------------ + +// n must be normalized in [0..1] (e.g. texture coordinates) +half triangleNoise(float2 n) { + // triangle noise, in [-1.0..1.0[ range + n = fract(n * float2(5.3987, 5.4421)); + n += dot(n.yx, n.xy + float2(21.5351, 14.3137)); + + float xy = n.x * n.y; + // compute in [0..2[ and remap to [-1.0..1.0[ + return fract(xy * 95.4307) + fract(xy * 75.04961) - 1.0; +} + +// n must not be normalize (e.g. window coordinates) +half interleavedGradientNoise(float2 n) { + return fract(52.982919 * fract(dot(float2(0.06711, 0.00584), n))); +} + +//------------------------------------------------------------------------------ +// Dithering +//------------------------------------------------------------------------------ + +half4 Dither_InterleavedGradientNoise(half4 rgba, const float temporalNoise01) { + // Jimenez 2014, "Next Generation Post-Processing in Call of Duty" + float2 uv = gl_FragCoord.xy + temporalNoise01; + + // The noise variable must be to workaround Adreno bug #1096. + float noise = interleavedGradientNoise(uv); + + // remap from [0..1[ to [-0.5..0.5[ + noise -= 0.5; + + return rgba + float4(noise / 255.0); +} + +half4 Dither_TriangleNoise(half4 rgba, const float temporalNoise01) { + // Gjøl 2016, "Banding in Games: A Noisy Rant" + float2 uv = gl_FragCoord.xy * frameUniforms.resolution.zw; + uv += float2(0.07 * temporalNoise01); + + // The noise variable must be to workaround Adreno bug #1096. + float noise = triangleNoise(uv); + + // noise is in [-1..1[ + + return rgba + float4(noise / 255.0); +} + +half4 Dither_Vlachos(half4 rgba, const float temporalNoise01) { + // Vlachos 2016, "Advanced VR Rendering" + float noise = dot(float2(171.0, 231.0), gl_FragCoord.xy + temporalNoise01); + half3 noiseRGB = fract(float3(noise) / float3(103.0, 71.0, 97.0)); + + // remap from [0..1[ to [-0.5..0.5[ + noiseRGB -= 0.5; + + return half4(rgba.rgb + (noiseRGB / 255.0), rgba.a); +} + +half4 Dither_TriangleNoiseRGB(half4 rgba, const float temporalNoise01) { + // Gjøl 2016, "Banding in Games: A Noisy Rant" + float2 uv = gl_FragCoord.xy * frameUniforms.resolution.zw; + uv += float2(0.07 * temporalNoise01); + + half3 noiseRGB = float3( + triangleNoise(uv), + triangleNoise(uv + 0.1337), + triangleNoise(uv + 0.3141)); + + // noise is in [-1..1[ + + return rgba + noiseRGB.xyzx / 255.0; +} + +//------------------------------------------------------------------------------ +// Dithering dispatch +//------------------------------------------------------------------------------ + +/** + * Dithers the specified RGBA color based on the current time and fragment + * coordinates the input must be in the final color space (including OECF). + * This dithering function assumes we are dithering to an 8-bit target. + * This function dithers the alpha channel assuming premultiplied output + */ +half4 dither(half4 rgba, const float temporalNoise01) { +#if DITHERING_OPERATOR == DITHERING_NONE + return rgba; +#elif DITHERING_OPERATOR == DITHERING_INTERLEAVED_NOISE + return Dither_InterleavedGradientNoise(rgba, temporalNoise01); +#elif DITHERING_OPERATOR == DITHERING_VLACHOS + return Dither_Vlachos(rgba, temporalNoise01); +#elif DITHERING_OPERATOR == DITHERING_TRIANGLE_NOISE + return Dither_TriangleNoise(rgba, temporalNoise01); +#elif DITHERING_OPERATOR == DITHERING_TRIANGLE_NOISE_RGB + return Dither_TriangleNoiseRGB(rgba, temporalNoise01); +#endif +} diff --git a/Assets/Filamented/FilamentCommonDithering.cginc.meta b/Assets/Filamented/FilamentCommonDithering.cginc.meta new file mode 100644 index 0000000..7d31355 --- /dev/null +++ b/Assets/Filamented/FilamentCommonDithering.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4bd29bb1bce8f064eafa7eb6f8f830eb +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentCommonGraphics.cginc b/Assets/Filamented/FilamentCommonGraphics.cginc new file mode 100644 index 0000000..936b699 --- /dev/null +++ b/Assets/Filamented/FilamentCommonGraphics.cginc @@ -0,0 +1,119 @@ +#ifndef FILAMENT_COMMON_GRAPHICS +#define FILAMENT_COMMON_GRAPHICS +//------------------------------------------------------------------------------ +// Common color operations +//------------------------------------------------------------------------------ + +/** + * Computes the luminance of the specified linear RGB color using the + * luminance coefficients from Rec. 709. + * + * @public-api + */ +half luminance(const half3 linearCol) { + return dot(linearCol, half3(0.2126, 0.7152, 0.0722)); +} + +/** + * Computes the pre-exposed intensity using the specified intensity and exposure. + * This function exists to force high precision on the two parameters + * ...Which isn't applicable yet. + */ +half computePreExposedIntensity(const float intensity, const float exposure) { + return intensity * exposure; +} + +void unpremultiply(inout half4 color) { + color.rgb /= max(color.a, FLT_EPS); +} + +/** + * Applies a full range YCbCr to sRGB conversion and returns an RGB color. + * + * @public-api + */ +half3 ycbcrToRgb(half luminance, half2 cbcr) { + // Taken from https://developer.apple.com/documentation/arkit/arframe/2867984-capturedimage + const half4x4 ycbcrToRgbTransform = { + 1.0000, 1.0000, 1.0000, 0.0000, + 0.0000, -0.3441, 1.7720, 0.0000, + 1.4020, -0.7141, 0.0000, 0.0000, + -0.7010, 0.5291, -0.8860, 1.0000 + }; + return mul(ycbcrToRgbTransform, half4(luminance, cbcr, 1.0)).rgb; +} + +//------------------------------------------------------------------------------ +// Tone mapping operations +//------------------------------------------------------------------------------ + +/* + * The input must be in the [0, 1] range. + */ +half3 Inverse_Tonemap_Unreal(const half3 x) { + return (x * -0.155) / (x - 1.019); +} + +/** + * Applies the inverse of the tone mapping operator to the specified HDR or LDR + * sRGB (non-linear) color and returns a linear sRGB color. The inverse tone mapping + * operator may be an approximation of the real inverse operation. + * + * @public-api + */ +half3 inverseTonemapSRGB(half3 color) { + // sRGB input + color = clamp(color, 0.0, 1.0); + return Inverse_Tonemap_Unreal(color); +} + +/** + * Applies the inverse of the tone mapping operator to the specified HDR or LDR + * linear RGB color and returns a linear RGB color. The inverse tone mapping operator + * may be an approximation of the real inverse operation. + * + * @public-api + */ +half3 inverseTonemap(half3 linearCol) { + // Linear input + linearCol = clamp(linearCol, 0.0, 1.0); + return Inverse_Tonemap_Unreal(pow(linearCol, 1.0 / 2.2)); +} + +//------------------------------------------------------------------------------ +// Common texture operations +//------------------------------------------------------------------------------ + +/** + * Decodes the specified RGBM value to linear HDR RGB. + */ +half3 decodeRGBM(half4 c) { + c.rgb *= (c.a * 16.0); + return c.rgb * c.rgb; +} + +//------------------------------------------------------------------------------ +// Common debug +//------------------------------------------------------------------------------ + +half3 heatmap(half v) { + half3 r = v * 2.1 - half3(1.8, 1.14, 0.3); + return 1.0 - r * r; +} + +half3 uintToColorDebug(uint v) { + if (v == 0u) { + return half3(0.0, 1.0, 0.0); // green + } else if (v == 1u) { + return half3(0.0, 0.0, 1.0); // blue + } else if (v == 2u) { + return half3(1.0, 1.0, 0.0); // yellow + } else if (v == 3u) { + return half3(1.0, 0.0, 0.0); // red + } else if (v == 4u) { + return half3(1.0, 0.0, 1.0); // purple + } else if (v == 5u) { + return half3(0.0, 1.0, 1.0); // cyan + } +} +#endif // FILAMENT_COMMON_GRAPHICS diff --git a/Assets/Filamented/FilamentCommonGraphics.cginc.meta b/Assets/Filamented/FilamentCommonGraphics.cginc.meta new file mode 100644 index 0000000..cb69a73 --- /dev/null +++ b/Assets/Filamented/FilamentCommonGraphics.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 2eddc0a27592cca48b1b8f5d14e9c083 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentCommonLighting.cginc b/Assets/Filamented/FilamentCommonLighting.cginc new file mode 100644 index 0000000..1481af6 --- /dev/null +++ b/Assets/Filamented/FilamentCommonLighting.cginc @@ -0,0 +1,79 @@ +#ifndef FILAMENT_COMMON_LIGHTING +#define FILAMENT_COMMON_LIGHTING + +struct Light { + float4 colorIntensity; // rgb, pre-exposed intensity + float3 l; + half attenuation; + half NoL; + float3 worldPosition; +}; + +struct PixelParams { + half3 diffuseColor; + half perceptualRoughness; + half perceptualRoughnessUnclamped; + half3 f0; + half roughness; + half3 dfg; + half3 energyCompensation; + +#if defined(MATERIAL_HAS_CLEAR_COAT) + half clearCoat; + half clearCoatPerceptualRoughness; + half clearCoatRoughness; +#endif + +#if defined(MATERIAL_HAS_SHEEN_COLOR) + half3 sheenColor; +#if !defined(SHADING_MODEL_CLOTH) + half sheenRoughness; + half sheenPerceptualRoughness; + half sheenScaling; + half sheenDFG; +#endif +#endif + +#if defined(MATERIAL_HAS_ANISOTROPY) + half3 anisotropicT; + half3 anisotropicB; + half anisotropy; +#endif + +#if defined(SHADING_MODEL_SUBSURFACE) || defined(HAS_REFRACTION) + half thickness; +#endif +#if defined(SHADING_MODEL_SUBSURFACE) + half3 subsurfaceColor; + half subsurfacePower; +#endif + +#if defined(SHADING_MODEL_CLOTH) && defined(MATERIAL_HAS_SUBSURFACE_COLOR) + half3 subsurfaceColor; +#endif + +#if defined(HAS_REFRACTION) + half etaRI; + half etaIR; + half transmission; + half uThickness; + half3 absorption; +#endif + +#if defined(MATERIAL_HAS_GLINT) + float2 uv; + float2 ddx_uv; + float2 ddy_uv; + float glintAlpha; + float glintDensity; +#endif +}; + +half computeMicroShadowing(half NoL, half visibility) { + // Chan 2018, "Material Advances in Call of Duty: WWII" + half aperture = rsqrt(1.0 - visibility); + half microShadow = saturate(NoL * aperture); + return microShadow * microShadow; +}; + +#endif // FILAMENT_COMMON_LIGHTING diff --git a/Assets/Filamented/FilamentCommonLighting.cginc.meta b/Assets/Filamented/FilamentCommonLighting.cginc.meta new file mode 100644 index 0000000..8860090 --- /dev/null +++ b/Assets/Filamented/FilamentCommonLighting.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b84d59f7502b982408baa3fa4d9a3081 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentCommonMaterial.cginc b/Assets/Filamented/FilamentCommonMaterial.cginc new file mode 100644 index 0000000..e331f2a --- /dev/null +++ b/Assets/Filamented/FilamentCommonMaterial.cginc @@ -0,0 +1,66 @@ +#ifndef FILAMENT_COMMON_MATERIAL +#define FILAMENT_COMMON_MATERIAL + +#if defined(TARGET_MOBILE) + // min roughness such that (MIN_PERCEPTUAL_ROUGHNESS^4) > 0 in fp16 (i.e. 2^(-14/4), rounded up) + #define MIN_PERCEPTUAL_ROUGHNESS 0.089 + #define MIN_ROUGHNESS 0.007921 +#else + #define MIN_PERCEPTUAL_ROUGHNESS 0.045 + #define MIN_ROUGHNESS 0.002025 +#endif + +#define MIN_N_DOT_V 1e-4 + +half clampNoV(half NoV) { + // Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886" + return max(NoV, MIN_N_DOT_V); +} + +half3 computeDiffuseColor(const half4 baseColor, half metallic) { + return baseColor.rgb * (1.0 - metallic); +} + +half3 computeF0(const half4 baseColor, half metallic, half reflectance) { + return baseColor.rgb * metallic + (reflectance * (1.0 - metallic)); +} + +half computeDielectricF0(half reflectance) { + return 0.16 * reflectance * reflectance; +} + +half computeMetallicFromSpecularColor(const half3 specularColor) { + return max3(specularColor); +} + +half computeRoughnessFromGlossiness(half glossiness) { + return 1.0 - glossiness; +} + +half perceptualRoughnessToRoughness(half perceptualRoughness) { + return perceptualRoughness * perceptualRoughness; +} + +half roughnessToPerceptualRoughness(half roughness) { + return sqrt(roughness); +} + +half iorToF0(half transmittedIor, half incidentIor) { + return sq((transmittedIor - incidentIor) / (transmittedIor + incidentIor)); +} + +half f0ToIor(half f0) { + half r = sqrt(f0); + return (1.0 + r) / (1.0 - r); +} + +half3 f0ClearCoatToSurface(const half3 f0) { + // Approximation of iorTof0(f0ToIor(f0), 1.5) + // This assumes that the clear coat layer has an IOR of 1.5 +#if FILAMENT_QUALITY == FILAMENT_QUALITY_LOW + return saturate(f0 * (f0 * 0.526868 + 0.529324) - 0.0482256); +#else + return saturate(f0 * (f0 * (0.941892 - 0.263008 * f0) + 0.346479) - 0.0285998); +#endif +} +#endif // FILAMENT_COMMON_MATERIAL diff --git a/Assets/Filamented/FilamentCommonMaterial.cginc.meta b/Assets/Filamented/FilamentCommonMaterial.cginc.meta new file mode 100644 index 0000000..5364dbc --- /dev/null +++ b/Assets/Filamented/FilamentCommonMaterial.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5060180d12900874c95c28e958268e8d +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentCommonMath.cginc b/Assets/Filamented/FilamentCommonMath.cginc new file mode 100644 index 0000000..7b68656 --- /dev/null +++ b/Assets/Filamented/FilamentCommonMath.cginc @@ -0,0 +1,125 @@ +#ifndef FILAMENT_COMMON_MATH +#define FILAMENT_COMMON_MATH +//------------------------------------------------------------------------------ +// Common math +//------------------------------------------------------------------------------ + +/** @public-api */ +#define PI 3.14159265359 +/** @public-api */ +#define HALF_PI 1.570796327 + +#define MEDIUMP_FLT_MAX 65504.0 +#define MEDIUMP_FLT_MIN 0.00006103515625 + +#ifdef TARGET_MOBILE +#define FLT_EPS MEDIUMP_FLT_MIN +#define saturateMediump(x) min(x, MEDIUMP_FLT_MAX) +#else +#define FLT_EPS 1e-5 +#define saturateMediump(x) x +#endif + +#ifdef TARGET_MOBILE +#define PREVENT_DIV0(n, d, magic) ((n) / max(d, magic)) +#else +#define PREVENT_DIV0(n, d, magic) ((n) / (d)) +#endif + +#define atan(x,y) atan2(y,x) + +//------------------------------------------------------------------------------ +// Scalar operations +//------------------------------------------------------------------------------ + +/** + * Computes x^5 using only multiply operations. + * + * @public-api + */ +half pow5(half x) { + half x2 = x * x; + return x2 * x2 * x; +} + +/** + * Computes x^2 as a single multiplication. + * + * @public-api + */ +half sq(half x) { + return x * x; +} + +//------------------------------------------------------------------------------ +// Vector operations +//------------------------------------------------------------------------------ + +/** + * Returns the maximum component of the specified vector. + * + * @public-api + */ +half max3(const half3 v) { + return max(v.x, max(v.y, v.z)); +} + +half vmax(const half2 v) { + return max(v.x, v.y); +} + +half vmax(const half3 v) { + return max(v.x, max(v.y, v.z)); +} + +half vmax(const half4 v) { + return max(max(v.x, v.y), max(v.y, v.z)); +} + +/** + * Returns the minimum component of the specified vector. + * + * @public-api + */ +half min3(const half3 v) { + return min(v.x, min(v.y, v.z)); +} + +half vmin(const half2 v) { + return min(v.x, v.y); +} + +half vmin(const half3 v) { + return min(v.x, min(v.y, v.z)); +} + +half vmin(const half4 v) { + return min(min(v.x, v.y), min(v.y, v.z)); +} + +//------------------------------------------------------------------------------ +// Trigonometry +//------------------------------------------------------------------------------ + +/** + * Approximates acos(x) with a max absolute error of 9.0x10^-3. + * Valid in the range -1..1. + */ +half acosFast(half x) { + // Lagarde 2014, "Inverse trigonometric functions GPU optimization for AMD GCN architecture" + // This is the approximation of degree 1, with a max absolute error of 9.0x10^-3 + half y = abs(x); + half p = -0.1565827 * y + 1.570796; + p *= sqrt(1.0 - y); + return x >= 0.0 ? p : PI - p; +} + +/** + * Approximates acos(x) with a max absolute error of 9.0x10^-3. + * Valid only in the range 0..1. + */ +half acosFastPositive(half x) { + half p = -0.1565827 * x + 1.570796; + return p * sqrt(1.0 - x); +} +#endif // FILAMENT_COMMON_MATH diff --git a/Assets/Filamented/FilamentCommonMath.cginc.meta b/Assets/Filamented/FilamentCommonMath.cginc.meta new file mode 100644 index 0000000..2067c0a --- /dev/null +++ b/Assets/Filamented/FilamentCommonMath.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5246a13d4fd80814c965c1f0197094c5 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentCommonOcclusion.cginc b/Assets/Filamented/FilamentCommonOcclusion.cginc new file mode 100644 index 0000000..e187ac4 --- /dev/null +++ b/Assets/Filamented/FilamentCommonOcclusion.cginc @@ -0,0 +1,120 @@ +#ifndef FILAMENT_COMMON_OCCLUSION +#define FILAMENT_COMMON_OCCLUSION +//------------------------------------------------------------------------------ +// Ambient occlusion configuration +//------------------------------------------------------------------------------ + +// Diffuse BRDFs +#define SPECULAR_AO_OFF 0 +#define SPECULAR_AO_SIMPLE 1 +#define SPECULAR_AO_BENT_NORMALS 2 + +//------------------------------------------------------------------------------ +// Ambient occlusion helpers +//------------------------------------------------------------------------------ + +half SpecularAO_Lagarde(half NoV, half visibility, half roughness) { + // Lagarde and de Rousiers 2014, "Moving Frostbite to PBR" + return saturate(pow(NoV + visibility, exp2(-16.0 * roughness - 1.0)) - 1.0 + visibility); +} + +#if defined(MATERIAL_HAS_BENT_NORMAL) +half sphericalCapsIntersection(half cosCap1, half cosCap2, half cosDistance) { + // Oat and Sander 2007, "Ambient Aperture Lighting" + // Approximation mentioned by Jimenez et al. 2016 + half r1 = acosFastPositive(cosCap1); + half r2 = acosFastPositive(cosCap2); + half d = acosFast(cosDistance); + + // We work with cosine angles, replace the original paper's use of + // cos(min(r1, r2)) with max(cosCap1, cosCap2) + // We also remove a multiplication by 2 * PI to simplify the computation + // since we divide by 2 * PI in computeBentSpecularAO() + + if (min(r1, r2) <= max(r1, r2) - d) { + return 1.0 - max(cosCap1, cosCap2); + } else if (r1 + r2 <= d) { + return 0.0; + } + + half delta = abs(r1 - r2); + half x = 1.0 - saturate((d - delta) / max(r1 + r2 - delta, 1e-4)); + // simplified smoothstep() + half area = sq(x) * (-2.0 * x + 3.0); + return area * (1.0 - max(cosCap1, cosCap2)); +} +#endif + +// This function could (should?) be implemented as a 3D LUT instead, but we need to save samplers +half SpecularAO_Cones(half NoV, half visibility, half roughness) { +#if defined(MATERIAL_HAS_BENT_NORMAL) + // Jimenez et al. 2016, "Practical Realtime Strategies for Accurate Indirect Occlusion" + + // aperture from ambient occlusion + half cosAv = sqrt(1.0 - visibility); + // aperture from roughness, log(10) / log(2) = 3.321928 + half cosAs = exp2(-3.321928 * sq(roughness)); + // angle betwen bent normal and reflection direction + half cosB = dot(shading_bentNormal, shading_reflected); + + // Remove the 2 * PI term from the denominator, it cancels out the same term from + // sphericalCapsIntersection() + half ao = sphericalCapsIntersection(cosAv, cosAs, cosB) / (1.0 - cosAs); + // Smoothly kill specular AO when entering the perceptual roughness range [0.1..0.3] + // Without this, specular AO can remove all reflections, which looks bad on metals + return lerp(1.0, ao, smoothstep(0.01, 0.09, roughness)); +#else + return SpecularAO_Lagarde(NoV, visibility, roughness); +#endif +} + +/** + * Computes a specular occlusion term from the ambient occlusion term. + */ +half computeSpecularAO(half NoV, half visibility, half roughness) { +#if SPECULAR_AMBIENT_OCCLUSION == SPECULAR_AO_SIMPLE + return SpecularAO_Lagarde(NoV, visibility, roughness); +#elif SPECULAR_AMBIENT_OCCLUSION == SPECULAR_AO_BENT_NORMALS + return SpecularAO_Cones(NoV, visibility, roughness); +#else + return 1.0; +#endif +} + +#if MULTI_BOUNCE_AMBIENT_OCCLUSION == 1 +/** + * Returns a color ambient occlusion based on a pre-computed visibility term. + * The albedo term is meant to be the diffuse color or f0 for the diffuse and + * specular terms respectively. + */ +half3 gtaoMultiBounce(half visibility, const half3 albedo) { + // Jimenez et al. 2016, "Practical Realtime Strategies for Accurate Indirect Occlusion" + half3 a = 2.0404 * albedo - 0.3324; + half3 b = -4.7951 * albedo + 0.6417; + half3 c = 2.7552 * albedo + 0.6903; + + return max((visibility), ((visibility * a + b) * visibility + c) * visibility); +} +#endif + +void multiBounceAO(half visibility, const half3 albedo, inout half3 color) { +#if MULTI_BOUNCE_AMBIENT_OCCLUSION == 1 + color *= gtaoMultiBounce(visibility, albedo); +#endif +} + +void multiBounceSpecularAO(half visibility, const half3 albedo, inout half3 color) { +#if MULTI_BOUNCE_AMBIENT_OCCLUSION == 1 && SPECULAR_AMBIENT_OCCLUSION != SPECULAR_AO_OFF + color *= gtaoMultiBounce(visibility, albedo); +#endif +} + +half singleBounceAO(half visibility) { +#if MULTI_BOUNCE_AMBIENT_OCCLUSION == 1 + return 1.0; +#else + return visibility; +#endif +} + +#endif // FILAMENT_COMMON_OCCLUSION diff --git a/Assets/Filamented/FilamentCommonOcclusion.cginc.meta b/Assets/Filamented/FilamentCommonOcclusion.cginc.meta new file mode 100644 index 0000000..4d36cbf --- /dev/null +++ b/Assets/Filamented/FilamentCommonOcclusion.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: ee3cbadb87ab9a24bb6e23ffd201081e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentCommonShading.cginc b/Assets/Filamented/FilamentCommonShading.cginc new file mode 100644 index 0000000..234b05e --- /dev/null +++ b/Assets/Filamented/FilamentCommonShading.cginc @@ -0,0 +1,57 @@ +#ifndef FILAMENT_COMMON_SHADING +#define FILAMENT_COMMON_SHADING +/* +// These variables should be in a struct but some GPU drivers ignore the +// precision qualifier on individual struct members +highp float3x3 shading_tangentToWorld; // TBN matrix +highp float3 shading_position; // position of the fragment in world space + float3 shading_view; // normalized vector from the fragment to the eye + float3 shading_normal; // normalized transformed normal, in world space + float3 shading_geometricNormal; // normalized geometric normal, in world space + float3 shading_reflected; // reflection of view about normal + float shading_NoV; // dot(normal, view), always strictly >= MIN_N_DOT_V + +#if defined(MATERIAL_HAS_BENT_NORMAL) + float3 shading_bentNormal; // normalized transformed normal, in world space +#endif + +#if defined(MATERIAL_HAS_CLEAR_COAT) + float3 shading_clearCoatNormal; // normalized clear coat layer normal, in world space +#endif + +highp float2 shading_normalizedViewportCoord; +*/ + +// Worry about that problem later. +struct ShadingParams { + float3x3 tangentToWorld; // TBN matrix + float3 position; // position of the fragment in world space + half3 view; // normalized vector from the fragment to the eye + half3 normal; // normalized transformed normal, in world space + half3 geometricNormal; // normalized geometric normal, in world space + half3 reflected; // reflection of view about normal + half NoV; // dot(normal, view), always strictly >= MIN_N_DOT_V + +#if defined(MATERIAL_HAS_BENT_NORMAL) + half3 bentNormal; // normalized transformed normal, in world space +#endif + +#if defined(MATERIAL_HAS_CLEAR_COAT) + half3 clearCoatNormal; // normalized clear coat layer normal, in world space +#endif + + half2 normalizedViewportCoord; + + // These parameters are provided to inject Unity lighting into Filament data. + half attenuation; + half3 ambient; + half4 lightmapUV; + +#if defined(USING_BAKERY_VERTEXLMSH) + half3 ambientSH[3]; +#elif defined(USING_BAKERY_VERTEXLMDIR) + half3 ambientDir; +#endif + +}; +#endif // FILAMENT_COMMON_SHADING diff --git a/Assets/Filamented/FilamentCommonShading.cginc.meta b/Assets/Filamented/FilamentCommonShading.cginc.meta new file mode 100644 index 0000000..095a029 --- /dev/null +++ b/Assets/Filamented/FilamentCommonShading.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8a20a50a44d8c5c4c84c86eb379db405 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentLightDirectional.cginc b/Assets/Filamented/FilamentLightDirectional.cginc new file mode 100644 index 0000000..def2156 --- /dev/null +++ b/Assets/Filamented/FilamentLightDirectional.cginc @@ -0,0 +1,90 @@ +#ifndef FILAMENT_LIGHT_DIRECTIONAL +#define FILAMENT_LIGHT_DIRECTIONAL + +#include "UnityLightingCommon.cginc" +//------------------------------------------------------------------------------ +// Directional light evaluation +//------------------------------------------------------------------------------ + +#if FILAMENT_QUALITY < FILAMENT_QUALITY_HIGH +//#define SUN_AS_AREA_LIGHT +#endif + +half3 sampleSunAreaLight(const half3 lightDirection, const ShadingParams shading) { + // Replaced frameUniforms.sun +#if defined(SUN_AS_AREA_LIGHT) + // cos(sunAngle), sin(sunAngle), 1/(sunAngle*HALO_SIZE-sunAngle), HALO_EXP + static const half sunAngle = 0.00951f; + static const half sunHaloSize = 10.0f; + static const half sunHaloFalloff = 80.0f; + static const half4 sunParameters = half4(cos(sunAngle), sin(sunAngle), 1/(sunAngle*sunHaloSize-sunAngle), sunHaloFalloff); + if (sunParameters.w >= 0.0) { + // simulate sun as disc area light + half LoR = dot(lightDirection, shading.reflected); + half d = sunParameters.x; + float3 s = shading.reflected - LoR * lightDirection; + return LoR < d ? + normalize(lightDirection * d + normalize(s) * sunParameters.y) : shading.reflected; + } +#endif + return lightDirection; +} + +half4 UnityLight_ColorIntensitySeperated() { + return half4(_LightColor0.xyz, 1.0); + + if (_LightColor0.w <= 0) return 0.0; + _LightColor0 += 0.000001; + return half4(_LightColor0.xyz / _LightColor0.w, _LightColor0.w); +} + +Light getDirectionalLight(ShadingParams shading) { + Light light; + // note: lightColorIntensity.w is always premultiplied by the exposure + light.colorIntensity = UnityLight_ColorIntensitySeperated(); + light.l = sampleSunAreaLight(_WorldSpaceLightPos0.xyz, shading); + light.attenuation = 1.0; + light.NoL = saturate(dot(shading.normal, light.l)); + return light; +} + +// Much of this function has changed from the original because we still use +// Unity's BIRP shadow handling. Sorry! +void evaluateDirectionalLight(const ShadingParams shading, const MaterialInputs material, + const PixelParams pixel, inout half3 color) { + + Light light = getDirectionalLight(shading); + + half visibility = 1.0; +#if defined(HAS_SHADOWING) + if (light.NoL > 0.0) { + half ssContactShadowOcclusion = 0.0; + + // hasDirectionalShadows && cascadeHasVisibleShadows + if (1) { + visibility*=shading.attenuation; + // apply directional shadows to visibility here + } + // if contact shadows are enabled + if (true && visibility > 0.0) { + // ssContactShadowOcclusion = screenSpaceContactShadow(light.l); + } + + visibility *= 1.0 - ssContactShadowOcclusion; + + #if defined(MATERIAL_HAS_AMBIENT_OCCLUSION) + visibility *= computeMicroShadowing(light.NoL, material.ambientOcclusion * 1.6 + 0.2); + #endif + } else { +#if defined(MATERIAL_CAN_SKIP_LIGHTING) + return; +#endif + } +#elif defined(MATERIAL_CAN_SKIP_LIGHTING) + if (light.NoL <= 0.0) return; +#endif + + color.rgb += surfaceShading(shading, pixel, light, visibility); +} + +#endif // FILAMENT_LIGHT_DIRECTIONAL diff --git a/Assets/Filamented/FilamentLightDirectional.cginc.meta b/Assets/Filamented/FilamentLightDirectional.cginc.meta new file mode 100644 index 0000000..f0b5cc2 --- /dev/null +++ b/Assets/Filamented/FilamentLightDirectional.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 57bf21b20c08f4f449bbd667549ef91b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentLightIndirect.cginc b/Assets/Filamented/FilamentLightIndirect.cginc new file mode 100644 index 0000000..21ce9ef --- /dev/null +++ b/Assets/Filamented/FilamentLightIndirect.cginc @@ -0,0 +1,1083 @@ +#ifndef FILAMENT_LIGHT_INDIRECT +#define FILAMENT_LIGHT_INDIRECT + +#include "FilamentCommonOcclusion.cginc" +#include "FilamentCommonGraphics.cginc" +#include "FilamentBRDF.cginc" +#include "UnityImageBasedLightingMinimal.cginc" +#include "UnityStandardUtils.cginc" +#include "UnityLightingCommon.cginc" +#include "SharedFilteringLib.hlsl" +#include "SharedSHLib.hlsl" +#include "SharedLightmapLib.hlsl" + +#include "FilamentLightLTCGI.cginc" +#include "FilamentLightVRCLV.cginc" +#include "FilamentLightMirror.cginc" + +//------------------------------------------------------------------------------ +// Image based lighting configuration +//------------------------------------------------------------------------------ + +// Spherical harmonics sampling algorithm +// Unity's default; basic SH sampling, with L2 SH enabled +#define SPHERICAL_HARMONICS_DEFAULT 0 +// Geometrics' deringing lightprobe sampling, using L1 SH +#define SPHERICAL_HARMONICS_GEOMETRICS 1 +// Activision's Quadratic Zonal Harmonics, using L1 SH +#define SPHERICAL_HARMONICS_ZH3 2 + +#define SPHERICAL_HARMONICS SPHERICAL_HARMONICS_ZH3 +// VRC Light Volumes-specific +#define SPHERICAL_HARMONICS_VRCLV SPHERICAL_HARMONICS_GEOMETRICS + + +// Whether to use non-linear SH sampling on Bakery lightmap modes. +// If ZH3 sampling is used, it will be used here. This increases the quality of the directional +// lighting on lightmapped surfaces, in exchange for a performance cost. +#define BAKERY_SHNONLINEAR 0 + +// IBL integration algorithm +#define IBL_INTEGRATION_PREFILTERED_CUBEMAP 0 +#define IBL_INTEGRATION_IMPORTANCE_SAMPLING 1 // Not supported! + +#define IBL_INTEGRATION IBL_INTEGRATION_PREFILTERED_CUBEMAP + +#define IBL_INTEGRATION_IMPORTANCE_SAMPLING_COUNT 64 + +// Refraction defines +#define REFRACTION_TYPE_SOLID 0 +#define REFRACTION_TYPE_THIN 1 + +#ifndef REFRACTION_TYPE +#define REFRACTION_TYPE REFRACTION_TYPE_SOLID +#endif + +#define REFRACTION_MODE_CUBEMAP 0 +#define REFRACTION_MODE_SCREEN 1 + +#ifndef REFRACTION_MODE +#define REFRACTION_MODE REFRACTION_MODE_CUBEMAP +#endif + +//------------------------------------------------------------------------------ +// IBL prefiltered DFG term implementations +//------------------------------------------------------------------------------ + +half3 PrefilteredDFG_LUT(half lod, half NoV) { + #if defined(USE_DFG_LUT) + // coord = sqrt(linear_roughness), which is the mapping used by cmgen. + return UNITY_SAMPLE_TEX2D(_DFG, half2(NoV, lod)); + #else + // Texture not available + return float3(1.0, 0.0, 0.0); + #endif +} + +//------------------------------------------------------------------------------ +// IBL environment BRDF dispatch +//------------------------------------------------------------------------------ + +half3 prefilteredDFG(half perceptualRoughness, half NoV) { + #if defined(USE_DFG_LUT) + // PrefilteredDFG_LUT() takes a LOD, which is sqrt(roughness) = perceptualRoughness + return PrefilteredDFG_LUT(perceptualRoughness, NoV); + #else + #if 0 + // Karis' approximation based on Lazarov's + const half4 c0 = half4(-1.0, -0.0275, -0.572, 0.022); + const half4 c1 = half4( 1.0, 0.0425, 1.040, -0.040); + half4 r = perceptualRoughness * c0 + c1; + half a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y; + return (half3(half2(-1.04, 1.04) * a004 + r.zw, 0.0)); + #endif + #if 0 + // Zioma's approximation based on Karis + return half3(half2(1.0, pow(1.0 - max(perceptualRoughness, NoV), 3.0)), 0.0); + #endif + return half3(0, 1, 1); + #endif +} + +//------------------------------------------------------------------------------ +// IBL irradiance implementations +//------------------------------------------------------------------------------ + +half3 Irradiance_SphericalHarmonics(const half3 n, const bool useL2) { + // Uses Unity's functions for reading SH. + half3 finalSH = half3(0,0,0); + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_DEFAULT) + finalSH = SHEvalLinearL0L1(half4(n, 1.0)); + #endif + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_GEOMETRICS) + half3 L0 = half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); + half3 L0L2 = half3(unity_SHBr.z, unity_SHBg.z, unity_SHBb.z) / 3.0; + L0 = (useL2) ? L0+L0L2 : L0-L0L2; + finalSH.r = shEvaluateDiffuseL1Geomerics_local(L0.r, unity_SHAr.xyz, n); + finalSH.g = shEvaluateDiffuseL1Geomerics_local(L0.g, unity_SHAg.xyz, n); + finalSH.b = shEvaluateDiffuseL1Geomerics_local(L0.b, unity_SHAb.xyz, n); + // Quadratic polynomials + #endif + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_ZH3) + finalSH = SHEvalLinearL0L1_ZH3Hallucinate(half4(n, 1.0)); + #endif + + // L2 contribution. + // Note that if UNITY_SAMPLE_FULL_SH_PER_PIXEL is not set, L2 will not be added here! + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_DEFAULT) + if (useL2) finalSH += SHEvalLinearL2(half4(n, 1.0)); + #endif + + return finalSH; +} + +half3 Irradiance_SphericalHarmonics(const float3 n) { + // Assume L2 is wanted + return Irradiance_SphericalHarmonics(n, true); +} + +#if UNITY_LIGHT_PROBE_PROXY_VOLUME +// normal should be normalized, w=1.0 +half3 Irradiance_SampleProbeVolume (half4 normal, float3 worldPos) +{ + const float transformToLocal = unity_ProbeVolumeParams.y; + const float texelSizeX = unity_ProbeVolumeParams.z; + + //The SH coefficients textures and probe occlusion are packed into 1 atlas. + //------------------------- + //| ShR | ShG | ShB | Occ | + //------------------------- + + float3 position = (transformToLocal == 1.0f) ? mul(unity_ProbeVolumeWorldToObject, float4(worldPos, 1.0)).xyz : worldPos; + float3 texCoord = (position - unity_ProbeVolumeMin.xyz) * unity_ProbeVolumeSizeInv.xyz; + texCoord.x = texCoord.x * 0.25f; + + // We need to compute proper X coordinate to sample. + // Clamp the coordinate otherwize we'll have leaking between RGB coefficients + float texCoordX = clamp(texCoord.x, 0.5f * texelSizeX, 0.25f - 0.5f * texelSizeX); + + // sampler state comes from SHr (all SH textures share the same sampler) + texCoord.x = texCoordX; + half4 SHAr = UNITY_SAMPLE_TEX3D_SAMPLER(unity_ProbeVolumeSH, unity_ProbeVolumeSH, texCoord); + + texCoord.x = texCoordX + 0.25f; + half4 SHAg = UNITY_SAMPLE_TEX3D_SAMPLER(unity_ProbeVolumeSH, unity_ProbeVolumeSH, texCoord); + + texCoord.x = texCoordX + 0.5f; + half4 SHAb = UNITY_SAMPLE_TEX3D_SAMPLER(unity_ProbeVolumeSH, unity_ProbeVolumeSH, texCoord); + + // Linear + constant polynomial terms + half3 x1; + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_DEFAULT) + x1.r = dot(SHAr, normal); + x1.g = dot(SHAg, normal); + x1.b = dot(SHAb, normal); + #endif + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_GEOMETRICS) + x1.r = shEvaluateDiffuseL1Geomerics_local(SHAr.w, SHAr.rgb, normal); + x1.g = shEvaluateDiffuseL1Geomerics_local(SHAg.w, SHAg.rgb, normal); + x1.b = shEvaluateDiffuseL1Geomerics_local(SHAb.w, SHAb.rgb, normal); + #endif + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_ZH3) + x1.r = SHEvalLinearL0L1_ZH3Hallucinate(float4(SHAr.w, SHAr.rgb), normal); + x1.g = SHEvalLinearL0L1_ZH3Hallucinate(float4(SHAg.w, SHAg.rgb), normal); + x1.b = SHEvalLinearL0L1_ZH3Hallucinate(float4(SHAb.w, SHAb.rgb), normal); + #endif + + return x1; +} +#endif + + +#if defined(_VRCLV) +half3 Irradiance_SampleVRCLightVolume(half3 normal, float3 worldPos, out Light derivedLight) +{ + derivedLight = (Light)0; + + // Bias sampling by surface normal to avoid artifacts + // Fetch Spherical Harmonics (SH) components from the VRC Light Volume + float3 L0, L1r, L1g, L1b; + LightVolumeSH(worldPos, L0, L1r, L1g, L1b, normal * getLightVolumeSurfaceBias()); + + // Compute irradiance using the SH components + half3 irradiance = 0.0; + + #if (SPHERICAL_HARMONICS_VRCLV == SPHERICAL_HARMONICS_DEFAULT) + irradiance.r = dot(L1r, normal.xyz) + L0.r; + irradiance.g = dot(L1g, normal.xyz) + L0.g; + irradiance.b = dot(L1b, normal.xyz) + L0.b; + #endif + + #if (SPHERICAL_HARMONICS_VRCLV == SPHERICAL_HARMONICS_GEOMETRICS) + irradiance.r = shEvaluateDiffuseL1Geomerics_local(L0.r, L1r, normal.xyz); + irradiance.g = shEvaluateDiffuseL1Geomerics_local(L0.g, L1g, normal.xyz); + irradiance.b = shEvaluateDiffuseL1Geomerics_local(L0.b, L1b, normal.xyz); + #endif + + #if (SPHERICAL_HARMONICS_VRCLV == SPHERICAL_HARMONICS_ZH3) + irradiance = SHEvalLinearL0L1_ZH3Hallucinate(normal.xyz, L0, L1r, L1g, L1b); + #endif + + #if defined(LIGHTMAP_SPECULAR) + half3 nL1x; half3 nL1y; half3 nL1z; + nL1x = half3(L1r[0], L1g[0], L1b[0]); + nL1y = half3(L1r[1], L1g[1], L1b[1]); + nL1z = half3(L1r[2], L1g[2], L1b[2]); + half3 dominantDir = half3(luminance(nL1x), luminance(nL1y), luminance(nL1z)); + + // Determine the light's direction and directionality + half L0_lum = max(FLT_EPS, luminance(L0)); + half L1_mag = length(dominantDir); + half directionality = saturate(L1_mag / L0_lum); + derivedLight.l = dominantDir / L1_mag; + + half3 directionalColor = half3(dot(L1r, derivedLight.l), dot(L1g, derivedLight.l), dot(L1b, derivedLight.l)); + half3 Li = L0 + max(0, directionalColor); + + derivedLight.colorIntensity = half4(Li, 1.0); + derivedLight.attenuation = directionality; + derivedLight.NoL = saturate(dot(normal, derivedLight.l)); + #endif + + return irradiance; +} + +half3 Irradiance_SampleVRCLightVolumeAdditive(half3 normal, float3 worldPos, out Light derivedLight) +{ + derivedLight = (Light)0; + + // Fetch Spherical Harmonics (SH) components from the VRC Light Volume + half3 L0, L1r, L1g, L1b; + LightVolumeAdditiveSH(worldPos, L0, L1r, L1g, L1b, normal * getLightVolumeSurfaceBias()); + + // Compute irradiance using the SH components + half3 irradiance = 0.0; + + // Doesn't support non-linear evaluation, so just evaluate normally. + irradiance.r = dot(L1r, normal.xyz) + L0.r; + irradiance.g = dot(L1g, normal.xyz) + L0.g; + irradiance.b = dot(L1b, normal.xyz) + L0.b; + + // Add derived light to existing derived light + #if defined(LIGHTMAP_SPECULAR) + half3 nL1x; half3 nL1y; half3 nL1z; + nL1x = half3(L1r[0], L1g[0], L1b[0]); + nL1y = half3(L1r[1], L1g[1], L1b[1]); + nL1z = half3(L1r[2], L1g[2], L1b[2]); + half3 dominantDir = half3(luminance(nL1x), luminance(nL1y), luminance(nL1z)); + + // Determine the light's direction and directionality + half L0_lum = max(FLT_EPS, luminance(L0)); + half L1_mag = length(dominantDir); + half directionality = saturate(L1_mag / L0_lum); + derivedLight.l = dominantDir / L1_mag; + + half3 directionalColor = half3(dot(L1r, derivedLight.l), dot(L1g, derivedLight.l), dot(L1b, derivedLight.l)); + half3 Li = L0 + max(0, directionalColor); + + derivedLight.colorIntensity = half4(Li, 1.0); + derivedLight.attenuation = directionality; + derivedLight.NoL = saturate(dot(normal, derivedLight.l)); + #endif + + return irradiance; +} +#endif + +half3 Irradiance_SphericalHarmonicsUnity (half3 normal, half3 ambient, float3 worldPos, out Light derivedLight) +{ + half3 ambient_contrib = 0.0; + derivedLight = (Light)0; + + // Gather VRC Light Volumes data, if present. + // This replaces the result of light probes. +#if defined(_VRCLV) + #if UNITY_LIGHT_PROBE_PROXY_VOLUME // I feel like this is an insane edge case + if (unity_ProbeVolumeParams.x == 1.0) + ambient_contrib = Irradiance_SampleProbeVolume(half4(normal, 1.0), worldPos); + else + ambient_contrib = Irradiance_SampleVRCLightVolume(normal, worldPos, derivedLight); + #else + ambient_contrib = Irradiance_SampleVRCLightVolume(normal, worldPos, derivedLight); + #endif + + ambient += max(half3(0, 0, 0), ambient_contrib); + + #ifdef UNITY_COLORSPACE_GAMMA + ambient = LinearToGammaSpace (ambient); + #endif + + return ambient; +#else + + #if UNITY_SAMPLE_FULL_SH_PER_PIXEL + // Completely per-pixel + #if UNITY_LIGHT_PROBE_PROXY_VOLUME + if (unity_ProbeVolumeParams.x == 1.0) + ambient_contrib = Irradiance_SampleProbeVolume(half4(normal, 1.0), worldPos); + else + ambient_contrib = Irradiance_SphericalHarmonics(normal, true); + #else + ambient_contrib = Irradiance_SphericalHarmonics(normal, true); + #endif + + ambient += max(half3(0, 0, 0), ambient_contrib); + + #ifdef UNITY_COLORSPACE_GAMMA + ambient = LinearToGammaSpace(ambient); + #endif + #elif (SHADER_TARGET < 30) || UNITY_STANDARD_SIMPLE + // Completely per-vertex + // nothing to do here. Gamma conversion on ambient from SH takes place in the vertex shader, see ShadeSHPerVertex. + #else + // L2 per-vertex, L0..L1 & gamma-correction per-pixel + // Ambient in this case is expected to be always Linear, see ShadeSHPerVertex() + #if UNITY_LIGHT_PROBE_PROXY_VOLUME + if (unity_ProbeVolumeParams.x == 1.0) + ambient_contrib = Irradiance_SampleProbeVolume (half4(normal, 1.0), worldPos); + else + ambient_contrib = Irradiance_SphericalHarmonics(normal, false); + #else + ambient_contrib = Irradiance_SphericalHarmonics(normal, false); + #endif + + ambient = max(half3(0, 0, 0), ambient+ambient_contrib); // include L2 contribution in vertex shader before clamp. + #ifdef UNITY_COLORSPACE_GAMMA + ambient = LinearToGammaSpace (ambient); + #endif + #endif + + return ambient; +#endif +} + +/* +half3 Irradiance_RoughnessOne(const half3 n) { + // note: lod used is always integer, hopefully the hardware skips tri-linear filtering + return decodeDataForIBL(textureLod(light_iblSpecular, n, frameUniforms.iblRoughnessOneLevel)); +} +*/ + +half IrradianceToExposureOcclusion(half3 irradiance) +{ + return saturate(length(irradiance + FLT_EPS) * getExposureOcclusionBias()); +} + +// Return light probes or lightmap. +float3 UnityGI_Irradiance(ShadingParams shading, float3 tangentNormal, out half occlusion, out Light derivedLight) +{ + float3 irradiance = shading.ambient; + // In order for the exposure occlusion to handle mixed lightmaps and etc well, we accumulate + // irradiance seperately, and calculate the exposure occlusion from that to avoid having directionality influence it. + float3 irradianceForAO; + occlusion = 1.0; + derivedLight = (Light)0; + + #if UNITY_SHOULD_SAMPLE_SH + irradiance += Irradiance_SphericalHarmonicsUnity(shading.normal, shading.ambient, shading.position, derivedLight); + #endif + + irradianceForAO = irradiance; + + // Should be stripped out at compile time if vertex LM mode is disabled. + if (getIsBakeryVertexMode() == false) + { + #if defined(LIGHTMAP_ON) + // Baked lightmaps + half4 bakedColorTex = SampleLightmapBicubic(shading.lightmapUV.xy); + half3 bakedColor = DecodeLightmap(bakedColorTex); + + #ifdef DIRLIGHTMAP_COMBINED + fixed4 bakedDirTex = SampleLightmapDirBicubic (shading.lightmapUV.xy); + + // Bakery's MonoSH mode replaces the regular directional lightmap + #if defined(_BAKERY_MONOSH) + irradiance = DecodeMonoSHLightmap (bakedColor, bakedDirTex, shading.normal, derivedLight); + + irradianceForAO = irradiance; + + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + irradiance = SubtractMainLightWithRealtimeAttenuationFromLightmap (irradiance, shading.attenuation, bakedColorTex, shading.normal); + #endif + #else + irradiance = DecodeDirectionalLightmap (bakedColor, bakedDirTex, shading.normal); + + irradianceForAO = irradiance; + + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + irradiance = SubtractMainLightWithRealtimeAttenuationFromLightmap (irradiance, shading.attenuation, bakedColorTex, shading.normal); + #endif + + #if defined(LIGHTMAP_SPECULAR) + irradiance = DecodeDirectionalLightmapSpecular(bakedColor, bakedDirTex, shading.normal, false, 0, derivedLight); + #endif + #endif + + #else // not directional lightmap + + #if defined(USING_BAKERY) + #if defined(_BAKERY_RNM) + // bakery rnm mode + irradiance = DecodeRNMLightmap(bakedColor, shading.lightmapUV.xy, tangentNormal, shading.tangentToWorld, derivedLight); + #endif + + #if defined(_BAKERY_SH) + // bakery sh mode + irradiance = DecodeSHLightmap(bakedColor, shading.lightmapUV.xy, shading.normal, derivedLight); + #endif + + irradianceForAO = irradiance; + + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + irradiance = SubtractMainLightWithRealtimeAttenuationFromLightmap(irradiance, shading.attenuation, bakedColorTex, shading.normal); + #endif + + #else + + irradiance += bakedColor; + + irradianceForAO = irradiance; + + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + irradiance = SubtractMainLightWithRealtimeAttenuationFromLightmap(irradiance, shading.attenuation, bakedColorTex, shading.normal); + #endif + #endif + + #endif + #endif + } + #if defined(USING_BAKERY_VERTEXLM) + if (getIsBakeryVertexMode() == true) + { + // Lightmap colour is already stored in shading.ambient. + // If directionality is on, then ambientDir contains directionality. + // If SH is on, then ambientSH[3] contains the SH data. + half4 bakedColorTex = float4(shading.ambient, 1.0); + + #if defined(USING_BAKERY_VERTEXLMSH) + irradiance = DecodeSHLightmapVertex(shading.ambient, shading.ambientSH, shading.normal, derivedLight); + irradianceForAO = irradiance; + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + irradiance = SubtractMainLightWithRealtimeAttenuationFromLightmap (irradiance, shading.attenuation, bakedColorTex, shading.normal); + #endif + #else + #if defined(USING_BAKERY_VERTEXLMDIR) + #if defined(_BAKERY_MONOSH) + irradiance = DecodeMonoSHLightmap (shading.ambient, shading.ambientDir, shading.normal, derivedLight, false); + irradianceForAO = irradiance; + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + irradiance = SubtractMainLightWithRealtimeAttenuationFromLightmap (irradiance, shading.attenuation, bakedColorTex, shading.normal); + #endif + #else + irradiance = DecodeDirectionalLightmap (shading.ambient, shading.ambientDir, shading.normal); + irradianceForAO = irradiance; + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + irradiance = SubtractMainLightWithRealtimeAttenuationFromLightmap (irradiance, shading.attenuation, bakedColorTex, shading.normal); + #endif + #if defined(LIGHTMAP_SPECULAR) + irradiance = DecodeDirectionalLightmapSpecular(shading.ambient, shading.ambientDir, shading.normal, false, 0, derivedLight); + #endif + #endif + #else + // No directionality, just light colour. + // Irradiance and IrradianceForAO already contain the irradiance, so just handle subtractive lighting. + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + irradiance = SubtractMainLightWithRealtimeAttenuationFromLightmap(irradiance, shading.attenuation, bakedColorTex, shading.normal); + #endif + #endif + #endif + } + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + // Dynamic lightmaps + fixed4 realtimeColorTex = SampleDynamicLightmapBicubic(shading.lightmapUV.zw); + half3 realtimeColor = DecodeRealtimeLightmap (realtimeColorTex); + + irradianceForAO += realtimeColor; + + #ifdef DIRLIGHTMAP_COMBINED + half4 realtimeDirTex = SampleDynamicLightmapDirBicubic(shading.lightmapUV.zw); + irradiance += DecodeDirectionalLightmap (realtimeColor, realtimeDirTex, shading.normal); + #else + irradiance += realtimeColor; + #endif + #endif + + occlusion = IrradianceToExposureOcclusion(irradianceForAO); + + return irradiance; +} + +//------------------------------------------------------------------------------ +// IBL irradiance dispatch +//------------------------------------------------------------------------------ + +half3 get_diffuseIrradiance_notUsed(const half3 n) { + return Irradiance_SphericalHarmonics(n); +} +//------------------------------------------------------------------------------ +// IBL specular +//------------------------------------------------------------------------------ + +UnityGIInput InitialiseUnityGIInput(const ShadingParams shading, const PixelParams pixel) +{ + UnityGIInput d; + d.worldPos = shading.position; + d.worldViewDir = -shading.view; + d.probeHDR[0] = unity_SpecCube0_HDR; + d.probeHDR[1] = unity_SpecCube1_HDR; + #if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) + d.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending + #endif + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + d.boxMax[0] = unity_SpecCube0_BoxMax; + d.probePosition[0] = unity_SpecCube0_ProbePosition; + d.boxMax[1] = unity_SpecCube1_BoxMax; + d.boxMin[1] = unity_SpecCube1_BoxMin; + d.probePosition[1] = unity_SpecCube1_ProbePosition; + #endif + return d; +} + +half perceptualRoughnessToLod(half perceptualRoughness) { + const half iblRoughnessOneLevel = 1.0/UNITY_SPECCUBE_LOD_STEPS; + // The mapping below is a quadratic fit for log2(perceptualRoughness)+iblRoughnessOneLevel when + // iblRoughnessOneLevel is 4. We found empirically that this mapping works very well for + // a 256 cubemap with 5 levels used. But also scales well for other iblRoughnessOneLevel values. + //return iblRoughnessOneLevel * perceptualRoughness * (2.0 - perceptualRoughness); + + // Unity's remapping (UNITY_SPECCUBE_LOD_STEPS is 6, not 4) + return iblRoughnessOneLevel * perceptualRoughness * (1.7 - 0.7 * perceptualRoughness); +} + +half3 prefilteredRadiance(const half3 r, half perceptualRoughness) { + half lod = perceptualRoughnessToLod(perceptualRoughness); + return DecodeHDR(UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, r, lod), unity_SpecCube0_HDR); +} + +half3 prefilteredRadiance(const half3 r, half roughness, half offset) { + const half iblRoughnessOneLevel = 1.0/UNITY_SPECCUBE_LOD_STEPS; + half lod = iblRoughnessOneLevel * roughness; + return DecodeHDR(UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, r, lod + offset), unity_SpecCube0_HDR); +} + +half3 Unity_GlossyEnvironment_local (UNITY_ARGS_TEXCUBE(tex), half4 hdr, Unity_GlossyEnvironmentData glossIn) +{ + half perceptualRoughness = glossIn.roughness /* perceptualRoughness */ ; + + // Workaround for issue where objects are blurrier than they should be + // due to specular AA. + #if defined(GEOMETRIC_SPECULAR_AA) + half roughnessAdjustment = 1-perceptualRoughness; + roughnessAdjustment = MIN_PERCEPTUAL_ROUGHNESS * roughnessAdjustment * roughnessAdjustment; + perceptualRoughness = perceptualRoughness - roughnessAdjustment; + #endif + + // Unity derivation + perceptualRoughness = perceptualRoughness*(1.7 - 0.7 * perceptualRoughness); + // Filament derivation + // perceptualRoughness = perceptualRoughness * (2.0 - perceptualRoughness); + half mip = perceptualRoughnessToMipmapLevel(perceptualRoughness); + half3 R = glossIn.reflUVW; + half4 rgbm = UNITY_SAMPLE_TEXCUBE_LOD(tex, R, mip); + + return DecodeHDR(rgbm, hdr); +} + +// Workaround: Construct the correct Unity variables and get the correct Unity spec values + +inline half3 UnityGI_prefilteredRadiance(const UnityGIInput data, const half perceptualRoughness, const float3 r) +{ + half3 specular; + + Unity_GlossyEnvironmentData glossIn = (Unity_GlossyEnvironmentData)0; + glossIn.roughness = perceptualRoughness; + glossIn.reflUVW = r; + + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + // we will tweak reflUVW in glossIn directly (as we pass it to Unity_GlossyEnvironment twice for probe0 and probe1), so keep original to pass into BoxProjectedCubemapDirection + half3 originalReflUVW = glossIn.reflUVW; + glossIn.reflUVW = BoxProjectedCubemapDirection (originalReflUVW, data.worldPos, data.probePosition[0], data.boxMin[0], data.boxMax[0]); + #endif + + #ifdef _GLOSSYREFLECTIONS_OFF + specular = unity_IndirectSpecColor.rgb; + #else + half3 env0 = Unity_GlossyEnvironment_local (UNITY_PASS_TEXCUBE(unity_SpecCube0), data.probeHDR[0], glossIn); + #ifdef UNITY_SPECCUBE_BLENDING + const float kBlendFactor = 0.99999; + float blendLerp = data.boxMin[0].w; + UNITY_BRANCH + if (blendLerp < kBlendFactor) + { + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + glossIn.reflUVW = BoxProjectedCubemapDirection (originalReflUVW, data.worldPos, data.probePosition[1], data.boxMin[1], data.boxMax[1]); + #endif + + half3 env1 = Unity_GlossyEnvironment_local (UNITY_PASS_TEXCUBE_SAMPLER(unity_SpecCube1,unity_SpecCube0), data.probeHDR[1], glossIn); + specular = lerp(env1, env0, blendLerp); + } + else + { + specular = env0; + } + #else + specular = env0; + #endif + #endif + + return specular; +} + +half3 getSpecularDominantDirection(const half3 n, const half3 r, half roughness) { + return lerp(r, n, roughness * roughness); +} + +half3 specularDFG(const PixelParams pixel) { +#if defined(SHADING_MODEL_CLOTH) + return pixel.f0 * pixel.dfg.z; +#else + return lerp(pixel.dfg.xxx, pixel.dfg.yyy, pixel.f0); +#endif +} + +/** + * Returns the reflected vector at the current shading point. The reflected vector + * return by this function might be different from shading.reflected: + * - For anisotropic material, we bend the reflection vector to simulate + * anisotropic indirect lighting + * - The reflected vector may be modified to point towards the dominant specular + * direction to match reference renderings when the roughness increases + */ + +half3 getReflectedVector(const PixelParams pixel, const half3 v, const half3 n) { +#if defined(MATERIAL_HAS_ANISOTROPY) + half3 anisotropyDirection = pixel.anisotropy >= 0.0 ? pixel.anisotropicB : pixel.anisotropicT; + half3 anisotropicTangent = cross(anisotropyDirection, v); + half3 anisotropicNormal = cross(anisotropicTangent, anisotropyDirection); + half bendFactor = abs(pixel.anisotropy) * saturate(5.0 * pixel.perceptualRoughness); + half3 bentNormal = normalize(lerp(n, anisotropicNormal, bendFactor)); + + half3 r = reflect(-v, bentNormal); +#else + half3 r = reflect(-v, n); +#endif + return r; +} + +half3 getReflectedVector(const ShadingParams shading, const PixelParams pixel, const half3 n) { +#if defined(MATERIAL_HAS_ANISOTROPY) + half3 r = getReflectedVector(pixel, shading.view, n); +#else + half3 r = shading.reflected; +#endif + return getSpecularDominantDirection(n, r, pixel.roughness); +} + +//------------------------------------------------------------------------------ +// Prefiltered importance sampling +//------------------------------------------------------------------------------ + +#if IBL_INTEGRATION == IBL_INTEGRATION_IMPORTANCE_SAMPLING + +void isEvaluateClearCoatIBL(const ShadingParams shading, const PixelParams pixel, + half specularAO, inout half3 Fd, inout half3 Fr) { +#if defined(MATERIAL_HAS_CLEAR_COAT) +#if defined(MATERIAL_HAS_NORMAL) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL) + // We want to use the geometric normal for the clear coat layer + half clearCoatNoV = clampNoV(dot(shading.clearCoatNormal, shading.view)); + half3 clearCoatNormal = shading.clearCoatNormal; +#else + half clearCoatNoV = shading.NoV; + half3 clearCoatNormal = shading.normal; +#endif + // The clear coat layer assumes an IOR of 1.5 (4% reflectance) + half Fc = F_Schlick(0.04, 1.0, clearCoatNoV) * pixel.clearCoat; + half attenuation = 1.0 - Fc; + Fd *= attenuation; + Fr *= attenuation; + + PixelParams p; + p.perceptualRoughness = pixel.clearCoatPerceptualRoughness; + p.f0 = 0.04; + p.roughness = perceptualRoughnessToRoughness(p.perceptualRoughness); +#if defined(MATERIAL_HAS_ANISOTROPY) + p.anisotropy = 0.0; +#endif + + half3 clearCoatLobe = isEvaluateSpecularIBL(p, clearCoatNormal, shading.view, clearCoatNoV); + Fr += clearCoatLobe * (specularAO * pixel.clearCoat); +#endif +} +#endif + + +//------------------------------------------------------------------------------ +// IBL evaluation +//------------------------------------------------------------------------------ + +void evaluateClothIndirectDiffuseBRDF(const ShadingParams shading, const PixelParams pixel, + inout half diffuse) { +#if defined(SHADING_MODEL_CLOTH) +#if defined(MATERIAL_HAS_SUBSURFACE_COLOR) + // Simulate subsurface scattering with a wrap diffuse term + diffuse *= Fd_Wrap(shading.NoV, 0.5); +#endif +#endif +} + +void evaluateSheenIBL(const ShadingParams shading, const PixelParams pixel, const UnityGIInput unityData, + half diffuseAO, inout half3 Fd, inout half3 Fr) { +#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SUBSURFACE) +#if defined(MATERIAL_HAS_SHEEN_COLOR) + // Albedo scaling of the base layer before we layer sheen on top + Fd *= pixel.sheenScaling; + Fr *= pixel.sheenScaling; + + half3 reflectance = pixel.sheenDFG * pixel.sheenColor; + reflectance *= computeSpecularAO(shading.NoV, diffuseAO, pixel.sheenRoughness); + + Fr += reflectance * UnityGI_prefilteredRadiance(unityData, pixel.sheenPerceptualRoughness, shading.reflected); +#endif +#endif +} + +void evaluateClearCoatIBL(const ShadingParams shading, const PixelParams pixel, const UnityGIInput unityData, + half diffuseAO, inout half3 Fd, inout half3 Fr) { +#if IBL_INTEGRATION == IBL_INTEGRATION_IMPORTANCE_SAMPLING + half specularAO = computeSpecularAO(shading.NoV, diffuseAO, pixel.clearCoatRoughness); + isEvaluateClearCoatIBL(pixel, specularAO, Fd, Fr); + return; +#endif + +#if defined(MATERIAL_HAS_CLEAR_COAT) +#if defined(MATERIAL_HAS_NORMAL) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL) + // We want to use the geometric normal for the clear coat layer + half clearCoatNoV = clampNoV(dot(shading.clearCoatNormal, shading.view)); + half3 clearCoatR = reflect(-shading.view, shading.clearCoatNormal); +#else + half clearCoatNoV = shading.NoV; + half3 clearCoatR = shading.reflected; +#endif + // The clear coat layer assumes an IOR of 1.5 (4% reflectance) + half Fc = F_Schlick(0.04, 1.0, clearCoatNoV) * pixel.clearCoat; + half attenuation = 1.0 - Fc; + Fd *= attenuation; + Fr *= attenuation; + + // TODO: Should we apply specularAO to the attenuation as well? + half specularAO = computeSpecularAO(clearCoatNoV, diffuseAO, pixel.clearCoatRoughness); + Fr += UnityGI_prefilteredRadiance(unityData, pixel.clearCoatPerceptualRoughness, clearCoatR) * (specularAO * Fc); +#endif +} + +void evaluateSubsurfaceIBL(const ShadingParams shading, const PixelParams pixel, const UnityGIInput unityData, + const float3 diffuseIrradiance, inout float3 Fd, inout float3 Fr) { +#if defined(SHADING_MODEL_SUBSURFACE) + float3 viewIndependent = diffuseIrradiance; + half transmissionRoughness = saturate(pixel.perceptualRoughness + pixel.thickness); + float3 viewDependent = UnityGI_prefilteredRadiance(unityData, transmissionRoughness, -shading.view); + float attenuation = (1.0 - pixel.thickness) / (2.0 * PI); + Fd += pixel.subsurfaceColor * (viewIndependent + viewDependent) * attenuation; +#elif defined(SHADING_MODEL_CLOTH) && defined(MATERIAL_HAS_SUBSURFACE_COLOR) + Fd *= saturate(pixel.subsurfaceColor + shading.NoV); +#endif +} + +#if defined(HAS_REFRACTION) + +struct Refraction { + half3 position; + half3 direction; + half d; +}; + +void refractionSolidSphere(const ShadingParams shading, const PixelParams pixel, + const half3 n, half3 r, out Refraction ray) { + r = refract(r, n, pixel.etaIR); + half NoR = dot(n, r); + half d = pixel.thickness * -NoR; + ray.position = half3(shading.position + r * d); + ray.d = d; + half3 n1 = normalize(NoR * r - n * 0.5); + ray.direction = refract(r, n1, pixel.etaRI); +} + +void refractionSolidBox(const ShadingParams shading, const PixelParams pixel, + const half3 n, half3 r, out Refraction ray) { + half3 rr = refract(r, n, pixel.etaIR); + half NoR = dot(n, rr); + half d = pixel.thickness / max(-NoR, 0.001); + ray.position = half3(shading.position + rr * d); + ray.direction = r; + ray.d = d; +#if REFRACTION_MODE == REFRACTION_MODE_CUBEMAP + // fudge direction vector, so we see the offset due to the thickness of the object + half envDistance = 10.0; // this should come from a ubo + ray.direction = normalize((ray.position - shading.position) + ray.direction * envDistance); +#endif +} + +void refractionThinSphere(const ShadingParams shading, const PixelParams pixel, + const half3 n, half3 r, out Refraction ray) { + half d = 0.0; +#if defined(MATERIAL_HAS_MICRO_THICKNESS) + // note: we need the refracted ray to calculate the distance traveled + // we could use shading.NoV, but we would lose the dependency on ior. + half3 rr = refract(r, n, pixel.etaIR); + half NoR = dot(n, rr); + d = pixel.uThickness / max(-NoR, 0.001); + ray.position = half3(shading.position + rr * d); +#else + ray.position = half3(shading.position); +#endif + ray.direction = r; + ray.d = d; +} + +void applyRefraction( + const ShadingParams shading, + const PixelParams pixel, + const UnityGIInput unityData, + half3 E, half3 Fd, half3 Fr, + inout half3 color) { + + Refraction ray; + half iblLuminance = 1.0; // unused + half refractionLodOffset = 0.0; // unused + +#if REFRACTION_TYPE == REFRACTION_TYPE_SOLID + refractionSolidSphere(shading, pixel, shading.normal, -shading.view, ray); +#elif REFRACTION_TYPE == REFRACTION_TYPE_THIN + refractionThinSphere(shading, pixel, shading.normal, -shading.view, ray); +#else +#error invalid REFRACTION_TYPE +#endif + + // compute transmission T +#if defined(MATERIAL_HAS_ABSORPTION) +#if defined(MATERIAL_HAS_THICKNESS) || defined(MATERIAL_HAS_MICRO_THICKNESS) + half3 T = min(1.0, exp(-pixel.absorption * ray.d)); +#else + half3 T = 1.0 - pixel.absorption; +#endif +#endif + + // Roughness remapping so that an IOR of 1.0 means no microfacet refraction and an IOR + // of 1.5 has full microfacet refraction + half perceptualRoughness = lerp(pixel.perceptualRoughnessUnclamped, 0.0, + saturate(pixel.etaIR * 3.0 - 2.0)); +#if REFRACTION_TYPE == REFRACTION_TYPE_THIN + // For thin surfaces, the light will bounce off at the second interface in the direction of + // the reflection, effectively adding to the specular, but this process will repeat itself. + // Each time the ray exits the surface on the front side after the first bounce, + // it's multiplied by E^2, and we get: E + E(1-E)^2 + E^3(1-E)^2 + ... + // This infinite series converges and is easy to simplify. + // Note: we calculate these bounces only on a single component, + // since it's a fairly subtle effect. + E *= 1.0 + pixel.transmission * (1.0 - E.g) / (1.0 + E.g); +#endif + + /* sample the cubemap or screen-space */ +#if REFRACTION_MODE == REFRACTION_MODE_CUBEMAP + // when reading from the cubemap, we are not pre-exposed so we apply iblLuminance + // which is not the case when we'll read from the screen-space buffer + + half3 Ft = UnityGI_prefilteredRadiance(unityData, perceptualRoughness, ray.direction) * iblLuminance; +#else + // compute the point where the ray exits the medium, if needed + //half4 p = half4(frameUniforms.clipFromWorldMatrix * half4(ray.position, 1.0)); + //p.xy = uvToRenderTargetUV(p.xy * (0.5 / p.w) + 0.5); + half4 p = UnityWorldToClipPos(half4(ray.position, 1.0)); + p.w = (0.5 / p.w); + p.xy = ComputeGrabScreenPos(p); + + // perceptualRoughness to LOD + // Empirical factor to compensate for the gaussian approximation of Dggx, chosen so + // cubemap and screen-space modes match at perceptualRoughness 0.125 + // TODO: Remove this factor temporarily until we find a better solution + // This overblurs many scenes and needs a more principled approach + // half tweakedPerceptualRoughness = perceptualRoughness * 1.74; + half tweakedPerceptualRoughness = perceptualRoughness; + half lod = max(0.0, 2.0 * log2(tweakedPerceptualRoughness) + refractionLodOffset); + + half3 Ft = UNITY_SAMPLE_TEX2D_LOD(REFRACTION_SOURCE, p.xy, lod).rgb * REFRACTION_MULTIPLIER; +#endif + + // base color changes the amount of light passing through the boundary + Ft *= pixel.diffuseColor; + + // fresnel from the first interface + Ft *= 1.0 - E; + + // apply absorption +#if defined(MATERIAL_HAS_ABSORPTION) + Ft *= T; +#endif + + Fr *= iblLuminance; + Fd *= iblLuminance; + color.rgb += Fr + lerp(Fd, Ft, pixel.transmission); +} +#endif + +void combineDiffuseAndSpecular(const ShadingParams shading, const PixelParams pixel, const UnityGIInput unityData, + const half3 E, const half3 Fd, const half3 Fr, + inout half3 color) { + const half iblLuminance = 1.0; // Unknown +#if defined(HAS_REFRACTION) + applyRefraction(shading, pixel, unityData, E, Fd, Fr, color); +#else + color.rgb += (Fd + Fr) * iblLuminance; +#endif +} + +void evaluateIBL(const ShadingParams shading, const MaterialInputs material, const PixelParams pixel, + inout half3 color) { + half ssao = 1.0; // Not implemented + half lightmapAO = 1.0; // Specular-only AO derived from baked lighting and exposure occlusion setting + half3 tangentNormal = half3(0, 0, 1); +#if defined(MATERIAL_HAS_NORMAL) + tangentNormal = material.normal; +#endif + + Light derivedLight = (Light)0; + + // Gather Unity GI data + UnityGIInput unityData = InitialiseUnityGIInput(shading, pixel); + + half3 unityIrradiance = UnityGI_Irradiance(shading, tangentNormal, + /*out*/ lightmapAO, /*out*/ derivedLight); + + // specular layer + half3 Fr; +#if IBL_INTEGRATION == IBL_INTEGRATION_PREFILTERED_CUBEMAP + half3 E = specularDFG(pixel); + half3 r = getReflectedVector(shading, pixel, shading.normal); + Fr = E * UnityGI_prefilteredRadiance(unityData, pixel.perceptualRoughness, r); +#elif IBL_INTEGRATION == IBL_INTEGRATION_IMPORTANCE_SAMPLING + // Not supported + half3 E = half3(0.0); // TODO: fix for importance sampling + Fr = isEvaluateSpecularIBL(pixel, shading.normal, shading.view, shading.NoV); +#endif + + // Support for using a mirror as a specular reflection source. +#if defined(MIRROR_REFLECTION) + MirrorReflectionSampler mirrorSampler; + half4 mirrorSpecular = mirrorSampler.getFilteredMirrorRadiance(shading, pixel.roughness); + Fr = lerp(Fr, E * mirrorSpecular, mirrorSpecular.a); +#endif + + // Ambient occlusion + half diffuseAO = min(material.ambientOcclusion, ssao); + half specularAO = computeSpecularAO(shading.NoV, diffuseAO*lightmapAO, pixel.roughness); + + half3 specularSingleBounceAO = singleBounceAO(specularAO) * pixel.energyCompensation; + Fr *= specularSingleBounceAO; + + // Gather LTCGI data, if present. +#if defined(_LTCGI) + accumulator_struct acc = (accumulator_struct)0; + + LTCGI_Contribution( + acc, + shading.position, + shading.normal, + shading.view, + pixel.perceptualRoughness, + (shading.lightmapUV.xy - unity_LightmapST.zw) / unity_LightmapST.xy + ); + + // Apply specular AO seperately for LTCGI pass, as it is a seperate set of lights. + half ltc_specularAO = computeSpecularAO(shading.NoV, diffuseAO, pixel.roughness); + half3 ltc_Fr = E * acc.specular; + + ltc_Fr *= singleBounceAO(ltc_specularAO) * pixel.energyCompensation; + specularAO = lerp(specularAO, ltc_specularAO, saturate(acc.specularIntensity)); + + Fr = lerp(Fr, ltc_Fr, saturate(acc.specularIntensity)); +#endif + + // diffuse layer + half diffuseBRDF = singleBounceAO(diffuseAO); // Fd_Lambert() is baked in the SH below + + evaluateClothIndirectDiffuseBRDF(shading, pixel, diffuseBRDF); + +#if defined(MATERIAL_HAS_BENT_NORMAL) + half3 diffuseNormal = shading.bentNormal; +#else + half3 diffuseNormal = shading.normal; +#endif + +#if IBL_INTEGRATION == IBL_INTEGRATION_PREFILTERED_CUBEMAP + //half3 diffuseIrradiance = get_diffuseIrradiance(diffuseNormal); + half3 diffuseIrradiance = unityIrradiance; +#elif IBL_INTEGRATION == IBL_INTEGRATION_IMPORTANCE_SAMPLING + half3 diffuseIrradiance = isEvaluateDiffuseIBL(pixel, diffuseNormal, shading.view); +#endif + +#if defined(_LTCGI) + diffuseIrradiance += acc.diffuse; +#endif + + // VRC Light Volumes also have an additive component which can be added over lightmapping. + #if defined(_VRCLV) && !UNITY_SHOULD_SAMPLE_SH + Light volumeLight = (Light)0; + diffuseIrradiance += Irradiance_SampleVRCLightVolumeAdditive(shading.normal, shading.position, volumeLight); + #endif + + half3 Fd = pixel.diffuseColor * diffuseIrradiance * (1.0 - E) * diffuseBRDF; + + // subsurface layer + evaluateSubsurfaceIBL(shading, pixel, unityData, diffuseIrradiance, Fd, Fr); + + // extra ambient occlusion term for the base and subsurface layers + multiBounceAO(diffuseAO, pixel.diffuseColor, Fd); + multiBounceSpecularAO(specularAO, pixel.f0, Fr); + + // sheen layer + evaluateSheenIBL(shading, pixel, unityData, diffuseAO, Fd, Fr); + + // clear coat layer + evaluateClearCoatIBL(shading, pixel, unityData, diffuseAO, Fd, Fr); + + // Note: iblLuminance is already premultiplied by the exposure + combineDiffuseAndSpecular(shading, pixel, unityData, E, Fd, Fr, color); + + #if defined(LIGHTMAP_SPECULAR) + PixelParams pixelForBakedSpecular = pixel; + + // Remap roughness to clamp at max roughness without a hard clamp + pixelForBakedSpecular.roughness = remap_almostIdentity(pixelForBakedSpecular.roughness, + 1-getLightmapSpecularMaxSmoothness(), 1-getLightmapSpecularMaxSmoothness()+MIN_ROUGHNESS); + + // Remove diffuse component + pixelForBakedSpecular.diffuseColor = 0; + + if (derivedLight.NoL >= 0.0) + { + // derived light contribution from lightmap + half diffuseAOForLightmap = min(material.ambientOcclusion * 0.8 + 0.3, 1.0); + diffuseAOForLightmap = computeMicroShadowing(derivedLight.NoL, diffuseAOForLightmap); + color += max(0, surfaceShading(shading, pixelForBakedSpecular, derivedLight, diffuseAOForLightmap)); + }; + #if defined(_VRCLV) && !UNITY_SHOULD_SAMPLE_SH + if (volumeLight.NoL >= 0.0) + { + // derived light contribution from lightmap + half diffuseAOForLightmap = min(material.ambientOcclusion * 0.8 + 0.3, 1.0); + diffuseAOForLightmap = computeMicroShadowing(volumeLight.NoL, diffuseAOForLightmap); + color += max(0, surfaceShading(shading, pixelForBakedSpecular, volumeLight, diffuseAOForLightmap)); + }; + #endif + #endif +} + +#endif // FILAMENT_LIGHT_INDIRECT diff --git a/Assets/Filamented/FilamentLightIndirect.cginc.meta b/Assets/Filamented/FilamentLightIndirect.cginc.meta new file mode 100644 index 0000000..51fa509 --- /dev/null +++ b/Assets/Filamented/FilamentLightIndirect.cginc.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7e6d53b497bfe2f46a359456c3dade1a +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentLightLTCGI.cginc b/Assets/Filamented/FilamentLightLTCGI.cginc new file mode 100644 index 0000000..768befc --- /dev/null +++ b/Assets/Filamented/FilamentLightLTCGI.cginc @@ -0,0 +1,55 @@ +#ifndef FILAMENT_LIGHT_LTCGI +#define FILAMENT_LIGHT_LTCGI + +#if defined(_LTCGI) + #if defined(_SPECULARHIGHLIGHTS_OFF) + #define LTCGI_SPECULAR_OFF + #endif +#include "Packages/at.pimaker.ltcgi/Shaders/LTCGI_structs.cginc" + +struct accumulator_struct { + half3 diffuse; + half3 specular; + half3 specularIntensity; +}; +void callback_diffuse(inout accumulator_struct acc, in ltcgi_output output); +void callback_specular(inout accumulator_struct acc, in ltcgi_output output); + +#define LTCGI_V2_CUSTOM_INPUT accumulator_struct +#define LTCGI_V2_DIFFUSE_CALLBACK callback_diffuse +#define LTCGI_V2_SPECULAR_CALLBACK callback_specular + +#include "Packages/at.pimaker.ltcgi/Shaders/LTCGI.cginc" + +void callback_diffuse(inout accumulator_struct acc, in ltcgi_output output) { + acc.diffuse += output.intensity * output.color; +} +void callback_specular(inout accumulator_struct acc, in ltcgi_output output) { + acc.specular += output.intensity * output.color; + acc.specularIntensity += output.intensity; +} +#endif + +//------------------------------------------------------------------------------ +// LTCGI evaluation +//------------------------------------------------------------------------------ + +// This is a small function to abstract the calls to the LTCGI functions. + +void evaluateLTCGI(const ShadingParams shading, const PixelParams pixel, inout half3 color) { +#if defined(_LTCGI) + accumulator_struct acc = (accumulator_struct)0; + + LTCGI_Contribution( + acc, + shading.position, + shading.normal, + shading.view, + pixel.perceptualRoughness, + shading.lightmapUV.xy + ); + color.rgb += acc.specular + acc.diffuse; +#endif +} + +#endif // FILAMENT_LIGHT_LTCGI diff --git a/Assets/Filamented/FilamentLightLTCGI.cginc.meta b/Assets/Filamented/FilamentLightLTCGI.cginc.meta new file mode 100644 index 0000000..7f2feea --- /dev/null +++ b/Assets/Filamented/FilamentLightLTCGI.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5ea4f7fc41b41824ba22dfe97495b44b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentLightMirror.cginc b/Assets/Filamented/FilamentLightMirror.cginc new file mode 100644 index 0000000..aa10723 --- /dev/null +++ b/Assets/Filamented/FilamentLightMirror.cginc @@ -0,0 +1,113 @@ +#ifndef FILAMENT_LIGHT_MIRROR +#define FILAMENT_LIGHT_MIRROR +// Commmon code for sampling from VRC (or similar) mirrors systems. +// +// Use a mirror as the source for the reflection. Multiple samples taken for roughness. +// This is a rough approximation for performance's sake. +// Based on https://www.shadertoy.com/view/DtBXDt (CC0) + +#if defined(MIRROR_REFLECTION) + UNITY_DECLARE_TEX2D_FLOAT(_ReflectionTex0); + UNITY_DECLARE_TEX2D_FLOAT(_ReflectionTex1); +#endif + +class MirrorReflectionSampler +{ + // Calculate R2 for index i + float2 getR2(float2 i) { + return frac(i * float2(0.245122333753, 0.430159709002)); + } + + uint hilbert_idx(uint2 uv, uint offset) + { + // Hilbert curve: + uint C = 0xB4361E9Cu;// cost lookup + uint P = 0xEC7A9107u;// pattern lookup + + uv += uint(offset) * uint2(2447445397u, 3242174893u); + + uint c = 0u;// accumulated cost + uint p = 0u;// current pattern + + const uint N = 7u;// tile size = 2^N + for(uint i = N; --i < N;) + { + uint2 m = (uv >> i) & 1u;// local uv + uint n = m.x ^ (m.y << 1u);// linearized local uv + uint o = (p << 3u) ^ (n << 1u);// offset into lookup tables + c += ((C >> o) & 3u) << (i << 1u);// accu cost (scaled by layer) + p = (P >> o) & 3u;// update pattern + } + + return c; + } + + inline half4 getMirrorReflection(float2 screenCoord) { + half4 refl = 0; +#if defined(MIRROR_REFLECTION) + refl = (unity_StereoEyeIndex == 0) + ? UNITY_SAMPLE_TEX2D(_ReflectionTex0, screenCoord) + : UNITY_SAMPLE_TEX2D(_ReflectionTex1, screenCoord); +#endif // MIRROR_REFLECTION + return refl; + } + + inline half4 getFilteredMirrorRadiance(const ShadingParams shading, float roughness) { + half4 refl = 0; + half weight = 0; + +#if defined(MIRROR_REFLECTION) + float2 refSize; + _ReflectionTex0.GetDimensions(refSize.x, refSize.y); + + // Since it's possible the user might not know the resolution will have + // a big impact on performance, force a resolution scale. + + half totalPixels = refSize.x * refSize.y; + const half minArea = 256.0 * 256.0; + const half maxArea = 1024.0 * 1024.0; + half resScale = saturate((totalPixels - minArea) / (maxArea - minArea)); + + // If there is no mirror texture, exit. + if (totalPixels <= 0) return 0; + + float3 normalOffset = shading.geometricNormal - shading.normal; + half2 normalVS = mul((float3x3)UNITY_MATRIX_V, normalOffset); + + half2 screenCoord = shading.normalizedViewportCoord; + + // At 256 or lower, do the full 64 samples and use a low roughness cutoff. + // At 1024 or higher, perform only one sample and no roughness. + + half roughnessCutoff = lerp(0.1h, 0.01h, resScale); + uint N = clamp(uint(lerp(64.0h, 1.0h, resScale)), 1, 64); // sample count + half dmax = roughness * lerp(4.0h, 0.01h, resScale); // max blur distance + + if (roughness >= roughnessCutoff) return 0; + + float sigma = dmax / 2.5; + sigma *= sigma; + + half idx = fmod(hilbert_idx(uint2(screenCoord * _ScreenParams.xy), 0), 100000.0h); + half sampleMask = 1.0; + + [loop] + for (uint i = 0.0; i < N; i++) { + half2 uvoff = dmax * (getR2(half2(idx + i, idx + i + 1)) - 0.5); + half bw = exp(-dot(uvoff, uvoff) / sigma); + + half2 sampleCoord = screenCoord + uvoff + normalVS; + + sampleMask *= 1.0 - length(saturate(sampleCoord) - sampleCoord) * bw; + + refl += bw * max(0, getMirrorReflection(sampleCoord)); + weight += bw; + } + + refl /= weight; + refl.a = 1 - saturate((roughness - MIN_ROUGHNESS) / roughnessCutoff) * sampleMask; +#endif // MIRROR_REFLECTION + return max(0, refl); + } +}; +#endif // FILAMENT_LIGHT_MIRROR diff --git a/Assets/Filamented/FilamentLightMirror.cginc.meta b/Assets/Filamented/FilamentLightMirror.cginc.meta new file mode 100644 index 0000000..261dec7 --- /dev/null +++ b/Assets/Filamented/FilamentLightMirror.cginc.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: fca3f7b17a3657942b1b54e5abb08eee +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentLightPunctual.cginc b/Assets/Filamented/FilamentLightPunctual.cginc new file mode 100644 index 0000000..5faa45b --- /dev/null +++ b/Assets/Filamented/FilamentLightPunctual.cginc @@ -0,0 +1,89 @@ +#ifndef FILAMENT_LIGHT_DYNAMIC +#define FILAMENT_LIGHT_DYNAMIC + +#include "UnityLightingCommon.cginc" +//------------------------------------------------------------------------------ +// Punctual lights evaluation +//------------------------------------------------------------------------------ + +// This is based off light_directional, not light_punctual, because of Unity's +// light model. + +half4 UnityLight_ColorIntensitySeperated_Punctual() { + return half4(_LightColor0.xyz, 1.0); + + if (_LightColor0.w <= 0) return 0.0; + return half4(_LightColor0.xyz / _LightColor0.w, _LightColor0.w); +} + +half getSquareFalloffAttenuation(half distanceSquare, half falloff) { + half factor = distanceSquare * falloff; + half smoothFactor = saturate(1.0 - factor * factor); + // We would normally divide by the square distance here + // but we do it at the call site + return smoothFactor * smoothFactor; +} + +half getDistanceAttenuation(const half3 posToLight, half falloff) { + half distanceSquare = dot(posToLight, posToLight); + half attenuation = getSquareFalloffAttenuation(distanceSquare, falloff); + // Assume a punctual light occupies a volume of 1cm to avoid a division by 0 + return attenuation * 1.0 / max(distanceSquare, 1e-4); +} + +half getAngleAttenuation(const half3 lightDir, const half3 l, const half2 scaleOffset) { + half cd = dot(lightDir, l); + half attenuation = saturate(cd * scaleOffset.x + scaleOffset.y); + return attenuation * attenuation; +} + +Light getLight(ShadingParams shading) { + Light light; + + // position-to-light vector + float3 posToLight = _WorldSpaceLightPos0.xyz - shading.position; + + // note: lightColorIntensity.w is always premultiplied by the exposure + light.colorIntensity = UnityLight_ColorIntensitySeperated_Punctual(); + light.l = normalize(posToLight); + light.attenuation = shading.attenuation; //getDistanceAttenuation(posToLight, _WorldSpaceLightPos0.w); + light.NoL = saturate(dot(shading.normal, light.l)); + light.worldPosition = _WorldSpaceLightPos0.xyz; + return light; +} + +// Much of this function has changed from the original because we still use +// Unity's BIRP shadow handling. Sorry! +void evaluatePunctualLights(const ShadingParams shading, const PixelParams pixel, inout half3 color) { + + Light light = getLight(shading); + + half visibility = 1.0; +#if defined(HAS_SHADOWING) + if (light.NoL > 0.0) { + float ssContactShadowOcclusion = 0.0; + + // hasDirectionalShadows && cascadeHasVisibleShadows + if (1) { + //visibility*=shading.attenuation; + // apply directional shadows to visibility here + } + // if contact shadows are enabled + if (true && visibility > 0.0) { + // ssContactShadowOcclusion = screenSpaceContactShadow(light.l); + } + + visibility *= 1.0 - ssContactShadowOcclusion; + } else { +#if defined(MATERIAL_CAN_SKIP_LIGHTING) + return; +#endif + } +#elif defined(MATERIAL_CAN_SKIP_LIGHTING) + if (light.NoL <= 0.0) return; +#endif + + color.rgb += surfaceShading(shading, pixel, light, visibility); +} + +#endif // FILAMENT_LIGHT_DYNAMIC diff --git a/Assets/Filamented/FilamentLightPunctual.cginc.meta b/Assets/Filamented/FilamentLightPunctual.cginc.meta new file mode 100644 index 0000000..0864707 --- /dev/null +++ b/Assets/Filamented/FilamentLightPunctual.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 394fef5252d2f1347875e9ed94bae290 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentLightVRCLV.cginc b/Assets/Filamented/FilamentLightVRCLV.cginc new file mode 100644 index 0000000..6512c30 --- /dev/null +++ b/Assets/Filamented/FilamentLightVRCLV.cginc @@ -0,0 +1,9 @@ +#ifndef FILAMENT_LIGHT_VRCLV +#define FILAMENT_LIGHT_VRCLV + +#include "SharedSHLib.hlsl" + +#if defined(_VRCLV) +#include "LightVolumes.cginc" +#endif +#endif // FILAMENT_LIGHT_VRCLV diff --git a/Assets/Filamented/FilamentLightVRCLV.cginc.meta b/Assets/Filamented/FilamentLightVRCLV.cginc.meta new file mode 100644 index 0000000..8c87795 --- /dev/null +++ b/Assets/Filamented/FilamentLightVRCLV.cginc.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f0a0d12901ef8c348a497006faeb60d2 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentMaterialInputs.cginc b/Assets/Filamented/FilamentMaterialInputs.cginc new file mode 100644 index 0000000..12d7f45 --- /dev/null +++ b/Assets/Filamented/FilamentMaterialInputs.cginc @@ -0,0 +1,217 @@ +#ifndef FILAMENT_MATERIAL_INPUTS +#define FILAMENT_MATERIAL_INPUTS + +// Decide if we can skip lighting when dot(n, l) <= 0.0 +#if defined(SHADING_MODEL_CLOTH) +#if !defined(MATERIAL_HAS_SUBSURFACE_COLOR) + #define MATERIAL_CAN_SKIP_LIGHTING +#endif +#elif defined(SHADING_MODEL_SUBSURFACE) + // Cannot skip lighting +#else + #define MATERIAL_CAN_SKIP_LIGHTING +#endif + +struct MaterialInputs { + half4 baseColor; +#if !defined(SHADING_MODEL_UNLIT) +#if !defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + half roughness; +#endif +#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + half metallic; + half reflectance; +#endif + half ambientOcclusion; +#endif + half4 emissive; + +#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SUBSURFACE) && !defined(SHADING_MODEL_UNLIT) + half3 sheenColor; + half sheenRoughness; +#endif + +#if defined(MATERIAL_HAS_GLINT) + float2 uv; + float glintAlpha; + float glintDensity; +#endif + + half clearCoat; + half clearCoatRoughness; + + half anisotropy; + half3 anisotropyDirection; + +#if defined(SHADING_MODEL_SUBSURFACE) || defined(HAS_REFRACTION) + half thickness; +#endif +#if defined(SHADING_MODEL_SUBSURFACE) + half subsurfacePower; + half3 subsurfaceColor; +#endif + +#if defined(SHADING_MODEL_CLOTH) + half3 sheenColor; +#if defined(MATERIAL_HAS_SUBSURFACE_COLOR) + half3 subsurfaceColor; +#endif +#endif + +#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + half3 specularColor; + half glossiness; +#endif + +#if defined(MATERIAL_HAS_NORMAL) + half3 normal; +#endif +#if defined(MATERIAL_HAS_BENT_NORMAL) + half3 bentNormal; +#endif +#if defined(MATERIAL_HAS_CLEAR_COAT) && defined(MATERIAL_HAS_CLEAR_COAT_NORMAL) + half3 clearCoatNormal; +#endif + +#if defined(MATERIAL_HAS_POST_LIGHTING_COLOR) + half4 postLightingColor; +#endif + +#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SUBSURFACE) && !defined(SHADING_MODEL_UNLIT) +#if defined(HAS_REFRACTION) +#if defined(MATERIAL_HAS_ABSORPTION) + half3 absorption; +#endif +#if defined(MATERIAL_HAS_TRANSMISSION) + half transmission; +#endif +#if defined(MATERIAL_HAS_IOR) + half ior; +#endif +#if defined(MATERIAL_HAS_MICRO_THICKNESS) && (REFRACTION_TYPE == REFRACTION_TYPE_THIN) + half microThickness; +#endif +#elif !defined(SHADING_MODEL_SPECULAR_GLOSSINESS) +#if defined(MATERIAL_HAS_IOR) + half ior; +#endif +#endif +#endif +}; + +void initMaterial(out MaterialInputs material) { + material = (MaterialInputs)0; + + material.baseColor = 1.0; +#if !defined(SHADING_MODEL_UNLIT) +#if !defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + material.roughness = 1.0; +#endif +#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + material.metallic = 0.0; + material.reflectance = 0.5; +#endif + material.ambientOcclusion = 1.0; +#endif + material.emissive = half4(half3(0.0.xxx), 1.0); + +#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SUBSURFACE) && !defined(SHADING_MODEL_UNLIT) +#if defined(MATERIAL_HAS_SHEEN_COLOR) + material.sheenColor = half3(0.0.xxx); + material.sheenRoughness = 0.0; +#endif +#endif + +#if defined(MATERIAL_HAS_CLEAR_COAT) + material.clearCoat = 1.0; + material.clearCoatRoughness = 0.0; +#endif + +#if defined(MATERIAL_HAS_ANISOTROPY) + material.anisotropy = 0.0; + material.anisotropyDirection = half3(1.0, 0.0, 0.0); +#endif + +#if defined(SHADING_MODEL_SUBSURFACE) || defined(HAS_REFRACTION) + material.thickness = 0.5; +#endif +#if defined(SHADING_MODEL_SUBSURFACE) + material.subsurfacePower = 12.234; + material.subsurfaceColor = half3(1.0.xxx); +#endif + +#if defined(SHADING_MODEL_CLOTH) + material.sheenColor = sqrt(material.baseColor.rgb); +#if defined(MATERIAL_HAS_SUBSURFACE_COLOR) + material.subsurfaceColor = half3(0.0.xxx); +#endif +#endif + +#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + material.glossiness = 0.0; + material.specularColor = half3(0.0.xxx); +#endif + +#if defined(MATERIAL_HAS_NORMAL) + material.normal = half3(0.0, 0.0, 1.0); +#endif +#if defined(MATERIAL_HAS_BENT_NORMAL) + material.bentNormal = half3(0.0, 0.0, 1.0); +#endif +#if defined(MATERIAL_HAS_CLEAR_COAT) && defined(MATERIAL_HAS_CLEAR_COAT_NORMAL) + material.clearCoatNormal = half3(0.0, 0.0, 1.0); +#endif + +#if defined(MATERIAL_HAS_POST_LIGHTING_COLOR) + material.postLightingColor = half4(0.0.xxx); +#endif + +#if defined(MATERIAL_HAS_GLINT) + material.uv = float2(0.0, 0.0); + material.glintAlpha = 0.05; + material.glintDensity = 10000.0; +#endif + +#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SUBSURFACE) && !defined(SHADING_MODEL_UNLIT) +#if defined(HAS_REFRACTION) +#if defined(MATERIAL_HAS_ABSORPTION) + material.absorption = half3(0.0.xxx); +#endif +#if defined(MATERIAL_HAS_TRANSMISSION) + material.transmission = 1.0; +#endif +#if defined(MATERIAL_HAS_IOR) + material.ior = 1.5; +#endif +#if defined(MATERIAL_HAS_MICRO_THICKNESS) && (REFRACTION_TYPE == REFRACTION_TYPE_THIN) + material.microThickness = 0.0; +#endif +#elif !defined(SHADING_MODEL_SPECULAR_GLOSSINESS) +#if defined(MATERIAL_HAS_IOR) + material.ior = 1.5; +#endif +#endif +#endif +} + +#if defined(MATERIAL_HAS_CUSTOM_SURFACE_SHADING) +/** @public-api */ +struct LightData { + half4 colorIntensity; + half3 l; + half NdotL; + half3 worldPosition; + half attenuation; + half visibility; +}; + +/** @public-api */ +struct ShadingData { + half3 diffuseColor; + half perceptualRoughness; + half3 f0; + half roughness; +}; +#endif + +#endif // FILAMENT_MATERIAL_INPUTS diff --git a/Assets/Filamented/FilamentMaterialInputs.cginc.meta b/Assets/Filamented/FilamentMaterialInputs.cginc.meta new file mode 100644 index 0000000..9408102 --- /dev/null +++ b/Assets/Filamented/FilamentMaterialInputs.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 22e197c1606ed7c4994632b8b210f3e6 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentShadingCloth.cginc b/Assets/Filamented/FilamentShadingCloth.cginc new file mode 100644 index 0000000..cfe3d56 --- /dev/null +++ b/Assets/Filamented/FilamentShadingCloth.cginc @@ -0,0 +1,58 @@ + +#ifndef FILAMENT_SHADING_CLOTH_INCLUDED +#define FILAMENT_SHADING_CLOTH_INCLUDED + +#include "FilamentBRDF.cginc" + +/** + * Evaluates lit materials with the cloth shading model. Similar to the standard + * model, the cloth shading model is based on a Cook-Torrance microfacet model. + * Its distribution and visibility terms are however very different to take into + * account the softer apperance of many types of cloth. Some highly reflecting + * fabrics like satin or leather should use the standard model instead. + * + * This shading model optionally models subsurface scattering events. The + * computation of these events is not physically based but can add necessary + * details to a material. + */ +half3 surfaceShading(const ShadingParams shading, const PixelParams pixel, const Light light, half occlusion) { + half3 h = normalize(shading.view + light.l); + half NoL = light.NoL; + half NoH = saturate(dot(shading.normal, h)); + half LoH = saturate(dot(light.l, h)); + + // specular BRDF + half D = distributionCloth(pixel.roughness, NoH); + half V = visibilityCloth(shading.NoV, NoL); + half3 F = pixel.f0; + // Ignore pixel.energyCompensation since we use a different BRDF here + half3 Fr = (D * V) * F; + + // diffuse BRDF + half diffuseLobe = diffuse(pixel.roughness, shading.NoV, NoL, LoH); +#if defined(MATERIAL_HAS_SUBSURFACE_COLOR) + // Energy conservative wrap diffuse to simulate subsurface scattering + diffuseLobe *= Fd_Wrap(dot(shading.normal, light.l), 0.5); +#endif + + // We do not multiply the diffuse term by the Fresnel term as discussed in + // Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886" + // The effect is fairly subtle and not deemed worth the cost for mobile + half3 Fd = diffuseLobe * pixel.diffuseColor; + +#if defined(MATERIAL_HAS_SUBSURFACE_COLOR) + // Cheap subsurface scatter + Fd *= saturate(pixel.subsurfaceColor + NoL); + // We need to apply NoL separately to the specular lobe since we already took + // it into account in the diffuse lobe + half3 color = Fd + Fr * NoL; + color *= light.colorIntensity.rgb * (light.colorIntensity.w * light.attenuation * occlusion); +#else + half3 color = Fd + Fr; + color *= light.colorIntensity.rgb * (light.colorIntensity.w * light.attenuation * NoL * occlusion); +#endif + + return color; +} + +#endif // FILAMENT_SHADING_CLOTH_INCLUDED diff --git a/Assets/Filamented/FilamentShadingCloth.cginc.meta b/Assets/Filamented/FilamentShadingCloth.cginc.meta new file mode 100644 index 0000000..631b14b --- /dev/null +++ b/Assets/Filamented/FilamentShadingCloth.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f2290f6a0fe3159419f54d6dace56a9d +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentShadingLit.cginc b/Assets/Filamented/FilamentShadingLit.cginc new file mode 100644 index 0000000..0cb623e --- /dev/null +++ b/Assets/Filamented/FilamentShadingLit.cginc @@ -0,0 +1,371 @@ +#ifndef FILAMENT_SHADING_LIT +#define FILAMENT_SHADING_LIT + +#include "FilamentMaterialInputs.cginc" +#include "FilamentCommonMath.cginc" +#include "FilamentCommonGraphics.cginc" +#include "FilamentCommonLighting.cginc" +#include "FilamentCommonMaterial.cginc" +#include "FilamentCommonShading.cginc" + + +#if defined(SHADING_MODEL_SUBSURFACE) + #include "FilamentShadingSubsurface.cginc" +#elif defined(SHADING_MODEL_CLOTH) + #include "FilamentShadingCloth.cginc" +#else + #include "FilamentShadingStandard.cginc" +#endif + +#include "FilamentLightIndirect.cginc" +#include "FilamentShadingLit.cginc" +#include "FilamentLightDirectional.cginc" +#include "FilamentLightPunctual.cginc" +#include "FilamentLightLTCGI.cginc" + +#include "UnityStandardInput.cginc" + +//------------------------------------------------------------------------------ +// Lighting +//------------------------------------------------------------------------------ + +#if defined(BLEND_MODE_MASKED) +half computeMaskedAlpha(half a) { + // Use derivatives to smooth alpha tested edges + return (a - getMaskThreshold()) / max(fwidth(a), 1e-3) + 0.5; +} + +half computeDiffuseAlpha(half a) { + // If we reach this point in the code, we already know that the fragment is not discarded due + // to the threshold factor. Therefore we can just output 1.0, which prevents a "punch through" + // effect from occuring. We do this only for TRANSLUCENT views in order to prevent breakage + // of ALPHA_TO_COVERAGE. + return (NEEDS_ALPHA_CHANNEL == 1.0) ? 1.0 : a; +} + +void applyAlphaMask(inout float4 baseColor) { + baseColor.a = computeMaskedAlpha(baseColor.a); + if (baseColor.a <= 0.0) { + discard; + } +} + +#else // not masked + +float computeDiffuseAlpha(float a) { +#if defined(BLEND_MODE_TRANSPARENT) || defined(BLEND_MODE_FADE) + return a; +#else + return 1.0; +#endif +} + +void applyAlphaMask(inout float4 baseColor) {} + +#endif + +#if defined(GEOMETRIC_SPECULAR_AA) +half normalFiltering(half perceptualRoughness, const half3 worldNormal) { + // Kaplanyan 2016, "Stable specular highlights" + // Tokuyoshi 2017, "Error Reduction and Simplification for Shading Anti-Aliasing" + // Tokuyoshi and Kaplanyan 2019, "Improved Geometric Specular Antialiasing" + + // This implementation is meant for deferred rendering in the original paper but + // we use it in forward rendering as well (as discussed in Tokuyoshi and Kaplanyan + // 2019). The main reason is that the forward version requires an expensive transform + // of the half vector by the tangent frame for every light. This is therefore an + // approximation but it works well enough for our needs and provides an improvement + // over our original implementation based on Vlachos 2015, "Advanced VR Rendering". + + half3 du = ddx(worldNormal); + half3 dv = ddy(worldNormal); + + half variance = _specularAntiAliasingVariance * (dot(du, du) + dot(dv, dv)); + + half roughness = perceptualRoughnessToRoughness(perceptualRoughness); + half kernelRoughness = min(2.0 * variance, _specularAntiAliasingThreshold); + half squareRoughness = saturate(roughness * roughness + kernelRoughness); + + return roughnessToPerceptualRoughness(sqrt(squareRoughness)); +} +#endif + +void getCommonPixelParams(const MaterialInputs material, inout PixelParams pixel) { + half4 baseColor = material.baseColor; + applyAlphaMask(baseColor); + +#if defined(BLEND_MODE_FADE) && !defined(SHADING_MODEL_UNLIT) + // Since we work in premultiplied alpha mode, we need to un-premultiply + // in fade mode so we can apply alpha to both the specular and diffuse + // components at the end + unpremultiply(baseColor); +#endif + +#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + // This is from KHR_materials_pbrSpecularGlossiness. + half3 specularColor = material.specularColor; + half metallic = computeMetallicFromSpecularColor(specularColor); + + pixel.diffuseColor = computeDiffuseColor(baseColor, metallic); + pixel.f0 = specularColor; +#elif !defined(SHADING_MODEL_CLOTH) + pixel.diffuseColor = computeDiffuseColor(baseColor, material.metallic); + #if !defined(SHADING_MODEL_SUBSURFACE) && (!defined(MATERIAL_HAS_REFLECTANCE) && defined(MATERIAL_HAS_IOR)) + half reflectance = iorToF0(max(1.0, material.ior), 1.0); +#else + // Assumes an interface from air to an IOR of 1.5 for dielectrics + half reflectance = computeDielectricF0(material.reflectance); +#endif + pixel.f0 = computeF0(baseColor, material.metallic, reflectance); +#else + pixel.diffuseColor = baseColor.rgb; + pixel.f0 = material.sheenColor; +#if defined(MATERIAL_HAS_SUBSURFACE_COLOR) + pixel.subsurfaceColor = material.subsurfaceColor; +#endif +#endif + +#if !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SUBSURFACE) +#if defined(HAS_REFRACTION) + // Air's Index of refraction is 1.000277 at STP but everybody uses 1.0 + const half airIor = 1.0; +#if !defined(MATERIAL_HAS_IOR) + // [common case] ior is not set in the material, deduce it from F0 + half materialor = f0ToIor(pixel.f0.g); +#else + // if ior is set in the material, use it (can lead to unrealistic materials) + half materialor = max(1.0, material.ior); +#endif + pixel.etaIR = airIor / materialor; // air -> material + pixel.etaRI = materialor / airIor; // material -> air +#if defined(MATERIAL_HAS_TRANSMISSION) + pixel.transmission = saturate(material.transmission); +#else + pixel.transmission = 1.0; +#endif +#if defined(MATERIAL_HAS_ABSORPTION) +#if defined(MATERIAL_HAS_THICKNESS) || defined(MATERIAL_HAS_MICRO_THICKNESS) + pixel.absorption = max(0.0, material.absorption); +#else + pixel.absorption = saturate(material.absorption); +#endif +#else + pixel.absorption = 0.0; +#endif +#if defined(MATERIAL_HAS_THICKNESS) + pixel.thickness = max(0.0, material.thickness); +#endif +#if defined(MATERIAL_HAS_MICRO_THICKNESS) && (REFRACTION_TYPE == REFRACTION_TYPE_THIN) + pixel.uThickness = max(0.0, material.microThickness); +#else + pixel.uThickness = 0.0; +#endif +#endif +#endif +} + +void getSheenPixelParams(const ShadingParams shading, const MaterialInputs material, inout PixelParams pixel) { +#if defined(MATERIAL_HAS_SHEEN_COLOR) && !defined(SHADING_MODEL_CLOTH) && !defined(SHADING_MODEL_SUBSURFACE) + pixel.sheenColor = material.sheenColor; + + half sheenPerceptualRoughness = material.sheenRoughness; + sheenPerceptualRoughness = clamp(sheenPerceptualRoughness, MIN_PERCEPTUAL_ROUGHNESS, 1.0); + +#if defined(GEOMETRIC_SPECULAR_AA) + sheenPerceptualRoughness = + normalFiltering(sheenPerceptualRoughness, shading.geometricNormal); +#endif + + pixel.sheenPerceptualRoughness = sheenPerceptualRoughness; + pixel.sheenRoughness = perceptualRoughnessToRoughness(sheenPerceptualRoughness); +#endif +} + +void getClearCoatPixelParams(const ShadingParams shading, const MaterialInputs material, inout PixelParams pixel) { +#if defined(MATERIAL_HAS_CLEAR_COAT) + pixel.clearCoat = material.clearCoat; + + // Clamp the clear coat roughness to avoid divisions by 0 + half clearCoatPerceptualRoughness = material.clearCoatRoughness; + clearCoatPerceptualRoughness = + clamp(clearCoatPerceptualRoughness, MIN_PERCEPTUAL_ROUGHNESS, 1.0); + +#if defined(GEOMETRIC_SPECULAR_AA) + clearCoatPerceptualRoughness = + normalFiltering(clearCoatPerceptualRoughness, shading.geometricNormal); +#endif + + pixel.clearCoatPerceptualRoughness = clearCoatPerceptualRoughness; + pixel.clearCoatRoughness = perceptualRoughnessToRoughness(clearCoatPerceptualRoughness); + +#if defined(CLEAR_COAT_IOR_CHANGE) + // The base layer's f0 is computed assuming an interface from air to an IOR + // of 1.5, but the clear coat layer forms an interface from IOR 1.5 to IOR + // 1.5. We recompute f0 by first computing its IOR, then reconverting to f0 + // by using the correct interface + pixel.f0 = lerp(pixel.f0, f0ClearCoatToSurface(pixel.f0), pixel.clearCoat); +#endif +#endif +} + +void getRoughnessPixelParams(const ShadingParams shading, const MaterialInputs material, inout PixelParams pixel) { +#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + half perceptualRoughness = computeRoughnessFromGlossiness(material.glossiness); +#else + half perceptualRoughness = material.roughness; +#endif + + // This is used by the refraction code and must be saved before we apply specular AA + pixel.perceptualRoughnessUnclamped = perceptualRoughness; + +#if defined(GEOMETRIC_SPECULAR_AA) + perceptualRoughness = normalFiltering(perceptualRoughness, shading.geometricNormal); +#endif + +#if defined(MATERIAL_HAS_CLEAR_COAT) && defined(MATERIAL_HAS_CLEAR_COAT_ROUGHNESS) + // This is a hack but it will do: the base layer must be at least as rough + // as the clear coat layer to take into account possible diffusion by the + // top layer + half basePerceptualRoughness = max(perceptualRoughness, pixel.clearCoatPerceptualRoughness); + perceptualRoughness = lerp(perceptualRoughness, basePerceptualRoughness, pixel.clearCoat); +#endif + + // Clamp the roughness to a minimum value to avoid divisions by 0 during lighting + pixel.perceptualRoughness = clamp(perceptualRoughness, MIN_PERCEPTUAL_ROUGHNESS, 1.0); + // Remaps the roughness to a perceptually linear roughness (roughness^2) + pixel.roughness = perceptualRoughnessToRoughness(pixel.perceptualRoughness); +} + +void getSubsurfacePixelParams(const MaterialInputs material, inout PixelParams pixel) { +#if defined(SHADING_MODEL_SUBSURFACE) + pixel.subsurfacePower = material.subsurfacePower; + pixel.subsurfaceColor = material.subsurfaceColor; + pixel.thickness = saturate(material.thickness); +#endif +} + +void getAnisotropyPixelParams(const ShadingParams shading, const MaterialInputs material, inout PixelParams pixel) { +#if defined(MATERIAL_HAS_ANISOTROPY) + half3 direction = material.anisotropyDirection; + pixel.anisotropy = material.anisotropy; + pixel.anisotropicT = normalize(mul(shading.tangentToWorld, direction)); + pixel.anisotropicB = normalize(cross(shading.geometricNormal, pixel.anisotropicT)); +#endif +} + +void getEnergyCompensationPixelParams(const ShadingParams shading, inout PixelParams pixel) { + // Pre-filtered DFG term used for image-based lighting + pixel.dfg = prefilteredDFG(pixel.perceptualRoughness, shading.NoV); + +#if !defined(SHADING_MODEL_CLOTH) + // Energy compensation for multiple scattering in a microfacet model + // See "Multiple-Scattering Microfacet BSDFs with the Smith Model" + pixel.energyCompensation = 1.0 + pixel.f0 * (1.0 / pixel.dfg.yyy - 1.0); +#else + pixel.energyCompensation = (1.0); +#endif + +#if !defined(SHADING_MODEL_CLOTH) +#if defined(MATERIAL_HAS_SHEEN_COLOR) + pixel.sheenDFG = prefilteredDFG(pixel.sheenPerceptualRoughness, shading.NoV).z; + pixel.sheenScaling = 1.0 - max3(pixel.sheenColor) * pixel.sheenDFG; +#endif +#endif +} + + +void geGlintPixelParams(const ShadingParams shading, const MaterialInputs material, inout PixelParams pixel) { +#if defined(MATERIAL_HAS_GLINT) + pixel.uv = material.uv; + pixel.ddx_uv = ddx(material.uv); + pixel.ddy_uv = ddy(material.uv); + pixel.glintAlpha = material.glintAlpha; + pixel.glintDensity = material.glintDensity; +#endif +} + +/** + * Computes all the parameters required to shade the current pixel/fragment. + * These parameters are derived from the MaterialInputs structure computed + * by the user's material code. + * + * This function is also responsible for discarding the fragment when alpha + * testing fails. + */ +void getPixelParams(const ShadingParams shading, const MaterialInputs material, out PixelParams pixel) { + pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + getSheenPixelParams(shading, material, pixel); + getClearCoatPixelParams(shading, material, pixel); + getRoughnessPixelParams(shading, material, pixel); + getSubsurfacePixelParams(material, pixel); + getAnisotropyPixelParams(shading, material, pixel); + geGlintPixelParams(shading, material, pixel); + getEnergyCompensationPixelParams(shading, pixel); +} + +/** + * This function evaluates all lights one by one: + * - Image based lights (IBL) + * - Directional lights + * - Punctual lights + * + * Area lights are currently not supported. + * + * Returns a pre-exposed HDR RGBA color in linear space. + */ +half4 evaluateLights(const ShadingParams shading, const MaterialInputs material) { + PixelParams pixel; + getPixelParams(shading, material, pixel); + + // Ideally we would keep the diffuse and specular components separate + // until the very end but it costs more ALUs on mobile. The gains are + // currently not worth the extra operations + half3 color = 0.0; + + // We always evaluate the IBL as not having one is going to be uncommon, + // it also saves 1 shader variant +#if defined(UNITY_PASS_FORWARDBASE) + evaluateIBL(shading, material, pixel, color); +#endif + +#if defined(HAS_DIRECTIONAL_LIGHTING) + evaluateDirectionalLight(shading, material, pixel, color); +#endif + +#if defined(HAS_DYNAMIC_LIGHTING) + evaluatePunctualLights(shading, pixel, color); +#endif + +#if defined(BLEND_MODE_FADE) && !defined(SHADING_MODEL_UNLIT) + // In fade mode we un-premultiply baseColor early on, so we need to + // premultiply again at the end (affects diffuse and specular lighting) + color *= material.baseColor.a; +#endif + + return half4(color, computeDiffuseAlpha(material.baseColor.a)); +} + +void addEmissive(const MaterialInputs material, inout half4 color) { +#if defined(MATERIAL_HAS_EMISSIVE) + float4 emissive = material.emissive; + //float attenuation = lerp(1.0, frameUniforms.exposure, emissive.w); + // Exposure not supported yet + float attenuation = emissive.w; + color.rgb += emissive.rgb * (attenuation * color.a); +#endif +} + +/** + * Evaluate lit materials. The actual shading model used to do so is defined + * by the function surfaceShading() found in shading_model_*.fs. + * + * Returns a pre-exposed HDR RGBA color in linear space. + */ +half4 evaluateMaterial(const ShadingParams shading, const MaterialInputs material) { + half4 color = evaluateLights(shading, material); + addEmissive(material, color); + return color; +} + +#endif // FILAMENT_SHADING_LIT diff --git a/Assets/Filamented/FilamentShadingLit.cginc.meta b/Assets/Filamented/FilamentShadingLit.cginc.meta new file mode 100644 index 0000000..c8838bd --- /dev/null +++ b/Assets/Filamented/FilamentShadingLit.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 521be760d19f10745a6999176e511627 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentShadingParameters.cginc b/Assets/Filamented/FilamentShadingParameters.cginc new file mode 100644 index 0000000..fd7dbc5 --- /dev/null +++ b/Assets/Filamented/FilamentShadingParameters.cginc @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// Material evaluation +//------------------------------------------------------------------------------ + +/** + * Computes global shading parameters used to apply lighting, such as the view + * vector in world space, the tangent frame at the shading point, etc. + */ + +void computeShadingParams(inout ShadingParams shading, float3 vertex_worldNormal, float4 vertex_worldTangent, float3 vertex_worldPosition, + float4 vertex_position, float3 frameUniforms_cameraPosition, bool isDoubleSided, bool gl_FrontFacing) { +#if defined(HAS_ATTRIBUTE_TANGENTS) + float3 n = vertex_worldNormal; +#if defined(MATERIAL_NEEDS_TBN) + float3 t = vertex_worldTangent.xyz; + float3 b = cross(n, t) * sign(vertex_worldTangent.w); +#endif + +#if defined(MATERIAL_HAS_DOUBLE_SIDED_CAPABILITY) + if (isDoubleSided) { + n = gl_FrontFacing ? n : -n; +#if defined(MATERIAL_NEEDS_TBN) + t = gl_FrontFacing ? t : -t; + b = gl_FrontFacing ? b : -b; +#endif + } +#endif + + shading.geometricNormal = normalize(n); + +#if defined(MATERIAL_NEEDS_TBN) + // We use unnormalized post-interpolation values, assuming mikktspace tangents + shading.tangentToWorld = float3x3(t, b, n); +#endif +#endif + + shading.position = vertex_worldPosition.xyz; + shading.view = normalize(frameUniforms_cameraPosition - shading.position); + + float2 viewportUV = vertex_position.xy / _ScreenParams.xy; + + #if defined(UNITY_SINGLE_PASS_STEREO) + viewportUV.x = viewportUV.x * 2.0 - float(unity_StereoEyeIndex); + #endif + + shading.normalizedViewportCoord = viewportUV; +} + + +/** + * Computes global shading parameters that the material might need to access + * before lighting: N dot V, the reflected vector and the shading normal (before + * applying the normal map). These parameters can be useful to material authors + * to compute other material properties. + * + * This function must be invoked by the user's material code (guaranteed by + * the material compiler) after setting a value for MaterialInputs.normal. + */ +void prepareMaterial(inout ShadingParams shading, const MaterialInputs material) { +#if defined(HAS_ATTRIBUTE_TANGENTS) +#if defined(MATERIAL_HAS_NORMAL) + shading.normal = normalize(mul(shading.tangentToWorld, material.normal)); +#else + shading.normal = shading.geometricNormal; +#endif // MATERIAL_HAS_NORMAL + shading.NoV = clampNoV(dot(shading.normal, shading.view)); + shading.reflected = reflect(-shading.view, shading.normal); + +#if defined(MATERIAL_HAS_BENT_NORMAL) + shading.bentNormal = normalize(mul(shading.tangentToWorld, material.bentNormal)); +#endif // MATERIAL_HAS_BENT_NORMAL + +#if defined(MATERIAL_HAS_CLEAR_COAT) +#if defined(MATERIAL_HAS_CLEAR_COAT_NORMAL) + shading.clearCoatNormal = normalize(mul(shading.tangentToWorld, material.clearCoatNormal)); +#else + shading.clearCoatNormal = shading.geometricNormal; +#endif // MATERIAL_HAS_CLEAR_COAT_NORMAL +#endif // MATERIAL_HAS_CLEAR_COAT +#endif // HAS_ATTRIBUTE_TANGENTS +} diff --git a/Assets/Filamented/FilamentShadingParameters.cginc.meta b/Assets/Filamented/FilamentShadingParameters.cginc.meta new file mode 100644 index 0000000..88ef57a --- /dev/null +++ b/Assets/Filamented/FilamentShadingParameters.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: ff03188209cc2b94e8c53a67c475e856 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentShadingStandard.cginc b/Assets/Filamented/FilamentShadingStandard.cginc new file mode 100644 index 0000000..02570ed --- /dev/null +++ b/Assets/Filamented/FilamentShadingStandard.cginc @@ -0,0 +1,213 @@ + +#ifndef FILAMENT_SHADING_STANDARD_INCLUDED +#define FILAMENT_SHADING_STANDARD_INCLUDED + +#include "FilamentBRDF.cginc" + +#if defined(MATERIAL_HAS_GLINT) +#include "SharedGlintyBRDF.hlsl" +#endif + +#if defined(MATERIAL_HAS_SHEEN_COLOR) +half3 sheenLobe(const PixelParams pixel, half NoV, half NoL, half NoH) { + half D = distributionCloth(pixel.sheenRoughness, NoH); + half V = visibilityCloth(NoV, NoL); + + return (D * V) * pixel.sheenColor; +} +#endif + +#if defined(MATERIAL_HAS_CLEAR_COAT) +half clearCoatLobe(const ShadingParams shading, const PixelParams pixel, + const half3 h, half NoH, half LoH, half3 NxH, out half Fcc) { +#if defined(MATERIAL_HAS_NORMAL) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL) + // If the material has a normal map, we want to use the geometric normal + // instead to avoid applying the normal map details to the clear coat layer + half clearCoatNoH = saturate(dot(shading.clearCoatNormal, h)); + half3 clearCoatNxH = cross(shading.clearCoatNormal, h); +#else + half clearCoatNoH = NoH; + half3 clearCoatNxH = NxH; +#endif + + // clear coat specular lobe + half D = distributionClearCoat(pixel.clearCoatRoughness, clearCoatNoH, clearCoatNxH, h); + half V = visibilityClearCoat(LoH); + half F = F_Schlick(0.04, 1.0, LoH) * pixel.clearCoat; // fix IOR to 1.5 + + Fcc = F; + return D * V * F; +} +#endif + +#if defined(MATERIAL_HAS_ANISOTROPY) +half3 anisotropicLobe(const ShadingParams shading, const PixelParams pixel, const Light light, + const half3 h, half NoV, half NoL, half NoH, half LoH) { + + half3 l = light.l; + half3 t = pixel.anisotropicT; + half3 b = pixel.anisotropicB; + half3 v = shading.view; + + half ToV = dot(t, v); + half BoV = dot(b, v); + half ToL = dot(t, l); + half BoL = dot(b, l); + half ToH = dot(t, h); + half BoH = dot(b, h); + + // Anisotropic parameters: at and ab are the roughness along the tangent and bitangent + // to simplify materials, we derive them from a single roughness parameter + // Kulla 2017, "Revisiting Physically Based Shading at Imageworks" + half at = max(pixel.roughness * (1.0 + pixel.anisotropy), MIN_ROUGHNESS); + half ab = max(pixel.roughness * (1.0 - pixel.anisotropy), MIN_ROUGHNESS); + + // specular anisotropic BRDF + half D = distributionAnisotropic(at, ab, ToH, BoH, NoH); + half V = visibilityAnisotropic(pixel.roughness, at, ab, ToV, BoV, ToL, BoL, NoV, NoL); + half3 F = fresnel(pixel.f0, LoH); + + return (D * V) * F; +} +#endif + +half3 isotropicLobe(const PixelParams pixel, const Light light, const half3 h, + half NoV, half NoL, half NoH, half LoH, half3 NxH) { + + half D = distribution(pixel.roughness, NoH, NxH, h); + half V = visibility(pixel.roughness, NoV, NoL); +#if defined(MATERIAL_HAS_SPECULAR_COLOR_FACTOR) || defined(MATERIAL_HAS_SPECULAR_FACTOR) + half3 F = fresnel(pixel.f0, pixel.f90, LoH); +#else + half3 F = fresnel(pixel.f0, LoH); +#endif + + return (D * V) * F; +} + +#if defined(MATERIAL_HAS_GLINT) +half3 isotropicGlintLobe(const ShadingParams shading, const PixelParams pixel, const Light light, + const half3 h, half NoV, half NoL, half NoH, half LoH) { + + float3 tangentH = mul(h, shading.tangentToWorld); + + float2x2 Jacobian = float2x2(pixel.ddx_uv, pixel.ddy_uv); + float2x2 uv_ellipsoid = get_uv_ellipsoid(Jacobian); + + half D = EvaluateGlintyNDF( + tangentH, + pixel.roughness, + pixel.glintAlpha, + pixel.uv, + uv_ellipsoid, + pixel.glintDensity, + 0.8 // Filter size + ); + D = max(0, D); + + half V = visibility(pixel.roughness, NoV, NoL); +#if defined(MATERIAL_HAS_SPECULAR_COLOR_FACTOR) || defined(MATERIAL_HAS_SPECULAR_FACTOR) + half3 F = fresnel(pixel.f0, pixel.f90, LoH); +#else + half3 F = fresnel(pixel.f0, LoH); +#endif + + return (D * V) * F; +} +#endif + +half3 specularLobe(const ShadingParams shading, const PixelParams pixel, const Light light, + const half3 h, half NoV, half NoL, half NoH, half LoH, half3 NxH) { +#if defined(MATERIAL_HAS_ANISOTROPY) + return anisotropicLobe(shading, pixel, light, h, NoV, NoL, NoH, LoH); +#elif defined(MATERIAL_HAS_GLINT) + return isotropicGlintLobe(shading, pixel, light, h, NoV, NoL, NoH, LoH); +#else + return isotropicLobe(pixel, light, h, NoV, NoL, NoH, LoH, NxH); +#endif +} + +half3 diffuseLobe(const PixelParams pixel, half NoV, half NoL, half LoH) { + return pixel.diffuseColor * diffuse(pixel.roughness, NoV, NoL, LoH); +} + +/** + * Evaluates lit materials with the standard shading model. This model comprises + * of 2 BRDFs: an optional clear coat BRDF, and a regular surface BRDF. + * + * Surface BRDF + * The surface BRDF uses a diffuse lobe and a specular lobe to render both + * dielectrics and conductors. The specular lobe is based on the Cook-Torrance + * micro-facet model (see brdf.fs for more details). In addition, the specular + * can be either isotropic or anisotropic. + * + * Clear coat BRDF + * The clear coat BRDF simulates a transparent, absorbing dielectric layer on + * top of the surface. Its IOR is set to 1.5 (polyutherane) to simplify + * our computations. This BRDF only contains a specular lobe and while based + * on the Cook-Torrance microfacet model, it uses cheaper terms than the surface + * BRDF's specular lobe (see brdf.fs). + */ +half3 surfaceShading(const ShadingParams shading, const PixelParams pixel, const Light light, +half occlusion) { + + half3 h = normalize(shading.view + light.l); + + half NoV = shading.NoV; + half NoL = saturate(light.NoL); + half NoH = saturate(dot(shading.normal, h)); + half LoH = saturate(dot(light.l, h)); + half3 NxH = cross(shading.normal, h); + + // Note: For Unity, specular and diffuse terms must be multiplied by Pi + // to match the light intensities of other shaders. + // This is partly because the diffuse term is already divided by Pi here. + half3 Fr = specularLobe(shading, pixel, light, h, NoV, NoL, NoH, LoH, NxH) * PI; + half3 Fd = diffuseLobe(pixel, NoV, NoL, LoH) * PI; + + // Unity toggle for disabling specular highlights. +#if defined(_SPECULARHIGHLIGHTS_OFF) + Fr = 0.0; +#endif + +#if defined(HAS_REFRACTION) + Fd *= (1.0 - pixel.transmission); +#endif + + // TODO: attenuate the diffuse lobe to avoid energy gain + + // The energy compensation term is used to counteract the darkening effect + // at high roughness + half3 color = Fd + Fr * pixel.energyCompensation; + +#if defined(MATERIAL_HAS_SHEEN_COLOR) + color *= pixel.sheenScaling; + color += sheenLobe(pixel, NoV, NoL, NoH); +#endif + +#if defined(MATERIAL_HAS_CLEAR_COAT) + half Fcc; + half clearCoat = clearCoatLobe(shading, pixel, h, NoH, LoH, NxH, Fcc); + half attenuation = 1.0 - Fcc; + +#if defined(MATERIAL_HAS_NORMAL) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL) + color *= attenuation * NoL; + + // If the material has a normal map, we want to use the geometric normal + // instead to avoid applying the normal map details to the clear coat layer + half clearCoatNoL = saturate(dot(shading.clearCoatNormal, light.l)); + color += clearCoat * clearCoatNoL; + + // Early exit to avoid the extra multiplication by NoL + return (color * light.colorIntensity.rgb) * + (light.colorIntensity.w * light.attenuation * occlusion); +#else + color *= attenuation; + color += clearCoat; +#endif +#endif + return (color * light.colorIntensity.rgb) * + (light.colorIntensity.w * light.attenuation * NoL * occlusion); +} + +#endif // FILAMENT_SHADING_STANDARD_INCLUDED diff --git a/Assets/Filamented/FilamentShadingStandard.cginc.meta b/Assets/Filamented/FilamentShadingStandard.cginc.meta new file mode 100644 index 0000000..e524211 --- /dev/null +++ b/Assets/Filamented/FilamentShadingStandard.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b4066f85461bf6e47b85dcf8bd04104c +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/FilamentShadingSubsurface.cginc b/Assets/Filamented/FilamentShadingSubsurface.cginc new file mode 100644 index 0000000..1950789 --- /dev/null +++ b/Assets/Filamented/FilamentShadingSubsurface.cginc @@ -0,0 +1,48 @@ +#ifndef FILAMENT_SHADING_SUBSURFACE_INCLUDED +#define FILAMENT_SHADING_SUBSURFACE_INCLUDED + +#include "FilamentBRDF.cginc" +/** + * Evalutes lit materials with the subsurface shading model. This model is a + * combination of a BRDF (the same used in shading_model_standard.fs, refer to that + * file for more information) and of an approximated BTDF to simulate subsurface + * scattering. The BTDF itself is not physically based and does not represent a + * correct interpretation of transmission events. + */ +half3 surfaceShading(const ShadingParams shading, const PixelParams pixel, const Light light, half occlusion) { + half3 h = normalize(shading.view + light.l); + + half NoL = light.NoL; + half NoH = saturate(dot(shading.normal, h)); + half LoH = saturate(dot(light.l, h)); + half3 NxH = cross(shading.normal, h); + + half3 Fr = 0.0; + if (NoL > 0.0) { + // specular BRDF + half D = distribution(pixel.roughness, NoH, NxH, h); + half V = visibility(pixel.roughness, shading.NoV, NoL); + half3 F = fresnel(pixel.f0, LoH); + Fr = (D * V) * F * pixel.energyCompensation; + } + + // diffuse BRDF + half3 Fd = pixel.diffuseColor * diffuse(pixel.roughness, shading.NoV, NoL, LoH); + + // NoL does not apply to transmitted light + half3 color = (Fd + Fr) * (NoL * occlusion); + + // subsurface scattering + // Use a spherical gaussian approximation of pow() for forwardScattering + // We could include distortion by adding shading.normal * distortion to light.l + half scatterVoH = saturate(dot(shading.view, -light.l)); + half forwardScatter = exp2(scatterVoH * pixel.subsurfacePower - pixel.subsurfacePower); + half backScatter = saturate(NoL * pixel.thickness + (1.0 - pixel.thickness)) * 0.5; + half subsurface = lerp(backScatter, 1.0, forwardScatter) * (1.0 - pixel.thickness); + color += pixel.subsurfaceColor * (subsurface * Fd_Lambert()); + + // TODO: apply occlusion to the transmitted light + return (color * light.colorIntensity.rgb) * (light.colorIntensity.w * light.attenuation); +} + +#endif // FILAMENT_SHADING_SUBSURFACE_INCLUDED diff --git a/Assets/Filamented/FilamentShadingSubsurface.cginc.meta b/Assets/Filamented/FilamentShadingSubsurface.cginc.meta new file mode 100644 index 0000000..6905767 --- /dev/null +++ b/Assets/Filamented/FilamentShadingSubsurface.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 9e45529e249ed1c4e8b0b3f44d64d3d6 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/LightVolumes.LICENSE.txt b/Assets/Filamented/LightVolumes.LICENSE.txt new file mode 100644 index 0000000..7dc260c --- /dev/null +++ b/Assets/Filamented/LightVolumes.LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 RED_SIM + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Assets/Filamented/LightVolumes.LICENSE.txt.meta b/Assets/Filamented/LightVolumes.LICENSE.txt.meta new file mode 100644 index 0000000..903013b --- /dev/null +++ b/Assets/Filamented/LightVolumes.LICENSE.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f7243e67baded214aa69bebae47a4592 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/LightVolumes.cginc b/Assets/Filamented/LightVolumes.cginc new file mode 100644 index 0000000..88e37de --- /dev/null +++ b/Assets/Filamented/LightVolumes.cginc @@ -0,0 +1,949 @@ +#ifndef VRC_LIGHT_VOLUMES_INCLUDED +#define VRC_LIGHT_VOLUMES_INCLUDED +#define VRCLV_VERSION 2 +#define VRCLV_MAX_VOLUMES_COUNT 32 +#define VRCLV_MAX_LIGHTS_COUNT 128 + + +#ifndef SHADER_TARGET_SURFACE_ANALYSIS +cbuffer LightVolumeUniforms { +#endif + +// Are Light Volumes enabled on scene? can be 0 or 1 +uniform float _UdonLightVolumeEnabled; + +// Rreturns 1, 2 or other number if there are light volumes on the scene. Number represents the light volumes system internal version number. +uniform float _UdonLightVolumeVersion; + +// All volumes count in scene +uniform float _UdonLightVolumeCount; + +// Additive volumes max overdraw count +uniform float _UdonLightVolumeAdditiveMaxOverdraw; + +// Additive volumes count +uniform float _UdonLightVolumeAdditiveCount; + +// Should volumes be blended with lightprobes? +uniform float _UdonLightVolumeProbesBlend; + +// Should volumes be with sharp edges when not blending with each other +uniform float _UdonLightVolumeSharpBounds; + +// World to Local (-0.5, 0.5) UVW Matrix 4x4 +uniform float4x4 _UdonLightVolumeInvWorldMatrix[VRCLV_MAX_VOLUMES_COUNT]; + +// L1 SH quaternion rotation (relative to baked rotation) +//uniform float4 _UdonLightVolumeRotationQuaternion[32]; +uniform float4 _UdonLightVolumeRotation[VRCLV_MAX_VOLUMES_COUNT * 2]; // Legacy! Used in this version to have back compatibility with older worlds. Array commented above will be used in future releases! Legacy! + +// Value that is needed to smoothly blend volumes ( BoundsScale / edgeSmooth ) +uniform float3 _UdonLightVolumeInvLocalEdgeSmooth[VRCLV_MAX_VOLUMES_COUNT]; + +// AABB Bounds of islands on the 3D Texture atlas. XYZ: UvwMin, W: Scale per axis +// uniform float4 _UdonLightVolumeUvwScale[96]; +uniform float3 _UdonLightVolumeUvw[VRCLV_MAX_VOLUMES_COUNT * 6]; // Legacy! AABB Bounds of islands on the 3D Texture atlas. Array commented above will be used in future releases! Legacy! + +// XYZ: AABB Bounds of islands on the 3D Texture atlas storing occlusion. W: Scale factor for the occlusion volume UVW +// This is optional data. If the volume has no occlusion, the value will be (-1, -1, -1, -1). +uniform float4 _UdonLightVolumeOcclusionUvw[VRCLV_MAX_VOLUMES_COUNT]; + +// Color multiplier (RGB) | If we actually need to rotate L1 components at all (A) +uniform float4 _UdonLightVolumeColor[VRCLV_MAX_VOLUMES_COUNT]; + +// Point Lights count +uniform float _UdonPointLightVolumeCount; + +// Cubemaps count in the custom textures array +uniform float _UdonPointLightVolumeCubeCount; + +// For point light: XYZ = Position, W = Inverse squared range +// For spot light: XYZ = Position, W = Inverse squared range, negated +// For area light: XYZ = Position, W = Width +uniform float4 _UdonPointLightVolumePosition[VRCLV_MAX_LIGHTS_COUNT]; + +// For point light: XYZ = Color, W = Cos of angle (for LUT) +// For spot light: XYZ = Color, W = Cos of outer angle if no custom texture, tan of outer angle otherwise +// For area light: XYZ = Color, W = 2 + Height +uniform float4 _UdonPointLightVolumeColor[VRCLV_MAX_LIGHTS_COUNT]; + +// For point light: XYZW = Rotation quaternion +// For spot light: XYZ = Direction, W = Cone falloff +// For area light: XYZW = Rotation quaternion +uniform float4 _UdonPointLightVolumeDirection[VRCLV_MAX_LIGHTS_COUNT]; + +// X = Custom ID: +// If parametric: X stores 0 +// If uses custom lut: X stores LUT ID with positive sign +// If uses custom texture: X stores texture ID with negative sign +// Y = Shadowmask index. If light doesn't use shadowmask, the index will be negative. +// Z = Squared Culling Range. Just a precalculated culling range to not recalculate in in shader. +uniform float3 _UdonPointLightVolumeCustomID[VRCLV_MAX_LIGHTS_COUNT]; + +// If we are far enough from a light that the irradiance +// is guaranteed lower than the threshold defined by this value, +// we cull the light. +uniform float _UdonLightBrightnessCutoff; + +// The number of volumes that provide occlusion data. +// We use this to take faster paths when no occlusion is needed. +uniform float _UdonLightVolumeOcclusionCount; + +#ifndef SHADER_TARGET_SURFACE_ANALYSIS +} +#endif + +#ifndef SHADER_TARGET_SURFACE_ANALYSIS + +// Main 3D Texture atlas +uniform Texture3D _UdonLightVolume; +uniform SamplerState sampler_UdonLightVolume; +// First elements must be cubemap faces (6 face textures per cubemap). Then goes other textures +uniform Texture2DArray _UdonPointLightVolumeTexture; +// Samples a texture using mip 0, and reusing a single sampler +#define LV_SAMPLE(tex, uvw) tex.SampleLevel(sampler_UdonLightVolume, uvw, 0) + +#else + +// Dummy macro definition to satisfy MojoShader (surface shaders). +#define LV_SAMPLE(tex, uvw) float4(0,0,0,0) + +#endif + +#define LV_PI 3.141592653589793f +#define LV_PI2 6.283185307179586f + +// Smoothstep to 0, 1 but cheaper +float LV_Smoothstep01(float x) { + return x * x * (3 - 2 * x); +} + +// Rotates vector by Quaternion +float3 LV_MultiplyVectorByQuaternion(float3 v, float4 q) { + float3 t = 2.0 * cross(q.xyz, v); + return v + q.w * t + cross(q.xyz, t); +} + +// Rotates vector by Matrix 2x3 +float3 LV_MultiplyVectorByMatrix2x3(float3 v, float3 r0, float3 r1) { + float3 r2 = cross(r0, r1); + return float3(dot(v, r0), dot(v, r1), dot(v, r2)); +} + +// Fast approximate inverse cosine. Max absolute error = 0.009. +// From https://seblagarde.wordpress.com/2014/12/01/inverse-trigonometric-functions-gpu-optimization-for-amd-gcn-architecture/ +float LV_FastAcos(float x) { + float absX = abs(x); + float res = -0.156583f * absX + LV_PI * 0.5f; + res *= sqrt(1.0f - absX); + return (x >= 0) ? res : (LV_PI - res); +} + +// Forms specular based on roughness +float LV_DistributionGGX(float NoH, float roughness) { + float f = (roughness - 1) * ((roughness + 1) * (NoH * NoH)) + 1; + return (roughness * roughness) / ((float) LV_PI * f * f); +} + +// Checks if local UVW point is in bounds from -0.5 to +0.5 +bool LV_PointLocalAABB(float3 localUVW) { + return all(abs(localUVW) <= 0.5); +} + +// Calculates local UVW using volume ID +float3 LV_LocalFromVolume(uint volumeID, float3 worldPos) { + return mul(_UdonLightVolumeInvWorldMatrix[volumeID], float4(worldPos, 1.0)).xyz; +} + +// Linear single SH L1 channel evaluation +float LV_EvaluateSH(float L0, float3 L1, float3 n) { + return L0 + dot(L1, n); +} + +// Samples a cubemap from _UdonPointLightVolumeTexture array +float4 LV_SampleCubemapArray(uint id, float3 dir) { + float3 absDir = abs(dir); + float2 uv; + uint face; + if (absDir.x >= absDir.y && absDir.x >= absDir.z) { + face = dir.x > 0 ? 0 : 1; + uv = float2((dir.x > 0 ? -dir.z : dir.z), -dir.y) * rcp(absDir.x); + } else if (absDir.y >= absDir.z) { + face = dir.y > 0 ? 2 : 3; + uv = float2(dir.x, (dir.y > 0 ? dir.z : -dir.z)) * rcp(absDir.y); + } else { + face = dir.z > 0 ? 4 : 5; + uv = float2((dir.z > 0 ? dir.x : -dir.x), -dir.y) * rcp(absDir.z); + } + float3 uvid = float3(uv * 0.5 + 0.5, id * 6 + face); + return LV_SAMPLE(_UdonPointLightVolumeTexture, uvid); +} + +// Projects irradiance from a planar quad with uniform radiant exitance into L1 spherical harmonics. +// Based on "Analytic Spherical Harmonic Coefficients for Polygonal Area Lights" by Wang and Ramamoorthi. +// https://cseweb.ucsd.edu/~ravir/ash.pdf. Assumes that shadingPosition is not behind the quad. +float4 LV_ProjectQuadLightIrradianceSH(float3 shadingPosition, float3 lightVertices[4]) { + // Transform the vertices into local space centered on the shading position, + // project, the polygon onto the unit sphere. + [unroll] for (uint edge0 = 0; edge0 < 4; edge0++) { + lightVertices[edge0] = normalize(lightVertices[edge0] - shadingPosition); + } + + // Precomputed directions of rotated zonal harmonics, + // and associated weights for each basis function. + // I.E. \omega_{l,d} and \alpha_{l,d}^m in the paper respectively. + const float3 zhDir0 = float3(0.866025, -0.500001, -0.000004); + const float3 zhDir1 = float3(-0.759553, 0.438522, -0.480394); + const float3 zhDir2 = float3(-0.000002, 0.638694, 0.769461); + const float3 zhWeightL1y = float3(2.1995339f, 2.50785367f, 1.56572711f); + const float3 zhWeightL1z = float3(-1.82572523f, -2.08165037f, 0.00000000f); + const float3 zhWeightL1x = float3(2.42459869f, 1.44790525f, 0.90397552f); + + float solidAngle = 0.0; + float3 surfaceIntegral = 0.0; + [loop] for (uint edge1 = 0; edge1 < 4; edge1++) { + uint next = (edge1 + 1) % 4; + uint prev = (edge1 + 4 - 1) % 4; + float3 prevVert = lightVertices[prev]; + float3 thisVert = lightVertices[edge1]; + float3 nextVert = lightVertices[next]; + + // Compute the solid angle subtended by the polygon at the shading position, + // using Arvo's formula (5.1) https://dl.acm.org/doi/pdf/10.1145/218380.218467. + // The L0 term is directly proportional to the solid angle. + float3 a = cross(thisVert, prevVert); + float3 b = cross(thisVert, nextVert); + float lenA = length(a); + float lenB = length(b); + solidAngle += LV_FastAcos(clamp(dot(a, b) / (lenA * lenB), -1, 1)); + + // Compute the integral of the legendre polynomials over the surface of the + // projected polygon for each zonal harmonic direction (S_l in the paper). + // Computed as a sum of line integrals over the edges of the polygon. + float3 mu = b * rcp(lenB); + float cosGamma = dot(thisVert, nextVert); + float gamma = LV_FastAcos(clamp(cosGamma, -1, 1)); + surfaceIntegral.x += gamma * dot(zhDir0, mu); + surfaceIntegral.y += gamma * dot(zhDir1, mu); + surfaceIntegral.z += gamma * dot(zhDir2, mu); + } + solidAngle = solidAngle - LV_PI2; + surfaceIntegral *= 0.5; + + // The L0 term is just the projection of the solid angle onto the L0 basis function. + const float normalizationL0 = 0.5f * sqrt(1.0f / LV_PI); + float l0 = normalizationL0 * solidAngle; + + // Combine each surface (sub)integral with the associated weights to get + // full surface integral for each L1 SH basis function. + float l1y = dot(zhWeightL1y, surfaceIntegral); + float l1z = dot(zhWeightL1z, surfaceIntegral); + float l1x = dot(zhWeightL1x, surfaceIntegral); + + // The l0, l1y, l1z, l1x are raw SH coefficients for radiance from the polygon. + // We need to apply some more transformations before we are done: + // (1) We want the coefficients for irradiance, so we need to convolve with the + // clamped cosine kernel, as detailed in https://cseweb.ucsd.edu/~ravir/papers/envmap/envmap.pdf. + // The kernel has coefficients PI and 2/3*PI for L0 and L1 respectively. + // (2) Unity's area lights underestimate the irradiance by a factor of PI for historical reasons. + // We need to divide by PI to match this 'incorrect' behavior. + // (3) Unity stores SH coefficients (unity_SHAr..unity_SHC) pre-multiplied with the constant + // part of each SH basis function, so we need to multiply by constant part to match it. + const float cosineKernelL0 = LV_PI; // (1) + const float cosineKernelL1 = LV_PI2 / 3.0f; // (1) + const float oneOverPi = 1.0f / LV_PI; // (2) + const float normalizationL1 = 0.5f * sqrt(3.0f / LV_PI); // (3) + const float weightL0 = cosineKernelL0 * normalizationL0 * oneOverPi; // (1), (2), (3) + const float weightL1 = cosineKernelL1 * normalizationL1 * oneOverPi; // (1), (2), (3) + l0 *= weightL0; + l1y *= weightL1; + l1z *= weightL1; + l1x *= weightL1; + + return float4(l1x, l1y, l1z, l0); +} + +// Samples a quad light, including culling +void LV_QuadLight(float3 worldPos, float3 centroidPos, float4 rotationQuat, float2 size, float3 color, float sqMaxDist, float occlusion, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, inout uint count) { + + float3 lightToWorldPos = worldPos - centroidPos; + + // Normal culling + float3 normal = LV_MultiplyVectorByQuaternion(float3(0, 0, 1), rotationQuat); + [branch] if (dot(normal, lightToWorldPos) < 0.0) return; + + // Attenuate the light based on distance to the bounding sphere, so we don't get hard seam at the edge. + float sqCutoffDist = sqMaxDist - dot(lightToWorldPos, lightToWorldPos); + color.rgb *= saturate(sqCutoffDist / sqMaxDist) * LV_PI * occlusion; + + // Compute the vertices of the quad + float2 halfSize = size * 0.5f; + float3 xAxis = LV_MultiplyVectorByQuaternion(float3(1, 0, 0), rotationQuat); + float3 yAxis = cross(normal, xAxis); + float3 verts[4]; + verts[0] = centroidPos + (-halfSize.x * xAxis) + ( halfSize.y * yAxis); + verts[1] = centroidPos + ( halfSize.x * xAxis) + ( halfSize.y * yAxis); + verts[2] = centroidPos + ( halfSize.x * xAxis) + (-halfSize.y * yAxis); + verts[3] = centroidPos + (-halfSize.x * xAxis) + (-halfSize.y * yAxis); + + // Project irradiance from the area light + float4 areaLightSH = LV_ProjectQuadLightIrradianceSH(worldPos, verts); + + // If the magnitude of L1 is greater than L0, we may get negative values + // when reconstructing. To avoid, normalize L1. This is effectively de-ringing. + float lenL1 = length(areaLightSH.xyz); + if (lenL1 > areaLightSH.w) areaLightSH.xyz *= areaLightSH.w / lenL1; + + L0 += areaLightSH.w * color.rgb; + L1r += areaLightSH.xyz * color.r; + L1g += areaLightSH.xyz * color.g; + L1b += areaLightSH.xyz * color.b; + + count++; +} + +// Calculates point light attenuation. Returns false if it's culled +float3 LV_PointLightAttenuation(float sqdist, float sqlightSize, float3 color, float brightnessCutoff, float sqMaxDist) { + float mask = saturate(1 - sqdist / sqMaxDist); + return mask * mask * color * sqlightSize / (sqdist + sqlightSize); +} + +// Calculates point light solid angle coefficient +float LV_PointLightSolidAngle(float sqdist, float sqlightSize) { + return saturate(sqrt(sqdist / (sqlightSize + sqdist))); +} + +// Calculares a spherical light source +void LV_SphereLight(float sqdist, float3 dirN, float sqlightSize, float3 color, float occlusion, float sqMaxDist, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, inout uint count) { + + float3 att = LV_PointLightAttenuation(sqdist, sqlightSize, color, _UdonLightBrightnessCutoff, sqMaxDist); + + float3 l0 = att * occlusion; + float3 l1 = dirN * LV_PointLightSolidAngle(sqdist, sqlightSize); + + L0 += l0; + L1r += l0.r * l1; + L1g += l0.g * l1; + L1b += l0.b * l1; + count++; + +} + +// Calculares a spherical spot light source +void LV_SphereSpotLight(float sqdist, float3 dirN, float sqlightSize, float3 att, float spotMask, float cosAngle, float coneFalloff, float occlusion, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, inout uint count) { + + float smoothedCone = LV_Smoothstep01(saturate(spotMask * coneFalloff)); + float3 l0 = att * (occlusion * smoothedCone); + float3 l1 = dirN * LV_PointLightSolidAngle(sqdist, sqlightSize * saturate(1 - cosAngle)); + + L0 += l0; + L1r += l0.r * l1; + L1g += l0.g * l1; + L1b += l0.b * l1; + count++; + +} + +// Calculares a spherical spot light source +void LV_SphereSpotLightCookie(float sqdist, float3 dirN, float sqlightSize, float3 att, float4 lightRot, float tanAngle, uint customId, float occlusion, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, inout uint count) { + + float3 localDir = LV_MultiplyVectorByQuaternion(-dirN, lightRot); + float2 uv = localDir.xy * rcp(localDir.z * tanAngle); + [branch] if ( + localDir.z <= 0.0 || // Culling by direction + abs(uv.x) > 1.0 || abs(uv.y) > 1.0 // Culling by UV + ) return; + + uint id = (uint) _UdonPointLightVolumeCubeCount * 5 - customId - 1; + float3 uvid = float3(uv * 0.5 + 0.5, id); + float angleSize = saturate(rsqrt(1 + tanAngle * tanAngle)); + float4 cookie = LV_SAMPLE(_UdonPointLightVolumeTexture, uvid); + + float3 l0 = att * cookie.rgb * (cookie.a * occlusion); + float3 l1 = dirN * LV_PointLightSolidAngle(sqdist, sqlightSize * (1 - angleSize)); + + L0 += l0; + L1r += l0.r * l1; + L1g += l0.g * l1; + L1b += l0.b * l1; + count++; + +} + +// Calculares a spherical spot light source +void LV_SphereSpotLightAttenuationLUT(float sqdist, float3 dirN, float sqlightSize, float3 color, float spotMask, float cosAngle, uint customId, float occlusion, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, inout uint count) { + + float dirRadius = sqdist * abs(sqlightSize); + float spot = 1 - saturate(spotMask * rcp(1 - cosAngle)); + uint id = (uint) _UdonPointLightVolumeCubeCount * 5 + customId - 1; + float3 uvid = float3(sqrt(float2(spot, dirRadius)), id); + float3 att = color.rgb * LV_SAMPLE(_UdonPointLightVolumeTexture, uvid).xyz * occlusion; + + L0 += att; + L1r += dirN * att.r; + L1g += dirN * att.g; + L1b += dirN * att.b; + + count++; + +} + +// Samples a spot light, point light or quad/area light +void LV_PointLight(uint id, float3 worldPos, float4 occlusion, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, inout uint count) { + + // IDs and range data + float3 customID_data = _UdonPointLightVolumeCustomID[id]; + int shadowId = (int) customID_data.y; // Shadowmask id + int customId = (int) customID_data.x; // Custom Texture ID + float sqrRange = customID_data.z; // Squared culling distance + + float4 pos = _UdonPointLightVolumePosition[id]; // Light position and inversed squared range + float3 dir = pos.xyz - worldPos; + float sqlen = max(dot(dir, dir), 1e-6); + [branch] if (sqlen > sqrRange) return; // Early distance based culling + float3 dirN = dir * rsqrt(sqlen); + + // Processing lights occlusion + float lightOcclusion = 1; + if (_UdonLightVolumeOcclusionCount != 0 && shadowId >= 0) { + lightOcclusion = dot(occlusion, float4(shadowId == 0, shadowId == 1, shadowId == 2, shadowId == 3)); + } + + float4 color = _UdonPointLightVolumeColor[id]; // Color, angle + float4 ldir = _UdonPointLightVolumeDirection[id]; // Dir + falloff or Rotation + + [branch] if (pos.w < 0) { // It is a spot light + + float angle = color.w; + float spotMask = dot(ldir.xyz, -dirN) - angle; + [branch] if(customId >= 0 && spotMask < 0) return; // Spot cone based culling + + [branch] if (customId > 0) { // If it uses Attenuation LUT + + LV_SphereSpotLightAttenuationLUT(sqlen, dirN, -pos.w, color.rgb, spotMask, angle, customId, lightOcclusion, L0, L1r, L1g, L1b, count); + + } else { // If it uses default parametric attenuation + + float3 att = LV_PointLightAttenuation(sqlen, -pos.w, color.rgb, _UdonLightBrightnessCutoff, sqrRange); + + [branch] if (customId < 0) { // If uses cookie + + LV_SphereSpotLightCookie(sqlen, dirN, -pos.w, att, ldir, angle, customId, lightOcclusion, L0, L1r, L1g, L1b, count); + + } else { // If it uses default parametric attenuation + + LV_SphereSpotLight(sqlen, dirN, -pos.w, att, spotMask, angle, ldir.w, lightOcclusion, L0, L1r, L1g, L1b, count); + + } + + } + + } else if (color.w <= 1.5f) { // It is a point light + + [branch] if (customId > 0) { // Using LUT + + float invSqRange = abs(pos.w); // Sign of range defines if it's point light (positive) or a spot light (negative) + float dirRadius = sqlen * invSqRange; + uint id = (uint) _UdonPointLightVolumeCubeCount * 5 + customId; + float3 uvid = float3(sqrt(float2(0, dirRadius)), id); + float3 att = color.rgb * LV_SAMPLE(_UdonPointLightVolumeTexture, uvid).xyz * lightOcclusion; + + L0 += att; + L1r += dirN * att.r; + L1g += dirN * att.g; + L1b += dirN * att.b; + + count++; + + } else { // If it uses default parametric attenuation + + float3 l0 = 0, l1r = 0, l1g = 0, l1b = 0; + LV_SphereLight(sqlen, dirN, pos.w, color.rgb, lightOcclusion, sqrRange, l0, l1r, l1g, l1b, count); + + float3 cubeColor = 1; + [branch] if (customId < 0) { // If it uses a cubemap + uint id = -customId - 1; // Cubemap ID starts from zero and should not take in count texture array slices count. + cubeColor = LV_SampleCubemapArray(id, LV_MultiplyVectorByQuaternion(dirN, ldir)).xyz; + } + + L0 += l0 * cubeColor; + L1r += l1r * cubeColor.r; + L1g += l1g * cubeColor.g; + L1b += l1b * cubeColor.b; + } + + } else { // It is an area light + + LV_QuadLight(worldPos, pos.xyz, ldir, float2(pos.w, color.w - 2.0f), color.rgb, sqrRange, lightOcclusion, L0, L1r, L1g, L1b, count); + + } + +} + +// Samples 3 SH textures and packing them into L1 channels +void LV_SampleLightVolumeTex(float3 uvw0, float3 uvw1, float3 uvw2, out float3 L0, out float3 L1r, out float3 L1g, out float3 L1b) { + // Sampling 3D Atlas + float4 tex0 = LV_SAMPLE(_UdonLightVolume, uvw0); + float4 tex1 = LV_SAMPLE(_UdonLightVolume, uvw1); + float4 tex2 = LV_SAMPLE(_UdonLightVolume, uvw2); + // Packing final data + L0 = tex0.rgb; + L1r = float3(tex1.r, tex2.r, tex0.a); + L1g = float3(tex1.g, tex2.g, tex1.a); + L1b = float3(tex1.b, tex2.b, tex2.a); +} + +// Bounds mask for a volume rotated in world space, using local UVW +float LV_BoundsMask(float3 localUVW, float3 invLocalEdgeSmooth) { + float3 distToMin = (localUVW + 0.5) * invLocalEdgeSmooth; + float3 distToMax = (0.5 - localUVW) * invLocalEdgeSmooth; + float3 fade = saturate(min(distToMin, distToMax)); + return fade.x * fade.y * fade.z; +} + +// Default light probes SH components +void LV_SampleLightProbe(inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b) { + L0 += float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); + L1r += unity_SHAr.xyz; + L1g += unity_SHAg.xyz; + L1b += unity_SHAb.xyz; +} + +// Applies deringing to light probes. Useful if they baked with Bakery L1 +void LV_SampleLightProbeDering(inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b) { + L0 += float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); + L1r += unity_SHAr.xyz * 0.565f; + L1g += unity_SHAg.xyz * 0.565f; + L1b += unity_SHAb.xyz * 0.565f; +} + +// Samples a Volume with ID and Local UVW +void LV_SampleVolume(uint id, float3 localUVW, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, out float4 occlusion) { + + // Additive UVW + //uint uvwID = id * 3; + //float4 uvwPos0 = _UdonLightVolumeUvwScale[uvwID]; + //float4 uvwPos1 = _UdonLightVolumeUvwScale[uvwID + 1]; + //float4 uvwPos2 = _UdonLightVolumeUvwScale[uvwID + 2]; + //float3 uvwScale = float3(uvwPos0.w, uvwPos1.w, uvwPos2.w); + + //float3 uvwScaled = saturate(localUVW + 0.5) * uvwScale; + //float3 uvw0 = uvwPos0.xyz + uvwScaled; + //float3 uvw1 = uvwPos1.xyz + uvwScaled; + //float3 uvw2 = uvwPos2.xyz + uvwScaled; + + // Legacy! Commented code above will be used in future releases! Legacy! + uint uvwID = id * 6; + float3 uvwScaled = saturate(localUVW + 0.5) * (_UdonLightVolumeUvw[uvwID + 1].xyz - _UdonLightVolumeUvw[uvwID].xyz); + float3 uvw0 = uvwScaled + _UdonLightVolumeUvw[uvwID].xyz; + float3 uvw1 = uvwScaled + _UdonLightVolumeUvw[uvwID + 2].xyz; + float3 uvw2 = uvwScaled + _UdonLightVolumeUvw[uvwID + 4].xyz; + + // Sample additive + float3 l0, l1r, l1g, l1b; + LV_SampleLightVolumeTex(uvw0, uvw1, uvw2, l0, l1r, l1g, l1b); + + // Sample occlusion + float4 uvwOcclusion = _UdonLightVolumeOcclusionUvw[id]; + [branch] if (uvwOcclusion.x >= 0) { + occlusion = 1.0f - LV_SAMPLE(_UdonLightVolume, uvwOcclusion.xyz + uvwScaled * uvwOcclusion.w); + } else { + occlusion = 1; + } + + // Color correction + float4 color = _UdonLightVolumeColor[id]; + L0 += l0 * color.rgb; + l1r *= color.r; + l1g *= color.g; + l1b *= color.b; + + // Rotate if needed + if (color.a != 0) { + //float4 r = _UdonLightVolumeRotationQuaternion[id]; + //L1r = LV_MultiplyVectorByQuaternion(L1r, r); + //L1g = LV_MultiplyVectorByQuaternion(L1g, r); + //L1b = LV_MultiplyVectorByQuaternion(L1b, r); + + // Legacy to support older light volumes worlds! Commented code above will be used in future releases! Legacy! + float3 r0 = _UdonLightVolumeRotation[id * 2].xyz; + float3 r1 = _UdonLightVolumeRotation[id * 2 + 1].xyz; + L1r += LV_MultiplyVectorByMatrix2x3(l1r, r0, r1); + L1g += LV_MultiplyVectorByMatrix2x3(l1g, r0, r1); + L1b += LV_MultiplyVectorByMatrix2x3(l1b, r0, r1); + } else { + L1r += l1r; + L1g += l1g; + L1b += l1b; + } + +} + +float4 LV_SampleVolumeOcclusion(uint id, float3 localUVW) { + + // Sample occlusion + float4 uvwOcclusion = _UdonLightVolumeOcclusionUvw[id]; + + [branch] if (uvwOcclusion.x >= 0) { + //uint uvwID = id * 3; + //float4 uvwPos0 = _UdonLightVolumeUvwScale[uvwID]; + //float4 uvwPos1 = _UdonLightVolumeUvwScale[uvwID + 1]; + //float4 uvwPos2 = _UdonLightVolumeUvwScale[uvwID + 2]; + //float3 uvwScale = float3(uvwPos0.w, uvwPos1.w, uvwPos2.w); + //float3 uvwScaled = saturate(localUVW + 0.5) * uvwScale; + + // Legacy to support older light volumes worlds! Commented code above will be used in future releases! Legacy! + uint uvwID = id * 6; + float3 uvwScaled = saturate(localUVW + 0.5) * (_UdonLightVolumeUvw[uvwID + 1].xyz - _UdonLightVolumeUvw[uvwID].xyz); + + return 1.0f - LV_SAMPLE(_UdonLightVolume, uvwOcclusion.xyz + uvwScaled * uvwOcclusion.w); + } else { + return 1; + } + +} + +// Calculates L1 SH based on the world position and occlusion factor. Only samples point lights, not light volumes. +void LV_PointLightVolumeSH(float3 worldPos, float4 occlusion, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b) { + + uint pointCount = min((uint) _UdonPointLightVolumeCount, VRCLV_MAX_LIGHTS_COUNT); + [branch] if (pointCount == 0) return; + + uint maxOverdraw = min((uint) _UdonLightVolumeAdditiveMaxOverdraw, VRCLV_MAX_LIGHTS_COUNT); + uint pcount = 0; // Point lights counter + + [loop] for (uint pid = 0; pid < pointCount && pcount < maxOverdraw; pid++) { + LV_PointLight(pid, worldPos, occlusion, L0, L1r, L1g, L1b, pcount); + } + +} + +// Calculates L1 SH and occlusion based on the world position. Only samples light volumes, not point lights. +void LV_LightVolumeSH(float3 worldPos, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, out float4 occlusion) { + + // Initializing output variables + occlusion = 1; + float4 mOcclusion = 1; // Multiplicative occlusion. Applies on top of regular occlusion + + // Clamping gloabal iteration counts + uint volumesCount = min((uint) _UdonLightVolumeCount, VRCLV_MAX_VOLUMES_COUNT); + + //if (_UdonLightVolumeVersion < VRCLV_VERSION || volumesCount == 0 ) { // Fallback to default light probes if Light Volume are not enabled or a version is too old to have a support + [branch] if (volumesCount == 0) { // Legacy! Fallback to default light probes if Light Volume are not enabled or a version is too old to have a support. Legacy! + LV_SampleLightProbe(L0, L1r, L1g, L1b); + return; + } + + uint maxOverdraw = min((uint) _UdonLightVolumeAdditiveMaxOverdraw, VRCLV_MAX_VOLUMES_COUNT); + uint additiveCount = min((uint) _UdonLightVolumeAdditiveCount, VRCLV_MAX_VOLUMES_COUNT); + bool lightProbesBlend = _UdonLightVolumeProbesBlend; + + uint volumeID_A = -1; // Main, dominant volume ID + uint volumeID_B = -1; // Secondary volume ID to blend main with + + float3 localUVW = 0; // Last local UVW to use in disabled Light Probes mode + float3 localUVW_A = 0; // Main local UVW + float3 localUVW_B = 0; // Secondary local UVW + + // Are A and B volumes NOT found? + bool isNoA = true; + bool isNoB = true; + + // Additive volumes variables + uint addVolumesCount = 0; + + // Iterating through all light volumes with simplified algorithm requiring Light Volumes to be sorted by weight in descending order + [loop] for (uint id = 0; id < volumesCount; id++) { + localUVW = LV_LocalFromVolume(id, worldPos); + [branch] if (LV_PointLocalAABB(localUVW)) { // Intersection test + [branch] if (id < additiveCount) { // Sampling additive volumes + [branch] if (addVolumesCount < maxOverdraw) { + float4 occ; // Multiplicative occlusion + LV_SampleVolume(id, localUVW, L0, L1r, L1g, L1b, occ); + mOcclusion *= occ; + addVolumesCount++; + } + } else if (isNoA) { // First, searching for volume A + volumeID_A = id; + localUVW_A = localUVW; + isNoA = false; + } else { // Next, searching for volume B if A found + volumeID_B = id; + localUVW_B = localUVW; + isNoB = false; + break; + } + } + } + + // If no volumes found, using Light Probes as fallback + [branch] if (isNoA && lightProbesBlend) { + LV_SampleLightProbe(L0, L1r, L1g, L1b); + occlusion *= mOcclusion; + return; + } + + // Fallback to lowest weight light volume if outside of every volume + localUVW_A = isNoA ? localUVW : localUVW_A; + volumeID_A = isNoA ? volumesCount - 1 : volumeID_A; + + // Volume A SH components, occlusion, and mask to blend volume sides + float3 L0_A = 0; + float3 L1r_A = 0; + float3 L1g_A = 0; + float3 L1b_A = 0; + float4 occlusion_A = 1; + + // Sampling Light Volume A + LV_SampleVolume(volumeID_A, localUVW_A, L0_A, L1r_A, L1g_A, L1b_A, occlusion_A); + + float mask = LV_BoundsMask(localUVW_A, _UdonLightVolumeInvLocalEdgeSmooth[volumeID_A]); + [branch] if (mask == 1 || isNoA || (_UdonLightVolumeSharpBounds && isNoB)) { // Returning SH A result if it's the center of mask or out of bounds + L0 += L0_A; + L1r += L1r_A; + L1g += L1g_A; + L1b += L1b_A; + occlusion = occlusion_A; + occlusion *= mOcclusion; + return; + } + + // Volume B SH components and occlusion + float3 L0_B = 0; + float3 L1r_B = 0; + float3 L1g_B = 0; + float3 L1b_B = 0; + float4 occlusion_B = 1; + + [branch] if (isNoB && lightProbesBlend) { // No Volume found and light volumes blending enabled + + // Sample Light Probes B + LV_SampleLightProbe(L0_B, L1r_B, L1g_B, L1b_B); + + } else { // Blending Volume A and Volume B + + // If no volume b found, use last one found to fallback + localUVW_B = isNoB ? localUVW : localUVW_B; + volumeID_B = isNoB ? volumesCount - 1 : volumeID_B; + + // Sampling Light Volume B + LV_SampleVolume(volumeID_B, localUVW_B, L0_B, L1r_B, L1g_B, L1b_B, occlusion_B); + + } + + // Lerping occlusion + occlusion = lerp(occlusion_B, occlusion_A, mask); + occlusion *= mOcclusion; + + // Lerping SH components + L0 += lerp(L0_B, L0_A, mask); + L1r += lerp(L1r_B, L1r_A, mask); + L1g += lerp(L1g_B, L1g_A, mask); + L1b += lerp(L1b_B, L1b_A, mask); + +} + +// Calculates L1 SH based on the world position from additive volumes only. Only samples light volumes, not point lights. +// Also returns an occlusion factor, which may be used for point light shadows. +void LV_LightVolumeAdditiveSH(float3 worldPos, inout float3 L0, inout float3 L1r, inout float3 L1g, inout float3 L1b, out float4 occlusion) { + + // Initializing output variables + occlusion = 1; + float4 mOcclusion = 1; // Multiplicative occlusion. Applies on top of regular occlusion + + // Clamping gloabal iteration counts + uint additiveCount = min((uint) _UdonLightVolumeAdditiveCount, VRCLV_MAX_VOLUMES_COUNT); + //if (_UdonLightVolumeVersion < VRCLV_VERSION || (additiveCount == 0 && pointCount == 0)) return; + [branch] if (additiveCount == 0 && (uint) _UdonPointLightVolumeCount == 0) return; // Legacy! + + uint volumesCount = min((uint) _UdonLightVolumeCount, VRCLV_MAX_VOLUMES_COUNT); + uint maxOverdraw = min((uint) _UdonLightVolumeAdditiveMaxOverdraw, VRCLV_MAX_VOLUMES_COUNT); + + uint volumeID_A = -1; // Main, dominant volume ID + uint volumeID_B = -1; // Secondary volume ID to blend main with + + float3 localUVW = 0; // Last local UVW to use in disabled Light Probes mode + float3 localUVW_A = 0; // Main local UVW for Y Axis and Free rotations + float3 localUVW_B = 0; // Secondary local UVW + + // Are A and B volumes NOT found? + bool isNoA = true; + bool isNoB = true; + + // Additive volumes variables + uint addVolumesCount = 0; + + // Iterating through all light volumes with simplified algorithm requiring Light Volumes to be sorted by weight in descending order + uint count = min(_UdonLightVolumeOcclusionCount == 0 ? additiveCount : volumesCount, VRCLV_MAX_VOLUMES_COUNT); // Only use all volumes if occlusion volumes are enabled + [loop] for (uint id = 0; id < count; id++) { + localUVW = LV_LocalFromVolume(id, worldPos); + [branch] if (LV_PointLocalAABB(localUVW)) { // Intersection test + [branch] if (id < additiveCount) { // Sampling additive volumes + [branch] if (addVolumesCount < maxOverdraw) { + float4 occ; // Multiplicative occlusion + LV_SampleVolume(id, localUVW, L0, L1r, L1g, L1b, occ); + mOcclusion *= occ; + addVolumesCount++; + } + } else if (isNoA) { // First, searching for volume A + volumeID_A = id; + localUVW_A = localUVW; + isNoA = false; + } else { // Next, searching for volume B if A found + volumeID_B = id; + localUVW_B = localUVW; + isNoB = false; + break; + } + } + } + + // If no volumes found, or we don't need the occlusion data, we are done + [branch] if (isNoA || _UdonLightVolumeOcclusionCount == 0) { + occlusion *= mOcclusion; + return; + } + + // Fallback to lowest weight light volume if outside of every volume + localUVW_A = isNoA ? localUVW : localUVW_A; + volumeID_A = isNoA ? volumesCount - 1 : volumeID_A; + + // Sampling Light Volume A + occlusion = LV_SampleVolumeOcclusion(volumeID_A, localUVW_A); + float mask = LV_BoundsMask(localUVW_A, _UdonLightVolumeInvLocalEdgeSmooth[volumeID_A]); + + [branch] if (mask == 1 || (_UdonLightVolumeSharpBounds && isNoB)) { + occlusion *= mOcclusion; + return; // Returning A result if it's the center of mask or out of bounds + } + + // Blending Volume A and Volume B + [branch] if (isNoB) occlusion = lerp(1, occlusion, mask); + else occlusion = lerp(LV_SampleVolumeOcclusion(volumeID_B, localUVW_B), occlusion, mask); + + occlusion *= mOcclusion; + +} + +// Calculates speculars for light volumes or any SH L1 data with privided f0 +float3 LightVolumeSpecular(float3 f0, float smoothness, float3 worldNormal, float3 viewDir, float3 L0, float3 L1r, float3 L1g, float3 L1b) { + + float3 specColor = max(float3(dot(reflect(-L1r, worldNormal), viewDir), dot(reflect(-L1g, worldNormal), viewDir), dot(reflect(-L1b, worldNormal), viewDir)), 0); + + float3 rDir = normalize(normalize(L1r) + viewDir); + float3 gDir = normalize(normalize(L1g) + viewDir); + float3 bDir = normalize(normalize(L1b) + viewDir); + + float rNh = saturate(dot(worldNormal, rDir)); + float gNh = saturate(dot(worldNormal, gDir)); + float bNh = saturate(dot(worldNormal, bDir)); + + float roughness = 1 - smoothness * 0.9f; + float roughExp = roughness * roughness; + + float rSpec = LV_DistributionGGX(rNh, roughExp); + float gSpec = LV_DistributionGGX(gNh, roughExp); + float bSpec = LV_DistributionGGX(bNh, roughExp); + + float3 specs = (rSpec + gSpec + bSpec) * f0; + float3 coloredSpecs = specs * specColor; + + float3 a = coloredSpecs + specs * L0; + float3 b = coloredSpecs * 3; + + return max(lerp(a, b, smoothness) * 0.5f, 0.0); + +} + +// Calculates speculars for light volumes or any SH L1 data +float3 LightVolumeSpecular(float3 albedo, float smoothness, float metallic, float3 worldNormal, float3 viewDir, float3 L0, float3 L1r, float3 L1g, float3 L1b) { + float3 specularf0 = lerp(0.04f, albedo, metallic); + return LightVolumeSpecular(specularf0, smoothness, worldNormal, viewDir, L0, L1r, L1g, L1b); +} + +// Calculates speculars for light volumes or any SH L1 data, but simplified, with only one dominant direction with provided f0 +float3 LightVolumeSpecularDominant(float3 f0, float smoothness, float3 worldNormal, float3 viewDir, float3 L0, float3 L1r, float3 L1g, float3 L1b) { + + float3 dominantDir = L1r + L1g + L1b; + float3 dir = normalize(normalize(dominantDir) + viewDir); + float nh = saturate(dot(worldNormal, dir)); + + float roughness = 1 - smoothness * 0.9f; + float roughExp = roughness * roughness; + + float spec = LV_DistributionGGX(nh, roughExp); + + return max(spec * L0 * f0, 0.0) * 1.5f; + +} + +// Calculates speculars for light volumes or any SH L1 data, but simplified, with only one dominant direction +float3 LightVolumeSpecularDominant(float3 albedo, float smoothness, float metallic, float3 worldNormal, float3 viewDir, float3 L0, float3 L1r, float3 L1g, float3 L1b) { + float3 specularf0 = lerp(0.04f, albedo, metallic); + return LightVolumeSpecularDominant(specularf0, smoothness, worldNormal, viewDir, L0, L1r, L1g, L1b); +} + +// Calculate Light Volume Color based on all SH components provided and the world normal +float3 LightVolumeEvaluate(float3 worldNormal, float3 L0, float3 L1r, float3 L1g, float3 L1b) { + return float3(LV_EvaluateSH(L0.r, L1r, worldNormal), LV_EvaluateSH(L0.g, L1g, worldNormal), LV_EvaluateSH(L0.b, L1b, worldNormal)); +} + +// Calculates L1 SH based on the world position. Samples both light volumes and point lights. +void LightVolumeSH(float3 worldPos, out float3 L0, out float3 L1r, out float3 L1g, out float3 L1b, float3 worldPosOffset = 0) { + L0 = 0; L1r = 0; L1g = 0; L1b = 0; + if (_UdonLightVolumeEnabled == 0) { + LV_SampleLightProbeDering(L0, L1r, L1g, L1b); + } else { + float4 occlusion = 1; + LV_LightVolumeSH(worldPos + worldPosOffset, L0, L1r, L1g, L1b, occlusion); + LV_PointLightVolumeSH(worldPos, occlusion, L0, L1r, L1g, L1b); + } +} + +// Calculates L1 SH based on the world position from additive volumes only. Samples both light volumes and point lights. +void LightVolumeAdditiveSH(float3 worldPos, out float3 L0, out float3 L1r, out float3 L1g, out float3 L1b, float3 worldPosOffset = 0) { + L0 = 0; L1r = 0; L1g = 0; L1b = 0; + if (_UdonLightVolumeEnabled != 0) { + float4 occlusion = 1; + LV_LightVolumeAdditiveSH(worldPos + worldPosOffset, L0, L1r, L1g, L1b, occlusion); + LV_PointLightVolumeSH(worldPos, occlusion, L0, L1r, L1g, L1b); + } +} + +// Calculates L0 SH based on the world position. Samples both light volumes and point lights. +float3 LightVolumeSH_L0(float3 worldPos, float3 worldPosOffset = 0) { + if (_UdonLightVolumeEnabled == 0) { + return float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); + } else { + float3 L0 = 0; float4 occlusion = 1; + float3 unused_L1; // Let's just pray that compiler will strip everything x.x + LV_LightVolumeSH(worldPos + worldPosOffset, L0, unused_L1, unused_L1, unused_L1, occlusion); + LV_PointLightVolumeSH(worldPos, occlusion, L0, unused_L1, unused_L1, unused_L1); + return L0; + } +} + +// Calculates L0 SH based on the world position from additive volumes only. Samples both light volumes and point lights. +float3 LightVolumeAdditiveSH_L0(float3 worldPos, float3 worldPosOffset = 0) { + if (_UdonLightVolumeEnabled == 0) { + return 0; + } else { + float3 L0 = 0; float4 occlusion = 1; + float3 unused_L1; // Let's just pray that compiler will strip everything x.x + LV_LightVolumeAdditiveSH(worldPos + worldPosOffset, L0, unused_L1, unused_L1, unused_L1, occlusion); + LV_PointLightVolumeSH(worldPos, occlusion, L0, unused_L1, unused_L1, unused_L1); + return L0; + } +} + +// Checks if Light Volumes are used in this scene. Returns 0 if not, returns 1 if enabled +float LightVolumesEnabled() { + return _UdonLightVolumeEnabled; +} + +// Returns the light volumes version +float LightVolumesVersion() { + return _UdonLightVolumeVersion == 0 ? _UdonLightVolumeEnabled : _UdonLightVolumeVersion; +} + +#endif diff --git a/Assets/Filamented/LightVolumes.cginc.meta b/Assets/Filamented/LightVolumes.cginc.meta new file mode 100644 index 0000000..a7a6e1a --- /dev/null +++ b/Assets/Filamented/LightVolumes.cginc.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c67a1cbd069a29046a0d0925825e13a7 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/SharedFilteringLib.hlsl b/Assets/Filamented/SharedFilteringLib.hlsl new file mode 100644 index 0000000..3929f0a --- /dev/null +++ b/Assets/Filamented/SharedFilteringLib.hlsl @@ -0,0 +1,47 @@ +#ifndef SERVICE_FILTERING_INCLUDED +#define SERVICE_FILTERING_INCLUDED + +half4 cubic(half v) +{ + half4 n = half4(1.0, 2.0, 3.0, 4.0) - v; + half4 s = n * n * n; + half x = s.x; + half y = s.y - 4.0 * s.x; + half z = s.z - 4.0 * s.y + 6.0 * s.x; + half w = 6.0 - x - y - z; + return half4(x, y, z, w); +} + + +// Unity's SampleTexture2DBicubic doesn't exist in 2018, which is our target here. +// So this is a similar function with tweaks to have similar semantics. + +half4 SampleTexture2DBicubicFilter(TEXTURE2D_PARAM(tex, smp), float2 coord, float4 texSize) +{ + coord = coord * texSize.xy - 0.5; + half fx = frac(coord.x); + half fy = frac(coord.y); + coord.x -= fx; + coord.y -= fy; + + half4 xcubic = cubic(fx); + half4 ycubic = cubic(fy); + + float4 c = float4(coord.x - 0.5, coord.x + 1.5, coord.y - 0.5, coord.y + 1.5); + float4 s = float4(xcubic.x + xcubic.y, xcubic.z + xcubic.w, ycubic.x + ycubic.y, ycubic.z + ycubic.w); + float4 offset = c + float4(xcubic.y, xcubic.w, ycubic.y, ycubic.w) / s; + + half4 sample0 = SAMPLE_TEXTURE2D(tex, smp, half2(offset.x, offset.z) * texSize.zw); + half4 sample1 = SAMPLE_TEXTURE2D(tex, smp, half2(offset.y, offset.z) * texSize.zw); + half4 sample2 = SAMPLE_TEXTURE2D(tex, smp, half2(offset.x, offset.w) * texSize.zw); + half4 sample3 = SAMPLE_TEXTURE2D(tex, smp, half2(offset.y, offset.w) * texSize.zw); + + half sx = s.x / (s.x + s.y); + half sy = s.z / (s.z + s.w); + + return lerp( + lerp(sample3, sample2, sx), + lerp(sample1, sample0, sx), sy); +} + +#endif // SERVICE_FILTERING_INCLUDED diff --git a/Assets/Filamented/SharedFilteringLib.hlsl.meta b/Assets/Filamented/SharedFilteringLib.hlsl.meta new file mode 100644 index 0000000..ff839cb --- /dev/null +++ b/Assets/Filamented/SharedFilteringLib.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: fe7137cdc73277e499772b823ca1974b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/SharedGlintyBRDF.hlsl b/Assets/Filamented/SharedGlintyBRDF.hlsl new file mode 100644 index 0000000..d18491b --- /dev/null +++ b/Assets/Filamented/SharedGlintyBRDF.hlsl @@ -0,0 +1,235 @@ +#ifndef GLINTY_NDF_INCLUDED +#define GLINTY_NDF_INCLUDED + +// "Evaluating and Sampling Glinty NDFs in Constant Time" +// Based on Kemppinen et al. 2025 +#define GLINT_PI 3.14159265358979 +#define GLINT_HALF_PI 3.14159265h + +// --- Internal Utilities --- + +half2 lambert_map(float3 v) { + return (half2)(v.xy / sqrt(1.0 + v.z)); +} + +// Maps GGX NDF to a 2D disk +float3 ndf_to_disk_ggx(float3 v, float alpha) { + float3 hemi = float3(v.xy / alpha, v.z); + float denom = dot(hemi, hemi); + half2 v_disk = lambert_map(normalize(hemi)) * 0.5h + 0.5h; + float jacobian_determinant = 1.0 / (alpha * alpha * denom * denom); + return float3(v_disk, jacobian_determinant); +} + +// 2x2 Inverse +float2x2 inverse2x2(float2x2 m) { + float det = m._m00 * m._m11 - m._m01 * m._m10; + return float2x2(m._m11, -m._m01, -m._m10, m._m00) / det; +} + +float2x2 inv_quadratic(float2x2 M) { + float D = determinant(M); + float2 col0 = float2(M._m00, M._m10) / D; + float2 col1 = float2(M._m01, M._m11) / D; + + float A = dot(col0, col0); + float B = -dot(col0, col1); + float C = dot(col1, col1); + return float2x2(C, B, B, A); +} + +// Converts UV Jacobian into an anisotropy-aware ellipsoid matrix +float2x2 get_uv_ellipsoid(float2x2 uv_J) { + float2x2 Q = inv_quadratic(transpose(uv_J)); + float tr = 0.5 * (Q._m00 + Q._m11); + float D = sqrt(max(0.0, tr * tr - determinant(Q))); + float l1 = tr - D; + float l2 = tr + D; + + float2 v1 = float2(l1 - Q._m11, Q._m10); + float2 v2 = float2(Q._m01, l2 - Q._m00); + float2 n = 1.0 / sqrt(float2(l1, l2)); + + float2 col0 = normalize(v1) * n.x; + float2 col1 = normalize(v2) * n.y; + // Constructing column-major equivalent for the math later + return float2x2(col0.x, col1.x, col0.y, col1.y); +} + +float query_lod(float2x2 uv_J, float filter_size) { + float s0 = length(float2(uv_J._m00, uv_J._m10)); + float s1 = length(float2(uv_J._m01, uv_J._m11)); + return log2(max(s0, s1) * filter_size) + pow(2.0, filter_size); +} + +uint2 shuffle_hash(uint2 v) { + v = v * 1664525u + 1013904223u; + v.x += v.y * 1664525u; + v.y += v.x * 1664525u; + v = v ^ (v >> 16u); + v.x += v.y * 1664525u; + v.y += v.x * 1664525u; + v = v ^ (v >> 16u); + return v; +} + +half2 rand2d(float2 x, float2 y, float l, uint i) { + uint2 ux = asuint(x), uy = asuint(y); + uint ul = asuint(l); + uint2 seed = (ux >> 16u | ux << 16u) ^ uy ^ ul ^ (i * 0x124u); + // Cast to half2 since random output is strictly [0, 1] + return (half2)(float2(shuffle_hash(seed)) * pow(0.5, 32.0)); +} + +half rand1d(float2 x, float2 y, float l, uint i) { + return rand2d(x, y, l, i).x; +} + +half fast_erf(half x) { + half e = exp(-x * x); + half sign_x = sign(x); + // Constants pre-calculated to half precision + half scale = sqrt((1.0h - e) / GLINT_HALF_PI); + half poly = 0.886226h + 0.155h * e - 0.042625h * e * e; // (sqrt(pi)/2), (31/200), (341/8000) + return sign_x * 2.0h * scale * poly; +} + +half gaussian_cdf(float x, float mu, float sigma) { + float z = (x - mu) / (sigma * 1.41421356); + return 0.5h + 0.5h * fast_erf((half)z); +} + +half integrate_interval(float x, float size, float mu, float stdev, float lower_limit, float upper_limit) { + return gaussian_cdf(min(x + size, upper_limit), mu, stdev) - gaussian_cdf(max(x - size, lower_limit), mu, stdev); +} + +half integrate_box(float2 x, float2 size, float2 mu, float2x2 sigma, float2 lower_limit, float2 upper_limit) { + return integrate_interval(x.x, size.x, mu.x, sqrt(sigma._m00), lower_limit.x, upper_limit.x) * + integrate_interval(x.y, size.y, mu.y, sqrt(sigma._m11), lower_limit.y, upper_limit.y); +} + +half glint_compensation(float2 x_a, float2x2 sigma_a, float res_a) { + half containing = integrate_box(0.5f.xx, 0.5f.xx, x_a, sigma_a, 0.0f.xx, 1.0f.xx); + half explicitly_evaluated = integrate_box(round(x_a * res_a) / res_a, (1.0 / res_a).xx, x_a, sigma_a, 0.0f.xx, 1.0f.xx); + return containing - explicitly_evaluated; +} + +float eval_normal(float2x2 cov, float2 x) { + float2x2 inv_cov = inverse2x2(cov); + return exp(-0.5 * dot(x, mul(inv_cov, x))) / (sqrt(determinant(cov)) * 2.0 * GLINT_PI); +} + +// --- Public Interface --- + +/** + * Main Glinty NDF Function + * @param h Local space half-vector + * @param alpha Macro-roughness (standard GGX roughness) + * @param glint_alpha Micro-roughness (the size/sharpness of individual glints, e.g., 0.01) + * @param uv Surface UV coordinates + * @param uv_J Jacobian of the UVs (use get_uv_ellipsoid(float2x2(ddx(uv), ddy(uv)))) + * @param glint_density Scaling factor for glint particles (e.g., 1000 to 1000000) + * @param filter_size Standard pixel filter size (e.g., 0.7 to 1.2) + */ +float EvaluateGlintyNDF(float3 h, float alpha, float glint_alpha, float2 uv, float2x2 uv_J, float glint_density, float filter_size) { + float res = sqrt(glint_density); + float2 x_s = uv; + float3 x_a_and_d = ndf_to_disk_ggx(h, alpha); + float2 x_a = x_a_and_d.xy; + float d = x_a_and_d.z; + + float lambda = query_lod(res * uv_J, filter_size); + float D_filter = 0.0; + + for(float m = 0.0; m < 2.0; m += 1.0) { + float l = floor(lambda) + m; + half w_lambda = (half)(1.0 - abs(lambda - l)); + + float res_s = res * exp2(-l); + float res_a = exp2(l); + + float2x2 uv_J2 = filter_size * uv_J; + float2x2 sigma_s = mul(uv_J2, transpose(uv_J2)); + + float det_J2 = determinant(uv_J2); + float det_sigma_s = det_J2 * det_J2; + float2x2 inv_sigma_s = float2x2(sigma_s._m11, -sigma_s._m01, -sigma_s._m10, sigma_s._m00) / det_sigma_s; + + float norm_s = 1.0 / (abs(det_J2) * 2.0 * GLINT_PI * glint_density); + + float var_a = d * glint_alpha * glint_alpha; + float norm_a = 1.0 / (var_a * 2.0 * GLINT_PI); + float stdev_a = sqrt(var_a); + + float2 base_i_a = clamp(round(x_a * res_a), 1.0, res_a - 1.0); + + for(int j_a = 0; j_a < 4; ++j_a) { + half2 offset_a = (half2)(float2(j_a & 1, j_a >> 1) - 0.5); + float2 i_a = base_i_a + offset_a; + + float2 base_i_s = round(x_s * res_s); + + for(int j_s = 0; j_s < 4; ++j_s) { + half2 offset_s = (half2)(float2(j_s & 1, j_s >> 1) - 0.5); + float2 i_s = base_i_s + offset_s; + + float2 g_s = (i_s + rand2d(i_s, i_a, l, 1u) - 0.5) / res_s; + float2 g_a = (i_a + rand2d(i_s, i_a, l, 2u) - 0.5) / res_a; + + half r = rand1d(i_s, i_a, l, 4u); + half roulette = smoothstep(max(0.0h, r - 0.1h), min(1.0h, r + 0.1h), w_lambda); + + float2 delta_a = x_a - g_a; + float eval_a = exp(-0.5 * dot(delta_a, delta_a) / var_a) * norm_a; + + float2 delta_s = x_s - g_s; + float eval_s = exp(-0.5 * dot(delta_s, mul(inv_sigma_s, delta_s))) * norm_s; + + D_filter += roulette * eval_a * eval_s; + } + } + D_filter += w_lambda * glint_compensation(x_a, stdev_a, res_a); + } + + return D_filter * d / GLINT_PI; +} + +/*** Sample implementation... + +// 1. Setup Inputs +float3 V = normalize(_WorldSpaceCameraPos - input.worldPos); +float3 L = normalize(_MainLightPosition.xyz); +float3 H = normalize(V + L); +float3 N = normalize(input.normal); + +// Transform H to local tangent space +float3 tangentH = WorldToTangent(H, input.tangent, input.bitangent, N); + +// 2. Prepare Derivatives for Anisotropic Filtering +float2x2 Jacobian = float2x2(ddx(input.uv), ddy(input.uv)); +float2x2 uv_ellipsoid = get_uv_ellipsoid(Jacobian); + +// 3. Evaluate NDF +// alpha: standard roughness (0.1 - 0.8) +// glint_alpha: micro-roughness (0.005 - 0.05) +// glint_density: how many particles (10^4 to 10^9) +float D = EvaluateGlintyNDF( + tangentH, + _Roughness, + _GlintMicroRoughness, + input.uv, + uv_ellipsoid, + _GlintDensity, + 0.8 // Filter size +); + +// 4. Standard BRDF integration +// Use D instead of the standard GGX D term in: (D * F * G) / (4 * NoV * NoL) +float NoL = saturate(dot(N, L)); +float NoV = saturate(dot(N, V)); +float3 spec = (D * F * G) / max(1e-4, 4.0 * NoV * NoL); +return float4(spec * NoL * _LightColor.rgb, 1.0); + +***/ + +#endif diff --git a/Assets/Filamented/SharedGlintyBRDF.hlsl.meta b/Assets/Filamented/SharedGlintyBRDF.hlsl.meta new file mode 100644 index 0000000..2d5f57d --- /dev/null +++ b/Assets/Filamented/SharedGlintyBRDF.hlsl.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 432a258c55e7def43840ac45004d72c4 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/SharedLightmapLib.hlsl b/Assets/Filamented/SharedLightmapLib.hlsl new file mode 100644 index 0000000..bcfa72c --- /dev/null +++ b/Assets/Filamented/SharedLightmapLib.hlsl @@ -0,0 +1,324 @@ +#ifndef COMMON_LIGHTMAP_INCLUDED +#define COMMON_LIGHTMAP_INCLUDED + +#include "SharedSHLib.hlsl" + +half4 UnityLightmap_ColorIntensitySeperated(half3 lightmap) { + lightmap += 0.000001; + return float4(lightmap.xyz / 1, 1); +} + +half4 SampleLightmapBicubic(float2 uv) +{ + #if defined(SHADER_API_D3D11) + float width, height; + unity_Lightmap.GetDimensions(width, height); + + float4 unity_Lightmap_TexelSize = float4(width, height, 1.0/width, 1.0/height); + + return SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(unity_Lightmap, samplerunity_Lightmap), + uv, unity_Lightmap_TexelSize); + #else + return SAMPLE_TEXTURE2D(unity_Lightmap, samplerunity_Lightmap, uv); + #endif +} + +half4 SampleLightmapDirBicubic(float2 uv) +{ + // We don't need to sample the directionality with bicubic filtering + #if defined(SHADER_API_D3D11) && false + float width, height; + unity_LightmapInd.GetDimensions(width, height); + + float4 unity_LightmapInd_TexelSize = float4(width, height, 1.0/width, 1.0/height); + + return SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(unity_LightmapInd, samplerunity_Lightmap), + uv, unity_LightmapInd_TexelSize); + #else + return SAMPLE_TEXTURE2D(unity_LightmapInd, samplerunity_Lightmap, uv); + #endif +} + +half4 SampleDynamicLightmapBicubic(float2 uv) +{ + #if defined(SHADER_API_D3D11) + float width, height; + unity_DynamicLightmap.GetDimensions(width, height); + + float4 unity_DynamicLightmap_TexelSize = float4(width, height, 1.0/width, 1.0/height); + + return SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(unity_DynamicLightmap, samplerunity_DynamicLightmap), + uv, unity_DynamicLightmap_TexelSize); + #else + return SAMPLE_TEXTURE2D(unity_DynamicLightmap, samplerunity_DynamicLightmap, uv); + #endif +} + +half4 SampleDynamicLightmapDirBicubic(float2 uv) +{ + // We don't need to sample the directionality with bicubic filtering + #if defined(SHADER_API_D3D11) && false + float width, height; + unity_DynamicDirectionality.GetDimensions(width, height); + + float4 unity_DynamicDirectionality_TexelSize = float4(width, height, 1.0/width, 1.0/height); + + return SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(unity_DynamicDirectionality, samplerunity_DynamicLightmap), + uv, unity_DynamicDirectionality_TexelSize); + #else + return SAMPLE_TEXTURE2D(unity_DynamicDirectionality, samplerunity_DynamicLightmap, uv); + #endif +} + +inline half3 DecodeDirectionalLightmapSpecular(half3 color, half4 dirTex, half3 normalWorld, + const bool isRealtimeLightmap, fixed4 realtimeNormalTex, out Light o_light) +{ + o_light = (Light)0; + o_light.colorIntensity = float4(color, 1.0); + o_light.l = dirTex.xyz * 2 - 1; + + // The length of the direction vector is the light's "directionality", i.e. 1 for all light coming from this direction, + // lower values for more spread out, ambient light. + half directionality = max(0.001, length(o_light.l)); + o_light.l /= directionality; + + #ifdef DYNAMICLIGHTMAP_ON + if (isRealtimeLightmap) + { + // Realtime directional lightmaps' intensity needs to be divided by N.L + // to get the incoming light intensity. Baked directional lightmaps are already + // output like that (including the max() to prevent div by zero). + half3 realtimeNormal = realtimeNormalTex.xyz * 2 - 1; + o_light.colorIntensity /= max(0.125, dot(realtimeNormal, o_light.l)); + } + #endif + + // Split light into the directional and ambient parts, according to the directionality factor. + half3 ambient = o_light.colorIntensity * (1 - directionality); + o_light.colorIntensity = o_light.colorIntensity * directionality; + o_light.attenuation = directionality; + + o_light.NoL = saturate(dot(normalWorld, o_light.l)); + + return color * lerp(1.0, o_light.NoL, directionality); +} + +#if defined(USING_BAKERY) && defined(LIGHTMAP_ON) +// needs specular variant? +half3 DecodeRNMLightmap(half3 color, half2 lightmapUV, half3 normalTangent, float3x3 tangentToWorld, out Light o_light) +{ + const float rnmBasis0 = float3(0.816496580927726f, 0, 0.5773502691896258f); + const float rnmBasis1 = float3(-0.4082482904638631f, 0.7071067811865475f, 0.5773502691896258f); + const float rnmBasis2 = float3(-0.4082482904638631f, -0.7071067811865475f, 0.5773502691896258f); + + half3 irradiance; + o_light = (Light)0; + + #if defined(SHADER_API_D3D11) + float width, height; + _RNM0.GetDimensions(width, height); + + float4 rnm_TexelSize = float4(width, height, 1.0/width, 1.0/height); + + half3 rnm0 = DecodeLightmap(SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(_RNM0, sampler_RNM0), lightmapUV, rnm_TexelSize)); + half3 rnm1 = DecodeLightmap(SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(_RNM1, sampler_RNM0), lightmapUV, rnm_TexelSize)); + half3 rnm2 = DecodeLightmap(SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(_RNM2, sampler_RNM0), lightmapUV, rnm_TexelSize)); + #else + half3 rnm0 = DecodeLightmap(SAMPLE_TEXTURE2D(_RNM0, sampler_RNM0, lightmapUV)); + half3 rnm1 = DecodeLightmap(SAMPLE_TEXTURE2D(_RNM1, sampler_RNM0, lightmapUV)); + half3 rnm2 = DecodeLightmap(SAMPLE_TEXTURE2D(_RNM2, sampler_RNM0, lightmapUV)); + #endif + + normalTangent.g *= -1; + + irradiance = saturate(dot(rnmBasis0, normalTangent)) * rnm0 + + saturate(dot(rnmBasis1, normalTangent)) * rnm1 + + saturate(dot(rnmBasis2, normalTangent)) * rnm2; + + #if defined(LIGHTMAP_SPECULAR) + float3 dominantDirT = rnmBasis0 * luminance(rnm0) + + rnmBasis1 * luminance(rnm1) + + rnmBasis2 * luminance(rnm2); + + half3 dominantDirTN = normalize(dominantDirT); + half3 specColor = saturate(dot(rnmBasis0, dominantDirTN)) * rnm0 + + saturate(dot(rnmBasis1, dominantDirTN)) * rnm1 + + saturate(dot(rnmBasis2, dominantDirTN)) * rnm2; + + o_light.l = normalize(mul(tangentToWorld, dominantDirT)); + half directionality = max(0.001, length(o_light.l)); + o_light.l /= directionality; + + // Split light into the directional and ambient parts, according to the directionality factor. + o_light.colorIntensity = float4(specColor * directionality, 1.0); + o_light.attenuation = directionality; + o_light.NoL = saturate(dot(normalTangent, dominantDirTN)); + #endif + + return irradiance; +} + +half3 DecodeSHLightmap(half3 L0, half2 lightmapUV, half3 normalWorld, out Light o_light) +{ + half3 irradiance; + o_light = (Light)0; + + #if defined(SHADER_API_D3D11) + float width, height; + _RNM0.GetDimensions(width, height); + + float4 rnm_TexelSize = float4(width, height, 1.0/width, 1.0/height); + + half3 nL1x = SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(_RNM0, sampler_RNM0), lightmapUV, rnm_TexelSize); + half3 nL1y = SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(_RNM1, sampler_RNM0), lightmapUV, rnm_TexelSize); + half3 nL1z = SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(_RNM2, sampler_RNM0), lightmapUV, rnm_TexelSize); + #else + half3 nL1x = SAMPLE_TEXTURE2D(_RNM0, sampler_RNM0, lightmapUV); + half3 nL1y = SAMPLE_TEXTURE2D(_RNM1, sampler_RNM0, lightmapUV); + half3 nL1z = SAMPLE_TEXTURE2D(_RNM2, sampler_RNM0, lightmapUV); + #endif + + nL1x = nL1x * 2 - 1; + nL1y = nL1y * 2 - 1; + nL1z = nL1z * 2 - 1; + half3 L1x = nL1x * L0 * 2; + half3 L1y = nL1y * L0 * 2; + half3 L1z = nL1z * L0 * 2; + + #ifdef BAKERY_SHNONLINEAR + half lumaL0 = dot(L0, half(1)); + half lumaL1x = dot(L1x, half(1)); + half lumaL1y = dot(L1y, half(1)); + half lumaL1z = dot(L1z, half(1)); + + half lumaSH = shEvaluateDiffuseL1Geomerics_local(lumaL0, float3(lumaL1x, lumaL1y, lumaL1z), normalWorld); + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_ZH3) + lumaSH = SHEvalLinearL0L1_ZH3Hallucinate(float4(lumaL0, lumaL1y, lumaL1z, lumaL1x), normalWorld); + #endif + + irradiance = L0 + normalWorld.x * L1x + normalWorld.y * L1y + normalWorld.z * L1z; + half regularLumaSH = dot(irradiance, 1); + irradiance *= lerp(1, lumaSH / regularLumaSH, saturate(regularLumaSH*16)); + #else + irradiance = L0 + normalWorld.x * L1x + normalWorld.y * L1y + normalWorld.z * L1z; + #endif + + #if defined(LIGHTMAP_SPECULAR) + half3 dominantDir = float3(luminance(nL1x), luminance(nL1y), luminance(nL1z)); + + o_light.l = dominantDir; + half directionality = max(0.001, length(o_light.l)); + o_light.l /= directionality; + + // Split light into the directional and ambient parts, according to the directionality factor. + o_light.colorIntensity = float4(irradiance * directionality, 1.0); + o_light.attenuation = directionality; + o_light.NoL = saturate(dot(normalWorld, o_light.l)); + #endif + + return irradiance; +} +#endif // USING_BAKERY + +#if defined(USING_BAKERY_VERTEXLMSH) +half3 DecodeSHLightmapVertex(half3 L0, half3 ambientSH[3], half3 normalWorld, out Light o_light) +{ + half3 irradiance; + o_light = (Light)0; + + half3 nL1x = ambientSH[0]; + half3 nL1y = ambientSH[1]; + half3 nL1z = ambientSH[2]; + + nL1x = nL1x * 2 - 1; + nL1y = nL1y * 2 - 1; + nL1z = nL1z * 2 - 1; + half3 L1x = nL1x * L0 * 2; + half3 L1y = nL1y * L0 * 2; + half3 L1z = nL1z * L0 * 2; + + #ifdef BAKERY_SHNONLINEAR + half lumaL0 = dot(L0, half(1)); + half lumaL1x = dot(L1x, half(1)); + half lumaL1y = dot(L1y, half(1)); + half lumaL1z = dot(L1z, half(1)); + half lumaSH = shEvaluateDiffuseL1Geomerics_local(lumaL0, half3(lumaL1x, lumaL1y, lumaL1z), normalWorld); + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_ZH3) + lumaSH = SHEvalLinearL0L1_ZH3Hallucinate(float4(lumaL0, lumaL1y, lumaL1z, lumaL1x), normalWorld); + #endif + + irradiance = L0 + normalWorld.x * L1x + normalWorld.y * L1y + normalWorld.z * L1z; + half regularLumaSH = dot(irradiance, 1); + irradiance *= lerp(1, lumaSH / regularLumaSH, saturate(regularLumaSH*16)); + #else + irradiance = L0 + normalWorld.x * L1x + normalWorld.y * L1y + normalWorld.z * L1z; + #endif + + #if defined(LIGHTMAP_SPECULAR) + half3 dominantDir = half3(luminance(nL1x), luminance(nL1y), luminance(nL1z)); + + o_light.l = dominantDir; + half directionality = max(0.001, length(o_light.l)); + o_light.l /= directionality; + + // Split light into the directional and ambient parts, according to the directionality factor. + o_light.colorIntensity = float4(irradiance * directionality, 1.0); + o_light.attenuation = directionality; + o_light.NoL = saturate(dot(normalWorld, o_light.l)); + #endif + + return irradiance; +} +#endif // USING_BAKERY_VERTEXLMSH + +#if defined(_BAKERY_MONOSH) +half3 DecodeMonoSHLightmap(half3 L0, half3 dominantDir, half3 normalWorld, out Light o_light, const bool remapDir = true) +{ + o_light = (Light)0; + + // Vertex mode is already in -1 to 1 range. + half3 nL1 = remapDir? dominantDir * 2 - 1 : dominantDir; + half3 L1x = nL1.x * L0 * 2; + half3 L1y = nL1.y * L0 * 2; + half3 L1z = nL1.z * L0 * 2; + + half3 sh; + + #if BAKERY_SHNONLINEAR + half lumaL0 = dot(L0, 1); + half lumaL1x = dot(L1x, 1); + half lumaL1y = dot(L1y, 1); + half lumaL1z = dot(L1z, 1); + half lumaSH = shEvaluateDiffuseL1Geomerics_local(lumaL0, half3(lumaL1x, lumaL1y, lumaL1z), normalWorld); + + #if (SPHERICAL_HARMONICS == SPHERICAL_HARMONICS_ZH3) + lumaSH = SHEvalLinearL0L1_ZH3Hallucinate(half4(lumaL0, lumaL1y, lumaL1z, lumaL1x), normalWorld); + #endif + + sh = L0 + normalWorld.x * L1x + normalWorld.y * L1y + normalWorld.z * L1z; + half regularLumaSH = dot(sh, 1); + + sh *= lerp(1, lumaSH / regularLumaSH, saturate(regularLumaSH*16)); + #else + sh = L0 + normalWorld.x * L1x + normalWorld.y * L1y + normalWorld.z * L1z; + #endif + + #if defined(LIGHTMAP_SPECULAR) + dominantDir = nL1; + + o_light.l = dominantDir; + half directionality = max(0.001, length(o_light.l)); + o_light.l /= directionality; + + // Split light into the directional and ambient parts, according to the directionality factor. + o_light.colorIntensity = float4(L0 * directionality, 1.0); + o_light.attenuation = directionality; + o_light.NoL = saturate(dot(normalWorld, o_light.l)); + #endif + + return sh; +} +#endif // _BAKERY_MONOSH +#endif // COMMON_LIGHTMAP_INCLUDED diff --git a/Assets/Filamented/SharedLightmapLib.hlsl.meta b/Assets/Filamented/SharedLightmapLib.hlsl.meta new file mode 100644 index 0000000..72386c5 --- /dev/null +++ b/Assets/Filamented/SharedLightmapLib.hlsl.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c512922fc41dba840aa70170a22bfb7d +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/SharedNormalShadowLib.hlsl b/Assets/Filamented/SharedNormalShadowLib.hlsl new file mode 100644 index 0000000..ffa043f --- /dev/null +++ b/Assets/Filamented/SharedNormalShadowLib.hlsl @@ -0,0 +1,58 @@ +#ifndef SERVICE_NORMALSHADOW_INCLUDED +#define SERVICE_NORMALSHADOW_INCLUDED + +// Ref: Normal Mapping Shadows by Boris Vorontsov + +// Please define a NormalMapShadowsParam parameter +// and SampleNormalMap function to sample the normal map. + +half NormalMapShadows (half3 lightDirTangent, NormalMapShadowsParam nmsParam, half noise, + half heightScale, half shadowHardness) +{ + const half screenShadowSamples = 20; + const half hardness = heightScale * shadowHardness; + const half sampleStep = 1.0 / screenShadowSamples; + + if (lightDirTangent.z <= 0.0) return 0.0; + + half2 dir = lightDirTangent.xy * heightScale; + + // Redundancy can't be helped + half3 normal = SampleNormalMap(nmsParam, 0); + + lightDirTangent = normalize(lightDirTangent); + half tangentNdotL = saturate(dot(lightDirTangent, normal)); + + half currentSample = sampleStep - sampleStep * noise; + + // Skip on backfaces + currentSample += (tangentNdotL <= 0.0); + + /* + From the PDF: + Trace from hit point to light direction and compute sum of dot products + between normal map and light direction. + If slope is bigger than 0, pixel is shadowed. If slope is also bigger + than previous maximal value, increase hardness of shadow. + */ + + half result = 0; + half slope = -tangentNdotL; + half maxslope = 0.0; + while (currentSample <= 1.0) + { + normal = SampleNormalMap(nmsParam, dir * currentSample); + tangentNdotL = dot(lightDirTangent, normal); + slope = slope - tangentNdotL; + if (slope > maxslope) + { + result += hardness * (1.0-currentSample); + } + maxslope = max(maxslope, slope); + currentSample += sampleStep; + } + + return result * sampleStep; +} + +#endif // SERVICE_NORMALSHADOW_INCLUDED diff --git a/Assets/Filamented/SharedNormalShadowLib.hlsl.meta b/Assets/Filamented/SharedNormalShadowLib.hlsl.meta new file mode 100644 index 0000000..35316ab --- /dev/null +++ b/Assets/Filamented/SharedNormalShadowLib.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5c0e8e86dec25b641897fd7c8211bb90 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/SharedParallaxLib.hlsl b/Assets/Filamented/SharedParallaxLib.hlsl new file mode 100644 index 0000000..9513cd9 --- /dev/null +++ b/Assets/Filamented/SharedParallaxLib.hlsl @@ -0,0 +1,164 @@ +#ifndef SERVICE_PARALLAX_INCLUDED +#define SERVICE_PARALLAX_INCLUDED + +// Please define a PerPixelHeightDisplacementParam parameter +// and ComputePerPixelHeightDisplacement function to sample the heightmap. + +float2 ParallaxRaymarching(float2 viewDir, PerPixelHeightDisplacementParam ppdParam, + float strength, out float outHeight) +{ + const float raymarch_steps = 10; + + float2 uvOffset = 0; + const float stepSize = 1.0 / raymarch_steps; + float2 uvDelta = viewDir * (stepSize * strength); + + float stepHeight = 1; + float surfaceHeight = ComputePerPixelHeightDisplacement(0, 0, ppdParam); + + float2 prevUVOffset = uvOffset; + float prevStepHeight = stepHeight; + float prevSurfaceHeight = surfaceHeight; + + for (int i = 1; i < raymarch_steps && stepHeight > surfaceHeight; i++) + { + prevUVOffset = uvOffset; + prevStepHeight = stepHeight; + prevSurfaceHeight = surfaceHeight; + + uvOffset -= uvDelta; + stepHeight -= stepSize; + surfaceHeight = ComputePerPixelHeightDisplacement(uvOffset, 0, ppdParam); + } + + float prevDifference = prevStepHeight - prevSurfaceHeight; + float difference = surfaceHeight - stepHeight; + float t = prevDifference / (prevDifference + difference); + uvOffset = prevUVOffset -uvDelta * t; + + outHeight = surfaceHeight; + return uvOffset; +} + +float2 ParallaxRaymarchingDynamic(float3 viewDir, PerPixelHeightDisplacementParam ppdParam, + float strength, float lod) +{ + const float minLayers = 8.0; + const float maxLayers = 48.0; + // lod should be dot(normalWS, viewDirWS) + float numLayers = lerp(maxLayers, minLayers, clamp(lod, 0, 1)); + + if (viewDir.z < 0.001) return 0; + + float heightScale = _Parallax; // 0.05 + float layerDepth = 1.0 / numLayers; + float currLayerDepth = 0.0; + float2 deltaUV = viewDir.xy * heightScale / (viewDir.z * numLayers); + float2 uvOffset = 0; + float height = 1.0 - ComputePerPixelHeightDisplacement(0, 0, ppdParam); + + for (int i = 0; i < numLayers; i++) { + currLayerDepth += layerDepth; + uvOffset -= deltaUV; + height = 1.0 - ComputePerPixelHeightDisplacement(uvOffset, 0, ppdParam); + if (height < currLayerDepth) { + break; + } + } + float2 prevOffset = uvOffset + deltaUV; + float nextDepth = height - currLayerDepth; + float prevDepth = 1.0 - ComputePerPixelHeightDisplacement(prevOffset, 0, ppdParam) - + currLayerDepth + layerDepth; + float2 parallaxUVs = lerp(uvOffset, prevOffset, nextDepth / (nextDepth - prevDepth)); + return parallaxUVs; +} + + +float2 ParallaxRaymarchingDynamicOffset(float3 viewDir, PerPixelHeightDisplacementParam ppdParam, + float strength, float lod) +{ + const float minLayers = 8.0; + const float maxLayers = 48.0; + float numLayers = lerp(maxLayers, minLayers, clamp(lod, 0, 1)); + + if (viewDir.z < 0.001) return 0; + + float heightScale = _Parallax; + float refPlane = 0.5; + + float layerDepth = 1.0 / numLayers; + float currLayerDepth = 0.0; + + float2 totalDelta = viewDir.xy * heightScale / viewDir.z; + float2 deltaUV = totalDelta / numLayers; + + // Shift the starting UVs forward so that the ray starts above the surface + float2 uvOffset = totalDelta * refPlane; + + float height = 1.0 - ComputePerPixelHeightDisplacement(uvOffset, 0, ppdParam); + + for (int i = 0; i < numLayers; i++) { + if (height < currLayerDepth) break; + + currLayerDepth += layerDepth; + uvOffset -= deltaUV; + height = 1.0 - ComputePerPixelHeightDisplacement(uvOffset, 0, ppdParam); + } + + float2 prevOffset = uvOffset + deltaUV; + float nextDepth = height - currLayerDepth; + float prevDepth = (1.0 - ComputePerPixelHeightDisplacement(prevOffset, 0, ppdParam)) - + (currLayerDepth - layerDepth); + + float weight = nextDepth / (nextDepth - prevDepth); + float2 parallaxUVs = lerp(uvOffset, prevOffset, weight); + + return parallaxUVs; +} + +float GetParallaxSelfShadow(float3 lightDir, float2 uv, PerPixelHeightDisplacementParam ppdParam, float noise) +{ + // lightDir.z is the cosine of the angle between the light and the tangent surface. + // If it's 0, we are at the horizon. + if (lightDir.z <= 0.0) return 0.0; + + const int numSamples = 16; + + float initialHeight = ComputePerPixelHeightDisplacement(0, 0, ppdParam); + + // Scale the penumbra by the surface depth. + float shadowHardness = 1.0 / (_BumpShadowHardness); + + float heightToTravel = 1.0 - initialHeight; + float2 uvStep = (lightDir.xy * _Parallax) / (lightDir.z * numSamples); + float stepHeight = heightToTravel / numSamples; + + float2 currentOffset = uvStep * noise; + float currentRayHeight = initialHeight + (stepHeight * noise); + + float shadowFactor = 1.0; + + [unroll(numSamples)] + for(int i = 0; i < numSamples; i++) + { + float mipLOD = (float(i) / float(numSamples)) * 7.0; + float sampledHeight = ComputePerPixelHeightDisplacement(currentOffset, mipLOD, ppdParam); + + if (sampledHeight > currentRayHeight) + { + float distanceAlongRay = (float)i / (float)numSamples; + float penetration = (sampledHeight - currentRayHeight) * (1.0 - distanceAlongRay); + + shadowFactor = min(shadowFactor, saturate(1.0 - penetration * shadowHardness * numSamples)); + } + + if (shadowFactor <= 0.0) break; + + currentOffset += uvStep; + currentRayHeight += stepHeight; + } + + return shadowFactor; +} + +#endif // SERVICE_PARALLAX_INCLUDED diff --git a/Assets/Filamented/SharedParallaxLib.hlsl.meta b/Assets/Filamented/SharedParallaxLib.hlsl.meta new file mode 100644 index 0000000..21f27e3 --- /dev/null +++ b/Assets/Filamented/SharedParallaxLib.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: ebaf59039a775d64fbb2ae9cfd1322d3 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/SharedSHLib.hlsl b/Assets/Filamented/SharedSHLib.hlsl new file mode 100644 index 0000000..be4b8be --- /dev/null +++ b/Assets/Filamented/SharedSHLib.hlsl @@ -0,0 +1,158 @@ +#ifndef COMMON_SH_INCLUDED +#define COMMON_SH_INCLUDED + +/* http://www.geomerics.com/wp-content/uploads/2015/08/CEDEC_Geomerics_ReconstructingDiffuseLighting1.pdf */ +half shEvaluateDiffuseL1Geomerics_local(half L0, half3 L1, float3 n) +{ + // average energy + // Add max0 to fix an issue caused by probes having a negative ambient component (???) + // I'm not sure how normal that is but this can't handle it + half R0 = max(L0, 0); + + // avg direction of incoming light + half3 R1 = 0.5f * L1; + + // directional brightness + half lenR1 = length(R1); + + // linear angle between normal and direction 0-1 + half q = dot(normalize(R1), n) * 0.5 + 0.5; + q = saturate(q); // Thanks to ScruffyRuffles for the bug identity. + + // power for q + // lerps from 1 (linear) to 3 (cubic) based on directionality + half p = 1.0f + 2.0f * lenR1 / R0; + + // dynamic range constant + // should vary between 4 (highly directional) and 0 (ambient) + half a = (1.0f - lenR1 / R0) / (1.0f + lenR1 / R0); + + return R0 * (a + (1.0f - a) * (p + 1.0f) * pow(q, p)); +} + +/* +// Paper: ZH3: Quadratic Zonal Harmonics, i3D 2024. https://torust.me/ZH3.pdf +// Code based on paper and demo https://www.shadertoy.com/view/Xfj3RK +// https://gist.github.com/pema99/f735ca33d1299abe0e143ee94fc61e73 +*/ + +// L1 radiance = L1 irradiance * PI / Y_1 / AHat_1 +// PI / (sqrt(3 / PI) / 2) / ((2 * PI) / 3) = sqrt(3 * PI) +const static float L0IrradianceToRadiance = 2 * sqrt(UNITY_PI); + +// L0 radiance = L0 irradiance * PI / Y_0 / AHat_0 +// PI / (sqrt(1 / PI) / 2) / PI = 2 * sqrt(PI) +const static float L1IrradianceToRadiance = sqrt(3 * UNITY_PI); + +const static float4 L0L1IrradianceToRadiance = float4(L0IrradianceToRadiance, L1IrradianceToRadiance, L1IrradianceToRadiance, L1IrradianceToRadiance); + +half SHEvalLinearL0L1_ZH3Hallucinate(half4 sh, float3 normal) +{ + float4 radiance = sh * L0L1IrradianceToRadiance; + + float3 zonalAxis = float3(radiance.w, radiance.y, radiance.z); + float l1Length = length(zonalAxis); + zonalAxis /= l1Length; + + float ratio = l1Length / radiance.x; + float zonalL2Coeff = radiance.x * ratio * (0.08 + 0.6 * ratio); // Curve-fit. + + float fZ = dot(zonalAxis, normal); + float zhNormal = sqrt(5.0f / (16.0f * UNITY_PI)) * (3.0f * fZ * fZ - 1.0f); + + float result = dot(sh, float4(1, float3(normal.y, normal.z, normal.x))); + result += 0.25f * zhNormal * zonalL2Coeff; + return result; +} + +// Evaluate irradiance in direction normal from the linear SH sh, +// hallucinating the ZH3 coefficient and then using that and linear SH +// for reconstruction. +half3 SHEvalLinearL0L1_ZH3Hallucinate(float3 normal) +{ + float3 shL0 = float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w) + + float3(unity_SHBr.z, unity_SHBg.z, unity_SHBb.z) / 3.0; + float3 shL1_1 = float3(unity_SHAr.y, unity_SHAg.y, unity_SHAb.y); + float3 shL1_2 = float3(unity_SHAr.z, unity_SHAg.z, unity_SHAb.z); + float3 shL1_3 = float3(unity_SHAr.x, unity_SHAg.x, unity_SHAb.x); + + float3 result = 0.0; + float4 a = float4(shL0.r, shL1_1.r, shL1_2.r, shL1_3.r); + float4 b = float4(shL0.g, shL1_1.g, shL1_2.g, shL1_3.g); + float4 c = float4(shL0.b, shL1_1.b, shL1_2.b, shL1_3.b); + result.r = SHEvalLinearL0L1_ZH3Hallucinate(a, normal); + result.g = SHEvalLinearL0L1_ZH3Hallucinate(b, normal); + result.b = SHEvalLinearL0L1_ZH3Hallucinate(c, normal); + return result; +} + +float3 SHEvalLinearL0L1_ZH3Hallucinate(float3 normal, float3 L0, + float3 L1r, float3 L1g, float3 L1b) +{ + float3 shL0 = L0; + float3 shL1_1 = float3(L1r.y, L1g.y, L1b.y); + float3 shL1_2 = float3(L1r.z, L1g.z, L1b.z); + float3 shL1_3 = float3(L1r.x, L1g.x, L1b.x); + + float3 result = 0.0; + float4 a = float4(shL0.r, shL1_1.r, shL1_2.r, shL1_3.r); + float4 b = float4(shL0.g, shL1_1.g, shL1_2.g, shL1_3.g); + float4 c = float4(shL0.b, shL1_1.b, shL1_2.b, shL1_3.b); + result.r = SHEvalLinearL0L1_ZH3Hallucinate(a, normal); + result.g = SHEvalLinearL0L1_ZH3Hallucinate(b, normal); + result.b = SHEvalLinearL0L1_ZH3Hallucinate(c, normal); + return result; +} + +// Evaluate irradiance in direction normal from the linear SH sh, +// computing a shared luminance axis from the linear components, +// hallucinating the ZH3 coefficients along that axis, +// and then using ZH3 and linear SH for reconstruction in the direction normal. +float3 SHEvalLinearL0L1_ZH3Hallucinate_LumAxis(float3 direction) +{ + // Get linear SH coefficients from Unity shader uniforms (without L2 folded into L0) + float3 shL0 = float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w) + + float3(unity_SHBr.z, unity_SHBg.z, unity_SHBb.z) / 3.0; + float3 shL1_1 = float3(unity_SHAr.y, unity_SHAg.y, unity_SHAb.y); + float3 shL1_2 = float3(unity_SHAr.z, unity_SHAg.z, unity_SHAb.z); + float3 shL1_3 = float3(unity_SHAr.x, unity_SHAg.x, unity_SHAb.x); + float3 sh[4] = { shL0, shL1_1, shL1_2, shL1_3 }; + + // Deconvolve irradiance -> radiance + float3 radianceSH[4]; + for (int i = 0; i < 3; i++) + { + radianceSH[0][i] = sh[0][i] * L0IrradianceToRadiance; + radianceSH[1][i] = sh[1][i] * L1IrradianceToRadiance; + radianceSH[2][i] = sh[2][i] * L1IrradianceToRadiance; + radianceSH[3][i] = sh[3][i] * L1IrradianceToRadiance; + } + + // Use the zonal axis from the luminance SH. + const float3 lumCoeffs = float3(0.2126f, 0.7152f, 0.0722f); // sRGB luminance. + float3 zonalAxis = normalize(float3(dot(radianceSH[3], lumCoeffs), dot(radianceSH[1], lumCoeffs), dot(radianceSH[2], lumCoeffs))); + float3 ratio = 0.0; + ratio.r = abs(dot(float3(radianceSH[3].r, radianceSH[1].r, radianceSH[2].r), zonalAxis)); + ratio.g = abs(dot(float3(radianceSH[3].g, radianceSH[1].g, radianceSH[2].g), zonalAxis)); + ratio.b = abs(dot(float3(radianceSH[3].b, radianceSH[1].b, radianceSH[2].b), zonalAxis)); + ratio /= radianceSH[0]; + float3 zonalL2Coeff = radianceSH[0] * (0.08f * ratio + 0.6f * ratio * ratio); // Curve-fit; Section 3.4.3 + float fZ = dot(zonalAxis, direction); + float zhDir = sqrt(5.0f / (16.0f * UNITY_PI)) * (3.0f * fZ * fZ - 1.0f); + + // Evaluate irradiance from linear SH in the given direction. + float4 shDir = float4(1, direction.y, direction.z, direction.x); + float3 result = float3(0.0, 0.0, 0.0); + result += sh[0] * shDir[0]; + result += sh[1] * shDir[1]; + result += sh[2] * shDir[2]; + result += sh[3] * shDir[3]; + + // Add irradiance from the ZH3 term. zonalL2Coeff is the ZH3 coefficient for a radiance signal, so we need to + // multiply by 1/4 (the L2 zonal scale for a normalized clamped cosine kernel) to evaluate irradiance. + result += 0.25f * zonalL2Coeff * zhDir; + + return result; +} + +#endif diff --git a/Assets/Filamented/SharedSHLib.hlsl.meta b/Assets/Filamented/SharedSHLib.hlsl.meta new file mode 100644 index 0000000..bc6b3f8 --- /dev/null +++ b/Assets/Filamented/SharedSHLib.hlsl.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9e297283be8c61040a72e7b5e467d43e +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/SharedSamplingLib.hlsl b/Assets/Filamented/SharedSamplingLib.hlsl new file mode 100644 index 0000000..32f04c7 --- /dev/null +++ b/Assets/Filamented/SharedSamplingLib.hlsl @@ -0,0 +1,1042 @@ +#ifndef COMMON_TEXTURE_SAMPLING +#define COMMON_TEXTURE_SAMPLING + +// From https://github.com/orels1/orels-Unity-Shaders +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// Credit to Jason Booth for digging this all up +// This originally comes from CoreRP, see Jason's comment below + +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_XBOXONE) + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + +// Texture abstraction + +#define TEXTURE2D(textureName) Texture2D textureName +#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName +#define TEXTURECUBE(textureName) TextureCube textureName +#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName +#define TEXTURE3D(textureName) Texture3D textureName + +#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) +#define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + +#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) +#define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + +#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + +#define RW_TEXTURE2D(type, textureName) RWTexture2D textureName +#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName +#define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + +#define SAMPLER(samplerName) SamplerState samplerName +#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + +#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + +#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) +#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) +#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) +#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + +#define PLATFORM_SUPPORT_GATHER +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_PSSL) + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + +// Texture abstraction + +#define TEXTURE2D(textureName) Texture2D textureName +#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName +#define TEXTURECUBE(textureName) TextureCube textureName +#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName +#define TEXTURE3D(textureName) Texture3D textureName + +#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) +#define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + +#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) +#define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + +#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + +#define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName +#define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName +#define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + +#define SAMPLER(samplerName) SamplerState samplerName +#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + +#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + +#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) +#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) +#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) +#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + +#define PLATFORM_SUPPORT_GATHER +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_D3D11) + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + +// Texture abstraction + +#define TEXTURE2D(textureName) Texture2D textureName +#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName +#define TEXTURECUBE(textureName) TextureCube textureName +#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName +#define TEXTURE3D(textureName) Texture3D textureName + +#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) +#define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + +#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) +#define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + +#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + +#define RW_TEXTURE2D(type, textureName) RWTexture2D textureName +#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName +#define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + +#define SAMPLER(samplerName) SamplerState samplerName +#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + +#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + +#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) +#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) +#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) +#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + +#define PLATFORM_SUPPORT_GATHER +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + +// Texture abstraction + +#define TEXTURE2D(textureName) Texture2D textureName +#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName +#define TEXTURECUBE(textureName) TextureCube textureName +#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName +#define TEXTURE3D(textureName) Texture3D textureName + +#define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName +#define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added +#define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added +#define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + +#define TEXTURE2D_HALF(textureName) Texture2D_half textureName +#define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added +#define TEXTURECUBE_HALF(textureName) TextureCube_half textureName +#define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added +#define TEXTURE3D_HALF(textureName) Texture3D_half textureName + +#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + +#define RW_TEXTURE2D(type, textureName) RWTexture2D textureName +#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName +#define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + +#define SAMPLER(samplerName) SamplerState samplerName +#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + +#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + +#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) +#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) +#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) +#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + +#define PLATFORM_SUPPORT_GATHER +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined +// TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + +// Texture abstraction + +#define TEXTURE2D(textureName) Texture2D textureName +#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName +#define TEXTURECUBE(textureName) TextureCube textureName +#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName +#define TEXTURE3D(textureName) Texture3D textureName + +#define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName +#define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added +#define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added +#define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + +#define TEXTURE2D_HALF(textureName) Texture2D_half textureName +#define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added +#define TEXTURECUBE_HALF(textureName) TextureCube_half textureName +#define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added +#define TEXTURE3D_HALF(textureName) Texture3D_half textureName + +#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + +#define RW_TEXTURE2D(type, textureName) RWTexture2D textureName +#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName +#define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + +#define SAMPLER(samplerName) SamplerState samplerName +#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + +#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + +#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) +#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) +#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) +#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + +#define PLATFORM_SUPPORT_GATHER +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) +// This file assume SHADER_API_SWITCH is defined + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + +// Texture abstraction + +#define TEXTURE2D(textureName) Texture2D textureName +#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName +#define TEXTURECUBE(textureName) TextureCube textureName +#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName +#define TEXTURE3D(textureName) Texture3D textureName + +#define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName +#define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added +#define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added +#define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + +#define TEXTURE2D_HALF(textureName) Texture2D_half textureName +#define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added +#define TEXTURECUBE_HALF(textureName) TextureCube_half textureName +#define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added +#define TEXTURE3D_HALF(textureName) Texture3D_half textureName + +#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + +#define RW_TEXTURE2D(type, textureName) RWTexture2D textureName +#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName +#define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + +#define SAMPLER(samplerName) SamplerState samplerName +#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + +#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + +#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) +#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) +#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + +#define PLATFORM_SUPPORT_GATHER +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + +// OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html +#if (SHADER_TARGET >= 46) +#define OPENGL4_1_SM5 1 +#else +#define OPENGL4_1_SM5 0 +#endif + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + +// Texture abstraction + +#define TEXTURE2D(textureName) Texture2D textureName +#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName +#define TEXTURECUBE(textureName) TextureCube textureName +#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName +#define TEXTURE3D(textureName) Texture3D textureName + +#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) +#define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + +#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) +#define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + +#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + +#define RW_TEXTURE2D(type, textureName) RWTexture2D textureName +#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName +#define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + +#define SAMPLER(samplerName) SamplerState samplerName +#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + +#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) +#ifdef UNITY_NO_CUBEMAP_ARRAY +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) +#else +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) +#endif +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + +#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) +#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + +#if OPENGL4_1_SM5 +#define PLATFORM_SUPPORT_GATHER +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) +#else +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) +#endif + +#elif defined(SHADER_API_GLES3) + +// GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html +#if (SHADER_TARGET >= 40) +#define GLES3_1_AEP 1 +#else +#define GLES3_1_AEP 0 +#endif + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + +// Texture abstraction + +#define TEXTURE2D(textureName) Texture2D textureName +#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName +#define TEXTURECUBE(textureName) TextureCube textureName +#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName +#define TEXTURE3D(textureName) Texture3D textureName + +#define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName +#define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added +#define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added +#define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + +#define TEXTURE2D_HALF(textureName) Texture2D_half textureName +#define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added +#define TEXTURECUBE_HALF(textureName) TextureCube_half textureName +#define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added +#define TEXTURE3D_HALF(textureName) Texture3D_half textureName + +#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) +#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + +#if GLES3_1_AEP +#define RW_TEXTURE2D(type, textureName) RWTexture2D textureName +#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName +#define RW_TEXTURE3D(type, textureName) RWTexture3D textureName +#else +#define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) +#define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) +#define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) +#endif + +#define SAMPLER(samplerName) SamplerState samplerName +#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + +#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) +#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) +#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName +#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + +#ifdef UNITY_NO_CUBEMAP_ARRAY +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) +#else +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) +#endif + +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + +#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) +#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) +#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) +#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + +#if GLES3_1_AEP +#define PLATFORM_SUPPORT_GATHER +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) +#else +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) +#endif + +#elif defined(SHADER_API_GLES) + +#define uint int + +#define rcp(x) 1.0 / (x) +#define ddx_fine ddx +#define ddy_fine ddy +#define asfloat +#define asuint(x) asint(x) +#define f32tof16 +#define f16tof32 + +#define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + +// Initialize arbitrary structure with zero values. +// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 +#define ZERO_INITIALIZE(type, name) name = (type)0; +#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + +// Texture util abstraction + +#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + +// Texture abstraction + +#define TEXTURE2D(textureName) sampler2D textureName +#define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray +#define TEXTURECUBE(textureName) samplerCUBE textureName +#define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray +#define TEXTURE3D(textureName) sampler3D textureName + +#define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName +#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray +#define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName +#define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray +#define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + +#define TEXTURE2D_HALF(textureName) sampler2D_half textureName +#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray +#define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName +#define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray +#define TEXTURE3D_HALF(textureName) sampler3D_half textureName + +#define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName +#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array +#define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName +#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + +#define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) +#define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) +#define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + +#define SAMPLER(samplerName) +#define SAMPLER_CMP(samplerName) + +#define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName +#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName +#define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName +#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName +#define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName +#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName +#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName +#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + +#define TEXTURE2D_ARGS(textureName, samplerName) textureName +#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName +#define TEXTURECUBE_ARGS(textureName, samplerName) textureName +#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName +#define TEXTURE3D_ARGS(textureName, samplerName) textureName +#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName +#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName +#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + +#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + +#if (SHADER_TARGET >= 30) +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) +#else +// No lod support. Very poor approximation with bias. +#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) +#endif + +#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) +#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) +#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) +#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) +#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) +#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) +#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) +// No lod support. Very poor approximation with bias. +#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) +#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) +#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) +#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) +#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) +#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) +#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + +#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) +#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) +#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) +#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + +// Not supported. Can't define as error because shader library is calling these functions. +#define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) +#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) +#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) +#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) +#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) +#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) +#define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) +#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + +// Gather not supported. Fallback to regular texture sampling. +#define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) +#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) +#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) +#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) +#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) +#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) +#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) +#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + +#endif // COMMON_TEXTURE_SAMPLING \ No newline at end of file diff --git a/Assets/Filamented/SharedSamplingLib.hlsl.meta b/Assets/Filamented/SharedSamplingLib.hlsl.meta new file mode 100644 index 0000000..ebb3a16 --- /dev/null +++ b/Assets/Filamented/SharedSamplingLib.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 25cfa7644c2f4bc4c91c60f98b7b63a4 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/Standard.shader b/Assets/Filamented/Standard.shader new file mode 100644 index 0000000..7e5b4cb --- /dev/null +++ b/Assets/Filamented/Standard.shader @@ -0,0 +1,219 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Silent/Filamented" +{ + Properties + { + _Color("Color", Color) = (1,1,1,1) + _MainTex("Albedo", 2D) = "white" {} + + _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 + + _Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5 + _GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0 + [Enum(Metallic Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel ("Smoothness texture channel", Float) = 0 + + [Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0 + _MetallicGlossMap("Metallic", 2D) = "white" {} + + [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0 + [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 + + _BumpScale("Scale", Float) = 1.0 + [Normal] _BumpMap("Normal Map", 2D) = "bump" {} + + _Parallax ("Height Scale", Range (0.005, 0.25)) = 0.02 + _ParallaxMap ("Height Map", 2D) = "black" {} + + _OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0 + _OcclusionMap("Occlusion", 2D) = "white" {} + + _EmissionColor("Color", Color) = (0,0,0) + _EmissionMap("Emission", 2D) = "white" {} + + _DetailMask("Detail Mask", 2D) = "white" {} + + _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {} + _DetailNormalMapScale("Scale", Float) = 1.0 + [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {} + + [Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0 + + // New settings + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 0.9 + + [Toggle(_NORMALMAP_SHADOW)]_NormalMapShadows("Normal Map Shadows", Range(0, 1)) = 0 + _BumpShadowHeightScale("Height Scale", Range(0, 1)) = 0.2 + _BumpShadowHardness("Shadow Hardness", Range(0, 100)) = 50 + + _specularAntiAliasingVariance("Specular AA Variance", Range(0, 1)) = 0.15 + _specularAntiAliasingThreshold("Specular AA Threshold", Range(0, 1)) = 0.25 + + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [Toggle(_BAKERY_VERTEXLM)]_BakeryVertexLM ("Use Bakery Vertex Lightmaps", Range(0, 1)) = 0 + _RNM0("RNM0", 2D) = "black" {} + _RNM1("RNM1", 2D) = "black" {} + _RNM2("RNM2", 2D) = "black" {} + + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + [ToggleUI]_AlphaToMaskMode("Alpha to Coverage", Int) = 0 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + + // Blending state + [HideInInspector] _Mode ("__mode", Float) = 0.0 + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + } + + CGINCLUDE + // OcclusionMap is always defined + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // Use specular AA controls + #define USE_GEOMETRIC_SPECULAR_AA + // _DFG is present + #define USE_DFG_LUT + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + Cull [_CullMode] + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + AlphaToMask [_AlphaToMaskMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature _EMISSION + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _PARALLAXMAP + + #pragma shader_feature_local _LIGHTMAPSPECULAR + #pragma shader_feature_local _NORMALMAP_SHADOW + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _BAKERY_VERTEXLM + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + #include "UnityStandardCoreForward.cginc" + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend [_SrcBlend] One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest LEqual + AlphaToMask [_AlphaToMaskMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP + + #pragma shader_feature_local _NORMALMAP_SHADOW + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + #include "UnityStandardCoreForward.cginc" + + ENDCG + } + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _PARALLAXMAP + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "UnityStandardShadow.cginc" + + ENDCG + } + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + // Meta not implemented + UsePass "Standard/META" + + } + + FallBack "VertexLit" + CustomEditor "SilentTools.FilamentedStandardShaderGUI" +} diff --git a/Assets/Filamented/Standard.shader.meta b/Assets/Filamented/Standard.shader.meta new file mode 100644 index 0000000..72b67b3 --- /dev/null +++ b/Assets/Filamented/Standard.shader.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 9829e18681954944a8b25de9b080a0b6 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _MetallicGlossMap: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _ParallaxMap: {instanceID: 0} + - _OcclusionMap: {instanceID: 0} + - _EmissionMap: {instanceID: 0} + - _DetailMask: {instanceID: 0} + - _DetailAlbedoMap: {instanceID: 0} + - _DetailNormalMap: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/StandardCloth.shader b/Assets/Filamented/StandardCloth.shader new file mode 100644 index 0000000..176e90d --- /dev/null +++ b/Assets/Filamented/StandardCloth.shader @@ -0,0 +1,221 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Silent/Filamented (Cloth setup)" +{ + Properties + { + _Color("Color", Color) = (1,1,1,1) + _MainTex("Albedo", 2D) = "white" {} + + _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 + + _Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5 + _GlossMapScale("Smoothness Factor", Range(0.0, 1.0)) = 1.0 + [Enum(Specular Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel ("Smoothness texture channel", Float) = 0 + + _SpecColor("Sheen", Color) = (0.2,0.2,0.2) + _SpecGlossMap("Sheen Map", 2D) = "white" {} + [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0 + [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 + + _BumpScale("Scale", Float) = 1.0 + [Normal] _BumpMap("Normal Map", 2D) = "bump" {} + + _Parallax ("Height Scale", Range (0.005, 0.25)) = 0.02 + _ParallaxMap ("Height Map", 2D) = "black" {} + + _OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0 + _OcclusionMap("Occlusion", 2D) = "white" {} + + _EmissionColor("Color", Color) = (0,0,0) + _EmissionMap("Emission", 2D) = "white" {} + + _DetailMask("Detail Mask", 2D) = "white" {} + + _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {} + _DetailNormalMapScale("Scale", Float) = 1.0 + [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {} + + [Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0 + + // New settings + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 0.9 + + [Toggle(_NORMALMAP_SHADOW)]_NormalMapShadows("Normal Map Shadows", Range(0, 1)) = 0 + _BumpShadowHeightScale("Height Scale", Range(0, 1)) = 0.2 + _BumpShadowHardness("Shadow Hardness", Range(0, 100)) = 50 + + _specularAntiAliasingVariance("Specular AA Variance", Range(0, 1)) = 0.15 + _specularAntiAliasingThreshold("Specular AA Threshold", Range(0, 1)) = 0.25 + + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [Toggle(_BAKERY_VERTEXLM)]_BakeryVertexLM ("Use Bakery Vertex Lightmaps", Range(0, 1)) = 0 + _RNM0("RNM0", 2D) = "black" {} + _RNM1("RNM1", 2D) = "black" {} + _RNM2("RNM2", 2D) = "black" {} + + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + [ToggleUI]_AlphaToMaskMode("Alpha to Coverage", Int) = 0 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + [HideInInspector] _ShaderType_Cloth("__cloth", Float) = 1.0 + + // Blending state + [HideInInspector] _Mode ("__mode", Float) = 0.0 + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + } + + CGINCLUDE + #define SHADING_MODEL_CLOTH + #define MATERIAL_HAS_SHEEN_COLOR + //#define MATERIAL_HAS_SUBSURFACE_COLOR + // OcclusionMap is always defined + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // Use specular AA controls + #define USE_GEOMETRIC_SPECULAR_AA + // _DFG is present + #define USE_DFG_LUT + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + Cull [_CullMode] + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + AlphaToMask [_AlphaToMaskMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature _EMISSION + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _PARALLAXMAP + + #pragma shader_feature_local _LIGHTMAPSPECULAR + #pragma shader_feature_local _NORMALMAP_SHADOW + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _BAKERY_VERTEXLM + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + #include "UnityStandardCoreForward.cginc" + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend [_SrcBlend] One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest LEqual + AlphaToMask [_AlphaToMaskMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP + + #pragma shader_feature_local _NORMALMAP_SHADOW + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + #include "UnityStandardCoreForward.cginc" + + ENDCG + } + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _PARALLAXMAP + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "UnityStandardShadow.cginc" + + ENDCG + } + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + // Meta not implemented + UsePass "Standard/META" + + } + + FallBack "VertexLit" + CustomEditor "SilentTools.FilamentedStandardShaderGUI" +} diff --git a/Assets/Filamented/StandardCloth.shader.meta b/Assets/Filamented/StandardCloth.shader.meta new file mode 100644 index 0000000..158ea68 --- /dev/null +++ b/Assets/Filamented/StandardCloth.shader.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: deca4036fd687004ca874acb20f3fd5f +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _SpecGlossMap: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _ParallaxMap: {instanceID: 0} + - _OcclusionMap: {instanceID: 0} + - _EmissionMap: {instanceID: 0} + - _DetailMask: {instanceID: 0} + - _DetailAlbedoMap: {instanceID: 0} + - _DetailNormalMap: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/StandardRoughness.shader b/Assets/Filamented/StandardRoughness.shader new file mode 100644 index 0000000..27a02d2 --- /dev/null +++ b/Assets/Filamented/StandardRoughness.shader @@ -0,0 +1,219 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Silent/Filamented (Roughness setup)" +{ + Properties + { + _Color("Color", Color) = (1,1,1,1) + _MainTex("Albedo", 2D) = "white" {} + + _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 + + _Glossiness("Roughness", Range(0.0, 1.0)) = 0.5 + _SpecGlossMap("Roughness Map", 2D) = "white" {} + + [Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0 + _MetallicGlossMap("Metallic", 2D) = "white" {} + + [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0 + [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 + + _BumpScale("Scale", Float) = 1.0 + [Normal] _BumpMap("Normal Map", 2D) = "bump" {} + + _Parallax ("Height Scale", Range (0.005, 0.25)) = 0.02 + _ParallaxMap ("Height Map", 2D) = "black" {} + + _OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0 + _OcclusionMap("Occlusion", 2D) = "white" {} + + _EmissionColor("Color", Color) = (0,0,0) + _EmissionMap("Emission", 2D) = "white" {} + + _DetailMask("Detail Mask", 2D) = "white" {} + + _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {} + _DetailNormalMapScale("Scale", Float) = 1.0 + [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {} + + [Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0 + + // New settings + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 0.9 + + [Toggle(_NORMALMAP_SHADOW)]_NormalMapShadows("Normal Map Shadows", Range(0, 1)) = 0 + _BumpShadowHeightScale("Height Scale", Range(0, 1)) = 0.2 + _BumpShadowHardness("Shadow Hardness", Range(0, 100)) = 50 + + _specularAntiAliasingVariance("Specular AA Variance", Range(0, 1)) = 0.15 + _specularAntiAliasingThreshold("Specular AA Threshold", Range(0, 1)) = 0.25 + + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [Toggle(_BAKERY_VERTEXLM)]_BakeryVertexLM ("Use Bakery Vertex Lightmaps", Range(0, 1)) = 0 + _RNM0("RNM0", 2D) = "black" {} + _RNM1("RNM1", 2D) = "black" {} + _RNM2("RNM2", 2D) = "black" {} + + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + [ToggleUI]_AlphaToMaskMode("Alpha to Coverage", Int) = 0 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + + // Blending state + [HideInInspector] _Mode ("__mode", Float) = 0.0 + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + } + + CGINCLUDE + #define SHADING_MODEL_METALLIC_ROUGHNESS + // OcclusionMap is always defined + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // Use specular AA controls + #define USE_GEOMETRIC_SPECULAR_AA + // _DFG is present + #define USE_DFG_LUT + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + Cull [_CullMode] + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + AlphaToMask [_AlphaToMaskMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature _EMISSION + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _PARALLAXMAP + + #pragma shader_feature_local _LIGHTMAPSPECULAR + #pragma shader_feature_local _NORMALMAP_SHADOW + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _BAKERY_VERTEXLM + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + #include "UnityStandardCoreForward.cginc" + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend [_SrcBlend] One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest LEqual + AlphaToMask [_AlphaToMaskMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP + + #pragma shader_feature_local _NORMALMAP_SHADOW + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + #include "UnityStandardCoreForward.cginc" + + ENDCG + } + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _PARALLAXMAP + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "UnityStandardShadow.cginc" + + ENDCG + } + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + // Meta not implemented + UsePass "Standard/META" + + } + + FallBack "VertexLit" + CustomEditor "SilentTools.FilamentedStandardShaderGUI" +} diff --git a/Assets/Filamented/StandardRoughness.shader.meta b/Assets/Filamented/StandardRoughness.shader.meta new file mode 100644 index 0000000..4b597dd --- /dev/null +++ b/Assets/Filamented/StandardRoughness.shader.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 075dbc3edcecd8747919086245d79325 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _SpecGlossMap: {instanceID: 0} + - _MetallicGlossMap: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _ParallaxMap: {instanceID: 0} + - _OcclusionMap: {instanceID: 0} + - _EmissionMap: {instanceID: 0} + - _DetailMask: {instanceID: 0} + - _DetailAlbedoMap: {instanceID: 0} + - _DetailNormalMap: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/StandardSpecular.shader b/Assets/Filamented/StandardSpecular.shader new file mode 100644 index 0000000..925346d --- /dev/null +++ b/Assets/Filamented/StandardSpecular.shader @@ -0,0 +1,218 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Silent/Filamented (Specular setup)" +{ + Properties + { + _Color("Color", Color) = (1,1,1,1) + _MainTex("Albedo", 2D) = "white" {} + + _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 + + _Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5 + _GlossMapScale("Smoothness Factor", Range(0.0, 1.0)) = 1.0 + [Enum(Specular Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel ("Smoothness texture channel", Float) = 0 + + _SpecColor("Specular", Color) = (0.2,0.2,0.2) + _SpecGlossMap("Specular", 2D) = "white" {} + [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0 + [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 + + _BumpScale("Scale", Float) = 1.0 + [Normal] _BumpMap("Normal Map", 2D) = "bump" {} + + _Parallax ("Height Scale", Range (0.005, 0.25)) = 0.02 + _ParallaxMap ("Height Map", 2D) = "black" {} + + _OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0 + _OcclusionMap("Occlusion", 2D) = "white" {} + + _EmissionColor("Color", Color) = (0,0,0) + _EmissionMap("Emission", 2D) = "white" {} + + _DetailMask("Detail Mask", 2D) = "white" {} + + _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {} + _DetailNormalMapScale("Scale", Float) = 1.0 + [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {} + + [Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0 + + // New settings + _ExposureOcclusion("Lightmap Occlusion Sensitivity", Range(0, 1)) = 0.2 + [Toggle(_LIGHTMAPSPECULAR)]_LightmapSpecular("Lightmap Specular", Range(0, 1)) = 1 + _LightmapSpecularMaxSmoothness("Lightmap Specular Max Smoothness", Range(0, 1)) = 0.9 + + [Toggle(_NORMALMAP_SHADOW)]_NormalMapShadows("Normal Map Shadows", Range(0, 1)) = 0 + _BumpShadowHeightScale("Height Scale", Range(0, 1)) = 0.2 + _BumpShadowHardness("Shadow Hardness", Range(0, 100)) = 50 + + _specularAntiAliasingVariance("Specular AA Variance", Range(0, 1)) = 0.15 + _specularAntiAliasingThreshold("Specular AA Threshold", Range(0, 1)) = 0.25 + + [KeywordEnum(None, SH, RNM, MonoSH)] _Bakery ("Bakery Mode", Int) = 0 + [Toggle(_BAKERY_VERTEXLM)]_BakeryVertexLM ("Use Bakery Vertex Lightmaps", Range(0, 1)) = 0 + _RNM0("RNM0", 2D) = "black" {} + _RNM1("RNM1", 2D) = "black" {} + _RNM2("RNM2", 2D) = "black" {} + + [Toggle(_LTCGI)] _LTCGI ("LTCGI", Int) = 0 + [Toggle(_VRCLV)] _VRCLV ("VRC Light Volumes", Int) = 0 + [IfDef(_VRCLV)] _VRCLVSurfaceBias("Light Volume Surface Bias", Range(0, 0.5)) = 0.05 + + [Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2 + [ToggleUI]_AlphaToMaskMode("Alpha to Coverage", Int) = 0 + + [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} + + // Blending state + [HideInInspector] _Mode ("__mode", Float) = 0.0 + [HideInInspector] _SrcBlend ("__src", Float) = 1.0 + [HideInInspector] _DstBlend ("__dst", Float) = 0.0 + [HideInInspector] _ZWrite ("__zw", Float) = 1.0 + } + + CGINCLUDE + #define SHADING_MODEL_SPECULAR_GLOSSINESS + // OcclusionMap is always defined + #define MATERIAL_HAS_AMBIENT_OCCLUSION + // Use specular AA controls + #define USE_GEOMETRIC_SPECULAR_AA + // _DFG is present + #define USE_DFG_LUT + ENDCG + + SubShader + { + Tags { "RenderType"="Opaque" "PerformanceChecks"="False" "LTCGI" = "_LTCGI" } + LOD 300 + + Cull [_CullMode] + + // ------------------------------------------------------------------ + // Base forward pass (directional light, emission, lightmaps, ...) + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Blend [_SrcBlend] [_DstBlend] + ZWrite [_ZWrite] + AlphaToMask [_AlphaToMaskMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature _EMISSION + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _PARALLAXMAP + + #pragma shader_feature_local _LIGHTMAPSPECULAR + #pragma shader_feature_local _NORMALMAP_SHADOW + #pragma shader_feature_local _ _BAKERY_RNM _BAKERY_SH _BAKERY_MONOSH + #pragma shader_feature_local _BAKERY_VERTEXLM + #pragma shader_feature_local _LTCGI + #pragma shader_feature_local _VRCLV + + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertBase + #pragma fragment fragBase + #include "UnityStandardCoreForward.cginc" + + ENDCG + } + // ------------------------------------------------------------------ + // Additive forward pass (one light per pass) + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd" } + Blend [_SrcBlend] One + Fog { Color (0,0,0,0) } // in additive pass fog should be black + ZWrite Off + ZTest LEqual + AlphaToMask [_AlphaToMaskMode] + + CGPROGRAM + #pragma target 4.0 + + // ------------------------------------- + + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP + + #pragma shader_feature_local _NORMALMAP_SHADOW + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertAdd + #pragma fragment fragAdd + #include "UnityStandardCoreForward.cginc" + + ENDCG + } + // ------------------------------------------------------------------ + // Shadow rendering pass + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + ZWrite On ZTest LEqual + + CGPROGRAM + #pragma target 3.0 + + // ------------------------------------- + + + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _PARALLAXMAP + #pragma multi_compile_shadowcaster + #pragma multi_compile_instancing + // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. + //#pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma vertex vertShadowCaster + #pragma fragment fragShadowCaster + + #include "UnityStandardShadow.cginc" + + ENDCG + } + + // Deferred not implemented + UsePass "Standard/DEFERRED" + + // Meta not implemented + UsePass "Standard/META" + + } + + FallBack "VertexLit" + CustomEditor "SilentTools.FilamentedStandardShaderGUI" +} diff --git a/Assets/Filamented/StandardSpecular.shader.meta b/Assets/Filamented/StandardSpecular.shader.meta new file mode 100644 index 0000000..972955f --- /dev/null +++ b/Assets/Filamented/StandardSpecular.shader.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: d1e71c1f97670b843a43924d87ceb04b +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _SpecGlossMap: {instanceID: 0} + - _BumpMap: {instanceID: 0} + - _ParallaxMap: {instanceID: 0} + - _OcclusionMap: {instanceID: 0} + - _EmissionMap: {instanceID: 0} + - _DetailMask: {instanceID: 0} + - _DetailAlbedoMap: {instanceID: 0} + - _DetailNormalMap: {instanceID: 0} + - _RNM0: {instanceID: 0} + - _RNM1: {instanceID: 0} + - _RNM2: {instanceID: 0} + nonModifiableTextures: + - _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityGlobalIllumination.cginc b/Assets/Filamented/UnityGlobalIllumination.cginc new file mode 100644 index 0000000..f36fab2 --- /dev/null +++ b/Assets/Filamented/UnityGlobalIllumination.cginc @@ -0,0 +1,207 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_GLOBAL_ILLUMINATION_INCLUDED +#define UNITY_GLOBAL_ILLUMINATION_INCLUDED + +// Functions sampling light environment data (lightmaps, light probes, reflection probes), which is then returned as the UnityGI struct. + +#include "UnityImageBasedLighting.cginc" +#include "UnityStandardUtils.cginc" +#include "UnityShadowLibrary.cginc" + +inline half3 DecodeDirectionalSpecularLightmap (half3 color, half4 dirTex, half3 normalWorld, bool isRealtimeLightmap, fixed4 realtimeNormalTex, out UnityLight o_light) +{ + o_light.color = color; + o_light.dir = dirTex.xyz * 2 - 1; + o_light.ndotl = 0; // Not use; + + // The length of the direction vector is the light's "directionality", i.e. 1 for all light coming from this direction, + // lower values for more spread out, ambient light. + half directionality = max(0.001, length(o_light.dir)); + o_light.dir /= directionality; + + #ifdef DYNAMICLIGHTMAP_ON + if (isRealtimeLightmap) + { + // Realtime directional lightmaps' intensity needs to be divided by N.L + // to get the incoming light intensity. Baked directional lightmaps are already + // output like that (including the max() to prevent div by zero). + half3 realtimeNormal = realtimeNormalTex.xyz * 2 - 1; + o_light.color /= max(0.125, dot(realtimeNormal, o_light.dir)); + } + #endif + + // Split light into the directional and ambient parts, according to the directionality factor. + half3 ambient = o_light.color * (1 - directionality); + o_light.color = o_light.color * directionality; + + // Technically this is incorrect, but helps hide jagged light edge at the object silhouettes and + // makes normalmaps show up. + ambient *= saturate(dot(normalWorld, o_light.dir)); + return ambient; +} + +inline void ResetUnityLight(out UnityLight outLight) +{ + outLight.color = half3(0, 0, 0); + outLight.dir = half3(0, 1, 0); // Irrelevant direction, just not null + outLight.ndotl = 0; // Not used +} + +inline half3 SubtractMainLightWithRealtimeAttenuationFromLightmap (half3 lightmap, half attenuation, half4 bakedColorTex, half3 normalWorld) +{ + // Let's try to make realtime shadows work on a surface, which already contains + // baked lighting and shadowing from the main sun light. + half3 shadowColor = unity_ShadowColor.rgb; + half shadowStrength = _LightShadowData.x; + + // Summary: + // 1) Calculate possible value in the shadow by subtracting estimated light contribution from the places occluded by realtime shadow: + // a) preserves other baked lights and light bounces + // b) eliminates shadows on the geometry facing away from the light + // 2) Clamp against user defined ShadowColor. + // 3) Pick original lightmap value, if it is the darkest one. + + + // 1) Gives good estimate of illumination as if light would've been shadowed during the bake. + // Preserves bounce and other baked lights + // No shadows on the geometry facing away from the light + half ndotl = LambertTerm (normalWorld, _WorldSpaceLightPos0.xyz); + half3 estimatedLightContributionMaskedByInverseOfShadow = ndotl * (1- attenuation) * _LightColor0.rgb; + half3 subtractedLightmap = lightmap - estimatedLightContributionMaskedByInverseOfShadow; + + // 2) Allows user to define overall ambient of the scene and control situation when realtime shadow becomes too dark. + half3 realtimeShadow = max(subtractedLightmap, shadowColor); + realtimeShadow = lerp(realtimeShadow, lightmap, shadowStrength); + + // 3) Pick darkest color + return min(lightmap, realtimeShadow); +} + +inline void ResetUnityGI(out UnityGI outGI) +{ + ResetUnityLight(outGI.light); + outGI.indirect.diffuse = 0; + outGI.indirect.specular = 0; +} + +inline UnityGI UnityGI_Base(UnityGIInput data, inout half occlusion, half3 normalWorld) +{ + UnityGI o_gi; + ResetUnityGI(o_gi); + + // Base pass with Lightmap support is responsible for handling ShadowMask / blending here for performance reason + #if defined(HANDLE_SHADOWS_BLENDING_IN_GI) + half bakedAtten = UnitySampleBakedOcclusion(data.lightmapUV.xy, data.worldPos); + float zDist = dot(_WorldSpaceCameraPos - data.worldPos, UNITY_MATRIX_V[2].xyz); + float fadeDist = UnityComputeShadowFadeDistance(data.worldPos, zDist); + data.atten = UnityMixRealtimeAndBakedShadows(data.atten, bakedAtten, UnityComputeShadowFade(fadeDist)); + #endif + + o_gi.light = data.light; + o_gi.light.color *= data.atten; + + #if UNITY_SHOULD_SAMPLE_SH + o_gi.indirect.diffuse = ShadeSHPerPixel(normalWorld, data.ambient, data.worldPos); + #endif + + #if defined(LIGHTMAP_ON) + // Baked lightmaps + half4 bakedColorTex = UNITY_SAMPLE_TEX2D(unity_Lightmap, data.lightmapUV.xy); + half3 bakedColor = DecodeLightmap(bakedColorTex); + + // Derive specular occlusion + + half bakedOcclusion = saturate(dot(bakedColor * 3.0, 1.0)); + occlusion *= bakedOcclusion; + + #ifdef DIRLIGHTMAP_COMBINED + fixed4 bakedDirTex = UNITY_SAMPLE_TEX2D_SAMPLER (unity_LightmapInd, unity_Lightmap, data.lightmapUV.xy); + o_gi.indirect.diffuse += DecodeDirectionalLightmap (bakedColor, bakedDirTex, normalWorld); + + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + ResetUnityLight(o_gi.light); + o_gi.indirect.diffuse = SubtractMainLightWithRealtimeAttenuationFromLightmap (o_gi.indirect.diffuse, data.atten, bakedColorTex, normalWorld); + #endif + + #else // not directional lightmap + o_gi.indirect.diffuse += bakedColor; + + #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + ResetUnityLight(o_gi.light); + o_gi.indirect.diffuse = SubtractMainLightWithRealtimeAttenuationFromLightmap(o_gi.indirect.diffuse, data.atten, bakedColorTex, normalWorld); + #endif + + #endif + #endif + + #ifdef DYNAMICLIGHTMAP_ON + // Dynamic lightmaps + fixed4 realtimeColorTex = UNITY_SAMPLE_TEX2D(unity_DynamicLightmap, data.lightmapUV.zw); + half3 realtimeColor = DecodeRealtimeLightmap (realtimeColorTex); + + #ifdef DIRLIGHTMAP_COMBINED + half4 realtimeDirTex = UNITY_SAMPLE_TEX2D_SAMPLER(unity_DynamicDirectionality, unity_DynamicLightmap, data.lightmapUV.zw); + o_gi.indirect.diffuse += DecodeDirectionalLightmap (realtimeColor, realtimeDirTex, normalWorld); + #else + o_gi.indirect.diffuse += realtimeColor; + #endif + #endif + + o_gi.indirect.diffuse *= occlusion; + return o_gi; +} + + +inline half3 UnityGI_IndirectSpecular(UnityGIInput data, half occlusion, Unity_GlossyEnvironmentData glossIn) +{ + half3 specular; + + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + // we will tweak reflUVW in glossIn directly (as we pass it to Unity_GlossyEnvironment twice for probe0 and probe1), so keep original to pass into BoxProjectedCubemapDirection + half3 originalReflUVW = glossIn.reflUVW; + glossIn.reflUVW = BoxProjectedCubemapDirection (originalReflUVW, data.worldPos, data.probePosition[0], data.boxMin[0], data.boxMax[0]); + #endif + + #ifdef _GLOSSYREFLECTIONS_OFF + specular = unity_IndirectSpecColor.rgb; + #else + half3 env0 = Unity_GlossyEnvironment (UNITY_PASS_TEXCUBE(unity_SpecCube0), data.probeHDR[0], glossIn); + #ifdef UNITY_SPECCUBE_BLENDING + const float kBlendFactor = 0.99999; + float blendLerp = data.boxMin[0].w; + UNITY_BRANCH + if (blendLerp < kBlendFactor) + { + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + glossIn.reflUVW = BoxProjectedCubemapDirection (originalReflUVW, data.worldPos, data.probePosition[1], data.boxMin[1], data.boxMax[1]); + #endif + + half3 env1 = Unity_GlossyEnvironment (UNITY_PASS_TEXCUBE_SAMPLER(unity_SpecCube1,unity_SpecCube0), data.probeHDR[1], glossIn); + specular = lerp(env1, env0, blendLerp); + } + else + { + specular = env0; + } + #else + specular = env0; + #endif + #endif + + return specular * occlusion; +} + +inline UnityGI UnityGlobalIllumination (UnityGIInput data, half occlusion, half3 normalWorld) +{ + return UnityGI_Base(data, occlusion, normalWorld); +} + +inline UnityGI UnityGlobalIllumination (UnityGIInput data, half occlusion, half3 normalWorld, Unity_GlossyEnvironmentData glossIn) +{ + UnityGI o_gi = UnityGI_Base(data, occlusion, normalWorld); + o_gi.indirect.specular = UnityGI_IndirectSpecular(data, occlusion, glossIn); + return o_gi; +} + +#endif \ No newline at end of file diff --git a/Assets/Filamented/UnityGlobalIllumination.cginc.meta b/Assets/Filamented/UnityGlobalIllumination.cginc.meta new file mode 100644 index 0000000..bf90a0f --- /dev/null +++ b/Assets/Filamented/UnityGlobalIllumination.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 50a0b962e7beb424ca767ae9656c4ed4 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityImageBasedLightingMinimal.cginc b/Assets/Filamented/UnityImageBasedLightingMinimal.cginc new file mode 100644 index 0000000..d551a8f --- /dev/null +++ b/Assets/Filamented/UnityImageBasedLightingMinimal.cginc @@ -0,0 +1,72 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_IMAGE_BASED_LIGHTING_INCLUDED +#define UNITY_IMAGE_BASED_LIGHTING_INCLUDED + +#include "UnityStandardUtils.cginc" + +// ---------------------------------------------------------------------------- +// GlossyEnvironment - Function to integrate the specular lighting with default sky or reflection probes +// ---------------------------------------------------------------------------- +struct Unity_GlossyEnvironmentData +{ + // - Deferred case have one cubemap + // - Forward case can have two blended cubemap (unusual should be deprecated). + + // Surface properties use for cubemap integration + half roughness; // CAUTION: This is perceptualRoughness but because of compatibility this name can't be change :( + half3 reflUVW; +}; + +// ---------------------------------------------------------------------------- + +Unity_GlossyEnvironmentData UnityGlossyEnvironmentSetup(half Smoothness, half3 worldViewDir, half3 Normal, half3 fresnel0) +{ + Unity_GlossyEnvironmentData g; + + g.roughness /* perceptualRoughness */ = SmoothnessToPerceptualRoughness(Smoothness); + g.reflUVW = reflect(-worldViewDir, Normal); + + return g; +} + +// ---------------------------------------------------------------------------- +half perceptualRoughnessToMipmapLevel(half perceptualRoughness) +{ + return perceptualRoughness * UNITY_SPECCUBE_LOD_STEPS; +} + +// ---------------------------------------------------------------------------- +half mipmapLevelToPerceptualRoughness(half mipmapLevel) +{ + return mipmapLevel / UNITY_SPECCUBE_LOD_STEPS; +} + +// ---------------------------------------------------------------------------- +half3 Unity_GlossyEnvironment (UNITY_ARGS_TEXCUBE(tex), half4 hdr, Unity_GlossyEnvironmentData glossIn) +{ + half perceptualRoughness = glossIn.roughness /* perceptualRoughness */ ; + +// TODO: CAUTION: remap from Morten may work only with offline convolution, see impact with runtime convolution! +// For now disabled +#if 0 + float m = PerceptualRoughnessToRoughness(perceptualRoughness); // m is the real roughness parameter + const float fEps = 1.192092896e-07F; // smallest such that 1.0+FLT_EPSILON != 1.0 (+1e-4h is NOT good here. is visibly very wrong) + float n = (2.0/max(fEps, m*m))-2.0; // remap to spec power. See eq. 21 in --> https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf + + n /= 4; // remap from n_dot_h formulatino to n_dot_r. See section "Pre-convolved Cube Maps vs Path Tracers" --> https://s3.amazonaws.com/docs.knaldtech.com/knald/1.0.0/lys_power_drops.html + + perceptualRoughness = pow( 2/(n+2), 0.25); // remap back to square root of real roughness (0.25 include both the sqrt root of the conversion and sqrt for going from roughness to perceptualRoughness) +#else + // MM: came up with a surprisingly close approximation to what the #if 0'ed out code above does. + perceptualRoughness = perceptualRoughness*(1.7 - 0.7*perceptualRoughness); +#endif + + + half mip = perceptualRoughnessToMipmapLevel(perceptualRoughness); + half3 R = glossIn.reflUVW; + half4 rgbm = UNITY_SAMPLE_TEXCUBE_LOD(tex, R, mip); + + return DecodeHDR(rgbm, hdr); +} +#endif // UNITY_IMAGE_BASED_LIGHTING_INCLUDED \ No newline at end of file diff --git a/Assets/Filamented/UnityImageBasedLightingMinimal.cginc.meta b/Assets/Filamented/UnityImageBasedLightingMinimal.cginc.meta new file mode 100644 index 0000000..b3eaab2 --- /dev/null +++ b/Assets/Filamented/UnityImageBasedLightingMinimal.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 3f43f0fa2318dbc4bb77ee6a480bc42a +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityLeftovers.cginc b/Assets/Filamented/UnityLeftovers.cginc new file mode 100644 index 0000000..c211282 --- /dev/null +++ b/Assets/Filamented/UnityLeftovers.cginc @@ -0,0 +1,164 @@ + +#ifndef UNITY_LEFTOVER_INCLUDED +#define UNITY_LEFTOVER_INCLUDED + +//------------------------------------------------------------------------------------- + +inline half Pow4 (half x) +{ + return x*x*x*x; +} + +inline float2 Pow4 (float2 x) +{ + return x*x*x*x; +} + +inline half3 Pow4 (half3 x) +{ + return x*x*x*x; +} + +inline half4 Pow4 (half4 x) +{ + return x*x*x*x; +} + +// Pow5 uses the same amount of instructions as generic pow(), but has 2 advantages: +// 1) better instruction pipelining +// 2) no need to worry about NaNs +inline half Pow5 (half x) +{ + return x*x * x*x * x; +} + +inline half2 Pow5 (half2 x) +{ + return x*x * x*x * x; +} + +inline half3 Pow5 (half3 x) +{ + return x*x * x*x * x; +} + +inline half4 Pow5 (half4 x) +{ + return x*x * x*x * x; +} + +inline half3 FresnelTerm (half3 F0, half cosA) +{ + half t = Pow5 (1 - cosA); // ala Schlick interpoliation + return F0 + (1-F0) * t; +} +inline half3 FresnelLerp (half3 F0, half3 F90, half cosA) +{ + half t = Pow5 (1 - cosA); // ala Schlick interpoliation + return lerp (F0, F90, t); +} +// approximage Schlick with ^4 instead of ^5 +inline half3 FresnelLerpFast (half3 F0, half3 F90, half cosA) +{ + half t = Pow4 (1 - cosA); + return lerp (F0, F90, t); +} + +// Note: Disney diffuse must be multiply by diffuseAlbedo / PI. This is done outside of this function. +half DisneyDiffuse(half NdotV, half NdotL, half LdotH, half perceptualRoughness) +{ + half fd90 = 0.5 + 2 * LdotH * LdotH * perceptualRoughness; + // Two schlick fresnel term + half lightScatter = (1 + (fd90 - 1) * Pow5(1 - NdotL)); + half viewScatter = (1 + (fd90 - 1) * Pow5(1 - NdotV)); + + return lightScatter * viewScatter; +} + +// NOTE: Visibility term here is the full form from Torrance-Sparrow model, it includes Geometric term: V = G / (N.L * N.V) +// This way it is easier to swap Geometric terms and more room for optimizations (except maybe in case of CookTorrance geom term) + +// Generic Smith-Schlick visibility term +inline half SmithVisibilityTerm (half NdotL, half NdotV, half k) +{ + half gL = NdotL * (1-k) + k; + half gV = NdotV * (1-k) + k; + return 1.0 / (gL * gV + 1e-5f); // This function is not intended to be running on Mobile, + // therefore epsilon is smaller than can be represented by half +} + +// Smith-Schlick derived for Beckmann +inline half SmithBeckmannVisibilityTerm (half NdotL, half NdotV, half roughness) +{ + half c = 0.797884560802865h; // c = sqrt(2 / Pi) + half k = roughness * c; + return SmithVisibilityTerm (NdotL, NdotV, k) * 0.25f; // * 0.25 is the 1/4 of the visibility term +} + +// Ref: http://jcgt.org/published/0003/02/03/paper.pdf +inline float SmithJointGGXVisibilityTerm (float NdotL, float NdotV, float roughness) +{ +#if 0 + // Original formulation: + // lambda_v = (-1 + sqrt(a2 * (1 - NdotL2) / NdotL2 + 1)) * 0.5f; + // lambda_l = (-1 + sqrt(a2 * (1 - NdotV2) / NdotV2 + 1)) * 0.5f; + // G = 1 / (1 + lambda_v + lambda_l); + + // Reorder code to be more optimal + half a = roughness; + half a2 = a * a; + + half lambdaV = NdotL * sqrt((-NdotV * a2 + NdotV) * NdotV + a2); + half lambdaL = NdotV * sqrt((-NdotL * a2 + NdotL) * NdotL + a2); + + // Simplify visibility term: (2.0f * NdotL * NdotV) / ((4.0f * NdotL * NdotV) * (lambda_v + lambda_l + 1e-5f)); + return 0.5f / (lambdaV + lambdaL + 1e-5f); // This function is not intended to be running on Mobile, + // therefore epsilon is smaller than can be represented by half +#else + // Approximation of the above formulation (simplify the sqrt, not mathematically correct but close enough) + float a = roughness; + float lambdaV = NdotL * (NdotV * (1 - a) + a); + float lambdaL = NdotV * (NdotL * (1 - a) + a); + +#if defined(SHADER_API_SWITCH) + return 0.5f / (lambdaV + lambdaL + 1e-4f); // work-around against hlslcc rounding error +#else + return 0.5f / (lambdaV + lambdaL + 1e-5f); +#endif + +#endif +} + +inline float GGXTerm (float NdotH, float roughness) +{ + float a2 = roughness * roughness; + float d = (NdotH * a2 - NdotH) * NdotH + 1.0f; // 2 mad + return UNITY_INV_PI * a2 / (d * d + 1e-7f); // This function is not intended to be running on Mobile, + // therefore epsilon is smaller than what can be represented by half +} + +inline half PerceptualRoughnessToSpecPower (half perceptualRoughness) +{ + half m = PerceptualRoughnessToRoughness(perceptualRoughness); // m is the true academic roughness. + half sq = max(1e-4f, m*m); + half n = (2.0 / sq) - 2.0; // https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf + n = max(n, 1e-4f); // prevent possible cases of pow(0,0), which could happen when roughness is 1.0 and NdotH is zero + return n; +} + +// BlinnPhong normalized as normal distribution function (NDF) +// for use in micro-facet model: spec=D*G*F +// eq. 19 in https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf +inline half NDFBlinnPhongNormalizedTerm (half NdotH, half n) +{ + // norm = (n+2)/(2*pi) + half normTerm = (n + 2.0) * (0.5/UNITY_PI); + + half specTerm = pow (NdotH, n); + return specTerm * normTerm; +} + +//------------------------------------------------------------------------------------- + + +#endif // UNITY_LEFTOVER_INCLUDED \ No newline at end of file diff --git a/Assets/Filamented/UnityLeftovers.cginc.meta b/Assets/Filamented/UnityLeftovers.cginc.meta new file mode 100644 index 0000000..5407903 --- /dev/null +++ b/Assets/Filamented/UnityLeftovers.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: bf6599aa7f0fc1541ba5f01441e20a46 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityLightingCommon.cginc b/Assets/Filamented/UnityLightingCommon.cginc new file mode 100644 index 0000000..5268a7c --- /dev/null +++ b/Assets/Filamented/UnityLightingCommon.cginc @@ -0,0 +1,53 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_LIGHTING_COMMON_INCLUDED +#define UNITY_LIGHTING_COMMON_INCLUDED + +fixed4 _LightColor0; +fixed4 _SpecColor; + +struct UnityLight +{ + half3 color; + half3 dir; + half ndotl; // Deprecated: Ndotl is now calculated on the fly and is no longer stored. Do not used it. +}; + +struct UnityIndirect +{ + half3 diffuse; + half3 specular; +}; + +struct UnityGI +{ + UnityLight light; + UnityIndirect indirect; +}; + +struct UnityGIInput +{ + UnityLight light; // pixel light, sent from the engine + + float3 worldPos; + half3 worldViewDir; + half atten; + half3 ambient; + + // interpolated lightmap UVs are passed as full float precision data to fragment shaders + // so lightmapUV (which is used as a tmp inside of lightmap fragment shaders) should + // also be full float precision to avoid data loss before sampling a texture. + float4 lightmapUV; // .xy = static lightmap UV, .zw = dynamic lightmap UV + + #if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) || defined(UNITY_ENABLE_REFLECTION_BUFFERS) + float4 boxMin[2]; + #endif + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + float4 boxMax[2]; + float4 probePosition[2]; + #endif + // HDR cubemap properties, use to decompress HDR texture + float4 probeHDR[2]; +}; + +#endif \ No newline at end of file diff --git a/Assets/Filamented/UnityLightingCommon.cginc.meta b/Assets/Filamented/UnityLightingCommon.cginc.meta new file mode 100644 index 0000000..945ff95 --- /dev/null +++ b/Assets/Filamented/UnityLightingCommon.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 7bb28a683afed86479840c9c04e34118 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityStandardConfig.cginc b/Assets/Filamented/UnityStandardConfig.cginc new file mode 100644 index 0000000..5a3d279 --- /dev/null +++ b/Assets/Filamented/UnityStandardConfig.cginc @@ -0,0 +1,302 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_STANDARD_CONFIG_INCLUDED +#define UNITY_STANDARD_CONFIG_INCLUDED + +// Filamented configuration + +#define FILAMENT_QUALITY_LOW 0 +#define FILAMENT_QUALITY_NORMAL 1 +#define FILAMENT_QUALITY_HIGH 2 + +// Sets a different quality level for mobile and other platforms. +#if !(defined(SHADER_API_MOBILE)) +#define FILAMENT_QUALITY FILAMENT_QUALITY_HIGH +#else +#define FILAMENT_QUALITY FILAMENT_QUALITY_LOW +#define TARGET_MOBILE +#endif + +// On mobile, 'half' data types are half-precision, but other platforms upgrade them +// to full-precision. Setting this will enable half-precision on other platforms, as well. +// Using half-precision will boost performance, but some visual artifacts may appear. +// #define FILAMENTED_USE_HALF_FLOAT + +#if !defined(SPECULAR_AMBIENT_OCCLUSION) +#define SPECULAR_AMBIENT_OCCLUSION SPECULAR_AO_BENT_NORMALS +#endif + +#define MULTI_BOUNCE_AMBIENT_OCCLUSION 1 + +// Whether to use specular AA by default +// in shaders that don't specify USE_GEOMETRIC_SPECULAR_AA. +#if !defined(USE_GEOMETRIC_SPECULAR_AA) +#define USE_GEOMETRIC_SPECULAR_AA_DEFAULT +#endif + +// Whether to use Unity's "Standard Input" texture defines, which are needed +// for Standard-like operation but can conflict with templates. +#if !defined(SKIP_UNITY_STANDARD_INPUT_DEFINES) +#define USE_UNITY_STANDARD_INPUT_DEFINES +#endif + +// Whether to sample all bands of SH in the fragment shader. +// Otherwise, L2 SH for light probes is sampled in the vertex shader. +// When this is disabled, L2 SH will be calculated in the vertex shader and +// added to the final light probe result. For base Unity, this is a good optimization. +// However, Filamented adds newer techniques for sampling Unity's L1 SH which +// produce a higher quality result, and adding the L2 contribution over them +// causes artifacts. In this case, it makes more sense to disable this optimization +// and skip reading the L2 SH entirely. +// You can adjust the technique used to sample the light probes in FilamentLightIndirect.cginc. +#ifndef UNITY_SAMPLE_FULL_SH_PER_PIXEL +#define UNITY_SAMPLE_FULL_SH_PER_PIXEL 1 +#endif + +// Whether to read the _DFG texture for DFG instead of the approximate one. +// The shader must have a _DFG texture property, so don't enable this here. +// For example, you can use this ShaderLab semantic to specify a DFG texture. +// [NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {} +// Then, set the default texture on the .shader in Unity +// and it will propagate to all materials. +// #define USE_DFG_LUT + +// When this flag is enabled, the half data types are set to use flexible precision. +#if defined(FILAMENTED_USE_HALF_FLOAT) && (defined(UNITY_COMPILER_HLSL) || defined(UNITY_COMPILER_DXC)) +#define half min16float +#define half2 min16float2 +#define half3 min16float3 +#define half4 min16float4 +#define half2x2 min16float2x2 +#define half3x3 min16float3x3 +#define half4x4 min16float4x4 +#define half2x3 min16float2x3 +#define half2x4 min16float2x4 +#define half3x2 min16float3x2 +#define half3x4 min16float3x4 +#define half4x2 min16float4x2 +#define half4x3 min16float4x3 +#define TARGET_MOBILE // Require fp16 optimizations +#endif + +// Filament cross-compatibility defines + +#if (DIRECTIONAL || DIRECTIONAL_COOKIE) +#define HAS_DIRECTIONAL_LIGHTING +#endif +#if (POINT || SPOT || POINT_COOKIE) +#define HAS_DYNAMIC_LIGHTING +#endif +#if (SHADOWS_SCREEN || SHADOWS_SHADOWMASK || LIGHTMAP_SHADOW || DIRECTIONAL_COOKIE) +#define HAS_SHADOWING +#endif + +#if _EMISSION +#define MATERIAL_HAS_EMISSIVE +#endif +#if defined(MATERIAL_HAS_NORMAL) +#define _NORMALMAP 1 +#endif +#if _NORMALMAP +#define MATERIAL_HAS_NORMAL +#endif + +#if (MATERIAL_NEEDS_TBN) +#define _TANGENT_TO_WORLD +#endif + +#if _ALPHAPREMULTIPLY_ON +#define BLEND_MODE_TRANSPARENT +#endif +#if _ALPHABLEND_ON +#define BLEND_MODE_FADE +// Workaround a bug where the blending premultiply step causes AO to apply +// strange lighting. +#undef MULTI_BOUNCE_AMBIENT_OCCLUSION +#endif +#if _ALPHATEST_ON +#define BLEND_MODE_MASKED +#endif + +#ifndef NEEDS_ALPHA_CHANNEL +#define NEEDS_ALPHA_CHANNEL 0 +#endif + +// By default, Standard assumes meshes have normals +#define HAS_ATTRIBUTE_TANGENTS + +// Standard includes many defines for excluding specific types of texture maps, +// but _OcclusionMap is not one of them. However, this is defined in the individual +// shader files to make it clearer. +//#define MATERIAL_HAS_AMBIENT_OCCLUSION + +// If USE_GEOMETRIC_SPECULAR_AA is set, don't use the default values +#if defined(USE_GEOMETRIC_SPECULAR_AA) +#define GEOMETRIC_SPECULAR_AA +#else +#if defined(USE_GEOMETRIC_SPECULAR_AA_DEFAULT) +#define GEOMETRIC_SPECULAR_AA +#define _specularAntiAliasingVariance 0.15 +#define _specularAntiAliasingThreshold 0.25 +#endif +#endif + +#if defined(_LIGHTMAPSPECULAR) +#define LIGHTMAP_SPECULAR +#endif + +#if defined(_NORMALMAP_SHADOW) && defined(MATERIAL_HAS_NORMAL) && defined(HAS_SHADOWING) +#define NORMALMAP_SHADOW +#endif + +#if defined(USE_DFG_LUT) +UNITY_DECLARE_TEX2D_FLOAT(_DFG); +#endif + +// Todo: Bakery seems to recommend disabling RNM when normal maps are not active. +#if defined(MATERIAL_HAS_NORMAL) +#if defined(_BAKERY_RNM) || defined(_BAKERY_SH) +// Set when Bakery-specific lightmap textures need to be read. +#define USING_BAKERY +UNITY_DECLARE_TEX2D_HALF(_RNM0); +UNITY_DECLARE_TEX2D_HALF(_RNM1); +UNITY_DECLARE_TEX2D_HALF(_RNM2); +#endif +#endif + +// For MonoSH, the extra textures aren't used. +#if defined(_BAKERY_MONOSH) +#endif + +// For vertex lightmaps, +#if defined(_BAKERY_VERTEXLM) + #define USING_BAKERY_VERTEXLM + + // Colour is reserved by vertex LM. + #ifdef HAS_ATTRIBUTE_COLOR + #undef HAS_ATTRIBUTE_COLOR + #endif + + // Required to know whether vertex mode is being used. + float bakeryLightmapMode; + + // Set if vertex lightmaps can contain shadowmask. + #if defined(SHADOWS_SHADOWMASK) + #define USING_BAKERY_VERTEXLMMASK + #endif + + // Set if vertex lightmaps can contain directionality. + #if defined(DIRLIGHTMAP_COMBINED) + #define USING_BAKERY_VERTEXLMDIR + #endif + + // ...And if they use SH. + #if defined(_BAKERY_SH) + #define USING_BAKERY_VERTEXLMSH + // UV3 is reserved by vertex LM SH. + #ifdef HAS_ATTRIBUTE_UV3 + #undef HAS_ATTRIBUTE_UV3 + #endif + #endif +#endif + +// Refraction source texture +#if REFRACTION_MODE == REFRACTION_MODE_SCREEN + #ifndef REFRACTION_SOURCE + #define REFRACTION_SOURCE _GrabPass + #define REFRACTION_MULTIPLIER 1.0 + #endif +UNITY_DECLARE_TEX2D_FLOAT(REFRACTION_SOURCE); +#endif + +// Define Specular cubemap constants +#ifndef UNITY_SPECCUBE_LOD_EXPONENT +#define UNITY_SPECCUBE_LOD_EXPONENT (1.5) +#endif +#ifndef UNITY_SPECCUBE_LOD_STEPS +#define UNITY_SPECCUBE_LOD_STEPS (6) +#endif + +// Energy conservation for Specular workflow is Monochrome. For instance: Red metal will make diffuse Black not Cyan +#ifndef UNITY_CONSERVE_ENERGY +#define UNITY_CONSERVE_ENERGY 1 +#endif +#ifndef UNITY_CONSERVE_ENERGY_MONOCHROME +#define UNITY_CONSERVE_ENERGY_MONOCHROME 1 +#endif + +// "platform caps" defines: they are controlled from TierSettings (Editor will determine values and pass them to compiler) +// UNITY_SPECCUBE_BOX_PROJECTION: TierSettings.reflectionProbeBoxProjection +// UNITY_SPECCUBE_BLENDING: TierSettings.reflectionProbeBlending +// UNITY_ENABLE_DETAIL_NORMALMAP: TierSettings.detailNormalMap +// UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS: TierSettings.semitransparentShadows + +// disregarding what is set in TierSettings, some features have hardware restrictions +// so we still add safety net, otherwise we might end up with shaders failing to compile + +#if defined(SHADER_TARGET_SURFACE_ANALYSIS) + // For surface shader code analysis pass, disable some features that don't affect inputs/outputs + #undef UNITY_SPECCUBE_BOX_PROJECTION + #undef UNITY_SPECCUBE_BLENDING + #undef UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS +#elif SHADER_TARGET < 30 + #undef UNITY_SPECCUBE_BOX_PROJECTION + #undef UNITY_SPECCUBE_BLENDING + #undef UNITY_ENABLE_DETAIL_NORMALMAP + #ifdef _PARALLAXMAP + #undef _PARALLAXMAP + #endif +#endif +#if (SHADER_TARGET < 30) || defined(SHADER_API_GLES) + #undef UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS +#endif + +#ifndef UNITY_SAMPLE_FULL_SH_PER_PIXEL + // Lightmap UVs and ambient color from SHL2 are shared in the vertex to pixel interpolators. Do full SH evaluation in the pixel shader when static lightmap and LIGHTPROBE_SH is enabled. + #define UNITY_SAMPLE_FULL_SH_PER_PIXEL (LIGHTMAP_ON && LIGHTPROBE_SH) + + // Shaders might fail to compile due to shader instruction count limit. Leave only baked lightmaps on SM20 hardware. + #if UNITY_SAMPLE_FULL_SH_PER_PIXEL && (SHADER_TARGET < 25) + #undef UNITY_SAMPLE_FULL_SH_PER_PIXEL + #undef LIGHTPROBE_SH + #endif +#endif + +#ifndef UNITY_BRDF_GGX +#define UNITY_BRDF_GGX 1 +#endif + +// Orthnormalize Tangent Space basis per-pixel +// Necessary to support high-quality normal-maps. Compatible with Maya and Marmoset. +// However xNormal expects oldschool non-orthnormalized basis - essentially preventing good looking normal-maps :( +// Due to the fact that xNormal is probably _the most used tool to bake out normal-maps today_ we have to stick to old ways for now. +// +// Disabled by default, until xNormal has an option to bake proper normal-maps. +#ifndef UNITY_TANGENT_ORTHONORMALIZE +#define UNITY_TANGENT_ORTHONORMALIZE 1 +#endif + + +// Some extra optimizations + +// Simplified Standard Shader is off by default and should not be used for Legacy Shaders +#ifndef UNITY_STANDARD_SIMPLE + #define UNITY_STANDARD_SIMPLE 0 +#endif + +// Setup a new define with meaningful name to know if we require world pos in fragment shader +#if UNITY_STANDARD_SIMPLE + #define UNITY_REQUIRE_FRAG_WORLDPOS 0 +#else + #define UNITY_REQUIRE_FRAG_WORLDPOS 1 +#endif + +// Should we pack worldPos along tangent (saving an interpolator) +// We want to skip this on mobile platforms, because worldpos gets packed into mediump +#if UNITY_REQUIRE_FRAG_WORLDPOS && !defined(_PARALLAXMAP) && !defined(SHADER_API_MOBILE) + #define UNITY_PACK_WORLDPOS_WITH_TANGENT 1 +#else + #define UNITY_PACK_WORLDPOS_WITH_TANGENT 0 +#endif + +#endif // UNITY_STANDARD_CONFIG_INCLUDED diff --git a/Assets/Filamented/UnityStandardConfig.cginc.meta b/Assets/Filamented/UnityStandardConfig.cginc.meta new file mode 100644 index 0000000..9f6fd47 --- /dev/null +++ b/Assets/Filamented/UnityStandardConfig.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5035d8f031d926640b7729712fd7b546 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityStandardCore.cginc b/Assets/Filamented/UnityStandardCore.cginc new file mode 100644 index 0000000..f9bca47 --- /dev/null +++ b/Assets/Filamented/UnityStandardCore.cginc @@ -0,0 +1,715 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_STANDARD_CORE_INCLUDED +#define UNITY_STANDARD_CORE_INCLUDED + +#include "UnityCG.cginc" +#include "UnityShaderVariables.cginc" +#include "UnityLightingCommon.cginc" + +// Workaround for some failsafes +#define UNITY_BRDF_PBS + +#include "FilamentMaterialInputs.cginc" +#include "FilamentCommonMath.cginc" +#include "FilamentCommonLighting.cginc" +#include "FilamentCommonMaterial.cginc" +#include "FilamentCommonShading.cginc" +#include "FilamentShadingParameters.cginc" + +#include "UnityStandardConfig.cginc" +#include "UnityStandardInput.cginc" +//#include "UnityPBSLighting.cginc" +#include "UnityStandardUtils.cginc" +#include "UnityImageBasedLightingMinimal.cginc" +#include "UnityGBuffer.cginc" +#include "UnityGlobalIllumination.cginc" + +#include "FilamentShadingLit.cginc" + +#include "SharedFilteringLib.hlsl" +// Note: AutoLight.cginc is included below. +//------------------------------------------------------------------------------------- +// counterpart for NormalizePerPixelNormal +// skips normalization per-vertex and expects normalization to happen per-pixel +half3 NormalizePerVertexNormal (float3 n) // takes float to avoid overflow +{ + #if (SHADER_TARGET < 30) || UNITY_STANDARD_SIMPLE + return normalize(n); + #else + return n; // will normalize per-pixel instead + #endif +} + +float3 NormalizePerPixelNormal (float3 n) +{ + #if (SHADER_TARGET < 30) || UNITY_STANDARD_SIMPLE + return n; + #else + return normalize((float3)n); // takes float to avoid overflow + #endif +} + +//------------------------------------------------------------------------------------- + +fixed4 SampleShadowMaskBicubic(float2 uv) +{ + #if defined(SHADER_API_D3D11) + float width, height; + unity_ShadowMask.GetDimensions(width, height); + + float4 unity_ShadowMask_TexelSize = float4(width, height, 1.0/width, 1.0/height); + + return SampleTexture2DBicubicFilter(TEXTURE2D_ARGS(unity_ShadowMask, samplerunity_ShadowMask), + uv, unity_ShadowMask_TexelSize); + #else + return SAMPLE_TEXTURE2D(unity_ShadowMask, samplerunity_ShadowMask, uv); + #endif +} +fixed UnitySampleBakedOcclusionBicubic (float2 lightmapUV, float3 worldPos) +{ + #if defined (SHADOWS_SHADOWMASK) + #if defined(LIGHTMAP_ON) + fixed4 rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); + #else + fixed4 rawOcclusionMask = fixed4(1.0, 1.0, 1.0, 1.0); + #if UNITY_LIGHT_PROBE_PROXY_VOLUME + if (unity_ProbeVolumeParams.x == 1.0) + rawOcclusionMask = LPPV_SampleProbeOcclusion(worldPos); + else + rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); + #else + rawOcclusionMask = SampleShadowMaskBicubic(lightmapUV.xy); + #endif + #endif + return saturate(dot(rawOcclusionMask, unity_OcclusionMaskSelector)); + + #else + + //In forward dynamic objects can only get baked occlusion from LPPV, light probe occlusion is done on the CPU by attenuating the light color. + fixed atten = 1.0f; + #if defined(UNITY_INSTANCING_ENABLED) && defined(UNITY_USE_SHCOEFFS_ARRAYS) + // ...unless we are doing instancing, and the attenuation is packed into SHC array's .w component. + atten = unity_SHC.w; + #endif + + #if UNITY_LIGHT_PROBE_PROXY_VOLUME && !defined(LIGHTMAP_ON) && !UNITY_STANDARD_SIMPLE + fixed4 rawOcclusionMask = atten.xxxx; + if (unity_ProbeVolumeParams.x == 1.0) + rawOcclusionMask = LPPV_SampleProbeOcclusion(worldPos); + return saturate(dot(rawOcclusionMask, unity_OcclusionMaskSelector)); + #endif + + return atten; + #endif +} + +void GetBakedAttenuation(inout float atten, float2 lightmapUV, float3 worldPos) +{ + // Base pass with Lightmap support is responsible for handling ShadowMask / blending here for performance reason + #if defined(HANDLE_SHADOWS_BLENDING_IN_GI) + half bakedAtten = UnitySampleBakedOcclusionBicubic(lightmapUV.xy, worldPos); + float zDist = dot(_WorldSpaceCameraPos - worldPos, UNITY_MATRIX_V[2].xyz); + float fadeDist = UnityComputeShadowFadeDistance(worldPos, zDist); + atten = UnityMixRealtimeAndBakedShadows(atten, bakedAtten, UnityComputeShadowFade(fadeDist)); + #endif +} + + +#define UnitySampleBakedOcclusion UnitySampleBakedOcclusionBicubic +#include "AutoLight.cginc" +//------------------------------------------------------------------------------------- +// Common fragment setup + +#ifdef _PARALLAXMAP + #define IN_VIEWDIR4PARALLAX(i) NormalizePerPixelNormal(half3(i.tangentToWorldAndPackedData[0].w,i.tangentToWorldAndPackedData[1].w,i.tangentToWorldAndPackedData[2].w)) + #define IN_VIEWDIR4PARALLAX_FWDADD(i) NormalizePerPixelNormal(i.viewDirForParallax.xyz) +#else + #define IN_VIEWDIR4PARALLAX(i) half3(0,0,0) + #define IN_VIEWDIR4PARALLAX_FWDADD(i) half3(0,0,0) +#endif + +#if UNITY_REQUIRE_FRAG_WORLDPOS + #if UNITY_PACK_WORLDPOS_WITH_TANGENT + #define IN_WORLDPOS(i) half3(i.tangentToWorldAndPackedData[0].w,i.tangentToWorldAndPackedData[1].w,i.tangentToWorldAndPackedData[2].w) + #else + #define IN_WORLDPOS(i) i.posWorld + #endif + #define IN_WORLDPOS_FWDADD(i) i.posWorld +#else + #define IN_WORLDPOS(i) half3(0,0,0) + #define IN_WORLDPOS_FWDADD(i) half3(0,0,0) +#endif + +#define IN_LIGHTDIR_FWDADD(i) half3(i.tangentToWorldAndLightDir[0].w, i.tangentToWorldAndLightDir[1].w, i.tangentToWorldAndLightDir[2].w) + +#define MATERIAL_SETUP(x) MaterialInputs x = \ + MaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndPackedData, IN_WORLDPOS(i)); + +#define MATERIAL_SETUP_FWDADD(x) MaterialInputs x = \ + MaterialSetup(i.tex, i.eyeVec.xyz, IN_VIEWDIR4PARALLAX_FWDADD(i), i.tangentToWorldAndLightDir, IN_WORLDPOS_FWDADD(i)); + +#if !defined(SKIP_UNITY_STANDARD_INPUT_DEFINES) +#if defined(SHADING_MODEL_CLOTH) + #define SETUP_BRDF_INPUT ClothMaterialSetup +inline MaterialInputs ClothMaterialSetup (float4 i_tex) +{ + half4 baseColor = half4(Albedo(i_tex), Alpha(i_tex)); + half4 specGloss = SheenColorGlossCloth(i_tex.xy); + half3 specColor = specGloss.rgb; + half smoothness = specGloss.a; + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + #if defined(MATERIAL_HAS_SHEEN_COLOR) + material.sheenColor = specColor; + #endif + #if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + material.glossiness = smoothness; + #else + material.roughness = computeRoughnessFromGlossiness(smoothness); + #endif + return material; +} +#else + +// Filament's preferred model, but not Unity's default +#if defined(SHADING_MODEL_METALLIC_ROUGHNESS) + #define SETUP_BRDF_INPUT RoughnessMaterialSetup +inline MaterialInputs RoughnessMaterialSetup (float4 i_tex) +{ + half4 baseColor = half4(Albedo(i_tex), Alpha(i_tex)); + half2 metallicGloss = MetallicRough(i_tex.xy); + half metallic = metallicGloss.x; + half smoothness = metallicGloss.y; // this is 1 minus the square root of real roughness m. + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + return material; +} +#else + +#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS) + #define SETUP_BRDF_INPUT SpecularMaterialSetup +inline MaterialInputs SpecularMaterialSetup (float4 i_tex) +{ + half4 baseColor = half4(Albedo(i_tex), Alpha(i_tex)); + half4 specGloss = SpecularGloss(i_tex.xy); + half3 specColor = specGloss.rgb; + half smoothness = specGloss.a; + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.specularColor = specColor; + material.glossiness = smoothness; + return material; +} +#endif + +#if (!defined(SHADING_MODEL_SPECULAR_GLOSSINESS)) + #define SETUP_BRDF_INPUT MetallicMaterialSetup +inline MaterialInputs MetallicMaterialSetup (float4 i_tex) +{ + half4 baseColor = half4(Albedo(i_tex), Alpha(i_tex)); + half2 metallicGloss = MetallicGloss(i_tex.xy); + half metallic = metallicGloss.x; + half smoothness = metallicGloss.y; // this is 1 minus the square root of real roughness m. + + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + material.baseColor = baseColor; + material.metallic = metallic; + material.roughness = computeRoughnessFromGlossiness(smoothness); + return material; +} +#endif +#endif +#endif +#endif + +#ifndef SETUP_BRDF_INPUT + #define SETUP_BRDF_INPUT NoneMaterialSetup +#endif + +inline MaterialInputs NoneMaterialSetup (float4 i_tex) +{ + MaterialInputs material = (MaterialInputs)0; + initMaterial(material); + return material; +} + +// parallax transformed texcoord is used to sample occlusion +inline MaterialInputs MaterialSetup (inout float4 i_tex, float3 i_eyeVec, half3 i_viewDirForParallax, float4 tangentToWorld[3], float3 i_posWorld) +{ +#if defined(SKIP_UNITY_STANDARD_INPUT_DEFINES) + MaterialInputs material = SETUP_BRDF_INPUT (i_tex); + return material; +#else + float3 viewDirWS = -normalize(i_posWorld - _WorldSpaceCameraPos); + float3 normalWS = normalize(tangentToWorld[2]); // normalize to avoid weird values + float parallaxLod = dot(normalWS, viewDirWS); + +#if !defined(PARALLAX_CUSTOM_INPUT) + i_tex = Parallax(i_tex, i_viewDirForParallax, parallaxLod); +#endif + + MaterialInputs material = SETUP_BRDF_INPUT (i_tex); + + // Added tangent output + #if _NORMALMAP + material.normal = NormalInTangentSpace(i_tex); + #endif + #if _EMISSION + material.emissive.rgb = Emission (i_tex); + material.emissive.a = 1.0; + #endif + material.ambientOcclusion = Occlusion(i_tex); + return material; +#endif +} + + +//------------------------------------------------------------------------------------- +inline half4 VertexGIForward(VertexInput v, float3 posWorld, half3 normalWorld) +{ + half4 ambientOrLightmapUV = 0; + // Static lightmaps + #ifdef LIGHTMAP_ON + ambientOrLightmapUV.xy = v.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + ambientOrLightmapUV.zw = 0; + // Sample light probe for Dynamic objects only (no static or dynamic lightmaps) + #elif UNITY_SHOULD_SAMPLE_SH + #ifdef VERTEXLIGHT_ON + // Approximated illumination from non-important point lights + ambientOrLightmapUV.rgb = Shade4PointLights ( + unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, + unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb, + unity_4LightAtten0, posWorld, normalWorld); + #endif + + ambientOrLightmapUV.rgb = ShadeSHPerVertex (normalWorld, ambientOrLightmapUV.rgb); + #endif + + #ifdef DYNAMICLIGHTMAP_ON + ambientOrLightmapUV.zw = v.uv2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + + #if defined(USING_BAKERY_VERTEXLMMASK) + if (getIsBakeryVertexMode()) + { + ambientOrLightmapUV = unpack4NFloats(v.uv1.x); + } + #endif + + return ambientOrLightmapUV; +} + +// ------------------------------------------------------------------ +// Base forward pass (directional light, emission, lightmaps, ...) + +struct VertexOutputForwardBase +{ + UNITY_POSITION(pos); + float4 tex : TEXCOORD0; + float4 eyeVec : TEXCOORD1; // eyeVec.xyz | fogCoord + float4 tangentToWorldAndPackedData[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax or worldPos] + half4 ambientOrLightmapUV : TEXCOORD5_centroid; // SH or Lightmap UV + UNITY_LIGHTING_COORDS(6,7) + + // next ones would not fit into SM2.0 limits, but they are always for SM3.0+ +#if UNITY_REQUIRE_FRAG_WORLDPOS && !UNITY_PACK_WORLDPOS_WITH_TANGENT + float3 posWorld : TEXCOORD8; +#endif + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float3 lightDirTS : TEXCOORD9; +#endif + +#if defined(_BAKERY_VERTEXLM) + float4 color : COLOR_centroid; + #if defined(USING_BAKERY_VERTEXLMDIR) + float3 lightDirection : TEXCOORD10_centroid; + #elif defined(_BAKERY_SH) + float3 shL1x : TEXCOORD10_centroid; + float3 shL1y : TEXCOORD11_centroid; + float3 shL1z : TEXCOORD12_centroid; + #endif +#else +#if defined(HAS_ATTRIBUTE_COLOR) + float4 color : COLOR_centroid; +#endif +#endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +VertexOutputForwardBase vertForwardBase (VertexInput v) +{ + UNITY_SETUP_INSTANCE_ID(v); + VertexOutputForwardBase o; + UNITY_INITIALIZE_OUTPUT(VertexOutputForwardBase, o); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + v.normal = normalize(v.normal.xyz); + #ifdef _TANGENT_TO_WORLD + v.tangent.xyz = normalize(v.tangent.xyz); + #endif + + float4 posWorld = mul(unity_ObjectToWorld, v.vertex); + #if UNITY_REQUIRE_FRAG_WORLDPOS + #if UNITY_PACK_WORLDPOS_WITH_TANGENT + o.tangentToWorldAndPackedData[0].w = posWorld.x; + o.tangentToWorldAndPackedData[1].w = posWorld.y; + o.tangentToWorldAndPackedData[2].w = posWorld.z; + #else + o.posWorld = posWorld.xyz; + #endif + #endif + o.pos = UnityObjectToClipPos(v.vertex); + + o.tex = TexCoords(v); + o.eyeVec.xyz = NormalizePerVertexNormal(posWorld.xyz - _WorldSpaceCameraPos); + float3 normalWorld = UnityObjectToWorldNormal(v.normal); + #ifdef _TANGENT_TO_WORLD + float4 tangentWorld = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + float3x3 tangentToWorld = CreateTangentToWorldPerVertex(normalWorld, tangentWorld.xyz, tangentWorld.w); + o.tangentToWorldAndPackedData[0].xyz = tangentToWorld[0]; + o.tangentToWorldAndPackedData[1].xyz = tangentToWorld[1]; + o.tangentToWorldAndPackedData[2].xyz = tangentToWorld[2]; + #else + o.tangentToWorldAndPackedData[0].xyz = 0; + o.tangentToWorldAndPackedData[1].xyz = 0; + o.tangentToWorldAndPackedData[2].xyz = normalWorld; + #endif + + //We need this for shadow receving + UNITY_TRANSFER_LIGHTING(o, v.uv1); + + o.ambientOrLightmapUV = VertexGIForward(v, posWorld, normalWorld); + + #ifdef _PARALLAXMAP + TANGENT_SPACE_ROTATION; + half3 viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex)); + + o.tangentToWorldAndPackedData[0].w = viewDirForParallax.x; + o.tangentToWorldAndPackedData[1].w = viewDirForParallax.y; + o.tangentToWorldAndPackedData[2].w = viewDirForParallax.z; + #endif + + #ifdef _TANGENT_TO_WORLD + #if defined(NORMALMAP_SHADOW) + float3 lightDirWS = normalize(_WorldSpaceLightPos0.xyz - posWorld.xyz * _WorldSpaceLightPos0.w); + o.lightDirTS = TransformToTangentSpace(tangentToWorld[0],tangentToWorld[1],tangentToWorld[2],lightDirWS); + #endif + #endif + + #if defined(HAS_ATTRIBUTE_COLOR) + o.color = v.color; + #endif + + #if defined(USING_BAKERY_VERTEXLM) + // Unpack from RGBM + o.color = v.color; + o.color.rgb *= o.color.a * 8.0f; + o.color.rgb *= o.color.rgb; + + #if defined(USING_BAKERY_VERTEXLMDIR) + o.lightDirection = unpack3NFloats(v.uv1.y) * 2 - 1; + #elif defined(USING_BAKERY_VERTEXLMSH) + o.shL1x = unpack3NFloats(v.uv1.y) * 2 - 1; + o.shL1y = unpack3NFloats(v.uv3.x) * 2 - 1; + o.shL1z = unpack3NFloats(v.uv3.y) * 2 - 1; + #endif + + #endif + + UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o,o.pos); + return o; +} + +void computeShadingParamsForwardBase(inout ShadingParams shading, VertexOutputForwardBase i, bool gl_FrontFacing = true) +{ + float3x3 tangentToWorld; + tangentToWorld[0] = i.tangentToWorldAndPackedData[0].xyz; + tangentToWorld[1] = i.tangentToWorldAndPackedData[1].xyz; + tangentToWorld[2] = i.tangentToWorldAndPackedData[2].xyz; + + if (getIsDoubleSided()) { + tangentToWorld[0] *= gl_FrontFacing ? 1 : -1; + tangentToWorld[1] *= gl_FrontFacing ? 1 : -1; + tangentToWorld[2] *= gl_FrontFacing ? 1 : -1; + } + + shading.geometricNormal = normalize(tangentToWorld[2].xyz); + shading.tangentToWorld = transpose(tangentToWorld); + + float2 viewportUV = i.pos.xy / _ScreenParams.xy; + + #if defined(UNITY_SINGLE_PASS_STEREO) + viewportUV.x = viewportUV.x * 2.0 - float(unity_StereoEyeIndex); + #endif + + shading.normalizedViewportCoord = viewportUV; + + shading.normal = shading.geometricNormal; + shading.position = IN_WORLDPOS(i); + shading.view = -NormalizePerPixelNormal(i.eyeVec); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position) + + #if (defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)) + GetBakedAttenuation(atten, i.ambientOrLightmapUV.xy, shading.position); + #endif + + shading.attenuation = atten; + + #if (defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)) + shading.ambient = 0; + shading.lightmapUV = i.ambientOrLightmapUV; + #else + shading.ambient = i.ambientOrLightmapUV.rgb; + shading.lightmapUV = 0; + #endif + +#if defined(USING_BAKERY_VERTEXLMMASK) + if (getIsBakeryVertexMode()) + { + shading.attenuation = saturate(dot(i.ambientOrLightmapUV, unity_OcclusionMaskSelector)); + } +#endif + +#if defined(USING_BAKERY_VERTEXLM) + shading.ambient = i.color; +#endif + +#if defined(USING_BAKERY_VERTEXLMSH) + shading.ambientSH[0] = i.shL1x; + shading.ambientSH[1] = i.shL1y; + shading.ambientSH[2] = i.shL1z; +#elif defined(USING_BAKERY_VERTEXLMDIR) + shading.ambientDir = i.lightDirection; +#endif +} + +half4 fragForwardBaseInternal (VertexOutputForwardBase i, bool gl_FrontFacing) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + float4 i_texBase = i.tex; + + MATERIAL_SETUP(material) + + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardBase(shading, i, gl_FrontFacing); + + prepareMaterial(shading, material); + +#if ((defined(_NORMALMAP) || defined(_PARALLAXMAP)) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + #if defined(_PARALLAXMAP) + PerPixelHeightDisplacementParam ppd = InitPerPixelHeightDisplacementParam(i.tex.xy); + float hShadow = GetParallaxSelfShadow(i.lightDirTS, i.tex.xy, ppd, noise); + shading.attenuation = min(shading.attenuation, hShadow); + #else + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); + #endif +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG(_unity_fogCoord, c.rgb); + return c; +} + +half4 fragForwardBase (VertexOutputForwardBase i, bool facing : SV_IsFrontFace) : SV_Target // backward compatibility (this used to be the fragment entry function) +{ + return fragForwardBaseInternal(i, facing); +} + +// ------------------------------------------------------------------ +// Additive forward pass (one light per pass) + +struct VertexOutputForwardAdd +{ + UNITY_POSITION(pos); + float4 tex : TEXCOORD0; + float4 eyeVec : TEXCOORD1; // eyeVec.xyz | fogCoord + float4 tangentToWorldAndLightDir[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:lightDir] + float3 posWorld : TEXCOORD5; + UNITY_LIGHTING_COORDS(6, 7) + + // next ones would not fit into SM2.0 limits, but they are always for SM3.0+ +#if defined(_PARALLAXMAP) + half3 viewDirForParallax : TEXCOORD8; +#endif + +#if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float3 lightDirTS : TEXCOORD9; +#endif + + // If Bakery LM mode is active, vertex colour is base lightmap. +#if defined(USING_BAKERY_VERTEXLMMASK) + fixed4 shadowMask : COLOR_centroid; +#else +#if defined(HAS_ATTRIBUTE_COLOR) + float4 color : COLOR_centroid; +#endif +#endif + + + UNITY_VERTEX_OUTPUT_STEREO +}; + +VertexOutputForwardAdd vertForwardAdd (VertexInput v) +{ + UNITY_SETUP_INSTANCE_ID(v); + VertexOutputForwardAdd o; + UNITY_INITIALIZE_OUTPUT(VertexOutputForwardAdd, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + float4 posWorld = mul(unity_ObjectToWorld, v.vertex); + o.pos = UnityObjectToClipPos(v.vertex); + + o.tex = TexCoords(v); + o.eyeVec.xyz = NormalizePerVertexNormal(posWorld.xyz - _WorldSpaceCameraPos); + o.posWorld = posWorld.xyz; + float3 normalWorld = UnityObjectToWorldNormal(v.normal); + #ifdef _TANGENT_TO_WORLD + float4 tangentWorld = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + float3x3 tangentToWorld = CreateTangentToWorldPerVertex(normalWorld, tangentWorld.xyz, tangentWorld.w); + o.tangentToWorldAndLightDir[0].xyz = tangentToWorld[0]; + o.tangentToWorldAndLightDir[1].xyz = tangentToWorld[1]; + o.tangentToWorldAndLightDir[2].xyz = tangentToWorld[2]; + #else + o.tangentToWorldAndLightDir[0].xyz = 0; + o.tangentToWorldAndLightDir[1].xyz = 0; + o.tangentToWorldAndLightDir[2].xyz = normalWorld; + #endif + //We need this for shadow receiving and lighting + UNITY_TRANSFER_LIGHTING(o, v.uv1); + + float3 lightDir = _WorldSpaceLightPos0.xyz - posWorld.xyz * _WorldSpaceLightPos0.w; + #ifndef USING_DIRECTIONAL_LIGHT + lightDir = NormalizePerVertexNormal(lightDir); + #endif + o.tangentToWorldAndLightDir[0].w = lightDir.x; + o.tangentToWorldAndLightDir[1].w = lightDir.y; + o.tangentToWorldAndLightDir[2].w = lightDir.z; + + #ifdef _PARALLAXMAP + TANGENT_SPACE_ROTATION; + o.viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex)); + #endif + + #ifdef _TANGENT_TO_WORLD + #if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + float3 lightDirWS = normalize(_WorldSpaceLightPos0.xyz - posWorld.xyz * _WorldSpaceLightPos0.w); + o.lightDirTS = TransformToTangentSpace(tangentToWorld[0],tangentToWorld[1],tangentToWorld[2],lightDirWS); + #endif + #endif + + #if defined(USING_BAKERY_VERTEXLMMASK) + o.shadowMask = unpack4NFloats(v.uv1.x); + #else + #if defined(HAS_ATTRIBUTE_COLOR) + o.color = v.color; + #endif + #endif + + UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o, o.pos); + return o; +} + +void computeShadingParamsForwardAdd(inout ShadingParams shading, VertexOutputForwardAdd i, bool gl_FrontFacing = true) +{ + float3x3 tangentToWorld; + tangentToWorld[0] = i.tangentToWorldAndLightDir[0].xyz; + tangentToWorld[1] = i.tangentToWorldAndLightDir[1].xyz; + tangentToWorld[2] = i.tangentToWorldAndLightDir[2].xyz; + + if (getIsDoubleSided()) { + tangentToWorld[0] *= gl_FrontFacing ? 1 : -1; + tangentToWorld[1] *= gl_FrontFacing ? 1 : -1; + tangentToWorld[2] *= gl_FrontFacing ? 1 : -1; + } + + shading.geometricNormal = normalize(tangentToWorld[2].xyz); + shading.tangentToWorld = transpose(tangentToWorld); + + float2 viewportUV = i.pos.xy / _ScreenParams.xy; + + #if defined(UNITY_SINGLE_PASS_STEREO) + viewportUV.x = viewportUV.x * 2.0 - float(unity_StereoEyeIndex); + #endif + + shading.normalizedViewportCoord = viewportUV; + + shading.normal = normalize(shading.geometricNormal); + shading.position = IN_WORLDPOS_FWDADD(i); + shading.view = -NormalizePerPixelNormal(i.eyeVec); + + UNITY_LIGHT_ATTENUATION(atten, i, shading.position) + shading.attenuation = atten; + +#if defined(USING_BAKERY_VERTEXLMMASK) + if (getIsBakeryVertexMode()) + { + shading.attenuation *= saturate(dot(i.shadowMask, unity_OcclusionMaskSelector)); + } +#endif +} + +half4 fragForwardAddInternal (VertexOutputForwardAdd i, bool gl_FrontFacing) +{ + UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy); + + MATERIAL_SETUP_FWDADD(material) + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + ShadingParams shading = (ShadingParams)0; + // Initialize shading with expected parameters + computeShadingParamsForwardAdd(shading, i, gl_FrontFacing); + + prepareMaterial(shading, material); + +#if ((defined(_NORMALMAP) || defined(_PARALLAXMAP)) && defined(NORMALMAP_SHADOW)) + float noise = noiseR2(i.pos.xy); + #if defined(_PARALLAXMAP) + PerPixelHeightDisplacementParam ppd = InitPerPixelHeightDisplacementParam(i.tex.xy); + float hShadow = GetParallaxSelfShadow(i.lightDirTS, i.tex.xy, ppd, noise); + shading.attenuation = min(shading.attenuation, hShadow); + #else + float nmShade = NormalTangentShadow (i.tex, i.lightDirTS, noise); + shading.attenuation = min(shading.attenuation, max(1-nmShade, 0)); + #endif +#endif + + float4 c = evaluateMaterial (shading, material); + + UNITY_EXTRACT_FOG_FROM_EYE_VEC(i); + UNITY_APPLY_FOG_COLOR(_unity_fogCoord, c.rgb, half4(0,0,0,0)); // fog towards black in additive pass + return c; +} + +half4 fragForwardAdd (VertexOutputForwardAdd i, bool facing : SV_IsFrontFace) : SV_Target // backward compatibility (this used to be the fragment entry function) +{ + return fragForwardAddInternal(i, facing); +} + +#endif // UNITY_STANDARD_CORE_INCLUDED diff --git a/Assets/Filamented/UnityStandardCore.cginc.meta b/Assets/Filamented/UnityStandardCore.cginc.meta new file mode 100644 index 0000000..31834ea --- /dev/null +++ b/Assets/Filamented/UnityStandardCore.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: a1dd140dcb1e25f499a372f1c7e3ffdd +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityStandardCoreForward.cginc b/Assets/Filamented/UnityStandardCoreForward.cginc new file mode 100644 index 0000000..50e609a --- /dev/null +++ b/Assets/Filamented/UnityStandardCoreForward.cginc @@ -0,0 +1,15 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_STANDARD_CORE_FORWARD_INCLUDED +#define UNITY_STANDARD_CORE_FORWARD_INCLUDED + +#include "UnityStandardConfig.cginc" + +#include "UnityStandardCore.cginc" +VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } +VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } +half4 fragBase (VertexOutputForwardBase i, bool facing : SV_IsFrontFace) : SV_Target { return fragForwardBaseInternal(i, facing); } +half4 fragAdd (VertexOutputForwardAdd i, bool facing : SV_IsFrontFace) : SV_Target { return fragForwardAddInternal(i, facing); } + + +#endif // UNITY_STANDARD_CORE_FORWARD_INCLUDED diff --git a/Assets/Filamented/UnityStandardCoreForward.cginc.meta b/Assets/Filamented/UnityStandardCoreForward.cginc.meta new file mode 100644 index 0000000..5b16f43 --- /dev/null +++ b/Assets/Filamented/UnityStandardCoreForward.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8e949ac172157a349a6c5a6b7d4bfe9e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityStandardInput.cginc b/Assets/Filamented/UnityStandardInput.cginc new file mode 100644 index 0000000..9ec2a0a --- /dev/null +++ b/Assets/Filamented/UnityStandardInput.cginc @@ -0,0 +1,474 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_STANDARD_INPUT_INCLUDED +#define UNITY_STANDARD_INPUT_INCLUDED + +#include "UnityCG.cginc" +#include "UnityStandardConfig.cginc" +#include "UnityStandardUtils.cginc" + +//------------------------------------------------------------------------------ +// Input configuration +//------------------------------------------------------------------------------ + +// Parallax settings +#define PARALLAX_NONE 0 +// Has a range of -1 to 1 +#define PARALLAX_ONESTEP 1 +// Has a range of -1 to 0 +#define PARALLAX_RAYMARCH 2 +#define PARALLAX_RAYMARCH_DYNAMIC 3 +// Has a range of -1 to 1 +#define PARALLAX_RAYMARCH_DYNAMIC_OFFSET 4 + +#define PARALLAX_OPERATOR PARALLAX_RAYMARCH_DYNAMIC_OFFSET + +//--------------------------------------- +// Directional lightmaps & Parallax require tangent space too +#if (_NORMALMAP || DIRLIGHTMAP_COMBINED || _PARALLAXMAP || MATERIAL_NEEDS_TBN) + #define _TANGENT_TO_WORLD 1 +#endif + +#if (_DETAIL_MULX2 || _DETAIL_MUL || _DETAIL_ADD || _DETAIL_LERP) + #define _DETAIL 1 +#endif + +//--------------------------------------- +#if defined(USE_UNITY_STANDARD_INPUT_DEFINES) + half4 _Color; + + sampler2D _MainTex; + float4 _MainTex_ST; + + sampler2D _DetailAlbedoMap; + float4 _DetailAlbedoMap_ST; + + sampler2D _BumpMap; + half _BumpScale; + + sampler2D _DetailMask; + sampler2D _DetailNormalMap; + half _DetailNormalMapScale; + + sampler2D _SpecGlossMap; + sampler2D _MetallicGlossMap; + half _Metallic; + float _Glossiness; + float _GlossMapScale; + + sampler2D _OcclusionMap; + half _OcclusionStrength; + + sampler2D _ParallaxMap; + half _Parallax; + + half4 _EmissionColor; + sampler2D _EmissionMap; +#endif // USE_UNITY_STANDARD_INPUT_DEFINES + +// Some settings that can't be removed yet. +// UVSec can be removed once a more rebost way of passing the extra UVs is done. +half _UVSec; +half _Cutoff; + +// New settings +half _ExposureOcclusion; +half _LightmapSpecularMaxSmoothness; + +#if defined(_VRCLV) +half _VRCLVSurfaceBias; +#endif + +half _BumpShadowHeightScale; +half _BumpShadowHardness; + +#if !defined(USE_GEOMETRIC_SPECULAR_AA_DEFAULT) +half _specularAntiAliasingVariance; +half _specularAntiAliasingThreshold; +#endif + +half _CullMode; + +//------------------------------------------------------------------------------------- +// Input functions + +struct VertexInput +{ + float4 vertex : POSITION; + half3 normal : NORMAL; + float2 uv0 : TEXCOORD0; + float2 uv1 : TEXCOORD1; +#if defined(DYNAMICLIGHTMAP_ON) || defined(UNITY_PASS_META) || defined(HAS_ATTRIBUTE_UV2) + float2 uv2 : TEXCOORD2; +#endif +#if defined(HAS_ATTRIBUTE_UV3) + float2 uv3 : TEXCOORD3; +#endif +#ifdef _TANGENT_TO_WORLD + half4 tangent : TANGENT; +#endif +#ifdef USING_BAKERY_VERTEXLM + float4 color : COLOR; + #ifdef USING_BAKERY_VERTEXLMSH + float2 uv3 : TEXCOORD3; + #endif +#else +#if defined(HAS_ATTRIBUTE_COLOR) + half4 color : COLOR; +#endif +#endif + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +#if defined(USE_UNITY_STANDARD_INPUT_DEFINES) + float4 TexCoords(VertexInput v) + { + float4 texcoord; + texcoord.xy = TRANSFORM_TEX(v.uv0, _MainTex); // Always source from uv0 + texcoord.zw = TRANSFORM_TEX(((_UVSec == 0) ? v.uv0 : v.uv1), _DetailAlbedoMap); + #if defined(HAS_ATTRIBUTE_UV2) + texcoord.zw = TRANSFORM_TEX(((_UVSec == 2) ? v.uv2 : texcoord.zw), _DetailAlbedoMap); + #endif + #if defined(HAS_ATTRIBUTE_UV3) + texcoord.zw = TRANSFORM_TEX(((_UVSec == 3) ? v.uv3 : texcoord.zw), _DetailAlbedoMap); + #endif + return texcoord; + } + + half DetailMask(float2 uv) + { + return tex2D (_DetailMask, uv).a; + } + + half3 Albedo(float4 texcoords) + { + half3 albedo = _Color.rgb * tex2D (_MainTex, texcoords.xy).rgb; + #if _DETAIL + #if (SHADER_TARGET < 30) + // SM20: instruction count limitation + // SM20: no detail mask + half mask = 1; + #else + half mask = DetailMask(texcoords.xy); + #endif + half3 detailAlbedo = tex2D (_DetailAlbedoMap, texcoords.zw).rgb; + #if _DETAIL_MULX2 + albedo *= LerpWhiteTo (detailAlbedo * unity_ColorSpaceDouble.rgb, mask); + #elif _DETAIL_MUL + albedo *= LerpWhiteTo (detailAlbedo, mask); + #elif _DETAIL_ADD + albedo += detailAlbedo * mask; + #elif _DETAIL_LERP + albedo = lerp (albedo, detailAlbedo, mask); + #endif + #endif + return albedo; + } + + half Alpha(float2 uv) + { + #if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) + return _Color.a; + #else + return tex2D(_MainTex, uv).a * _Color.a; + #endif + } + + half Occlusion(float2 uv) + { + #if (SHADER_TARGET < 30) + // SM20: instruction count limitation + // SM20: simpler occlusion + return tex2D(_OcclusionMap, uv).g; + #else + half occ = tex2D(_OcclusionMap, uv).g; + return LerpOneTo (occ, _OcclusionStrength); + #endif + } + + half4 SpecularGloss(float2 uv) + { + half4 sg; + #ifdef _SPECGLOSSMAP + #if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) + sg.rgb = tex2D(_SpecGlossMap, uv).rgb; + sg.a = tex2D(_MainTex, uv).a; + #else + sg = tex2D(_SpecGlossMap, uv); + #endif + sg.a *= _GlossMapScale; + #else + sg.rgb = _SpecColor.rgb; + #ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + sg.a = tex2D(_MainTex, uv).a * _GlossMapScale; + #else + sg.a = _Glossiness; + #endif + #endif + return sg; + } + + half2 MetallicGloss(float2 uv) + { + half2 mg; + + #ifdef _METALLICGLOSSMAP + #ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + mg.r = tex2D(_MetallicGlossMap, uv).r; + mg.g = tex2D(_MainTex, uv).a; + #else + mg = tex2D(_MetallicGlossMap, uv).ra; + #endif + mg.g *= _GlossMapScale; + #else + mg.r = _Metallic; + #ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + mg.g = tex2D(_MainTex, uv).a * _GlossMapScale; + #else + mg.g = _Glossiness; + #endif + #endif + return mg; + } + + half2 MetallicRough(float2 uv) + { + half2 mg; + #ifdef _METALLICGLOSSMAP + mg.r = tex2D(_MetallicGlossMap, uv).r; + #else + mg.r = _Metallic; + #endif + + #ifdef _SPECGLOSSMAP + mg.g = 1.0f - tex2D(_SpecGlossMap, uv).r; + #else + mg.g = 1.0f - _Glossiness; + #endif + return mg; + } + + half3 Emission(float2 uv) + { + #ifndef _EMISSION + return 0; + #else + return tex2D(_EmissionMap, uv).rgb * _EmissionColor.rgb; + #endif + } + + half4 SheenColorGlossCloth(float2 uv) + { + half4 sg; + #ifdef _SPECGLOSSMAP + #if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) + sg.rgb = tex2D(_SpecGlossMap, uv).rgb; + sg.a = tex2D(_MainTex, uv).a; + #else + sg = tex2D(_SpecGlossMap, uv); + #endif + sg.rgb *= _SpecColor.rgb; + sg.a *= _GlossMapScale; + #else + sg.rgb = _SpecColor.rgb; + #ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + sg.a = tex2D(_MainTex, uv).a * _GlossMapScale; + #else + sg.a = _Glossiness; + #endif + #endif + return sg; + } + + #ifdef _NORMALMAP + half3 NormalInTangentSpace(float4 texcoords) + { + half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, texcoords.xy), _BumpScale); + + #if _DETAIL && defined(UNITY_ENABLE_DETAIL_NORMALMAP) + half mask = DetailMask(texcoords.xy); + half3 detailNormalTangent = UnpackScaleNormal(tex2D (_DetailNormalMap, texcoords.zw), _DetailNormalMapScale); + #if _DETAIL_LERP + normalTangent = lerp( + normalTangent, + detailNormalTangent, + mask); + #else + normalTangent = lerp( + normalTangent, + BlendNormals(normalTangent, detailNormalTangent), + mask); + #endif + #endif + + return normalTangent; + } + #endif + + struct PerPixelHeightDisplacementParam + { + float2 uv; + float2 dX; + float2 dY; + }; + + #if defined(PARALLAX_CUSTOM_INPUT) + // Dummy function + #else + PerPixelHeightDisplacementParam InitPerPixelHeightDisplacementParam(float2 uv) + { + PerPixelHeightDisplacementParam ppd; + + ppd.uv = uv; + ppd.dX = ddx(uv); + ppd.dY = ddy(uv); + + return ppd; + } + + float ComputePerPixelHeightDisplacement(float2 offset, float lod, PerPixelHeightDisplacementParam ppdParam) + { + float height = 1; + float strength = _Parallax; + // Probably can use LOD to skip reading if too far + height = + tex2Dgrad(_ParallaxMap, ppdParam.uv + offset, ppdParam.dX, ppdParam.dY).g; + + height = clamp(height, 0, 0.9999); + + return height; + } + + #include "SharedParallaxLib.hlsl" + + float4 Parallax (float4 texcoords, half3 viewDir, half lod) + { + #if !defined(_PARALLAXMAP) || (SHADER_TARGET < 30) || (PARALLAX_OPERATOR == PARALLAX_NONE) + // Disable parallax on pre-SM3.0 shader target models + return texcoords; + #else + PerPixelHeightDisplacementParam ppd = InitPerPixelHeightDisplacementParam(texcoords.xy); + #if (PARALLAX_OPERATOR == PARALLAX_ONESTEP) + half h = tex2D (_ParallaxMap, texcoords.xy).g; + float2 offset = ParallaxOffset1Step (h, _Parallax, viewDir); + return float4(texcoords.xy + offset, texcoords.zw + offset); + #endif + #if (PARALLAX_OPERATOR == PARALLAX_RAYMARCH) + float height = 1.0; + viewDir = normalize(viewDir); + viewDir.xy /= (viewDir.z + 0.42); + float2 offset = ParallaxRaymarching(viewDir, ppd, _Parallax, /* out */ height); + return float4(texcoords.xy + offset, texcoords.zw + offset); + #endif + #if (PARALLAX_OPERATOR == PARALLAX_RAYMARCH_DYNAMIC) + float2 offset = ParallaxRaymarchingDynamic(viewDir, ppd, _Parallax, lod); + return float4(texcoords.xy + offset, texcoords.zw + offset); + #endif + #if (PARALLAX_OPERATOR == PARALLAX_RAYMARCH_DYNAMIC_OFFSET) + float2 offset = ParallaxRaymarchingDynamicOffset(viewDir, ppd, _Parallax, lod); + return float4(texcoords.xy + offset, texcoords.zw + offset); + #endif + #endif + return texcoords; + } + #endif // USE_UNITY_STANDARD_INPUT_DEFINES + + #if (defined(_NORMALMAP) && defined(NORMALMAP_SHADOW)) + struct NormalMapShadowsParam + { + float4 uv; + float2 dX; + float2 dY; + }; + + NormalMapShadowsParam InitNormalMapShadowsParam(float4 uv) + { + NormalMapShadowsParam nms; + + nms.uv = uv; + nms.dX = ddx(uv.xy); + nms.dY = ddy(uv.xy); + + return nms; + } + + float3 SampleNormalMap (NormalMapShadowsParam nmsParam, float2 offset) { + return NormalInTangentSpace(float4(nmsParam.uv.xy + offset, nmsParam.uv.zw + offset)); + } + + #include "SharedNormalShadowLib.hlsl" + + float NormalTangentShadow(float4 texcoords, half3 lightDirTS, float noise) + { + float _HeightScale = _BumpShadowHeightScale; + float _ShadowHardness = _BumpShadowHardness; + NormalMapShadowsParam nms = InitNormalMapShadowsParam(texcoords); + nms.uv = texcoords; + return NormalMapShadows (lightDirTS, nms, noise, _HeightScale, _ShadowHardness); + } + + #endif +#else // USE_UNITY_STANDARD_INPUT_DEFINES + float4 TexCoords(VertexInput v) + { + float4 texcoord; + texcoord.xy = (v.uv0); // Always source from uv0 + texcoord.zw = (((_UVSec == 0) ? v.uv0 : v.uv1)); + #if defined(HAS_ATTRIBUTE_UV2) + texcoord.zw = (((_UVSec == 2) ? v.uv2 : texcoord.zw)); + #endif + #if defined(HAS_ATTRIBUTE_UV3) + texcoord.zw = (((_UVSec == 3) ? v.uv3 : texcoord.zw)); + #endif + return texcoord; + } + +#endif // USE_UNITY_STANDARD_INPUT_DEFINES + +half getMaskThreshold() +{ + return _Cutoff; +} + +bool getIsDoubleSided() +{ + return _CullMode == 0; +} + +half getExposureOcclusionBias() +{ + return 1.0/(_ExposureOcclusion); +} + +half getLightmapSpecularMaxSmoothness() +{ + return _LightmapSpecularMaxSmoothness; +} + +bool getIsBakeryVertexMode() +{ +#if defined(USING_BAKERY_VERTEXLM) + // Todo: Move these somewhere better. + #define BAKERYMODE_DEFAULT 0 + // When vertex lightmap is set in Bakery, it sets this float to the renderer via + // SetPropertyBlock. Similarly, it only sets RNM/SH if the textures are used and present, + // but those are switched at compile time per-material. + #define BAKERYMODE_VERTEXLM 1.0f + #define BAKERYMODE_RNM 2.0f + #define BAKERYMODE_SH 3.0f + + return (bakeryLightmapMode == BAKERYMODE_VERTEXLM); +#endif + return false; +} + +half getLightVolumeSurfaceBias() +{ + #if defined(_VRCLV) + return _VRCLVSurfaceBias; + #else + return 0; + #endif +} + +#endif // UNITY_STANDARD_INPUT_INCLUDED diff --git a/Assets/Filamented/UnityStandardInput.cginc.meta b/Assets/Filamented/UnityStandardInput.cginc.meta new file mode 100644 index 0000000..bc21080 --- /dev/null +++ b/Assets/Filamented/UnityStandardInput.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b82b8515f6fc2424b82b84c40f636d93 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityStandardMeta.cginc b/Assets/Filamented/UnityStandardMeta.cginc new file mode 100644 index 0000000..9751f71 --- /dev/null +++ b/Assets/Filamented/UnityStandardMeta.cginc @@ -0,0 +1,94 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_STANDARD_META_INCLUDED +#define UNITY_STANDARD_META_INCLUDED + +// Functionality for Standard shader "meta" pass +// (extracts albedo/emission for lightmapper etc.) + +#include "UnityCG.cginc" +#include "UnityStandardInput.cginc" +#include "UnityMetaPass.cginc" +#include "UnityStandardCore.cginc" +#include "FilamentShadingLit.cginc" + +struct v2f_meta +{ + float4 pos : SV_POSITION; + float4 uv : TEXCOORD0; +#ifdef EDITOR_VISUALIZATION + float2 vizUV : TEXCOORD1; + float4 lightCoord : TEXCOORD2; +#endif +#ifdef HAS_ATTRIBUTE_COLOR + float4 color : COLOR_Centroid; +#endif +#ifdef REQUIRE_META_WORLDPOS + float4 worldPos : TEXCOORD3; +#endif +}; + +v2f_meta vert_meta (VertexInput v) +{ + v2f_meta o; + o.pos = UnityMetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST, unity_DynamicLightmapST); + o.uv = TexCoords(v); +#ifdef EDITOR_VISUALIZATION + o.vizUV = 0; + o.lightCoord = 0; + if (unity_VisualizationMode == EDITORVIZ_TEXTURE) + o.vizUV = UnityMetaVizUV(unity_EditorViz_UVIndex, v.uv0.xy, v.uv1.xy, v.uv2.xy, unity_EditorViz_Texture_ST); + else if (unity_VisualizationMode == EDITORVIZ_SHOWLIGHTMASK) + { + o.vizUV = v.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + o.lightCoord = mul(unity_EditorViz_WorldToLight, mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1))); + } +#endif +#ifdef HAS_ATTRIBUTE_COLOR + o.color = v.color; +#endif +#ifdef REQUIRE_META_WORLDPOS + float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; + float3 worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldPos.xyz = worldPos; +#endif + return o; +} + +// Albedo for lightmapping should basically be diffuse color. +// But rough metals (black diffuse) still scatter quite a lot of light around, so +// we want to take some of that into account too. +half3 UnityLightmappingAlbedo (half3 diffuse, half3 specular, half smoothness) +{ + half roughness = SmoothnessToRoughness(smoothness); + half3 res = diffuse; + res += specular * roughness * 0.5; + return res; +} + +float4 frag_meta (v2f_meta i) : SV_Target +{ + // we're interested in diffuse & specular colors, + // and surface roughness to produce final albedo. + MaterialInputs material = SETUP_BRDF_INPUT (i.uv); + + PixelParams pixel = (PixelParams)0; + getCommonPixelParams(material, pixel); + + UnityMetaInput o; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); + +#ifdef EDITOR_VISUALIZATION + o.Albedo = pixel.diffuseColor; + o.VizUV = i.vizUV; + o.LightCoord = i.lightCoord; +#else + o.Albedo = UnityLightmappingAlbedo (pixel.diffuseColor, pixel.f0, 1-pixel.perceptualRoughness); +#endif + o.SpecularColor = pixel.f0; + o.Emission = material.emissive; + + return UnityMetaFragment(o); +} + +#endif // UNITY_STANDARD_META_INCLUDED diff --git a/Assets/Filamented/UnityStandardMeta.cginc.meta b/Assets/Filamented/UnityStandardMeta.cginc.meta new file mode 100644 index 0000000..b5fb794 --- /dev/null +++ b/Assets/Filamented/UnityStandardMeta.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 988393ba3605c6d439da49623e84146f +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityStandardShadow.cginc b/Assets/Filamented/UnityStandardShadow.cginc new file mode 100644 index 0000000..316d2bb --- /dev/null +++ b/Assets/Filamented/UnityStandardShadow.cginc @@ -0,0 +1,225 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_STANDARD_SHADOW_INCLUDED +#define UNITY_STANDARD_SHADOW_INCLUDED + +// NOTE: had to split shadow functions into separate file, +// otherwise compiler gives trouble with LIGHTING_COORDS macro (in UnityStandardCore.cginc) + + +#include "UnityCG.cginc" +#include "UnityShaderVariables.cginc" +#include "UnityStandardConfig.cginc" +#include "UnityStandardUtils.cginc" + +#if (defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_ON)) && defined(UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS) + #define UNITY_STANDARD_USE_DITHER_MASK 1 +#endif + +// Need to output UVs in shadow caster, since we need to sample texture and do clip/dithering based on it +#if defined(_ALPHATEST_ON) || defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_ON) +#define UNITY_STANDARD_USE_SHADOW_UVS 1 +#endif + +// Has a non-empty shadow caster output struct (it's an error to have empty structs on some platforms...) +#if !defined(V2F_SHADOW_CASTER_NOPOS_IS_EMPTY) || defined(UNITY_STANDARD_USE_SHADOW_UVS) +#define UNITY_STANDARD_USE_SHADOW_OUTPUT_STRUCT 1 +#endif + +#ifdef UNITY_STEREO_INSTANCING_ENABLED +#define UNITY_STANDARD_USE_STEREO_SHADOW_OUTPUT_STRUCT 1 +#endif + + +half4 _Color; +half _Cutoff; +sampler2D _MainTex; +float4 _MainTex_ST; +#ifdef UNITY_STANDARD_USE_DITHER_MASK +sampler3D _DitherMaskLOD; +#endif + +// Handle PremultipliedAlpha from Fade or Transparent shading mode +half4 _SpecColor; +half _Metallic; +#ifdef _SPECGLOSSMAP +sampler2D _SpecGlossMap; +#endif +#ifdef _METALLICGLOSSMAP +sampler2D _MetallicGlossMap; +#endif + +#if defined(UNITY_STANDARD_USE_SHADOW_UVS) && defined(_PARALLAXMAP) +sampler2D _ParallaxMap; +half _Parallax; +#endif + +half MetallicSetup_ShadowGetOneMinusReflectivity(half2 uv) +{ + half metallicity = _Metallic; + #ifdef _METALLICGLOSSMAP + metallicity = tex2D(_MetallicGlossMap, uv).r; + #endif + return OneMinusReflectivityFromMetallic(metallicity); +} + +half RoughnessSetup_ShadowGetOneMinusReflectivity(half2 uv) +{ + half metallicity = _Metallic; +#ifdef _METALLICGLOSSMAP + metallicity = tex2D(_MetallicGlossMap, uv).r; +#endif + return OneMinusReflectivityFromMetallic(metallicity); +} + +half SpecularSetup_ShadowGetOneMinusReflectivity(half2 uv) +{ + half3 specColor = _SpecColor.rgb; + #ifdef _SPECGLOSSMAP + specColor = tex2D(_SpecGlossMap, uv).rgb; + #endif + return (1 - SpecularStrength(specColor)); +} + +// Lazy workaround - I'd like to redo this later. +half UNITY_SETUP_BRDF_INPUT_ShadowGetOneMinusReflectivity(half2 uv) +{ + #ifdef SHADING_MODEL_SPECULAR_GLOSSINESS + half3 specColor = _SpecColor.rgb; + #ifdef _SPECGLOSSMAP + specColor = tex2D(_SpecGlossMap, uv).rgb; + #endif + return (1 - SpecularStrength(specColor)); + #else + half metallicity = _Metallic; + #ifdef _METALLICGLOSSMAP + metallicity = tex2D(_MetallicGlossMap, uv).r; + #endif + return OneMinusReflectivityFromMetallic(metallicity); + #endif + +} + + +// SHADOW_ONEMINUSREFLECTIVITY(): workaround to get one minus reflectivity based on UNITY_SETUP_BRDF_INPUT +#define SHADOW_JOIN2(a, b) a##b +#define SHADOW_JOIN(a, b) SHADOW_JOIN2(a,b) +#define SHADOW_ONEMINUSREFLECTIVITY SHADOW_JOIN(UNITY_SETUP_BRDF_INPUT, _ShadowGetOneMinusReflectivity) + +struct VertexInput +{ + float4 vertex : POSITION; + float3 normal : NORMAL; + float2 uv0 : TEXCOORD0; + #if defined(UNITY_STANDARD_USE_SHADOW_UVS) && defined(_PARALLAXMAP) + half4 tangent : TANGENT; + #endif + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +#ifdef UNITY_STANDARD_USE_SHADOW_OUTPUT_STRUCT +struct VertexOutputShadowCaster +{ + V2F_SHADOW_CASTER_NOPOS + #if defined(UNITY_STANDARD_USE_SHADOW_UVS) + float2 tex : TEXCOORD1; + + #if defined(_PARALLAXMAP) + half3 viewDirForParallax : TEXCOORD2; + #endif + #endif +}; +#endif + +#ifdef UNITY_STANDARD_USE_STEREO_SHADOW_OUTPUT_STRUCT +struct VertexOutputStereoShadowCaster +{ + UNITY_VERTEX_OUTPUT_STEREO +}; +#endif + +// We have to do these dances of outputting SV_POSITION separately from the vertex shader, +// and inputting VPOS in the pixel shader, since they both map to "POSITION" semantic on +// some platforms, and then things don't go well. + + +void vertShadowCaster (VertexInput v + , out float4 opos : SV_POSITION + #ifdef UNITY_STANDARD_USE_SHADOW_OUTPUT_STRUCT + , out VertexOutputShadowCaster o + #endif + #ifdef UNITY_STANDARD_USE_STEREO_SHADOW_OUTPUT_STRUCT + , out VertexOutputStereoShadowCaster os + #endif +) +{ + UNITY_SETUP_INSTANCE_ID(v); + #ifdef UNITY_STANDARD_USE_STEREO_SHADOW_OUTPUT_STRUCT + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(os); + #endif + TRANSFER_SHADOW_CASTER_NOPOS(o,opos) + #if defined(UNITY_STANDARD_USE_SHADOW_UVS) + o.tex = TRANSFORM_TEX(v.uv0, _MainTex); + + #ifdef _PARALLAXMAP + TANGENT_SPACE_ROTATION; + o.viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex)); + #endif + #endif +} + +half4 fragShadowCaster (UNITY_POSITION(vpos) +#ifdef UNITY_STANDARD_USE_SHADOW_OUTPUT_STRUCT + , VertexOutputShadowCaster i +#endif +) : SV_Target +{ + #if defined(UNITY_STANDARD_USE_SHADOW_UVS) + #if defined(_PARALLAXMAP) && (SHADER_TARGET >= 30) + half3 viewDirForParallax = normalize(i.viewDirForParallax); + fixed h = tex2D (_ParallaxMap, i.tex.xy).g; + half2 offset = ParallaxOffset1Step (h, _Parallax, viewDirForParallax); + i.tex.xy += offset; + #endif + + #if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) + half alpha = _Color.a; + #else + half alpha = tex2D(_MainTex, i.tex.xy).a * _Color.a; + #endif + #if defined(_ALPHATEST_ON) + clip (alpha - _Cutoff); + #endif + #if defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_ON) + #if defined(_ALPHAPREMULTIPLY_ON) + half outModifiedAlpha; + PreMultiplyAlpha(half3(0, 0, 0), alpha, SHADOW_ONEMINUSREFLECTIVITY(i.tex), outModifiedAlpha); + alpha = outModifiedAlpha; + #endif + #if defined(UNITY_STANDARD_USE_DITHER_MASK) + // Use dither mask for alpha blended shadows, based on pixel position xy + // and alpha level. Our dither texture is 4x4x16. + #ifdef LOD_FADE_CROSSFADE + #define _LOD_FADE_ON_ALPHA + alpha *= unity_LODFade.y; + #endif + half alphaRef = tex3D(_DitherMaskLOD, float3(vpos.xy*0.25,alpha*0.9375)).a; + clip (alphaRef - 0.01); + #else + clip (alpha - _Cutoff); + #endif + #endif + #endif // #if defined(UNITY_STANDARD_USE_SHADOW_UVS) + + #ifdef LOD_FADE_CROSSFADE + #ifdef _LOD_FADE_ON_ALPHA + #undef _LOD_FADE_ON_ALPHA + #else + UnityApplyDitherCrossFade(vpos.xy); + #endif + #endif + + SHADOW_CASTER_FRAGMENT(i) +} + +#endif // UNITY_STANDARD_SHADOW_INCLUDED diff --git a/Assets/Filamented/UnityStandardShadow.cginc.meta b/Assets/Filamented/UnityStandardShadow.cginc.meta new file mode 100644 index 0000000..63606ef --- /dev/null +++ b/Assets/Filamented/UnityStandardShadow.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: a0a28b8f70e8f7d43b7045ffc69e4691 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/UnityStandardUtils.cginc b/Assets/Filamented/UnityStandardUtils.cginc new file mode 100644 index 0000000..cbb5ebb --- /dev/null +++ b/Assets/Filamented/UnityStandardUtils.cginc @@ -0,0 +1,382 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_STANDARD_UTILS_INCLUDED +#define UNITY_STANDARD_UTILS_INCLUDED + +#include "UnityCG.cginc" +#include "UnityStandardConfig.cginc" +#include "SharedSamplingLib.hlsl" + +// Helper functions, maybe move into UnityCG.cginc + +half SpecularStrength(half3 specular) +{ + #if (SHADER_TARGET < 30) + // SM2.0: instruction count limitation + // SM2.0: simplified SpecularStrength + return specular.r; // Red channel - because most metals are either monocrhome or with redish/yellowish tint + #else + return max (max (specular.r, specular.g), specular.b); + #endif +} + +// Diffuse/Spec Energy conservation +inline half3 EnergyConservationBetweenDiffuseAndSpecular (half3 albedo, half3 specColor, out half oneMinusReflectivity) +{ + oneMinusReflectivity = 1 - SpecularStrength(specColor); + #if !UNITY_CONSERVE_ENERGY + return albedo; + #elif UNITY_CONSERVE_ENERGY_MONOCHROME + return albedo * oneMinusReflectivity; + #else + return albedo * (half3(1,1,1) - specColor); + #endif +} + +inline half OneMinusReflectivityFromMetallic(half metallic) +{ + // We'll need oneMinusReflectivity, so + // 1-reflectivity = 1-lerp(dielectricSpec, 1, metallic) = lerp(1-dielectricSpec, 0, metallic) + // store (1-dielectricSpec) in unity_ColorSpaceDielectricSpec.a, then + // 1-reflectivity = lerp(alpha, 0, metallic) = alpha + metallic*(0 - alpha) = + // = alpha - metallic * alpha + half oneMinusDielectricSpec = unity_ColorSpaceDielectricSpec.a; + return oneMinusDielectricSpec - metallic * oneMinusDielectricSpec; +} + +inline half3 DiffuseAndSpecularFromMetallic (half3 albedo, half metallic, out half3 specColor, out half oneMinusReflectivity) +{ + specColor = lerp (unity_ColorSpaceDielectricSpec.rgb, albedo, metallic); + oneMinusReflectivity = OneMinusReflectivityFromMetallic(metallic); + return albedo * oneMinusReflectivity; +} + +inline half3 PreMultiplyAlpha (half3 diffColor, half alpha, half oneMinusReflectivity, out half outModifiedAlpha) +{ + #if defined(_ALPHAPREMULTIPLY_ON) + // NOTE: shader relies on pre-multiply alpha-blend (_SrcBlend = One, _DstBlend = OneMinusSrcAlpha) + + // Transparency 'removes' from Diffuse component + diffColor *= alpha; + + #if (SHADER_TARGET < 30) + // SM2.0: instruction count limitation + // Instead will sacrifice part of physically based transparency where amount Reflectivity is affecting Transparency + // SM2.0: uses unmodified alpha + outModifiedAlpha = alpha; + #else + // Reflectivity 'removes' from the rest of components, including Transparency + // outAlpha = 1-(1-alpha)*(1-reflectivity) = 1-(oneMinusReflectivity - alpha*oneMinusReflectivity) = + // = 1-oneMinusReflectivity + alpha*oneMinusReflectivity + outModifiedAlpha = 1-oneMinusReflectivity + alpha*oneMinusReflectivity; + #endif + #else + outModifiedAlpha = alpha; + #endif + return diffColor; +} + +// Same as ParallaxOffset in Unity CG, except: +// *) precision - half instead of float +half2 ParallaxOffset1Step (half h, half height, half3 viewDir) +{ + h = h * height - height/2.0; + half3 v = normalize(viewDir); + v.z += 0.42; + return h * (v.xy / v.z); +} + +half LerpOneTo(half b, half t) +{ + half oneMinusT = 1 - t; + return oneMinusT + b * t; +} + +half3 LerpWhiteTo(half3 b, half t) +{ + half oneMinusT = 1 - t; + return half3(oneMinusT, oneMinusT, oneMinusT) + b * t; +} + +half3 UnpackScaleNormalDXT5nm(half4 packednormal, half bumpScale) +{ + half3 normal; + normal.xy = (packednormal.wy * 2 - 1); + #if (SHADER_TARGET >= 30) + // SM2.0: instruction count limitation + // SM2.0: normal scaler is not supported + normal.xy *= bumpScale; + #endif + normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy))); + return normal; +} + +half3 UnpackScaleNormalRGorAG(half4 packednormal, half bumpScale) +{ + #if defined(UNITY_NO_DXT5nm) + half3 normal = packednormal.xyz * 2 - 1; + #if (SHADER_TARGET >= 30) + // SM2.0: instruction count limitation + // SM2.0: normal scaler is not supported + normal.xy *= bumpScale; + #endif + return normal; + #elif defined(UNITY_ASTC_NORMALMAP_ENCODING) + half3 normal; + normal.xy = (packednormal.wy * 2 - 1); + normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy))); + normal.xy *= bumpScale; + return normal; + #else + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = (packednormal.xy * 2 - 1); + #if (SHADER_TARGET >= 30) + // SM2.0: instruction count limitation + // SM2.0: normal scaler is not supported + normal.xy *= bumpScale; + #endif + normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy))); + return normal; + #endif +} + +half3 UnpackScaleNormal(half4 packednormal, half bumpScale) +{ + return UnpackScaleNormalRGorAG(packednormal, bumpScale); +} + +half3 BlendNormals(half3 n1, half3 n2) +{ + return normalize(half3(n1.xy + n2.xy, n1.z*n2.z)); +} + +half3x3 CreateTangentToWorldPerVertex(half3 normal, half3 tangent, half tangentSign) +{ + // For odd-negative scale transforms we need to flip the sign + half sign = tangentSign * unity_WorldTransformParams.w; + half3 binormal = cross(normal, tangent) * sign; + return half3x3(tangent, binormal, normal); +} + +//------------------------------------------------------------------------------------- +half3 ShadeSHPerVertex (half3 normal, half3 ambient) +{ + #if UNITY_SAMPLE_FULL_SH_PER_PIXEL + // Completely per-pixel + // nothing to do here + #elif (SHADER_TARGET < 30) || UNITY_STANDARD_SIMPLE + // Completely per-vertex + ambient += max(half3(0,0,0), ShadeSH9 (half4(normal, 1.0))); + #else + // L2 per-vertex, L0..L1 & gamma-correction per-pixel + + // NOTE: SH data is always in Linear AND calculation is split between vertex & pixel + // Convert ambient to Linear and do final gamma-correction at the end (per-pixel) + #ifdef UNITY_COLORSPACE_GAMMA + ambient = GammaToLinearSpace (ambient); + #endif + ambient += SHEvalLinearL2 (half4(normal, 1.0)); // no max since this is only L2 contribution + #endif + + return ambient; +} + +half3 ShadeSHPerPixel (half3 normal, half3 ambient, float3 worldPos) +{ + half3 ambient_contrib = 0.0; + + #if UNITY_SAMPLE_FULL_SH_PER_PIXEL + // Completely per-pixel + #if UNITY_LIGHT_PROBE_PROXY_VOLUME + if (unity_ProbeVolumeParams.x == 1.0) + ambient_contrib = SHEvalLinearL0L1_SampleProbeVolume(half4(normal, 1.0), worldPos); + else + ambient_contrib = SHEvalLinearL0L1(half4(normal, 1.0)); + #else + ambient_contrib = SHEvalLinearL0L1(half4(normal, 1.0)); + #endif + + ambient_contrib += SHEvalLinearL2(half4(normal, 1.0)); + + ambient += max(half3(0, 0, 0), ambient_contrib); + + #ifdef UNITY_COLORSPACE_GAMMA + ambient = LinearToGammaSpace(ambient); + #endif + #elif (SHADER_TARGET < 30) || UNITY_STANDARD_SIMPLE + // Completely per-vertex + // nothing to do here. Gamma conversion on ambient from SH takes place in the vertex shader, see ShadeSHPerVertex. + #else + // L2 per-vertex, L0..L1 & gamma-correction per-pixel + // Ambient in this case is expected to be always Linear, see ShadeSHPerVertex() + #if UNITY_LIGHT_PROBE_PROXY_VOLUME + if (unity_ProbeVolumeParams.x == 1.0) + ambient_contrib = SHEvalLinearL0L1_SampleProbeVolume (half4(normal, 1.0), worldPos); + else + ambient_contrib = SHEvalLinearL0L1 (half4(normal, 1.0)); + #else + ambient_contrib = SHEvalLinearL0L1 (half4(normal, 1.0)); + #endif + + ambient = max(half3(0, 0, 0), ambient+ambient_contrib); // include L2 contribution in vertex shader before clamp. + #ifdef UNITY_COLORSPACE_GAMMA + ambient = LinearToGammaSpace (ambient); + #endif + #endif + + return ambient; +} + +//------------------------------------------------------------------------------------- +inline float3 BoxProjectedCubemapDirection (float3 worldRefl, float3 worldPos, float4 cubemapCenter, float4 boxMin, float4 boxMax) +{ + // Do we have a valid reflection probe? + UNITY_BRANCH + if (cubemapCenter.w > 0.0) + { + float3 nrdir = normalize(worldRefl); + + #if 1 + float3 rbmax = (boxMax.xyz - worldPos) / nrdir; + float3 rbmin = (boxMin.xyz - worldPos) / nrdir; + + float3 rbminmax = (nrdir > 0.0f) ? rbmax : rbmin; + + #else // Optimized version + float3 rbmax = (boxMax.xyz - worldPos); + float3 rbmin = (boxMin.xyz - worldPos); + + float3 select = step (float3(0,0,0), nrdir); + float3 rbminmax = lerp (rbmax, rbmin, select); + rbminmax /= nrdir; + #endif + + float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z); + + worldPos -= cubemapCenter.xyz; + worldRefl = worldPos + nrdir * fa; + } + return worldRefl; +} + + +//------------------------------------------------------------------------------------- +// Derivative maps +// http://www.rorydriscoll.com/2012/01/11/derivative-maps/ +// For future use. + +// Project the surface gradient (dhdx, dhdy) onto the surface (n, dpdx, dpdy) +half3 CalculateSurfaceGradient(half3 n, half3 dpdx, half3 dpdy, half dhdx, half dhdy) +{ + half3 r1 = cross(dpdy, n); + half3 r2 = cross(n, dpdx); + return (r1 * dhdx + r2 * dhdy) / dot(dpdx, r1); +} + +// Move the normal away from the surface normal in the opposite surface gradient direction +half3 PerturbNormal(half3 n, half3 dpdx, half3 dpdy, half dhdx, half dhdy) +{ + //TODO: normalize seems to be necessary when scales do go beyond the 2...-2 range, should we limit that? + //how expensive is a normalize? Anything cheaper for this case? + return normalize(n - CalculateSurfaceGradient(n, dpdx, dpdy, dhdx, dhdy)); +} + +// Calculate the surface normal using the uv-space gradient (dhdu, dhdv) +half3 CalculateSurfaceNormal(half3 position, half3 normal, half2 gradient, half2 uv) +{ + half3 dpdx = ddx(position); + half3 dpdy = ddy(position); + + half dhdx = dot(gradient, ddx(uv)); + half dhdy = dot(gradient, ddy(uv)); + + return PerturbNormal(normal, dpdx, dpdy, dhdx, dhdy); +} + +#ifndef UNITY_STANDARD_BRDF_INCLUDED +//----------------------------------------------------------------------------- +// Helper to convert smoothness to roughness +//----------------------------------------------------------------------------- + +half PerceptualRoughnessToRoughness(half perceptualRoughness) +{ + return perceptualRoughness * perceptualRoughness; +} + +half RoughnessToPerceptualRoughness(half roughness) +{ + return sqrt(roughness); +} + +// Smoothness is the user facing name +// it should be perceptualSmoothness but we don't want the user to have to deal with this name +half SmoothnessToRoughness(half smoothness) +{ + return (1 - smoothness) * (1 - smoothness); +} + +float SmoothnessToPerceptualRoughness(float smoothness) +{ + return (1 - smoothness); +} + +//------------------------------------------------------------------------------------- + +inline float3 Unity_SafeNormalize(float3 inVec) +{ + float dp3 = max(0.001f, dot(inVec, inVec)); + return inVec * rsqrt(dp3); +} +#endif // UNITY_STANDARD_BRDF_INCLUDED + +half3 TransformToTangentSpace(half3 tangent, half3 binormal, half3 normal, half3 v) +{ + // Mali400 shader compiler prefers explicit dot product over using a half3x3 matrix + return half3(dot(tangent, v), dot(binormal, v), dot(normal, v)); +} + +// R dither mask +float noiseR2(float2 pixel) { + const float a1 = 0.75487766624669276; + const float a2 = 0.569840290998; + return frac(a1 * float(pixel.x) + a2 * float(pixel.y)); +} + +// Uh... Unity? +#define LambertTerm(x,y) dot(x,y) + +//------------------------------------------------------------------------------------- + +float remap_almostIdentity( float x, float m, float n ) +{ + if( x>m ) return x; + const float a = 2.0*n - m; + const float b = 2.0*m - 3.0*n; + const float t = x/m; + return (a*t + b)*t*t + n; +} + +//------------------------------------------------------------------------------------- +// Bakery utility functions +//------------------------------------------------------------------------------------- + +#ifdef USING_BAKERY_VERTEXLM +float4 unpack4NFloats(float src) +{ + return frac(float4(src / (262144.0*64), src / (4096.0*64), src / (64.0*64), src)); +} +float3 unpack3NFloats(float src) +{ + float r = frac(src); + float g = frac(src * 256.0); + float b = frac(src * 65536.0); + return float3(r, g, b); +} +#endif + +//------------------------------------------------------------------------------------- + +#endif // UNITY_STANDARD_UTILS_INCLUDED diff --git a/Assets/Filamented/UnityStandardUtils.cginc.meta b/Assets/Filamented/UnityStandardUtils.cginc.meta new file mode 100644 index 0000000..e50e171 --- /dev/null +++ b/Assets/Filamented/UnityStandardUtils.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 6e4b7f491e8ccad4f97d96ae867ed5fa +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/dfg-c.exr b/Assets/Filamented/dfg-c.exr new file mode 100644 index 0000000..ce3a47b Binary files /dev/null and b/Assets/Filamented/dfg-c.exr differ diff --git a/Assets/Filamented/dfg-c.exr.meta b/Assets/Filamented/dfg-c.exr.meta new file mode 100644 index 0000000..c869640 --- /dev/null +++ b/Assets/Filamented/dfg-c.exr.meta @@ -0,0 +1,127 @@ +fileFormatVersion: 2 +guid: 8bb11aba411074a45ba9b48cdabf4447 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 0 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 1 + swizzle: 50462976 + cookieLightType: 1 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 128 + resizeAlgorithm: 1 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/dfg-ms.exr b/Assets/Filamented/dfg-ms.exr new file mode 100644 index 0000000..7f7b8e3 Binary files /dev/null and b/Assets/Filamented/dfg-ms.exr differ diff --git a/Assets/Filamented/dfg-ms.exr.meta b/Assets/Filamented/dfg-ms.exr.meta new file mode 100644 index 0000000..e4a04ca --- /dev/null +++ b/Assets/Filamented/dfg-ms.exr.meta @@ -0,0 +1,116 @@ +fileFormatVersion: 2 +guid: b6b1f1fa6be1ce54f8bcd5428c160a28 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 0 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + applyGammaDecoding: 1 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 128 + resizeAlgorithm: 1 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 128 + resizeAlgorithm: 1 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 128 + resizeAlgorithm: 1 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Filamented/dfg-s.exr b/Assets/Filamented/dfg-s.exr new file mode 100644 index 0000000..1048da9 Binary files /dev/null and b/Assets/Filamented/dfg-s.exr differ diff --git a/Assets/Filamented/dfg-s.exr.meta b/Assets/Filamented/dfg-s.exr.meta new file mode 100644 index 0000000..9df63ee --- /dev/null +++ b/Assets/Filamented/dfg-s.exr.meta @@ -0,0 +1,116 @@ +fileFormatVersion: 2 +guid: 15666b1e4a43bd44ab4d0fde9f680eb1 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 2 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + applyGammaDecoding: 1 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/New Terrain.asset b/Assets/New Terrain.asset new file mode 100644 index 0000000..37e4cc9 Binary files /dev/null and b/Assets/New Terrain.asset differ diff --git a/Assets/New Terrain.asset.meta b/Assets/New Terrain.asset.meta new file mode 100644 index 0000000..3add6da --- /dev/null +++ b/Assets/New Terrain.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c18a975daaa61e0428328c1fb95a246d +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 15600000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NewBrush.brush b/Assets/NewBrush.brush new file mode 100644 index 0000000..46f955c --- /dev/null +++ b/Assets/NewBrush.brush @@ -0,0 +1,43 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 12146, guid: 0000000000000000e000000000000000, type: 0} + m_Name: NewBrush + m_EditorClassIdentifier: + m_Mask: {fileID: 2800000, guid: e696aba64d826ce458a4773d6869d24d, type: 3} + m_Falloff: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: -0.0082034655 + outSlope: -0.0082034655 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0.2875 + - serializedVersion: 3 + time: 0.9958191 + value: 1 + inSlope: -0.0054955687 + outSlope: -0.0054955687 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.43095422 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + m_RadiusScale: 1.4849247 + m_BlackWhiteRemapMin: 0 + m_BlackWhiteRemapMax: 1 + m_InvertRemapRange: 0 diff --git a/Assets/NewBrush.brush.meta b/Assets/NewBrush.brush.meta new file mode 100644 index 0000000..80217b9 --- /dev/null +++ b/Assets/NewBrush.brush.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ee8db08e286a47d4e881193e62d75fa4 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NewLayer 1.terrainlayer b/Assets/NewLayer 1.terrainlayer new file mode 100644 index 0000000..520a5ec --- /dev/null +++ b/Assets/NewLayer 1.terrainlayer @@ -0,0 +1,22 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1953259897 &8574412962073106934 +TerrainLayer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: NewLayer 1 + m_DiffuseTexture: {fileID: 2800000, guid: c57e180f932d0d146871b6f26e370477, type: 3} + m_NormalMapTexture: {fileID: 2800000, guid: cd64ffe65058cdd41a6298847a386ed6, type: 3} + m_MaskMapTexture: {fileID: 0} + m_TileSize: {x: 5, y: 5} + m_TileOffset: {x: 0, y: 0} + m_Specular: {r: 0, g: 0, b: 0, a: 0} + m_Metallic: 0 + m_Smoothness: 0.533 + m_NormalScale: 1 + m_DiffuseRemapMin: {x: 0, y: 0, z: 0, w: 0} + m_DiffuseRemapMax: {x: 1, y: 1, z: 1, w: 1} + m_MaskMapRemapMin: {x: 0, y: 0, z: 0, w: 0} + m_MaskMapRemapMax: {x: 1, y: 1, z: 1, w: 1} diff --git a/Assets/NewLayer 1.terrainlayer.meta b/Assets/NewLayer 1.terrainlayer.meta new file mode 100644 index 0000000..ca6c34b --- /dev/null +++ b/Assets/NewLayer 1.terrainlayer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f2f1c8f84a5061543ba1228f88713373 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 8574412962073106934 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NewLayer.terrainlayer b/Assets/NewLayer.terrainlayer new file mode 100644 index 0000000..3c72a3e --- /dev/null +++ b/Assets/NewLayer.terrainlayer @@ -0,0 +1,22 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1953259897 &8574412962073106934 +TerrainLayer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: NewLayer + m_DiffuseTexture: {fileID: 2800000, guid: a9bb3ec0f95c8f2428b2e20934f10572, type: 3} + m_NormalMapTexture: {fileID: 2800000, guid: 2798ac84bc36710448d16a364454a983, type: 3} + m_MaskMapTexture: {fileID: 0} + m_TileSize: {x: 1, y: 1} + m_TileOffset: {x: 0, y: 0} + m_Specular: {r: 0, g: 0, b: 0, a: 0} + m_Metallic: 0 + m_Smoothness: 0 + m_NormalScale: 1 + m_DiffuseRemapMin: {x: 0, y: 0, z: 0, w: 0} + m_DiffuseRemapMax: {x: 1, y: 1, z: 1, w: 1} + m_MaskMapRemapMin: {x: 0, y: 0, z: 0, w: 0} + m_MaskMapRemapMax: {x: 1, y: 1, z: 1, w: 1} diff --git a/Assets/NewLayer.terrainlayer.meta b/Assets/NewLayer.terrainlayer.meta new file mode 100644 index 0000000..7b9f3bf --- /dev/null +++ b/Assets/NewLayer.terrainlayer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6d1d795c68b444244befc146ff7d3088 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 8574412962073106934 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PawHeightMap.png b/Assets/PawHeightMap.png new file mode 100644 index 0000000..2494120 Binary files /dev/null and b/Assets/PawHeightMap.png differ diff --git a/Assets/PawHeightMap.png.meta b/Assets/PawHeightMap.png.meta new file mode 100644 index 0000000..49d8169 --- /dev/null +++ b/Assets/PawHeightMap.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: e696aba64d826ce458a4773d6869d24d +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Silent Till_Small.png.meta b/Assets/Silent Till_Small.png.meta new file mode 100644 index 0000000..a5bec26 --- /dev/null +++ b/Assets/Silent Till_Small.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 854128c09b99ce94591c945860c34599 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Silly Home.unity b/Assets/Silly Home.unity index 5de21cc..874a10d 100644 --- a/Assets/Silly Home.unity +++ b/Assets/Silly Home.unity @@ -123,6 +123,309 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &143864352 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 143864356} + - component: {fileID: 143864355} + - component: {fileID: 143864354} + - component: {fileID: 143864353} + m_Layer: 0 + m_Name: Plane + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!64 &143864353 +MeshCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 143864352} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 5 + m_Convex: 0 + m_CookingOptions: 30 + m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &143864354 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 143864352} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 07c79a7d189201643b097576d74e86df, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &143864355 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 143864352} + m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &143864356 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 143864352} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0.9, z: 0} + m_LocalScale: {x: 250, y: 1, z: 250} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &330659345 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 330659349} + - component: {fileID: 330659348} + - component: {fileID: 330659347} + - component: {fileID: 330659346} + m_Layer: 0 + m_Name: Cube (1) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &330659346 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 330659345} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &330659347 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 330659345} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &330659348 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 330659345} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &330659349 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 330659345} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -7.9800024, y: 2.7872076, z: 204.90167} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &644214177 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 644214180} + - component: {fileID: 644214179} + - component: {fileID: 644214178} + m_Layer: 0 + m_Name: Terrain + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 2147483647 + m_IsActive: 1 +--- !u!154 &644214178 +TerrainCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 644214177} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 2 + m_TerrainData: {fileID: 15600000, guid: c18a975daaa61e0428328c1fb95a246d, type: 2} + m_EnableTreeColliders: 0 +--- !u!218 &644214179 +Terrain: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 644214177} + m_Enabled: 1 + serializedVersion: 6 + m_TerrainData: {fileID: 15600000, guid: c18a975daaa61e0428328c1fb95a246d, type: 2} + m_TreeDistance: 5000 + m_TreeBillboardDistance: 50 + m_TreeCrossFadeLength: 5 + m_TreeMaximumFullLODCount: 50 + m_DetailObjectDistance: 80 + m_DetailObjectDensity: 1 + m_HeightmapPixelError: 5 + m_SplatMapDistance: 1000 + m_HeightmapMaximumLOD: 0 + m_ShadowCastingMode: 2 + m_DrawHeightmap: 1 + m_DrawInstanced: 0 + m_DrawTreesAndFoliage: 1 + m_StaticShadowCaster: 0 + m_IgnoreQualitySettings: 0 + m_ReflectionProbeUsage: 1 + m_MaterialTemplate: {fileID: 10652, guid: 0000000000000000f000000000000000, type: 0} + m_BakeLightProbesForTrees: 1 + m_PreserveTreePrototypeLayers: 0 + m_DeringLightProbesForTrees: 1 + m_ReceiveGI: 1 + m_ScaleInLightmap: 0.0256 + m_LightmapParameters: {fileID: 15203, guid: 0000000000000000f000000000000000, type: 0} + m_GroupingID: 0 + m_RenderingLayerMask: 1 + m_AllowAutoConnect: 1 + m_EnableHeightmapRayTracing: 1 + m_EnableTreesAndDetailsRayTracing: 0 + m_TreeMotionVectorModeOverride: 3 +--- !u!4 &644214180 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 644214177} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -500, y: 0, z: -500} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &743971517 GameObject: m_ObjectHideFlags: 0 @@ -215,6 +518,225 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &895598040 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 100002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_Name + value: Avatar_Utility + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalPosition.x + value: -17.539045 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalPosition.y + value: 0.006728649 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalPosition.z + value: 220.8275 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: f950e9463c219da499826fbb7c22258c, type: 3} +--- !u!1 &1318567611 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1318567615} + - component: {fileID: 1318567614} + - component: {fileID: 1318567613} + - component: {fileID: 1318567612} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &1318567612 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1318567611} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1318567613 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1318567611} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1318567614 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1318567611} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1318567615 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1318567611} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 4.88, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1325467763 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 100002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_Name + value: Avatar_Utility (1) + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalPosition.x + value: -155.73093 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalPosition.y + value: 6.061159 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalPosition.z + value: 56.586075 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: f950e9463c219da499826fbb7c22258c, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: f950e9463c219da499826fbb7c22258c, type: 3} --- !u!1 &2105906646 GameObject: m_ObjectHideFlags: 0 @@ -315,3 +837,9 @@ SceneRoots: m_Roots: - {fileID: 743971520} - {fileID: 2105906648} + - {fileID: 644214180} + - {fileID: 1318567615} + - {fileID: 330659349} + - {fileID: 895598040} + - {fileID: 143864356} + - {fileID: 1325467763} diff --git a/Assets/ground_0009_1k_ReJG9N(2).meta b/Assets/ground_0009_1k_ReJG9N(2).meta new file mode 100644 index 0000000..c8669d6 --- /dev/null +++ b/Assets/ground_0009_1k_ReJG9N(2).meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7aca7f28dd5fa4442a7fbd9ac861bf7c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX.meta b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX.meta new file mode 100644 index 0000000..b8ce928 --- /dev/null +++ b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5599abcaa07075d49bb0409d0dde07de +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_ao_1k.jpg b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_ao_1k.jpg new file mode 100644 index 0000000..869dd69 Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_ao_1k.jpg differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_color_1k.jpg b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_color_1k.jpg new file mode 100644 index 0000000..bcd23b6 Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_color_1k.jpg differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_height_1k.png b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_height_1k.png new file mode 100644 index 0000000..fcf96de Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_height_1k.png differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_normal_directx_1k.png b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_normal_directx_1k.png new file mode 100644 index 0000000..fb646bf Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_normal_directx_1k.png differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_normal_opengl_1k.png b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_normal_opengl_1k.png new file mode 100644 index 0000000..aa79ea0 Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_normal_opengl_1k.png differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_roughness_1k.jpg b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_roughness_1k.jpg new file mode 100644 index 0000000..0f8dda3 Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/__MACOSX/._ground_0009_roughness_1k.jpg differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_ao_1k.jpg b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_ao_1k.jpg new file mode 100644 index 0000000..d384f4d Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_ao_1k.jpg differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_ao_1k.jpg.meta b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_ao_1k.jpg.meta new file mode 100644 index 0000000..8c167e5 --- /dev/null +++ b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_ao_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: de5cf241f2c58454da1fe0443bee959f +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_color_1k.jpg b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_color_1k.jpg new file mode 100644 index 0000000..1d69817 Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_color_1k.jpg differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_color_1k.jpg.meta b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_color_1k.jpg.meta new file mode 100644 index 0000000..31e6f64 --- /dev/null +++ b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_color_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: a9bb3ec0f95c8f2428b2e20934f10572 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_height_1k.png b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_height_1k.png new file mode 100644 index 0000000..159f84d Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_height_1k.png differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_height_1k.png.meta b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_height_1k.png.meta new file mode 100644 index 0000000..a52afb4 --- /dev/null +++ b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_height_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 923563f2dea8af84999be74dcfc38df4 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_directx_1k.png b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_directx_1k.png new file mode 100644 index 0000000..6456106 Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_directx_1k.png differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_directx_1k.png.meta b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_directx_1k.png.meta new file mode 100644 index 0000000..81e2b6c --- /dev/null +++ b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_directx_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 5fa0094295ff857448377641cabd562e +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_opengl_1k.png b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_opengl_1k.png new file mode 100644 index 0000000..58950d0 Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_opengl_1k.png differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_opengl_1k.png.meta b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_opengl_1k.png.meta new file mode 100644 index 0000000..f75e33d --- /dev/null +++ b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_normal_opengl_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 2798ac84bc36710448d16a364454a983 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 1 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_roughness_1k.jpg b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_roughness_1k.jpg new file mode 100644 index 0000000..aa10543 Binary files /dev/null and b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_roughness_1k.jpg differ diff --git a/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_roughness_1k.jpg.meta b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_roughness_1k.jpg.meta new file mode 100644 index 0000000..4a40441 --- /dev/null +++ b/Assets/ground_0009_1k_ReJG9N(2)/ground_0009_roughness_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: d20fd551c0ad58c42bbec3ec7c21a929 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8.meta b/Assets/ground_0043_1k_jtamM8.meta new file mode 100644 index 0000000..d8dc56e --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 550f5ec1b56c1e646af380ca6549e895 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_ao_1k.jpg b/Assets/ground_0043_1k_jtamM8/ground_0043_ao_1k.jpg new file mode 100644 index 0000000..006c1b8 Binary files /dev/null and b/Assets/ground_0043_1k_jtamM8/ground_0043_ao_1k.jpg differ diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_ao_1k.jpg.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_ao_1k.jpg.meta new file mode 100644 index 0000000..5e6edaa --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_ao_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: ce2faad59b551294e8947faafae5bd9d +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_color_1k.jpg b/Assets/ground_0043_1k_jtamM8/ground_0043_color_1k.jpg new file mode 100644 index 0000000..722fc56 Binary files /dev/null and b/Assets/ground_0043_1k_jtamM8/ground_0043_color_1k.jpg differ diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_color_1k.jpg.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_color_1k.jpg.meta new file mode 100644 index 0000000..d5fbff4 --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_color_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: c57e180f932d0d146871b6f26e370477 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_description.txt b/Assets/ground_0043_1k_jtamM8/ground_0043_description.txt new file mode 100644 index 0000000..58603f5 --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_description.txt @@ -0,0 +1,10 @@ +Name: +Sand Dunes (Ground 0043) + +Description: +This is a sandy ground with a lot of dunes. + +If you are texturing a desert, it is the go-to material. + +Author: +https://www.texturecan.com \ No newline at end of file diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_description.txt.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_description.txt.meta new file mode 100644 index 0000000..96ab106 --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_description.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: baa1a4af078ce0847a25896958a0c40a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_height_1k.png b/Assets/ground_0043_1k_jtamM8/ground_0043_height_1k.png new file mode 100644 index 0000000..482dc75 Binary files /dev/null and b/Assets/ground_0043_1k_jtamM8/ground_0043_height_1k.png differ diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_height_1k.png.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_height_1k.png.meta new file mode 100644 index 0000000..0fa5f8d --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_height_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 220ec1ef2f3459f41aa34f977201f82f +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_keywords.txt b/Assets/ground_0043_1k_jtamM8/ground_0043_keywords.txt new file mode 100644 index 0000000..14a7c7f --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_keywords.txt @@ -0,0 +1 @@ +Sand, Dune, Ground, Yellow, Sandy, Desert \ No newline at end of file diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_keywords.txt.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_keywords.txt.meta new file mode 100644 index 0000000..a6e3527 --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_keywords.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 68fdb7180448909409e46697ec88578e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_normal_directx_1k.png b/Assets/ground_0043_1k_jtamM8/ground_0043_normal_directx_1k.png new file mode 100644 index 0000000..7f3bdb6 Binary files /dev/null and b/Assets/ground_0043_1k_jtamM8/ground_0043_normal_directx_1k.png differ diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_normal_directx_1k.png.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_normal_directx_1k.png.meta new file mode 100644 index 0000000..856540e --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_normal_directx_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 6b0673266cabdd64a8c6506541f9589a +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_normal_opengl_1k.png b/Assets/ground_0043_1k_jtamM8/ground_0043_normal_opengl_1k.png new file mode 100644 index 0000000..3f99f30 Binary files /dev/null and b/Assets/ground_0043_1k_jtamM8/ground_0043_normal_opengl_1k.png differ diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_normal_opengl_1k.png.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_normal_opengl_1k.png.meta new file mode 100644 index 0000000..bb536ae --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_normal_opengl_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: cd64ffe65058cdd41a6298847a386ed6 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 1 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_preview.jpg b/Assets/ground_0043_1k_jtamM8/ground_0043_preview.jpg new file mode 100644 index 0000000..eac34f1 Binary files /dev/null and b/Assets/ground_0043_1k_jtamM8/ground_0043_preview.jpg differ diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_preview.jpg.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_preview.jpg.meta new file mode 100644 index 0000000..bda14e0 --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_preview.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 10e7bb0cce1a7684fbca8c9a2f0531f0 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_roughness_1k.jpg b/Assets/ground_0043_1k_jtamM8/ground_0043_roughness_1k.jpg new file mode 100644 index 0000000..aa81ee5 Binary files /dev/null and b/Assets/ground_0043_1k_jtamM8/ground_0043_roughness_1k.jpg differ diff --git a/Assets/ground_0043_1k_jtamM8/ground_0043_roughness_1k.jpg.meta b/Assets/ground_0043_1k_jtamM8/ground_0043_roughness_1k.jpg.meta new file mode 100644 index 0000000..226da47 --- /dev/null +++ b/Assets/ground_0043_1k_jtamM8/ground_0043_roughness_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 1587ac0eb55ead34b821bf8890e25710 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH.meta b/Assets/others_0020_1k_wSx9VH.meta new file mode 100644 index 0000000..53a4cbe --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 983d98a1165b0ee4aa7240836fec3a87 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH/Water.mat b/Assets/others_0020_1k_wSx9VH/Water.mat new file mode 100644 index 0000000..5494881 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/Water.mat @@ -0,0 +1,135 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Water + m_Shader: {fileID: 4800000, guid: 075dbc3edcecd8747919086245d79325, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: + - _ALPHAPREMULTIPLY_ON + - _LIGHTMAPSPECULAR + - _NORMALMAP + - _PARALLAXMAP + m_InvalidKeywords: + - _BAKERY_NONE + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 2800000, guid: c3da5382652d2564180166bb42a22127, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DFG: + m_Texture: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 2, y: 2} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 200, y: 200} + m_Offset: {x: 0, y: 0} + - _MOESMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 2800000, guid: e722003505eb0e44caab6b336ded700e, type: 3} + m_Scale: {x: 200, y: 200} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 2800000, guid: 741868f3285c73042aa10ed614740f2f, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RNM0: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RNM1: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RNM2: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AlphaToMaskMode: 0 + - _Bakery: 0 + - _BakeryVertexLM: 0 + - _BumpScale: 1 + - _BumpShadowHardness: 50 + - _BumpShadowHeightScale: 0.2 + - _CullMode: 2 + - _Cutoff: 0.476 + - _DetailNormalMapScale: 1 + - _DstBlend: 10 + - _Emission: 0 + - _ExposureOcclusion: 0.2 + - _GlossMapScale: 1 + - _Glossiness: 0 + - _GlossyReflections: 1 + - _IOR: 1.5 + - _LTCGI: 0 + - _LightmapSpecular: 1 + - _LightmapSpecularMaxSmoothness: 0.9 + - _Metallic: 0 + - _MetallicScale: 0 + - _Mode: 3 + - _NormalMapShadows: 0 + - _OcclusionScale: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.25 + - _SmoothnessScale: 0 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _Transmission: 1 + - _UVSec: 0 + - _VRCLV: 0 + - _VRCLVSurfaceBias: 0.05 + - _ZWrite: 0 + - _specularAntiAliasingThreshold: 0.25 + - _specularAntiAliasingVariance: 0.15 + m_Colors: + - _Absorption: {r: 0, g: 0, b: 0, a: 0} + - _Color: {r: 1, g: 1, b: 1, a: 0.6392157} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SpecColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/others_0020_1k_wSx9VH/Water.mat.meta b/Assets/others_0020_1k_wSx9VH/Water.mat.meta new file mode 100644 index 0000000..7daf4f7 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/Water.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 07c79a7d189201643b097576d74e86df +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH/__MACOSX.meta b/Assets/others_0020_1k_wSx9VH/__MACOSX.meta new file mode 100644 index 0000000..dcd4574 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/__MACOSX.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ad9095e5778706b4da8efa9371fa0e38 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_ao_1k.jpg b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_ao_1k.jpg new file mode 100644 index 0000000..a5d2f4a Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_ao_1k.jpg differ diff --git a/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_color_1k.jpg b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_color_1k.jpg new file mode 100644 index 0000000..002a68e Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_color_1k.jpg differ diff --git a/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_height_1k.png b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_height_1k.png new file mode 100644 index 0000000..6e8079a Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_height_1k.png differ diff --git a/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_normal_directx_1k.png b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_normal_directx_1k.png new file mode 100644 index 0000000..d4690ee Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_normal_directx_1k.png differ diff --git a/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_normal_opengl_1k.png b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_normal_opengl_1k.png new file mode 100644 index 0000000..e19b8ef Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_normal_opengl_1k.png differ diff --git a/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_roughness_1k.jpg b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_roughness_1k.jpg new file mode 100644 index 0000000..1d91952 Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/__MACOSX/._others_0020_roughness_1k.jpg differ diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_ao_1k.jpg b/Assets/others_0020_1k_wSx9VH/others_0020_ao_1k.jpg new file mode 100644 index 0000000..7d33f2a Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/others_0020_ao_1k.jpg differ diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_ao_1k.jpg.meta b/Assets/others_0020_1k_wSx9VH/others_0020_ao_1k.jpg.meta new file mode 100644 index 0000000..3d01700 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/others_0020_ao_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: d71fc4d0d70773448a6d4fb898e7de64 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_color_1k.jpg b/Assets/others_0020_1k_wSx9VH/others_0020_color_1k.jpg new file mode 100644 index 0000000..a1321c5 Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/others_0020_color_1k.jpg differ diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_color_1k.jpg.meta b/Assets/others_0020_1k_wSx9VH/others_0020_color_1k.jpg.meta new file mode 100644 index 0000000..0ff7874 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/others_0020_color_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: e722003505eb0e44caab6b336ded700e +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_height_1k.png b/Assets/others_0020_1k_wSx9VH/others_0020_height_1k.png new file mode 100644 index 0000000..ac1905e Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/others_0020_height_1k.png differ diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_height_1k.png.meta b/Assets/others_0020_1k_wSx9VH/others_0020_height_1k.png.meta new file mode 100644 index 0000000..494b497 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/others_0020_height_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 741868f3285c73042aa10ed614740f2f +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_normal_directx_1k.png b/Assets/others_0020_1k_wSx9VH/others_0020_normal_directx_1k.png new file mode 100644 index 0000000..7ac2586 Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/others_0020_normal_directx_1k.png differ diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_normal_directx_1k.png.meta b/Assets/others_0020_1k_wSx9VH/others_0020_normal_directx_1k.png.meta new file mode 100644 index 0000000..07aba90 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/others_0020_normal_directx_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 041dc237549ff9f4197551fe589218f5 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_normal_opengl_1k.png b/Assets/others_0020_1k_wSx9VH/others_0020_normal_opengl_1k.png new file mode 100644 index 0000000..cf8d687 Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/others_0020_normal_opengl_1k.png differ diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_normal_opengl_1k.png.meta b/Assets/others_0020_1k_wSx9VH/others_0020_normal_opengl_1k.png.meta new file mode 100644 index 0000000..6affc70 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/others_0020_normal_opengl_1k.png.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: c3da5382652d2564180166bb42a22127 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 1 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_roughness_1k.jpg b/Assets/others_0020_1k_wSx9VH/others_0020_roughness_1k.jpg new file mode 100644 index 0000000..64f6358 Binary files /dev/null and b/Assets/others_0020_1k_wSx9VH/others_0020_roughness_1k.jpg differ diff --git a/Assets/others_0020_1k_wSx9VH/others_0020_roughness_1k.jpg.meta b/Assets/others_0020_1k_wSx9VH/others_0020_roughness_1k.jpg.meta new file mode 100644 index 0000000..335e974 --- /dev/null +++ b/Assets/others_0020_1k_wSx9VH/others_0020_roughness_1k.jpg.meta @@ -0,0 +1,140 @@ +fileFormatVersion: 2 +guid: 101db4ae9d8a70044938e165ad97e994 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: