This commit is contained in:
左右看
2023-06-28 00:35:46 +08:00
parent cb5bab5ce9
commit 0d848e4d07
524 changed files with 78452 additions and 12 deletions
@@ -0,0 +1,70 @@
Shader "Hidden/MetalGlossChannelSwap"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_SmoothnessMultiplier ("Smoothness Multiplier", float) = 1
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float _SmoothnessMultiplier;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// From the GLTF 2.0 spec
// The metallic-roughness texture. The metalness values are sampled from the B channel.
// The roughness values are sampled from the G channel. These values are linear.
// If other channels are present (R or A), they are ignored for metallic-roughness calculations.
//
// Unity, by default, puts metallic in R channel and glossiness in A channel.
// Unity uses a metallic-gloss texture so we need to invert the value in the g channel.
//
// Conversion Summary
// Unity R channel goes into B channel
// Unity A channel goes into G channel, then inverted
float4 result = float4(0, 1 - (col.a * _SmoothnessMultiplier), col.r, 1);
#ifdef UNITY_COLORSPACE_GAMMA
#else
// hack for linear color space, need to figure out
// right way to sample textures.
result.xyz = GammaToLinearSpace(result.xyz);
#endif
return result;
}
ENDCG
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 200d9689f5dda4633867345ba978a8dd
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,66 @@
Shader "Hidden/NormalChannel"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
// fixed4 frag (v2f i) : SV_Target
// {
// float4 col = tex2D(_MainTex, i.uv);
// float4 res = float4(col.a, col.g, 1, 1);
// //res = float4(0.5,0.5,1,1);
// //res.xyz = GammaToLinearSpaceExact(res.xyz);
// // If a texture is marked as a normal map
// // the values are stored in the A and G channel.
// return res;
// }
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// If a texture is marked as a normal map
// the values are stored in the A and G channel.
float3 unpacked = UnpackNormal(col);
float4 result = float4(unpacked * 0.5f + 0.5f, 1);
return result;
}
ENDCG
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 12e0e6f24241d4f38811bfce257ae65d
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,23 @@
Notes on Standard (Specular setup).mat and Standard (Specular setup).shadervariants
-----------------------------------------------------------------------------------
The Unity Standard and Standard (Specular setup) shaders have some extra requirements if you want to modify Materials at runtime, because - behind the scenes - it is actually many different shaders rolled into one. If you use scripting to change a Material that would cause it to use a different variant of the Standard Shader, you must enable that variant by using the Material.EnableKeyword function.
When you use Material.EnableKeyword at runtime, the editor will compile the respective shader variant on the fly, so you will see the correct shading displayed.
When you build a standalone player however, Unity will only compile the shaders that are referenced by objects in your scene. So in case you don't already have a material either in your Scene or in the Resources folder that uses a particular shader variant, your code will call for a shader that hasn't been compiled and you'll see incorrect shading.
GLTFSceneImporter.cs makes heavy use of Material.EnableKeyword, since based on the data in the GLTF file, different features like normal maps, emmission, or alpha modes must be turned on or off in the shader at runtime. The nature of building an importer that can load *any* GLTF file that is unknown at compile-time means that we cannot anticipate which shader features will be used, and therefore must enable the variants manually.
This can be done in one of 2 ways:
1. Through the use of the ShaderVariantCollection (and add the keywords you need)
2. By adding a material to the Assets/Resources folder (and add textures to the texture fields, change Colors to be anything other than black, and change floats to anything other than 0 -you don't need to use the material on anything because as long as it's in the Resources folder Unity will presume it's going to be needed)
Both methods will cause the compiler to deliver the necessary shader variants for the standalone player.
Links:
------
https://docs.unity3d.com/Manual/MaterialsAccessingViaScript.html
https://docs.unity3d.com/ScriptReference/ShaderVariantCollection.html
https://docs.unity3d.com/ScriptReference/Material.EnableKeyword.html
http://answers.unity3d.com/questions/970290/emission-at-run-time-works-in-editor-but-not-in-bu.html
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f3bf00dab702a054fb2572323e59feff
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,83 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Standard (Specular setup)
m_Shader: {fileID: 45, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _EMISSION _SPECGLOSSMAP
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 250d45d62e6ce1c48a49ed3015b523eb
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!200 &20000000
ShaderVariantCollection:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Standard (Specular setup)
m_Shaders:
- first: {fileID: 45, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: DIRECTIONAL _ALPHATEST_ON _EMISSION _NORMALMAP _SPECGLOSSMAP
passType: 4
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ad96276ecf34f304cae080332f7f9051
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 20000000
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,313 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1002552911756402
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4053236427204222}
- component: {fileID: 114843937143698750}
- component: {fileID: 1294434418350029168}
m_Layer: 0
m_Name: GLTF
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4053236427204222
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1002552911756402}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4225727463385260}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &114843937143698750
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1002552911756402}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9087a95f22bcee64ebc45f6deec08714, type: 3}
m_Name:
m_EditorClassIdentifier:
GLTFUri:
Multithreaded: 0
UseStream: 1
AppendStreamingAssets: 0
PlayAnimationOnLoad: 1
Factory: {fileID: 0}
loadOnStart: 0
MaterialsOnly: 0
RetryCount: 10
RetryTimeout: 2
MaximumLod: 300
Timeout: 8
Collider: 0
shaderOverride: {fileID: 0}
--- !u!215 &1294434418350029168
ReflectionProbe:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1002552911756402}
m_Enabled: 1
serializedVersion: 2
m_Type: 0
m_Mode: 1
m_RefreshMode: 0
m_TimeSlicingMode: 0
m_Resolution: 128
m_UpdateFrequency: 0
m_BoxSize: {x: 10, y: 10, z: 10}
m_BoxOffset: {x: 0, y: 0, z: 0}
m_NearClip: 0.1
m_FarClip: 1000
m_ShadowDistance: 100
m_ClearFlags: 1
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0}
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_IntensityMultiplier: 0.4
m_BlendDistance: 1
m_HDR: 1
m_BoxProjection: 0
m_RenderDynamicObjects: 0
m_UseOcclusionCulling: 1
m_Importance: 1
m_CustomBakedTexture: {fileID: 0}
--- !u!1 &1034827199715104
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4225727463385260}
- component: {fileID: 45916004938725370}
m_Layer: 0
m_Name: TestScenePrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4225727463385260
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1034827199715104}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4095513381898270}
- {fileID: 4053236427204222}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!45 &45916004938725370
Skybox:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1034827199715104}
m_Enabled: 1
m_CustomSkybox: {fileID: 2100000, guid: b4101f3a635a9cd4187c92cf274d68ce, type: 2}
--- !u!1 &1191679913451980
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4698259391897058}
- component: {fileID: 108668277531277172}
m_Layer: 0
m_Name: Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &4698259391897058
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1191679913451980}
m_LocalRotation: {x: 0.2588191, y: 0, z: 0, w: 0.9659258}
m_LocalPosition: {x: 0, y: 5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4095513381898270}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 30, y: 0, z: 0}
--- !u!108 &108668277531277172
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1191679913451980}
m_Enabled: 1
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10
m_Shadows:
m_Type: 0
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &1478240168550960
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4095513381898270}
- component: {fileID: 20961921853974160}
- component: {fileID: 3629069418977858857}
m_Layer: 0
m_Name: Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4095513381898270
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1478240168550960}
m_LocalRotation: {x: -0, y: 1, z: -0, w: -0.000000063325004}
m_LocalPosition: {x: 0, y: 0, z: 1.3}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4698259391897058}
m_Father: {fileID: 4225727463385260}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &20961921853974160
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1478240168550960}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 1, g: 1, b: 1, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.1
far clip plane: 1000
field of view: 45.84
orthographic: 0
orthographic size: 100
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 0
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!45 &3629069418977858857
Skybox:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1478240168550960}
m_Enabled: 1
m_CustomSkybox: {fileID: 2100000, guid: ab1d3ce216922394fa9b7b0bcf303df6, type: 2}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 426ae0d14f1f31f48af072147ac6abe9
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: