Added terrain and basic terrain textures
This commit is contained in:
347
Assets/Filamented/Extras/FilamentedFractal.shader
Normal file
347
Assets/Filamented/Extras/FilamentedFractal.shader
Normal file
@ -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"
|
||||
}
|
||||
16
Assets/Filamented/Extras/FilamentedFractal.shader.meta
Normal file
16
Assets/Filamented/Extras/FilamentedFractal.shader.meta
Normal file
@ -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:
|
||||
397
Assets/Filamented/Extras/FilamentedGlinty.shader
Normal file
397
Assets/Filamented/Extras/FilamentedGlinty.shader
Normal file
@ -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"
|
||||
}
|
||||
16
Assets/Filamented/Extras/FilamentedGlinty.shader.meta
Normal file
16
Assets/Filamented/Extras/FilamentedGlinty.shader.meta
Normal file
@ -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:
|
||||
468
Assets/Filamented/Extras/FilamentedMirrorTemplate.shader
Normal file
468
Assets/Filamented/Extras/FilamentedMirrorTemplate.shader
Normal file
@ -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"
|
||||
}
|
||||
@ -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:
|
||||
389
Assets/Filamented/Extras/FilamentedPaintingCanvas.shader
Normal file
389
Assets/Filamented/Extras/FilamentedPaintingCanvas.shader
Normal file
@ -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<n.y && n.x<n.z) ? int3(0,1,2) :
|
||||
(n.y<n.z) ? int3(1,2,0) :
|
||||
int3(2,0,1) ;
|
||||
// determine median axis (in x; yz are following axis)
|
||||
int3 me = clamp(3 - mi - ma, 0, 2);
|
||||
|
||||
// project+fetch
|
||||
float4 x = tex2Dgrad( sam, float2( p[ma.y], p[ma.z]),
|
||||
float2(dpdx[ma.y],dpdx[ma.z]),
|
||||
float2(dpdy[ma.y],dpdy[ma.z]) );
|
||||
float4 y = tex2Dgrad( sam, float2( p[me.y], p[me.z]),
|
||||
float2(dpdx[me.y],dpdx[me.z]),
|
||||
float2(dpdy[me.y],dpdy[me.z]) );
|
||||
|
||||
// blend factors
|
||||
float2 w = float2(n[ma.x],n[me.x]);
|
||||
// make local support
|
||||
w = clamp( (w-0.5773)/(1.0-0.5773), 0.0, 1.0 );
|
||||
// shape transition
|
||||
w = pow( w, k/8.0 );
|
||||
// blend and return
|
||||
return (x*w.x + y*w.y) / (w.x + w.y);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Sample the UVs for the canvas bumps first. These are applied to the
|
||||
// surface normal, but also the texture sampling.
|
||||
float3x3 tangentToWorldOnly = float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz);
|
||||
float3 normal = mul ( float3( 0, 0, 1 ), tangentToWorldOnly );
|
||||
half3 normalTangent = UnpackScaleNormal(biplanar(_BumpMap, i_posWorld * _BumpSize, normal, 1.0), _BumpScale);
|
||||
half4 packedMap = biplanar (_MOESMap, i_posWorld * _BumpSize, normal, 1.0);
|
||||
|
||||
half4 baseColor = bicubicFilter (_MainTex, i_tex.xy + normalTangent * 0.01 * _BumpScaleWarp, _MainTex_TexelSize);
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "VertexLit"
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1fe9ddc772e6c846835192876484746
|
||||
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:
|
||||
410
Assets/Filamented/Extras/FilamentedSimpleRotation.shader
Normal file
410
Assets/Filamented/Extras/FilamentedSimpleRotation.shader
Normal file
@ -0,0 +1,410 @@
|
||||
Shader "Silent/Filamented Extras/Simple Rotate Filamented"
|
||||
{
|
||||
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)
|
||||
[IfDef(_ALPHATEST_ON)]_Cutoff("Alpha Cutoff", Range(0, 1)) = 0.5
|
||||
[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 Color", Color) = (1,1,1,1)
|
||||
[HeaderEx(Rotation Properties)]
|
||||
[ToggleUI]_MaskRotationByUV("Limit Rotation to Positive UV", Float) = 0
|
||||
_RotateSpeed("Rotation Speed", Float) = 0
|
||||
_RotationAxis("Rotation Axis", Vector) = (0, 0, 1, 0)
|
||||
_RotationOffset("Rotation Offset", Vector) = (0, 0, 0, 0)
|
||||
[ToggleUI]_RotationOffsetByWorldPos("Add Random Offset by World Position", 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
|
||||
// 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.
|
||||
#else
|
||||
#include "Packages/s-ilent.filamented/Filamented/UnityStandardShadow.cginc"
|
||||
#endif
|
||||
|
||||
uniform half _RotateSpeed;
|
||||
uniform half3 _RotationAxis;
|
||||
uniform half3 _RotationOffset;
|
||||
uniform float _MaskRotationByUV;
|
||||
uniform float _RotationOffsetByWorldPos;
|
||||
|
||||
// Vertex functions are called from UnityStandardCore/Shadow.
|
||||
// You can alter values here, or copy the function in and modify it.
|
||||
|
||||
float3x3 AngleAxis3x3(float angle, float3 axis)
|
||||
{
|
||||
float c, s;
|
||||
sincos(angle, s, c);
|
||||
|
||||
float t = 1 - c;
|
||||
float x = axis.x;
|
||||
float y = axis.y;
|
||||
float z = axis.z;
|
||||
|
||||
return float3x3(
|
||||
t * x * x + c, t * x * y - s * z, t * x * z + s * y,
|
||||
t * x * y + s * z, t * y * y + c, t * y * z - s * x,
|
||||
t * x * z - s * y, t * y * z + s * x, t * z * z + c
|
||||
);
|
||||
}
|
||||
|
||||
inline float hash13(float3 p3)
|
||||
{
|
||||
p3 = frac(p3 * 443.8975);
|
||||
p3 += dot(p3, p3.yzx + 19.19);
|
||||
return frac((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
inline void VertexCommon(inout VertexInput v)
|
||||
{
|
||||
bool shouldRotate = (!_MaskRotationByUV || v.uv0.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"
|
||||
}
|
||||
@ -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:
|
||||
359
Assets/Filamented/Extras/FilamentedTemplate.shader
Normal file
359
Assets/Filamented/Extras/FilamentedTemplate.shader
Normal file
@ -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"
|
||||
}
|
||||
13
Assets/Filamented/Extras/FilamentedTemplate.shader.meta
Normal file
13
Assets/Filamented/Extras/FilamentedTemplate.shader.meta
Normal file
@ -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:
|
||||
465
Assets/Filamented/Extras/FilamentedTemplateDetails.shader
Normal file
465
Assets/Filamented/Extras/FilamentedTemplateDetails.shader
Normal file
@ -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"
|
||||
}
|
||||
@ -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:
|
||||
349
Assets/Filamented/Extras/FilamentedTemplateRefraction.shader
Normal file
349
Assets/Filamented/Extras/FilamentedTemplateRefraction.shader
Normal file
@ -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"
|
||||
}
|
||||
@ -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:
|
||||
740
Assets/Filamented/Extras/FilamentedTemplateSelector.shader
Normal file
740
Assets/Filamented/Extras/FilamentedTemplateSelector.shader
Normal file
@ -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"
|
||||
}
|
||||
@ -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:
|
||||
371
Assets/Filamented/Extras/FilamentedTemplateVertexColor.shader
Normal file
371
Assets/Filamented/Extras/FilamentedTemplateVertexColor.shader
Normal file
@ -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"
|
||||
}
|
||||
@ -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:
|
||||
722
Assets/Filamented/Extras/FilamentedTextureBlending.shader
Normal file
722
Assets/Filamented/Extras/FilamentedTextureBlending.shader
Normal file
@ -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"
|
||||
}
|
||||
@ -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:
|
||||
432
Assets/Filamented/Extras/FilamentedTriplanar.shader
Normal file
432
Assets/Filamented/Extras/FilamentedTriplanar.shader
Normal file
@ -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<n.y && n.x<n.z) ? int3(0,1,2) :
|
||||
(n.y<n.z) ? int3(1,2,0) :
|
||||
int3(2,0,1) ;
|
||||
// determine median axis (in x; yz are following axis)
|
||||
int3 me = clamp(3 - mi - ma, 0, 2);
|
||||
|
||||
// project+fetch
|
||||
float4 x = tex2Dgrad( sam, float2( p[ma.y], p[ma.z]),
|
||||
float2(dpdx[ma.y],dpdx[ma.z]),
|
||||
float2(dpdy[ma.y],dpdy[ma.z]) );
|
||||
float4 y = tex2Dgrad( sam, float2( p[me.y], p[me.z]),
|
||||
float2(dpdx[me.y],dpdx[me.z]),
|
||||
float2(dpdy[me.y],dpdy[me.z]) );
|
||||
|
||||
// blend factors
|
||||
float2 w = float2(n[ma.x],n[me.x]);
|
||||
// make local support
|
||||
w = clamp( (w-0.5773)/(1.0-0.5773), 0.0, 1.0 );
|
||||
// shape transition
|
||||
w = pow( w, k/8.0 );
|
||||
// blend and return
|
||||
return (x*w.x + y*w.y) / (w.x + w.y);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
float3x3 tangentToWorldOnly = float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz);
|
||||
|
||||
float3 normal = mul ( float3( 0, 0, 1 ), tangentToWorldOnly );
|
||||
|
||||
//float2 x0 = i_posWorld.xz * _UVTransform1.xy + _UVTransform1.zw;
|
||||
//float2 y0 = i_posWorld.zy * _UVTransform0.xy + _UVTransform0.zw;
|
||||
//float2 z0 = i_posWorld.xy * _UVTransform2.xy + _UVTransform2.zw;
|
||||
|
||||
float3 transformedPos = float3(
|
||||
dot(float4(i_posWorld.xyz, 1), _UVTransform0),
|
||||
dot(float4(i_posWorld.xyz, 1), _UVTransform1),
|
||||
dot(float4(i_posWorld.xyz, 1), _UVTransform2)
|
||||
);
|
||||
|
||||
float4 baseColor = 0;
|
||||
fixed3 normalTangent = 0.0f;
|
||||
float4 packedMap = 0;
|
||||
|
||||
baseColor = biplanar( _MainTex, transformedPos, normal, 1.0) * _Color;
|
||||
normalTangent = UnpackScaleNormal(biplanar( _BumpMap, transformedPos, normal, 1.0), _BumpScale);
|
||||
packedMap = biplanar( _MOESMap, transformedPos, normal, 1.0);
|
||||
|
||||
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 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"
|
||||
}
|
||||
16
Assets/Filamented/Extras/FilamentedTriplanar.shader.meta
Normal file
16
Assets/Filamented/Extras/FilamentedTriplanar.shader.meta
Normal file
@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 044744ced35f660428c5b5f0477a6e1d
|
||||
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:
|
||||
404
Assets/Filamented/Extras/PixelFilamentedTemplate.shader
Normal file
404
Assets/Filamented/Extras/PixelFilamentedTemplate.shader
Normal file
@ -0,0 +1,404 @@
|
||||
/*
|
||||
Filamented Pixel Art is a shader designed for rendering PBR with pixel art.
|
||||
It uses the same techniques as my Pixel Standard shader, but adapted for
|
||||
Filamented.
|
||||
https://gitlab.com/s-ilent/pixelstandard
|
||||
*/
|
||||
Shader "Silent/Filamented Extras/Pixel Art Filamented"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[CheckDFGTexture]
|
||||
[BlendModeSelector(_SrcBlend, _DstBlend, _CustomRenderQueue, _ZWrite, _AtoCmode)] _Mode ("__mode", Float) = 0.0
|
||||
[Enum(UnityEngine.Rendering.CullMode)]_CullMode("Cull Mode", Int) = 2
|
||||
[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 Color", Color) = (1,1,1,1)
|
||||
[HeaderEx(Texture Animation)]
|
||||
[Toggle(_ANIMATED)] _Animated ("Texture Animation", Float) = 0
|
||||
[NoScaleOffset]_AnimationMainTex("Animated Albedo", 2DArray) = "white" {}
|
||||
[Enum(PingPong, 0, Linear, 1)]_AnimationMode("Animation Mode",Float) = 0
|
||||
_AnimationSpeed("Animation Speed", Float) = 1.0
|
||||
[HeaderEx(Animation)]
|
||||
[ToggleUI]_QuakeWater("Quake-style Distortion", Float) = 0
|
||||
|
||||
[HeaderEx(System)]
|
||||
[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]
|
||||
|
||||
[HideInInspector][Enum(UnityEngine.Rendering.BlendMode)]_SrcBlend ("__src", Float) = 1
|
||||
[HideInInspector][Enum(UnityEngine.Rendering.BlendMode)]_DstBlend ("__dst", Float) = 0
|
||||
[HideInInspector][Enum(Off,0,On,1)]_ZWrite ("__zw", Float) = 1
|
||||
[HideInInspector]_AtoCmode("Cutout Transparency", Float) = 0
|
||||
|
||||
[NonModifiableTextureData][HideInInspector] _DFG("DFG", 2D) = "white" {}
|
||||
}
|
||||
|
||||
CustomEditor "Silent.FilamentedExtras.Unity.FilamentedExtrasInspector"
|
||||
|
||||
CGINCLUDE
|
||||
#pragma shader_feature_local _ANIMATED
|
||||
|
||||
// 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 SKIP_UNITY_STANDARD_INPUT_DEFINES
|
||||
// If this is not defined, Unity Standard textures like _MainTex and _BumpMap
|
||||
// will be automatically defined.
|
||||
|
||||
#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"
|
||||
|
||||
uniform half4 _Color;
|
||||
uniform half _BumpScale;
|
||||
uniform half _MetallicScale;
|
||||
uniform half _OcclusionScale;
|
||||
uniform half _SmoothnessScale;
|
||||
uniform half _Emission;
|
||||
uniform half3 _EmissionColor;
|
||||
|
||||
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); half4 _MainTex_TexelSize;
|
||||
TEXTURE2D(_MOESMap); SAMPLER(sampler_MOESMap); half4 _MOESMap_TexelSize;
|
||||
TEXTURE2D(_BumpMap); SAMPLER(sampler_BumpMap); half4 _BumpMap_TexelSize;
|
||||
|
||||
half4 _MainTex_ST;
|
||||
|
||||
#if defined(_ANIMATED)
|
||||
TEXTURE2D_ARRAY(_AnimationMainTex); SAMPLER(sampler_AnimationMainTex); half4 _AnimationMainTex_TexelSize;
|
||||
TEXTURE2D_ARRAY(_AnimationMOESMap); SAMPLER(sampler_AnimationMOESMap); half4 _AnimationMOESMap_TexelSize;
|
||||
TEXTURE2D_ARRAY(_AnimationBumpMap); SAMPLER(sampler_AnimationBumpMap); half4 _AnimationBumpMap_TexelSize;
|
||||
uniform fixed _AnimationMode;
|
||||
uniform float _AnimationSpeed;
|
||||
#endif
|
||||
|
||||
uniform fixed _QuakeWater;
|
||||
|
||||
// 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); }
|
||||
|
||||
// Returns pixel sharpened to nearest pixel boundary.
|
||||
// texSize is Unity _Texture_TexelSize; zw is w/h, xy is 1/wh
|
||||
float2 sharpSample2( float4 texSize , float2 coord )
|
||||
{
|
||||
float2 boxSize = clamp(fwidth(coord) * texSize.zw, 1e-5, 1.0);
|
||||
coord = coord * texSize.zw - 0.5 * boxSize;
|
||||
float2 txOffset = smoothstep(1.0 - boxSize, 1.0, frac(coord));
|
||||
return (floor(coord) + 0.5 + txOffset) * texSize.xy;
|
||||
}
|
||||
|
||||
float4 SampleTexture2DPixelFiltering(TEXTURE2D_PARAM(tex, smp), float2 coord, float4 texSize)
|
||||
{
|
||||
float2 boxSize = clamp(fwidth(coord) * texSize.zw, 1e-5, 1);
|
||||
coord = coord * texSize.zw - 0.5 * boxSize;
|
||||
float2 txOffset = smoothstep(1 - boxSize, 1, frac(coord));
|
||||
coord = (floor(coord) + 0.5 + txOffset) * texSize.xy;
|
||||
|
||||
return SAMPLE_TEXTURE2D_GRAD(tex, smp, coord, ddx(coord), ddy(coord));
|
||||
}
|
||||
|
||||
float4 SampleTexture2DArrayPixelFiltering(TEXTURE2D_ARRAY_PARAM(tex, smp), float2 coord, float4 texSize, float index)
|
||||
{
|
||||
float2 boxSize = clamp(fwidth(coord) * texSize.zw, 1e-5, 1);
|
||||
coord = coord * texSize.zw - 0.5 * boxSize;
|
||||
float2 txOffset = smoothstep(1 - boxSize, 1, frac(coord));
|
||||
coord = (floor(coord) + 0.5 + txOffset) * texSize.xy;
|
||||
|
||||
return SAMPLE_TEXTURE2D_ARRAY_GRAD(tex, smp, coord, index, ddx(coord), ddy(coord));
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
i_tex.xy = i_tex * _MainTex_ST.xy + _MainTex_ST.zw;
|
||||
// Animation stuff first.
|
||||
if (_QuakeWater)
|
||||
{
|
||||
i_tex.xy += float2(sin(_Time.y + i_tex.y * UNITY_PI),cos(_Time.y + i_tex.x * UNITY_PI)) * 0.1;
|
||||
}
|
||||
|
||||
// Sample with derivatives to avoid artifacts.
|
||||
half4 baseColor = SampleTexture2DPixelFiltering(TEXTURE2D_ARGS(_MainTex, sampler_MainTex), i_tex.xy, _MainTex_TexelSize);
|
||||
half4 packedMap = SampleTexture2DPixelFiltering(TEXTURE2D_ARGS(_MOESMap, sampler_MOESMap), i_tex.xy, _MOESMap_TexelSize);
|
||||
half3 normalTangent = UnpackScaleNormal(SampleTexture2DPixelFiltering(TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), i_tex.xy, _BumpMap_TexelSize), _BumpScale);
|
||||
|
||||
#if defined(_ANIMATED)
|
||||
uint width, height, elements;
|
||||
_AnimationMainTex.GetDimensions(width, height, elements);
|
||||
float tex_index = 0;
|
||||
|
||||
switch (_AnimationMode) {
|
||||
case 0:
|
||||
float t = _Time.y * _AnimationSpeed;
|
||||
float phase = floor(t); // separate the integer part
|
||||
t = frac(t); // fractional part of time, in [0, 1)
|
||||
t = phase % 2 < 1 ? t : 1 - t; // reverse time every other cycle
|
||||
tex_index = t * (elements - 1);
|
||||
break;
|
||||
case 1:
|
||||
tex_index = floor(frac(_Time.y * _AnimationSpeed) * elements);
|
||||
break;
|
||||
}
|
||||
|
||||
baseColor = SampleTexture2DArrayPixelFiltering(TEXTURE2D_ARRAY_ARGS(_AnimationMainTex, sampler_AnimationMainTex), i_tex.xy, _AnimationMainTex_TexelSize, tex_index );
|
||||
#endif
|
||||
|
||||
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 * _Color;
|
||||
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 [_SrcBlend] 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FallBack "VertexLit"
|
||||
}
|
||||
17
Assets/Filamented/Extras/PixelFilamentedTemplate.shader.meta
Normal file
17
Assets/Filamented/Extras/PixelFilamentedTemplate.shader.meta
Normal file
@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dfcee83c1697d34db26ab4c73ff85d1
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures:
|
||||
- _MainTex: {instanceID: 0}
|
||||
- _BumpMap: {instanceID: 0}
|
||||
- _MOESMap: {instanceID: 0}
|
||||
- _AnimationMainTex: {instanceID: 0}
|
||||
- _RNM0: {instanceID: 0}
|
||||
- _RNM1: {instanceID: 0}
|
||||
- _RNM2: {instanceID: 0}
|
||||
nonModifiableTextures:
|
||||
- _DFG: {fileID: 2800000, guid: b6b1f1fa6be1ce54f8bcd5428c160a28, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user