提交 743f7360 编写于 作者: timchen1002's avatar timchen1002

update

上级 d54970e1
......@@ -36,7 +36,7 @@
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
</PropertyGroup>
<ItemGroup>
<Compile Include="Assets\Scripts\Editor\CustomShaderGUI.cs" />
<Compile Include="Assets\Custom RP\Editor\CustomShaderGUI.cs" />
<Reference Include="UnityEngine">
<HintPath>F:/Unity/2021.1.16f1c1/Editor/Data/Managed/UnityEngine/UnityEngine.dll</HintPath>
</Reference>
......
......@@ -36,31 +36,31 @@
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
</PropertyGroup>
<ItemGroup>
<Compile Include="Assets\Scripts\Runtime\ShadowSettings.cs" />
<Compile Include="Assets\Scripts\Examples\MeshBall.cs" />
<Compile Include="Assets\Scripts\Runtime\CustomRenderPipeline.cs" />
<Compile Include="Assets\Scripts\Runtime\Lighting.cs" />
<Compile Include="Assets\Scripts\Runtime\CameraRenderer.Editor.cs" />
<Compile Include="Assets\Scripts\Runtime\CustomRenderPipelineAsset.cs" />
<Compile Include="Assets\Scripts\Runtime\Shadows.cs" />
<Compile Include="Assets\Scripts\Runtime\CameraRenderer.cs" />
<Compile Include="Assets\Scripts\Examples\PerObjectMaterialProperties.cs" />
<None Include="Assets\ShaderLibrary\Light.hlsl" />
<None Include="Assets\Shaders\UnlitInput.hlsl" />
<None Include="Assets\ShaderLibrary\UnityInput.hlsl" />
<None Include="Assets\ShaderLibrary\Lighting.hlsl" />
<None Include="Assets\ShaderLibrary\GI.hlsl" />
<None Include="Assets\ShaderLibrary\Shadows.hlsl" />
<None Include="Assets\Shaders\Lit.shader" />
<None Include="Assets\Shaders\UnlitPass.hlsl" />
<None Include="Assets\Shaders\LitInput.hlsl" />
<None Include="Assets\Shaders\Unlit.shader" />
<None Include="Assets\Shaders\LitPass.hlsl" />
<None Include="Assets\ShaderLibrary\Common.hlsl" />
<None Include="Assets\ShaderLibrary\Surface.hlsl" />
<None Include="Assets\Shaders\MetaPass.hlsl" />
<None Include="Assets\ShaderLibrary\BRDF.hlsl" />
<None Include="Assets\Shaders\ShadowCasterPass.hlsl" />
<Compile Include="Assets\Custom RP\Runtime\ShadowSettings.cs" />
<Compile Include="Assets\Custom RP\Runtime\Lighting.cs" />
<Compile Include="Assets\Custom RP\Runtime\Shadows.cs" />
<Compile Include="Assets\Custom RP\Examples\PerObjectMaterialProperties.cs" />
<Compile Include="Assets\Custom RP\Examples\MeshBall.cs" />
<Compile Include="Assets\Custom RP\Runtime\CameraRenderer.Editor.cs" />
<Compile Include="Assets\Custom RP\Runtime\CustomRenderPipeline.cs" />
<Compile Include="Assets\Custom RP\Runtime\CustomRenderPipelineAsset.cs" />
<Compile Include="Assets\Custom RP\Runtime\CameraRenderer.cs" />
<None Include="Assets\Custom RP\ShaderLibrary\Surface.hlsl" />
<None Include="Assets\Custom RP\Shaders\UnlitInput.hlsl" />
<None Include="Assets\Custom RP\ShaderLibrary\Common.hlsl" />
<None Include="Assets\Custom RP\Shaders\Lit.shader" />
<None Include="Assets\Custom RP\Shaders\UnlitPass.hlsl" />
<None Include="Assets\Custom RP\ShaderLibrary\Lighting.hlsl" />
<None Include="Assets\Custom RP\ShaderLibrary\Shadows.hlsl" />
<None Include="Assets\Custom RP\ShaderLibrary\Light.hlsl" />
<None Include="Assets\Custom RP\ShaderLibrary\UnityInput.hlsl" />
<None Include="Assets\Custom RP\Shaders\LitInput.hlsl" />
<None Include="Assets\Custom RP\Shaders\Unlit.shader" />
<None Include="Assets\Custom RP\ShaderLibrary\GI.hlsl" />
<None Include="Assets\Custom RP\ShaderLibrary\BRDF.hlsl" />
<None Include="Assets\Custom RP\Shaders\ShadowCasterPass.hlsl" />
<None Include="Assets\Custom RP\Shaders\MetaPass.hlsl" />
<None Include="Assets\Custom RP\Shaders\LitPass.hlsl" />
<Reference Include="UnityEngine">
<HintPath>F:/Unity/2021.1.16f1c1/Editor/Data/Managed/UnityEngine/UnityEngine.dll</HintPath>
</Reference>
......
......@@ -9,14 +9,14 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0541bba9596b30844bd298f80ab9eed1, type: 3}
m_Name: Custom_RP
m_Script: {fileID: 11500000, guid: c09c9ba443ab8425ca7560934947ff53, type: 3}
m_Name: Custom RP
m_EditorClassIdentifier:
useDynamicBatching: 0
useGPUInstancing: 1
useSRPBatcher: 1
shadows:
maxDistance: 16
maxDistance: 30
distanceFade: 0.1
directional:
atlasSize: 4096
......
fileFormatVersion: 2
guid: f7152e1e3f0bfdd49b0284c702bfa510
guid: aedb7cce3445b224592309643d5e4de5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
......
fileFormatVersion: 2
guid: badeaaa8bec5ff346a91dbf82418c783
guid: b794ab6b110571242b7f151322d2a774
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
fileFormatVersion: 2
guid: 61301eaf64b8175428a85c48c776f417
guid: 41bef6e9187c345828b09960dd1cbfa6
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
public class CustomShaderGUI : ShaderGUI {
MaterialEditor editor;
Object[] materials;
MaterialProperty[] properties;
bool showPresets;
bool Clipping {
set => SetProperty("_Clipping", "_CLIPPING", value);
}
bool HasPremultiplyAlpha => HasProperty("_PremulAlpha");
bool PremultiplyAlpha {
set => SetProperty("_PremulAlpha", "_PREMULTIPLY_ALPHA", value);
}
BlendMode SrcBlend {
set => SetProperty("_SrcBlend", (float)value);
}
BlendMode DstBlend {
set => SetProperty("_DstBlend", (float)value);
}
bool ZWrite {
set => SetProperty("_ZWrite", value ? 1f : 0f);
}
enum ShadowMode {
On, Clip, Dither, Off
}
ShadowMode Shadows {
set {
if (SetProperty("_Shadows", (float)value)) {
SetKeyword("_SHADOWS_CLIP", value == ShadowMode.Clip);
SetKeyword("_SHADOWS_DITHER", value == ShadowMode.Dither);
}
}
}
RenderQueue RenderQueue {
set {
foreach (Material m in materials) {
m.renderQueue = (int)value;
}
}
}
public override void OnGUI (
MaterialEditor materialEditor, MaterialProperty[] properties
) {
EditorGUI.BeginChangeCheck();
base.OnGUI(materialEditor, properties);
editor = materialEditor;
materials = materialEditor.targets;
this.properties = properties;
BakedEmission();
EditorGUILayout.Space();
showPresets = EditorGUILayout.Foldout(showPresets, "Presets", true);
if (showPresets) {
OpaquePreset();
ClipPreset();
FadePreset();
TransparentPreset();
}
if (EditorGUI.EndChangeCheck()) {
SetShadowCasterPass();
CopyLightMappingProperties();
}
}
void CopyLightMappingProperties () {
MaterialProperty mainTex = FindProperty("_MainTex", properties, false);
MaterialProperty baseMap = FindProperty("_BaseMap", properties, false);
if (mainTex != null && baseMap != null) {
mainTex.textureValue = baseMap.textureValue;
mainTex.textureScaleAndOffset = baseMap.textureScaleAndOffset;
}
MaterialProperty color = FindProperty("_Color", properties, false);
MaterialProperty baseColor =
FindProperty("_BaseColor", properties, false);
if (color != null && baseColor != null) {
color.colorValue = baseColor.colorValue;
}
}
void BakedEmission () {
EditorGUI.BeginChangeCheck();
editor.LightmapEmissionProperty();
if (EditorGUI.EndChangeCheck()) {
foreach (Material m in editor.targets) {
m.globalIlluminationFlags &=
~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
}
}
}
void OpaquePreset () {
if (PresetButton("Opaque")) {
Clipping = false;
Shadows = ShadowMode.On;
PremultiplyAlpha = false;
SrcBlend = BlendMode.One;
DstBlend = BlendMode.Zero;
ZWrite = true;
RenderQueue = RenderQueue.Geometry;
}
}
void ClipPreset () {
if (PresetButton("Clip")) {
Clipping = true;
Shadows = ShadowMode.Clip;
PremultiplyAlpha = false;
SrcBlend = BlendMode.One;
DstBlend = BlendMode.Zero;
ZWrite = true;
RenderQueue = RenderQueue.AlphaTest;
}
}
void FadePreset () {
if (PresetButton("Fade")) {
Clipping = false;
Shadows = ShadowMode.Dither;
PremultiplyAlpha = false;
SrcBlend = BlendMode.SrcAlpha;
DstBlend = BlendMode.OneMinusSrcAlpha;
ZWrite = false;
RenderQueue = RenderQueue.Transparent;
}
}
void TransparentPreset () {
if (HasPremultiplyAlpha && PresetButton("Transparent")) {
Clipping = false;
Shadows = ShadowMode.Dither;
PremultiplyAlpha = true;
SrcBlend = BlendMode.One;
DstBlend = BlendMode.OneMinusSrcAlpha;
ZWrite = false;
RenderQueue = RenderQueue.Transparent;
}
}
bool PresetButton (string name) {
if (GUILayout.Button(name)) {
editor.RegisterPropertyChangeUndo(name);
return true;
}
return false;
}
bool HasProperty (string name) =>
FindProperty(name, properties, false) != null;
void SetProperty (string name, string keyword, bool value) {
if (SetProperty(name, value ? 1f : 0f)) {
SetKeyword(keyword, value);
}
}
bool SetProperty (string name, float value) {
MaterialProperty property = FindProperty(name, properties, false);
if (property != null) {
property.floatValue = value;
return true;
}
return false;
}
void SetKeyword (string keyword, bool enabled) {
if (enabled) {
foreach (Material m in materials) {
m.EnableKeyword(keyword);
}
}
else {
foreach (Material m in materials) {
m.DisableKeyword(keyword);
}
}
}
void SetShadowCasterPass () {
MaterialProperty shadows = FindProperty("_Shadows", properties, false);
if (shadows == null || shadows.hasMixedValue) {
return;
}
bool enabled = shadows.floatValue < (float)ShadowMode.Off;
foreach (Material m in materials) {
m.SetShaderPassEnabled("ShadowCaster", enabled);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 63f209c1640cac74884a5a7d9b8a6bbb
guid: aaa44aa82ac4b401280aa00633c3262e
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
fileFormatVersion: 2
guid: 71cb5ce47a3c0ad4689c76000c3bb7e4
guid: b08f84cadf408444798120bf37e58218
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
using UnityEngine;
using UnityEngine.Rendering;
public class MeshBall : MonoBehaviour {
static int
baseColorId = Shader.PropertyToID("_BaseColor"),
metallicId = Shader.PropertyToID("_Metallic"),
smoothnessId = Shader.PropertyToID("_Smoothness");
[SerializeField]
Mesh mesh = default;
[SerializeField]
Material material = default;
[SerializeField]
LightProbeProxyVolume lightProbeVolume = null;
Matrix4x4[] matrices = new Matrix4x4[1023];
Vector4[] baseColors = new Vector4[1023];
float[]
metallic = new float[1023],
smoothness = new float[1023];
MaterialPropertyBlock block;
void Awake () {
for (int i = 0; i < matrices.Length; i++) {
matrices[i] = Matrix4x4.TRS(
Random.insideUnitSphere * 10f,
Quaternion.Euler(
Random.value * 360f, Random.value * 360f, Random.value * 360f
),
Vector3.one * Random.Range(0.5f, 1.5f)
);
baseColors[i] =
new Vector4(
Random.value, Random.value, Random.value,
Random.Range(0.5f, 1f)
);
metallic[i] = Random.value < 0.25f ? 1f : 0f;
smoothness[i] = Random.Range(0.05f, 0.95f);
}
}
void Update () {
if (block == null) {
block = new MaterialPropertyBlock();
block.SetVectorArray(baseColorId, baseColors);
block.SetFloatArray(metallicId, metallic);
block.SetFloatArray(smoothnessId, smoothness);
if (!lightProbeVolume) {
var positions = new Vector3[1023];
for (int i = 0; i < matrices.Length; i++) {
positions[i] = matrices[i].GetColumn(3);
}
var lightProbes = new SphericalHarmonicsL2[1023];
var occlusionProbes = new Vector4[1023];
LightProbes.CalculateInterpolatedLightAndOcclusionProbes(
positions, lightProbes, occlusionProbes
);
block.CopySHCoefficientArraysFrom(lightProbes);
block.CopyProbeOcclusionArrayFrom(occlusionProbes);
}
}
Graphics.DrawMeshInstanced(
mesh, 0, material, matrices, 1023, block,
ShadowCastingMode.On, true, 0, null,
lightProbeVolume ?
LightProbeUsage.UseProxyVolume : LightProbeUsage.CustomProvided,
lightProbeVolume
);
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 8e200ec0b15a385468e1ad94ba6331ab
guid: 2f4e5bddc090f46f8acfc6475bf68617
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using UnityEngine;
[DisallowMultipleComponent]
public class PerObjectMaterialProperties : MonoBehaviour {
static int
baseColorId = Shader.PropertyToID("_BaseColor"),
cutoffId = Shader.PropertyToID("_Cutoff"),
metallicId = Shader.PropertyToID("_Metallic"),
smoothnessId = Shader.PropertyToID("_Smoothness"),
emissionColorId = Shader.PropertyToID("_EmissionColor");
static MaterialPropertyBlock block;
[SerializeField]
Color baseColor = Color.white;
[SerializeField, Range(0f, 1f)]
float alphaCutoff = 0.5f, metallic = 0f, smoothness = 0.5f;
[SerializeField, ColorUsage(false, true)]
Color emissionColor = Color.black;
void Awake () {
OnValidate();
}
void OnValidate () {
if (block == null) {
block = new MaterialPropertyBlock();
}
block.SetColor(baseColorId, baseColor);
block.SetFloat(cutoffId, alphaCutoff);
block.SetFloat(metallicId, metallic);
block.SetFloat(smoothnessId, smoothness);
block.SetColor(emissionColorId, emissionColor);
GetComponent<Renderer>().SetPropertyBlock(block);
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: be15b46f5c3ccb44996b3508a76c4bf2
guid: 12b34fac330b345eea0c6df7126deddc
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
fileFormatVersion: 2
guid: fc71a22a99a17fb42a0ecc13ae7ac927
guid: 183aea273daae4735ab292ef6f533100
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
using UnityEditor;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
partial class CameraRenderer {
partial void DrawGizmos ();
partial void DrawUnsupportedShaders ();
partial void PrepareForSceneWindow ();
partial void PrepareBuffer ();
#if UNITY_EDITOR
static ShaderTagId[] legacyShaderTagIds = {
new ShaderTagId("Always"),
new ShaderTagId("ForwardBase"),
new ShaderTagId("PrepassBase"),
new ShaderTagId("Vertex"),
new ShaderTagId("VertexLMRGBM"),
new ShaderTagId("VertexLM")
};
static Material errorMaterial;
string SampleName { get; set; }
partial void DrawGizmos () {
if (Handles.ShouldRenderGizmos()) {
context.DrawGizmos(camera, GizmoSubset.PreImageEffects);
context.DrawGizmos(camera, GizmoSubset.PostImageEffects);
}
}
partial void DrawUnsupportedShaders () {
if (errorMaterial == null) {
errorMaterial =
new Material(Shader.Find("Hidden/InternalErrorShader"));
}
var drawingSettings = new DrawingSettings(
legacyShaderTagIds[0], new SortingSettings(camera)
) {
overrideMaterial = errorMaterial
};
for (int i = 1; i < legacyShaderTagIds.Length; i++) {
drawingSettings.SetShaderPassName(i, legacyShaderTagIds[i]);
}
var filteringSettings = FilteringSettings.defaultValue;
context.DrawRenderers(
cullingResults, ref drawingSettings, ref filteringSettings
);
}
partial void PrepareForSceneWindow () {
if (camera.cameraType == CameraType.SceneView) {
ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
}
}
partial void PrepareBuffer () {
Profiler.BeginSample("Editor Only");
buffer.name = SampleName = camera.name;
Profiler.EndSample();
}
#else
const string SampleName = bufferName;
#endif
}
\ No newline at end of file
fileFormatVersion: 2
guid: ad3150bd302b9684e9244154722b4d93
guid: f7117d16a1eb8460a870459aa0c75f09
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using UnityEngine;
using UnityEngine.Rendering;
public partial class CameraRenderer {
const string bufferName = "Render Camera";
static ShaderTagId
unlitShaderTagId = new ShaderTagId("SRPDefaultUnlit"),
litShaderTagId = new ShaderTagId("CustomLit");
CommandBuffer buffer = new CommandBuffer {
name = bufferName
};
ScriptableRenderContext context;
Camera camera;
CullingResults cullingResults;
Lighting lighting = new Lighting();
public void Render (
ScriptableRenderContext context, Camera camera,
bool useDynamicBatching, bool useGPUInstancing,
ShadowSettings shadowSettings
) {
this.context = context;
this.camera = camera;
PrepareBuffer();
PrepareForSceneWindow();
if (!Cull(shadowSettings.maxDistance)) {
return;
}
buffer.BeginSample(SampleName);
ExecuteBuffer();
lighting.Setup(context, cullingResults, shadowSettings);
buffer.EndSample(SampleName);
Setup();
DrawVisibleGeometry(useDynamicBatching, useGPUInstancing);
DrawUnsupportedShaders();
DrawGizmos();
lighting.Cleanup();
Submit();
}
bool Cull (float maxShadowDistance) {
if (camera.TryGetCullingParameters(out ScriptableCullingParameters p)) {
p.shadowDistance = Mathf.Min(maxShadowDistance, camera.farClipPlane);
cullingResults = context.Cull(ref p);
return true;
}
return false;
}
void Setup () {
context.SetupCameraProperties(camera);
CameraClearFlags flags = camera.clearFlags;
buffer.ClearRenderTarget(
flags <= CameraClearFlags.Depth,
flags == CameraClearFlags.Color,
flags == CameraClearFlags.Color ?
camera.backgroundColor.linear : Color.clear
);
buffer.BeginSample(SampleName);
ExecuteBuffer();
}
void Submit () {
buffer.EndSample(SampleName);
ExecuteBuffer();
context.Submit();
}
void ExecuteBuffer () {
context.ExecuteCommandBuffer(buffer);
buffer.Clear();
}
void DrawVisibleGeometry (bool useDynamicBatching, bool useGPUInstancing) {
var sortingSettings = new SortingSettings(camera) {
criteria = SortingCriteria.CommonOpaque
};
var drawingSettings = new DrawingSettings(
unlitShaderTagId, sortingSettings
) {
enableDynamicBatching = useDynamicBatching,
enableInstancing = useGPUInstancing,
perObjectData =
PerObjectData.Lightmaps | PerObjectData.ShadowMask |
PerObjectData.LightProbe | PerObjectData.OcclusionProbe |
PerObjectData.LightProbeProxyVolume |
PerObjectData.OcclusionProbeProxyVolume
};
drawingSettings.SetShaderPassName(1, litShaderTagId);
var filteringSettings = new FilteringSettings(RenderQueueRange.opaque);
context.DrawRenderers(
cullingResults, ref drawingSettings, ref filteringSettings
);
context.DrawSkybox(camera);
sortingSettings.criteria = SortingCriteria.CommonTransparent;
drawingSettings.sortingSettings = sortingSettings;
filteringSettings.renderQueueRange = RenderQueueRange.transparent;
context.DrawRenderers(
cullingResults, ref drawingSettings, ref filteringSettings
);
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: a9e70a38f407c0e40bc30bc4ea0ec3f4
guid: 88453deb1b55d4571baf0a2dc0985627
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using UnityEngine;
using UnityEngine.Rendering;
public class CustomRenderPipeline : RenderPipeline {
CameraRenderer renderer = new CameraRenderer();
bool useDynamicBatching, useGPUInstancing;
ShadowSettings shadowSettings;
public CustomRenderPipeline (
bool useDynamicBatching, bool useGPUInstancing, bool useSRPBatcher,
ShadowSettings shadowSettings
) {
this.shadowSettings = shadowSettings;
this.useDynamicBatching = useDynamicBatching;
this.useGPUInstancing = useGPUInstancing;
GraphicsSettings.useScriptableRenderPipelineBatching = useSRPBatcher;
GraphicsSettings.lightsUseLinearIntensity = true;
}
protected override void Render (
ScriptableRenderContext context, Camera[] cameras
) {
foreach (Camera camera in cameras) {
renderer.Render(
context, camera, useDynamicBatching, useGPUInstancing,
shadowSettings
);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 7801b1ecb6785ac4e879356c5121b295
guid: f4b31ba9f94df4291bbb76c90b3da14c
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using UnityEngine;
using UnityEngine.Rendering;
[CreateAssetMenu(menuName = "Rendering/Custom Render Pipeline")]
public class CustomRenderPipelineAsset : RenderPipelineAsset {
[SerializeField]
bool useDynamicBatching = true, useGPUInstancing = true, useSRPBatcher = true;
[SerializeField]
ShadowSettings shadows = default;
protected override RenderPipeline CreatePipeline () {
return new CustomRenderPipeline(
useDynamicBatching, useGPUInstancing, useSRPBatcher, shadows
);
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 0541bba9596b30844bd298f80ab9eed1
guid: c09c9ba443ab8425ca7560934947ff53
MonoImporter:
externalObjects: {}
serializedVersion: 2
......
using Unity.Collections;
using UnityEngine;
using UnityEngine.Rendering;
public class Lighting {
const string bufferName = "Lighting";
const int maxDirLightCount = 4;
static int
dirLightCountId = Shader.PropertyToID("_DirectionalLightCount"),
dirLightColorsId = Shader.PropertyToID("_DirectionalLightColors"),
dirLightDirectionsId = Shader.PropertyToID("_DirectionalLightDirections"),
dirLightShadowDataId =
Shader.PropertyToID("_DirectionalLightShadowData");
static Vector4[]
dirLightColors = new Vector4[maxDirLightCount],
dirLightDirections = new Vector4[maxDirLightCount],
dirLightShadowData = new Vector4[maxDirLightCount];
CommandBuffer buffer = new CommandBuffer {
name = bufferName
};
CullingResults cullingResults;
Shadows shadows = new Shadows();
public void Setup (
ScriptableRenderContext context, CullingResults cullingResults,
ShadowSettings shadowSettings
) {
this.cullingResults = cullingResults;
buffer.BeginSample(bufferName);
shadows.Setup(context, cullingResults, shadowSettings);
SetupLights();
shadows.Render();
buffer.EndSample(bufferName);
context.ExecuteCommandBuffer(buffer);
buffer.Clear();
}
public void Cleanup () {
shadows.Cleanup();
}
void SetupLights () {
NativeArray<VisibleLight> visibleLights = cullingResults.visibleLights;
int dirLightCount = 0;
for (int i = 0; i < visibleLights.Length; i++) {
VisibleLight visibleLight = visibleLights[i];
if (visibleLight.lightType == LightType.Directional) {
SetupDirectionalLight(dirLightCount++, ref visibleLight);
if (dirLightCount >= maxDirLightCount) {
break;
}
}
}
buffer.SetGlobalInt(dirLightCountId, dirLightCount);
buffer.SetGlobalVectorArray(dirLightColorsId, dirLightColors);
buffer.SetGlobalVectorArray(dirLightDirectionsId, dirLightDirections);
buffer.SetGlobalVectorArray(dirLightShadowDataId, dirLightShadowData);
}
void SetupDirectionalLight (int index, ref VisibleLight visibleLight) {
dirLightColors[index] = visibleLight.finalColor;
dirLightDirections[index] = -visibleLight.localToWorldMatrix.GetColumn(2);
dirLightShadowData[index] =
shadows.ReserveDirectionalShadows(visibleLight.light, index);
}
}
\ No newline at end of file
using UnityEngine;
[System.Serializable]
public class ShadowSettings {
public enum MapSize {
_256 = 256, _512 = 512, _1024 = 1024,
_2048 = 2048, _4096 = 4096, _8192 = 8192
}
public enum FilterMode {
PCF2x2, PCF3x3, PCF5x5, PCF7x7
}
[Min(0.001f)]
public float maxDistance = 100f;
[Range(0.001f, 1f)]
public float distanceFade = 0.1f;
[System.Serializable]
public struct Directional {
public MapSize atlasSize;
public FilterMode filter;
[Range(1, 4)]
public int cascadeCount;
[Range(0f, 1f)]
public float cascadeRatio1, cascadeRatio2, cascadeRatio3;
public Vector3 CascadeRatios =>
new Vector3(cascadeRatio1, cascadeRatio2, cascadeRatio3);
[Range(0.001f, 1f)]
public float cascadeFade;
public enum CascadeBlendMode {
Hard, Soft, Dither
}
public CascadeBlendMode cascadeBlend;
}
public Directional directional = new Directional {
atlasSize = MapSize._1024,
filter = FilterMode.PCF2x2,
cascadeCount = 4,
cascadeRatio1 = 0.1f,
cascadeRatio2 = 0.25f,
cascadeRatio3 = 0.5f,
cascadeFade = 0.1f,
cascadeBlend = Directional.CascadeBlendMode.Hard
};
}
\ No newline at end of file
using UnityEngine;
using UnityEngine.Rendering;
public class Shadows {
const string bufferName = "Shadows";
const int maxShadowedDirLightCount = 4, maxCascades = 4;
static string[] directionalFilterKeywords = {
"_DIRECTIONAL_PCF3",
"_DIRECTIONAL_PCF5",
"_DIRECTIONAL_PCF7",
};
static string[] cascadeBlendKeywords = {
"_CASCADE_BLEND_SOFT",
"_CASCADE_BLEND_DITHER"
};
static string[] shadowMaskKeywords = {
"_SHADOW_MASK_ALWAYS",
"_SHADOW_MASK_DISTANCE"
};
static int
dirShadowAtlasId = Shader.PropertyToID("_DirectionalShadowAtlas"),
dirShadowMatricesId = Shader.PropertyToID("_DirectionalShadowMatrices"),
cascadeCountId = Shader.PropertyToID("_CascadeCount"),
cascadeCullingSpheresId = Shader.PropertyToID("_CascadeCullingSpheres"),
cascadeDataId = Shader.PropertyToID("_CascadeData"),
shadowAtlasSizeId = Shader.PropertyToID("_ShadowAtlasSize"),
shadowDistanceFadeId = Shader.PropertyToID("_ShadowDistanceFade");
static Vector4[]
cascadeCullingSpheres = new Vector4[maxCascades],
cascadeData = new Vector4[maxCascades];
static Matrix4x4[]
dirShadowMatrices = new Matrix4x4[maxShadowedDirLightCount * maxCascades];
struct ShadowedDirectionalLight {
public int visibleLightIndex;
public float slopeScaleBias;
public float nearPlaneOffset;
}
ShadowedDirectionalLight[] shadowedDirectionalLights =
new ShadowedDirectionalLight[maxShadowedDirLightCount];
int shadowedDirLightCount;
CommandBuffer buffer = new CommandBuffer {
name = bufferName
};
ScriptableRenderContext context;
CullingResults cullingResults;
ShadowSettings settings;
bool useShadowMask;
public void Setup (
ScriptableRenderContext context, CullingResults cullingResults,
ShadowSettings settings
) {
this.context = context;
this.cullingResults = cullingResults;
this.settings = settings;
shadowedDirLightCount = 0;
useShadowMask = false;
}
public void Cleanup () {
buffer.ReleaseTemporaryRT(dirShadowAtlasId);
ExecuteBuffer();
}
public Vector4 ReserveDirectionalShadows (
Light light, int visibleLightIndex
) {
if (
shadowedDirLightCount < maxShadowedDirLightCount &&
light.shadows != LightShadows.None && light.shadowStrength > 0f
) {
float maskChannel = -1;
LightBakingOutput lightBaking = light.bakingOutput;
if (
lightBaking.lightmapBakeType == LightmapBakeType.Mixed &&
lightBaking.mixedLightingMode == MixedLightingMode.Shadowmask
) {
useShadowMask = true;
maskChannel = lightBaking.occlusionMaskChannel;
}
if (!cullingResults.GetShadowCasterBounds(
visibleLightIndex, out Bounds b
)) {
return new Vector4(-light.shadowStrength, 0f, 0f, maskChannel);
}
shadowedDirectionalLights[shadowedDirLightCount] =
new ShadowedDirectionalLight {
visibleLightIndex = visibleLightIndex,
slopeScaleBias = light.shadowBias,
nearPlaneOffset = light.shadowNearPlane
};
return new Vector4(
light.shadowStrength,
settings.directional.cascadeCount * shadowedDirLightCount++,
light.shadowNormalBias, maskChannel
);
}
return new Vector4(0f, 0f, 0f, -1f);
}
public void Render () {
if (shadowedDirLightCount > 0) {
RenderDirectionalShadows();
}
else {
buffer.GetTemporaryRT(
dirShadowAtlasId, 1, 1,
32, FilterMode.Bilinear, RenderTextureFormat.Shadowmap
);
}
buffer.BeginSample(bufferName);
SetKeywords(shadowMaskKeywords, useShadowMask ?
QualitySettings.shadowmaskMode == ShadowmaskMode.Shadowmask ? 0 : 1 :
-1
);
buffer.EndSample(bufferName);
ExecuteBuffer();
}
void RenderDirectionalShadows () {
int atlasSize = (int)settings.directional.atlasSize;
buffer.GetTemporaryRT(
dirShadowAtlasId, atlasSize, atlasSize,
32, FilterMode.Bilinear, RenderTextureFormat.Shadowmap
);
buffer.SetRenderTarget(
dirShadowAtlasId,
RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store
);
buffer.ClearRenderTarget(true, false, Color.clear);
buffer.BeginSample(bufferName);
ExecuteBuffer();
int tiles = shadowedDirLightCount * settings.directional.cascadeCount;
int split = tiles <= 1 ? 1 : tiles <= 4 ? 2 : 4;
int tileSize = atlasSize / split;
for (int i = 0; i < shadowedDirLightCount; i++) {
RenderDirectionalShadows(i, split, tileSize);
}
buffer.SetGlobalInt(cascadeCountId, settings.directional.cascadeCount);
buffer.SetGlobalVectorArray(
cascadeCullingSpheresId, cascadeCullingSpheres
);
buffer.SetGlobalVectorArray(cascadeDataId, cascadeData);
buffer.SetGlobalMatrixArray(dirShadowMatricesId, dirShadowMatrices);
float f = 1f - settings.directional.cascadeFade;
buffer.SetGlobalVector(
shadowDistanceFadeId, new Vector4(
1f / settings.maxDistance, 1f / settings.distanceFade,
1f / (1f - f * f)
)
);
SetKeywords(
directionalFilterKeywords, (int)settings.directional.filter - 1
);
SetKeywords(
cascadeBlendKeywords, (int)settings.directional.cascadeBlend - 1
);
buffer.SetGlobalVector(
shadowAtlasSizeId, new Vector4(atlasSize, 1f / atlasSize)
);
buffer.EndSample(bufferName);
ExecuteBuffer();
}
void SetKeywords (string[] keywords, int enabledIndex) {
for (int i = 0; i < keywords.Length; i++) {
if (i == enabledIndex) {
buffer.EnableShaderKeyword(keywords[i]);
}
else {
buffer.DisableShaderKeyword(keywords[i]);
}
}
}
void RenderDirectionalShadows (int index, int split, int tileSize) {
ShadowedDirectionalLight light = shadowedDirectionalLights[index];
var shadowSettings =
new ShadowDrawingSettings(cullingResults, light.visibleLightIndex);
int cascadeCount = settings.directional.cascadeCount;
int tileOffset = index * cascadeCount;
Vector3 ratios = settings.directional.CascadeRatios;
float cullingFactor =
Mathf.Max(0f, 0.8f - settings.directional.cascadeFade);
for (int i = 0; i < cascadeCount; i++) {
cullingResults.ComputeDirectionalShadowMatricesAndCullingPrimitives(
light.visibleLightIndex, i, cascadeCount, ratios, tileSize,
light.nearPlaneOffset, out Matrix4x4 viewMatrix,
out Matrix4x4 projectionMatrix, out ShadowSplitData splitData
);
splitData.shadowCascadeBlendCullingFactor = cullingFactor;
shadowSettings.splitData = splitData;
if (index == 0) {
SetCascadeData(i, splitData.cullingSphere, tileSize);
}
int tileIndex = tileOffset + i;
dirShadowMatrices[tileIndex] = ConvertToAtlasMatrix(
projectionMatrix * viewMatrix,
SetTileViewport(tileIndex, split, tileSize), split
);
buffer.SetViewProjectionMatrices(viewMatrix, projectionMatrix);
buffer.SetGlobalDepthBias(0f, light.slopeScaleBias);
ExecuteBuffer();
context.DrawShadows(ref shadowSettings);
buffer.SetGlobalDepthBias(0f, 0f);
}
}
void SetCascadeData (int index, Vector4 cullingSphere, float tileSize) {
float texelSize = 2f * cullingSphere.w / tileSize;
float filterSize = texelSize * ((float)settings.directional.filter + 1f);
cullingSphere.w -= filterSize;
cullingSphere.w *= cullingSphere.w;
cascadeCullingSpheres[index] = cullingSphere;
cascadeData[index] = new Vector4(
1f / cullingSphere.w,
filterSize * 1.4142136f
);
}
Matrix4x4 ConvertToAtlasMatrix (Matrix4x4 m, Vector2 offset, int split) {
if (SystemInfo.usesReversedZBuffer) {
m.m20 = -m.m20;
m.m21 = -m.m21;
m.m22 = -m.m22;
m.m23 = -m.m23;
}
float scale = 1f / split;
m.m00 = (0.5f * (m.m00 + m.m30) + offset.x * m.m30) * scale;
m.m01 = (0.5f * (m.m01 + m.m31) + offset.x * m.m31) * scale;
m.m02 = (0.5f * (m.m02 + m.m32) + offset.x * m.m32) * scale;
m.m03 = (0.5f * (m.m03 + m.m33) + offset.x * m.m33) * scale;
m.m10 = (0.5f * (m.m10 + m.m30) + offset.y * m.m30) * scale;
m.m11 = (0.5f * (m.m11 + m.m31) + offset.y * m.m31) * scale;
m.m12 = (0.5f * (m.m12 + m.m32) + offset.y * m.m32) * scale;
m.m13 = (0.5f * (m.m13 + m.m33) + offset.y * m.m33) * scale;
m.m20 = 0.5f * (m.m20 + m.m30);
m.m21 = 0.5f * (m.m21 + m.m31);
m.m22 = 0.5f * (m.m22 + m.m32);
m.m23 = 0.5f * (m.m23 + m.m33);
return m;
}
Vector2 SetTileViewport (int index, int split, float tileSize) {
Vector2 offset = new Vector2(index % split, index / split);
buffer.SetViewport(new Rect(
offset.x * tileSize, offset.y * tileSize, tileSize, tileSize
));
return offset;
}
void ExecuteBuffer () {
context.ExecuteCommandBuffer(buffer);
buffer.Clear();
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 7eb1a0578eb0ca940abef40cdf6bb122
guid: 2db33945469a2400395335697cbf5a93
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
// BRDF相关库
#ifndef CUSTOM_BRDF_INCLUDED
#ifndef CUSTOM_BRDF_INCLUDED
#define CUSTOM_BRDF_INCLUDED
// BRDF属性
struct BRDF
{
// 漫反射
float3 diffuse;
// 镜面反射
float3 specular;
// 粗糙度
float roughness;
struct BRDF {
float3 diffuse;
float3 specular;
float roughness;
};
// 电介质的反射率平均约0.04
#define MIN_REFLECTIVITY 0.04
// 计算不反射的值,将范围从 0-1 调整到 0-0.96,保持和URP中一样
float OneMinusReflectivity(float metallic)
{
float range = 1.0 - MIN_REFLECTIVITY;
return range - metallic * range;
float OneMinusReflectivity (float metallic) {
float range = 1.0 - MIN_REFLECTIVITY;
return range - metallic * range;
}
// 获取表面的BRDF数据
BRDF GetBRDF(inout Surface surface, bool applyAlphaToDiffuse = false)
{
BRDF brdf;
float oneMinusReflectivity = OneMinusReflectivity(surface.metallic);
brdf.diffuse = surface.color * oneMinusReflectivity;
// 透明度预乘
if (applyAlphaToDiffuse)
{
brdf.diffuse *= surface.alpha;
}
brdf.specular = lerp(MIN_REFLECTIVITY, surface.color, surface.metallic);
// 光滑度转为实际粗糙度
float perceptualSmoothness = PerceptualSmoothnessToPerceptualRoughness(surface.smoothness);
brdf.roughness = PerceptualRoughnessToRoughness(perceptualSmoothness);
return brdf;
BRDF GetBRDF (Surface surface, bool applyAlphaToDiffuse = false) {
BRDF brdf;
float oneMinusReflectivity = OneMinusReflectivity(surface.metallic);
brdf.diffuse = surface.color * oneMinusReflectivity;
if (applyAlphaToDiffuse) {
brdf.diffuse *= surface.alpha;
}
brdf.specular = lerp(MIN_REFLECTIVITY, surface.color, surface.metallic);
float perceptualRoughness =
PerceptualSmoothnessToPerceptualRoughness(surface.smoothness);
brdf.roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
return brdf;
}
// 根据公式得到镜面反射强度
float SpecularStrength(Surface surface, BRDF brdf, Light light)
{
float SpecularStrength (Surface surface, BRDF brdf, Light light) {
float3 h = SafeNormalize(light.direction + surface.viewDirection);
float nh2 = Square(saturate(dot(surface.normal, h)));
float lh2 = Square(saturate(dot(light.direction, h)));
......@@ -54,7 +40,6 @@ float SpecularStrength(Surface surface, BRDF brdf, Light light)
return r2 / (d2 * max(0.1, lh2) * normalization);
}
// 获取基于BRDF的直接照明
float3 DirectBRDF (Surface surface, BRDF brdf, Light light) {
return SpecularStrength(surface, brdf, light) * brdf.specular + brdf.diffuse;
}
......
fileFormatVersion: 2
guid: dda9dd1e15e8efa44b7b4c6c80775bd8
guid: b94bd1713a4fb458b9edcca758d01545
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
// 公共方法库
#ifndef CUSTOM_COMMON_INCLUDED
#ifndef CUSTOM_COMMON_INCLUDED
#define CUSTOM_COMMON_INCLUDED
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#include "UnityInput.hlsl"
// 定义一些宏取代常用的转换矩阵
#define UNITY_MATRIX_M unity_ObjectToWorld
#define UNITY_MATRIX_I_M unity_WorldToObject
#define UNITY_MATRIX_V unity_MatrixV
......@@ -14,21 +12,18 @@
#define UNITY_MATRIX_P glstate_matrix_projection
#if defined(_SHADOW_MASK_ALWAYS) || defined(_SHADOW_MASK_DISTANCE)
#define SHADOWS_SHADOWMASK
#define SHADOWS_SHADOWMASK
#endif
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
// 获取值的平方
float Square(float x)
{
return x * x;
float Square (float x) {
return x * x;
}
// 计算两点间距离的平方
float DistanceSquared(float3 pA, float3 pB)
{
return dot(pA - pB, pA - pB);
float DistanceSquared(float3 pA, float3 pB) {
return dot(pA - pB, pA - pB);
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 8affe3d00ecf5d04ebb205a1b24c2dce
guid: 921873fe4a5914b0a8f141f07893698d
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_GI_INCLUDED
#define CUSTOM_GI_INCLUDED
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
TEXTURE2D(unity_Lightmap);
SAMPLER(samplerunity_Lightmap);
TEXTURE2D(unity_ShadowMask);
SAMPLER(samplerunity_ShadowMask);
TEXTURE3D_FLOAT(unity_ProbeVolumeSH);
SAMPLER(samplerunity_ProbeVolumeSH);
#if defined(LIGHTMAP_ON)
#define GI_ATTRIBUTE_DATA float2 lightMapUV : TEXCOORD1;
#define GI_VARYINGS_DATA float2 lightMapUV : VAR_LIGHT_MAP_UV;
#define TRANSFER_GI_DATA(input, output) \
output.lightMapUV = input.lightMapUV * \
unity_LightmapST.xy + unity_LightmapST.zw;
#define GI_FRAGMENT_DATA(input) input.lightMapUV
#else
#define GI_ATTRIBUTE_DATA
#define GI_VARYINGS_DATA
#define TRANSFER_GI_DATA(input, output)
#define GI_FRAGMENT_DATA(input) 0.0
#endif
struct GI {
float3 diffuse;
ShadowMask shadowMask;
};
float3 SampleLightMap (float2 lightMapUV) {
#if defined(LIGHTMAP_ON)
return SampleSingleLightmap(
TEXTURE2D_ARGS(unity_Lightmap, samplerunity_Lightmap), lightMapUV,
float4(1.0, 1.0, 0.0, 0.0),
#if defined(UNITY_LIGHTMAP_FULL_HDR)
false,
#else
true,
#endif
float4(LIGHTMAP_HDR_MULTIPLIER, LIGHTMAP_HDR_EXPONENT, 0.0, 0.0)
);
#else
return 0.0;
#endif
}
float3 SampleLightProbe (Surface surfaceWS) {
#if defined(LIGHTMAP_ON)
return 0.0;
#else
if (unity_ProbeVolumeParams.x) {
return SampleProbeVolumeSH4(
TEXTURE3D_ARGS(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH),
surfaceWS.position, surfaceWS.normal,
unity_ProbeVolumeWorldToObject,
unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z,
unity_ProbeVolumeMin.xyz, unity_ProbeVolumeSizeInv.xyz
);
}
else {
float4 coefficients[7];
coefficients[0] = unity_SHAr;
coefficients[1] = unity_SHAg;
coefficients[2] = unity_SHAb;
coefficients[3] = unity_SHBr;
coefficients[4] = unity_SHBg;
coefficients[5] = unity_SHBb;
coefficients[6] = unity_SHC;
return max(0.0, SampleSH9(coefficients, surfaceWS.normal));
}
#endif
}
float4 SampleLightProbeOcclusion (Surface surfaceWS) {
return unity_ProbesOcclusion;
}
float4 SampleBakedShadows (float2 lightMapUV, Surface surfaceWS) {
#if defined(LIGHTMAP_ON)
return SAMPLE_TEXTURE2D(
unity_ShadowMask, samplerunity_ShadowMask, lightMapUV
);
#else
if (unity_ProbeVolumeParams.x) {
return SampleProbeOcclusion(
TEXTURE3D_ARGS(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH),
surfaceWS.position, unity_ProbeVolumeWorldToObject,
unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z,
unity_ProbeVolumeMin.xyz, unity_ProbeVolumeSizeInv.xyz
);
}
else {
return unity_ProbesOcclusion;
}
#endif
}
GI GetGI (float2 lightMapUV, Surface surfaceWS) {
GI gi;
gi.diffuse = SampleLightMap(lightMapUV) + SampleLightProbe(surfaceWS);
gi.shadowMask.always = false;
gi.shadowMask.distance = false;
gi.shadowMask.shadows = 1.0;
#if defined(_SHADOW_MASK_ALWAYS)
gi.shadowMask.always = true;
gi.shadowMask.shadows = SampleBakedShadows(lightMapUV, surfaceWS);
#elif defined(_SHADOW_MASK_DISTANCE)
gi.shadowMask.distance = true;
gi.shadowMask.shadows = SampleBakedShadows(lightMapUV, surfaceWS);
#endif
return gi;
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 172451413b465f34786bae0116837245
guid: 188ff707ce3e84a37825705a59d648bd
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_LIGHT_INCLUDED
#define CUSTOM_LIGHT_INCLUDED
#define MAX_DIRECTIONAL_LIGHT_COUNT 4
CBUFFER_START(_CustomLight)
int _DirectionalLightCount;
float4 _DirectionalLightColors[MAX_DIRECTIONAL_LIGHT_COUNT];
float4 _DirectionalLightDirections[MAX_DIRECTIONAL_LIGHT_COUNT];
float4 _DirectionalLightShadowData[MAX_DIRECTIONAL_LIGHT_COUNT];
CBUFFER_END
struct Light {
float3 color;
float3 direction;
float attenuation;
};
int GetDirectionalLightCount () {
return _DirectionalLightCount;
}
DirectionalShadowData GetDirectionalShadowData (
int lightIndex, ShadowData shadowData
) {
DirectionalShadowData data;
data.strength = _DirectionalLightShadowData[lightIndex].x;
data.tileIndex =
_DirectionalLightShadowData[lightIndex].y + shadowData.cascadeIndex;
data.normalBias = _DirectionalLightShadowData[lightIndex].z;
data.shadowMaskChannel = _DirectionalLightShadowData[lightIndex].w;
return data;
}
Light GetDirectionalLight (int index, Surface surfaceWS, ShadowData shadowData) {
Light light;
light.color = _DirectionalLightColors[index].rgb;
light.direction = _DirectionalLightDirections[index].xyz;
DirectionalShadowData dirShadowData =
GetDirectionalShadowData(index, shadowData);
light.attenuation =
GetDirectionalShadowAttenuation(dirShadowData, shadowData, surfaceWS);
return light;
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 02fdfa9fa783df346a5e57ca14275e5e
guid: 265f4c35c0f1e42c2a028bbda0726867
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_LIGHTING_INCLUDED
#define CUSTOM_LIGHTING_INCLUDED
float3 IncomingLight (Surface surface, Light light) {
return
saturate(dot(surface.normal, light.direction) * light.attenuation) *
light.color;
}
float3 GetLighting (Surface surface, BRDF brdf, Light light) {
return IncomingLight(surface, light) * DirectBRDF(surface, brdf, light);
}
float3 GetLighting (Surface surfaceWS, BRDF brdf, GI gi) {
ShadowData shadowData = GetShadowData(surfaceWS);
shadowData.shadowMask = gi.shadowMask;
float3 color = gi.diffuse * brdf.diffuse;
for (int i = 0; i < GetDirectionalLightCount(); i++) {
Light light = GetDirectionalLight(i, surfaceWS, shadowData);
color += GetLighting(surfaceWS, brdf, light);
}
return color;
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: a6c7860b1963c2a4983cfc471820dbfd
guid: 2497186494b3c431e832c9a1d0cc4406
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_SHADOWS_INCLUDED
#define CUSTOM_SHADOWS_INCLUDED
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Shadow/ShadowSamplingTent.hlsl"
#if defined(_DIRECTIONAL_PCF3)
#define DIRECTIONAL_FILTER_SAMPLES 4
#define DIRECTIONAL_FILTER_SETUP SampleShadow_ComputeSamples_Tent_3x3
#elif defined(_DIRECTIONAL_PCF5)
#define DIRECTIONAL_FILTER_SAMPLES 9
#define DIRECTIONAL_FILTER_SETUP SampleShadow_ComputeSamples_Tent_5x5
#elif defined(_DIRECTIONAL_PCF7)
#define DIRECTIONAL_FILTER_SAMPLES 16
#define DIRECTIONAL_FILTER_SETUP SampleShadow_ComputeSamples_Tent_7x7
#endif
#define MAX_SHADOWED_DIRECTIONAL_LIGHT_COUNT 4
#define MAX_CASCADE_COUNT 4
TEXTURE2D_SHADOW(_DirectionalShadowAtlas);
#define SHADOW_SAMPLER sampler_linear_clamp_compare
SAMPLER_CMP(SHADOW_SAMPLER);
CBUFFER_START(_CustomShadows)
int _CascadeCount;
float4 _CascadeCullingSpheres[MAX_CASCADE_COUNT];
float4 _CascadeData[MAX_CASCADE_COUNT];
float4x4 _DirectionalShadowMatrices
[MAX_SHADOWED_DIRECTIONAL_LIGHT_COUNT * MAX_CASCADE_COUNT];
float4 _ShadowAtlasSize;
float4 _ShadowDistanceFade;
CBUFFER_END
struct ShadowMask {
bool always;
bool distance;
float4 shadows;
};
float GetBakedShadow (ShadowMask mask, int channel) {
float shadow = 1.0;
if (mask.always || mask.distance) {
if (channel >= 0) {
shadow = mask.shadows[channel];
}
}
return shadow;
}
float GetBakedShadow (ShadowMask mask, int channel, float strength) {
if (mask.always || mask.distance) {
return lerp(1.0, GetBakedShadow(mask, channel), strength);
}
return 1.0;
}
struct ShadowData {
int cascadeIndex;
float cascadeBlend;
float strength;
ShadowMask shadowMask;
};
float MixBakedAndRealtimeShadows (
ShadowData global, float shadow, int shadowMaskChannel, float strength
) {
float baked = GetBakedShadow(global.shadowMask, shadowMaskChannel);
if (global.shadowMask.always) {
shadow = lerp(1.0, shadow, global.strength);
shadow = min(baked, shadow);
return lerp(1.0, shadow, strength);
}
if (global.shadowMask.distance) {
shadow = lerp(baked, shadow, global.strength);
return lerp(1.0, shadow, strength);
}
return lerp(1.0, shadow, strength * global.strength);
}
float FadedShadowStrength (float distance, float scale, float fade) {
return saturate((1.0 - distance * scale) * fade);
}
ShadowData GetShadowData (Surface surfaceWS) {
ShadowData data;
data.shadowMask.always = false;
data.shadowMask.distance = false;
data.shadowMask.shadows = 1.0;
data.cascadeBlend = 1.0;
data.strength = FadedShadowStrength(
surfaceWS.depth, _ShadowDistanceFade.x, _ShadowDistanceFade.y
);
int i;
for (i = 0; i < _CascadeCount; i++) {
float4 sphere = _CascadeCullingSpheres[i];
float distanceSqr = DistanceSquared(surfaceWS.position, sphere.xyz);
if (distanceSqr < sphere.w) {
float fade = FadedShadowStrength(
distanceSqr, _CascadeData[i].x, _ShadowDistanceFade.z
);
if (i == _CascadeCount - 1) {
data.strength *= fade;
}
else {
data.cascadeBlend = fade;
}
break;
}
}
if (i == _CascadeCount) {
data.strength = 0.0;
}
#if defined(_CASCADE_BLEND_DITHER)
else if (data.cascadeBlend < surfaceWS.dither) {
i += 1;
}
#endif
#if !defined(_CASCADE_BLEND_SOFT)
data.cascadeBlend = 1.0;
#endif
data.cascadeIndex = i;
return data;
}
struct DirectionalShadowData {
float strength;
int tileIndex;
float normalBias;
int shadowMaskChannel;
};
float SampleDirectionalShadowAtlas (float3 positionSTS) {
return SAMPLE_TEXTURE2D_SHADOW(
_DirectionalShadowAtlas, SHADOW_SAMPLER, positionSTS
);
}
float FilterDirectionalShadow (float3 positionSTS) {
#if defined(DIRECTIONAL_FILTER_SETUP)
float weights[DIRECTIONAL_FILTER_SAMPLES];
float2 positions[DIRECTIONAL_FILTER_SAMPLES];
float4 size = _ShadowAtlasSize.yyxx;
DIRECTIONAL_FILTER_SETUP(size, positionSTS.xy, weights, positions);
float shadow = 0;
for (int i = 0; i < DIRECTIONAL_FILTER_SAMPLES; i++) {
shadow += weights[i] * SampleDirectionalShadowAtlas(
float3(positions[i].xy, positionSTS.z)
);
}
return shadow;
#else
return SampleDirectionalShadowAtlas(positionSTS);
#endif
}
float GetCascadedShadow (
DirectionalShadowData directional, ShadowData global, Surface surfaceWS
) {
float3 normalBias = surfaceWS.normal *
(directional.normalBias * _CascadeData[global.cascadeIndex].y);
float3 positionSTS = mul(
_DirectionalShadowMatrices[directional.tileIndex],
float4(surfaceWS.position + normalBias, 1.0)
).xyz;
float shadow = FilterDirectionalShadow(positionSTS);
if (global.cascadeBlend < 1.0) {
normalBias = surfaceWS.normal *
(directional.normalBias * _CascadeData[global.cascadeIndex + 1].y);
positionSTS = mul(
_DirectionalShadowMatrices[directional.tileIndex + 1],
float4(surfaceWS.position + normalBias, 1.0)
).xyz;
shadow = lerp(
FilterDirectionalShadow(positionSTS), shadow, global.cascadeBlend
);
}
return shadow;
}
float GetDirectionalShadowAttenuation (
DirectionalShadowData directional, ShadowData global, Surface surfaceWS
) {
#if !defined(_RECEIVE_SHADOWS)
return 1.0;
#endif
float shadow;
if (directional.strength * global.strength <= 0.0) {
shadow = GetBakedShadow(
global.shadowMask, directional.shadowMaskChannel,
abs(directional.strength)
);
}
else {
shadow = GetCascadedShadow(directional, global, surfaceWS);
shadow = MixBakedAndRealtimeShadows(
global, shadow, directional.shadowMaskChannel, directional.strength
);
}
return shadow;
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: c7d5fcbd6bd13b04da4785c60ca22495
guid: 9538e7aa48fbf4d08bd0a5569537d276
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_SURFACE_INCLUDED
#define CUSTOM_SURFACE_INCLUDED
struct Surface {
float3 position;
float3 normal;
float3 viewDirection;
float depth;
float3 color;
float alpha;
float metallic;
float smoothness;
float dither;
};
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: ab8dce4b88eb72c4897fa48126f98ebd
guid: 1261912f03d8c4de2b9974630ef65445
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_UNITY_INPUT_INCLUDED
#define CUSTOM_UNITY_INPUT_INCLUDED
CBUFFER_START(UnityPerDraw)
float4x4 unity_ObjectToWorld;
float4x4 unity_WorldToObject;
float4 unity_LODFade;
real4 unity_WorldTransformParams;
float4 unity_ProbesOcclusion;
float4 unity_LightmapST;
float4 unity_DynamicLightmapST;
float4 unity_SHAr;
float4 unity_SHAg;
float4 unity_SHAb;
float4 unity_SHBr;
float4 unity_SHBg;
float4 unity_SHBb;
float4 unity_SHC;
float4 unity_ProbeVolumeParams;
float4x4 unity_ProbeVolumeWorldToObject;
float4 unity_ProbeVolumeSizeInv;
float4 unity_ProbeVolumeMin;
CBUFFER_END
float4x4 unity_MatrixVP;
float4x4 unity_MatrixV;
float4x4 glstate_matrix_projection;
float3 _WorldSpaceCameraPos;
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 963698e3dc3a5284994ab2ea9c2877d1
guid: 17a2d899cf2494d72a789255e1c5012d
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 54920b50b42280f4faa13292bc839719
guid: 725b9a301060546ae912eb515a7d91c7
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
Shader "Custom RP/Lit" {
Properties {
_BaseMap("Texture", 2D) = "white" {}
_BaseColor("Color", Color) = (0.5, 0.5, 0.5, 1.0)
_Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[Toggle(_CLIPPING)] _Clipping ("Alpha Clipping", Float) = 0
[Toggle(_RECEIVE_SHADOWS)] _ReceiveShadows ("Receive Shadows", Float) = 1
[KeywordEnum(On, Clip, Dither, Off)] _Shadows ("Shadows", Float) = 0
_Metallic ("Metallic", Range(0, 1)) = 0
_Smoothness ("Smoothness", Range(0, 1)) = 0.5
[NoScaleOffset] _EmissionMap("Emission", 2D) = "white" {}
[HDR] _EmissionColor("Emission", Color) = (0.0, 0.0, 0.0, 0.0)
[Toggle(_PREMULTIPLY_ALPHA)] _PremulAlpha ("Premultiply Alpha", Float) = 0
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend", Float) = 1
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend", Float) = 0
[Enum(Off, 0, On, 1)] _ZWrite ("Z Write", Float) = 1
[HideInInspector] _MainTex("Texture for Lightmap", 2D) = "white" {}
[HideInInspector] _Color("Color for Lightmap", Color) = (0.5, 0.5, 0.5, 1.0)
}
SubShader {
HLSLINCLUDE
#include "../ShaderLibrary/Common.hlsl"
#include "LitInput.hlsl"
ENDHLSL
Pass {
Tags {
"LightMode" = "CustomLit"
}
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
HLSLPROGRAM
#pragma target 3.5
#pragma shader_feature _CLIPPING
#pragma shader_feature _RECEIVE_SHADOWS
#pragma shader_feature _PREMULTIPLY_ALPHA
#pragma multi_compile _ _DIRECTIONAL_PCF3 _DIRECTIONAL_PCF5 _DIRECTIONAL_PCF7
#pragma multi_compile _ _CASCADE_BLEND_SOFT _CASCADE_BLEND_DITHER
#pragma multi_compile _ _SHADOW_MASK_ALWAYS _SHADOW_MASK_DISTANCE
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_instancing
#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
#include "LitPass.hlsl"
ENDHLSL
}
Pass {
Tags {
"LightMode" = "ShadowCaster"
}
ColorMask 0
HLSLPROGRAM
#pragma target 3.5
#pragma shader_feature _ _SHADOWS_CLIP _SHADOWS_DITHER
#pragma multi_compile_instancing
#pragma vertex ShadowCasterPassVertex
#pragma fragment ShadowCasterPassFragment
#include "ShadowCasterPass.hlsl"
ENDHLSL
}
Pass {
Tags {
"LightMode" = "Meta"
}
Cull Off
HLSLPROGRAM
#pragma target 3.5
#pragma vertex MetaPassVertex
#pragma fragment MetaPassFragment
#include "MetaPass.hlsl"
ENDHLSL
}
}
CustomEditor "CustomShaderGUI"
}
\ No newline at end of file
fileFormatVersion: 2
guid: 6848ac66b88696c4ea2f1389e0877b8e
guid: d2c448af154f94dda8a9c42d2b0171f0
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_LIT_INPUT_INCLUDED
#define CUSTOM_LIT_INPUT_INCLUDED
TEXTURE2D(_BaseMap);
TEXTURE2D(_EmissionMap);
SAMPLER(sampler_BaseMap);
UNITY_INSTANCING_BUFFER_START(UnityPerMaterial)
UNITY_DEFINE_INSTANCED_PROP(float4, _BaseMap_ST)
UNITY_DEFINE_INSTANCED_PROP(float4, _BaseColor)
UNITY_DEFINE_INSTANCED_PROP(float4, _EmissionColor)
UNITY_DEFINE_INSTANCED_PROP(float, _Cutoff)
UNITY_DEFINE_INSTANCED_PROP(float, _Metallic)
UNITY_DEFINE_INSTANCED_PROP(float, _Smoothness)
UNITY_INSTANCING_BUFFER_END(UnityPerMaterial)
float2 TransformBaseUV (float2 baseUV) {
float4 baseST = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BaseMap_ST);
return baseUV * baseST.xy + baseST.zw;
}
float4 GetBase (float2 baseUV) {
float4 map = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, baseUV);
float4 color = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BaseColor);
return map * color;
}
float3 GetEmission (float2 baseUV) {
float4 map = SAMPLE_TEXTURE2D(_EmissionMap, sampler_BaseMap, baseUV);
float4 color = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _EmissionColor);
return map.rgb * color.rgb;
}
float GetCutoff (float2 baseUV) {
return UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Cutoff);
}
float GetMetallic (float2 baseUV) {
return UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Metallic);
}
float GetSmoothness (float2 baseUV) {
return UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Smoothness);
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 69d7da49567b5224da7d86aa2f6732e4
guid: 573a7862ca40349c6a034051954a0375
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_LIT_PASS_INCLUDED
#define CUSTOM_LIT_PASS_INCLUDED
#include "../ShaderLibrary/Surface.hlsl"
#include "../ShaderLibrary/Shadows.hlsl"
#include "../ShaderLibrary/Light.hlsl"
#include "../ShaderLibrary/BRDF.hlsl"
#include "../ShaderLibrary/GI.hlsl"
#include "../ShaderLibrary/Lighting.hlsl"
struct Attributes {
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 baseUV : TEXCOORD0;
GI_ATTRIBUTE_DATA
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings {
float4 positionCS : SV_POSITION;
float3 positionWS : VAR_POSITION;
float3 normalWS : VAR_NORMAL;
float2 baseUV : VAR_BASE_UV;
GI_VARYINGS_DATA
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Varyings LitPassVertex (Attributes input) {
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
TRANSFER_GI_DATA(input, output);
output.positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(output.positionWS);
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
output.baseUV = TransformBaseUV(input.baseUV);
return output;
}
float4 LitPassFragment (Varyings input) : SV_TARGET {
UNITY_SETUP_INSTANCE_ID(input);
float4 base = GetBase(input.baseUV);
#if defined(_CLIPPING)
clip(base.a - GetCutoff(input.baseUV));
#endif
Surface surface;
surface.position = input.positionWS;
surface.normal = normalize(input.normalWS);
surface.viewDirection = normalize(_WorldSpaceCameraPos - input.positionWS);
surface.depth = -TransformWorldToView(input.positionWS).z;
surface.color = base.rgb;
surface.alpha = base.a;
surface.metallic = GetMetallic(input.baseUV);
surface.smoothness = GetSmoothness(input.baseUV);
surface.dither = InterleavedGradientNoise(input.positionCS.xy, 0);
#if defined(_PREMULTIPLY_ALPHA)
BRDF brdf = GetBRDF(surface, true);
#else
BRDF brdf = GetBRDF(surface);
#endif
GI gi = GetGI(GI_FRAGMENT_DATA(input), surface);
float3 color = GetLighting(surface, brdf, gi);
color += GetEmission(input.baseUV);
return float4(color, surface.alpha);
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 0a7dab52c92acc3438e7792caa536224
guid: 1e4737e49ebaa40b093265b56544bfc5
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_META_PASS_INCLUDED
#define CUSTOM_META_PASS_INCLUDED
#include "../ShaderLibrary/Surface.hlsl"
#include "../ShaderLibrary/Shadows.hlsl"
#include "../ShaderLibrary/Light.hlsl"
#include "../ShaderLibrary/BRDF.hlsl"
bool4 unity_MetaFragmentControl;
float unity_OneOverOutputBoost;
float unity_MaxOutputValue;
struct Attributes {
float3 positionOS : POSITION;
float2 baseUV : TEXCOORD0;
float2 lightMapUV : TEXCOORD1;
};
struct Varyings {
float4 positionCS : SV_POSITION;
float2 baseUV : VAR_BASE_UV;
};
Varyings MetaPassVertex (Attributes input) {
Varyings output;
input.positionOS.xy =
input.lightMapUV * unity_LightmapST.xy + unity_LightmapST.zw;
input.positionOS.z = input.positionOS.z > 0.0 ? FLT_MIN : 0.0;
output.positionCS = TransformWorldToHClip(input.positionOS);
output.baseUV = TransformBaseUV(input.baseUV);
return output;
}
float4 MetaPassFragment (Varyings input) : SV_TARGET {
float4 base = GetBase(input.baseUV);
Surface surface;
ZERO_INITIALIZE(Surface, surface);
surface.color = base.rgb;
surface.metallic = GetMetallic(input.baseUV);
surface.smoothness = GetSmoothness(input.baseUV);
BRDF brdf = GetBRDF(surface);
float4 meta = 0.0;
if (unity_MetaFragmentControl.x) {
meta = float4(brdf.diffuse, 1.0);
meta.rgb += brdf.specular * brdf.roughness * 0.5;
meta.rgb = min(
PositivePow(meta.rgb, unity_OneOverOutputBoost), unity_MaxOutputValue
);
}
else if (unity_MetaFragmentControl.y) {
meta = float4(GetEmission(input.baseUV), 1.0);
}
return meta;
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: cbc7a501efec9804894a575cb1e8d0be
guid: 3dbae2431dbcb44778f5982ca718a465
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_SHADOW_CASTER_PASS_INCLUDED
#define CUSTOM_SHADOW_CASTER_PASS_INCLUDED
struct Attributes {
float3 positionOS : POSITION;
float2 baseUV : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings {
float4 positionCS : SV_POSITION;
float2 baseUV : VAR_BASE_UV;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Varyings ShadowCasterPassVertex (Attributes input) {
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
#if UNITY_REVERSED_Z
output.positionCS.z =
min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
#else
output.positionCS.z =
max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
#endif
output.baseUV = TransformBaseUV(input.baseUV);
return output;
}
void ShadowCasterPassFragment (Varyings input) {
UNITY_SETUP_INSTANCE_ID(input);
float4 base = GetBase(input.baseUV);
#if defined(_SHADOWS_CLIP)
clip(base.a - GetCutoff(input.baseUV));
#elif defined(_SHADOWS_DITHER)
float dither = InterleavedGradientNoise(input.positionCS.xy, 0);
clip(base.a - dither);
#endif
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: cf100188a4ff11e4081d3f693d2e2070
guid: bc8b230d49c674e83a182412dbfd5024
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
Shader "Custom RP/Unlit" {
Properties {
_BaseMap("Texture", 2D) = "white" {}
[HDR] _BaseColor("Color", Color) = (1.0, 1.0, 1.0, 1.0)
_Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[Toggle(_CLIPPING)] _Clipping ("Alpha Clipping", Float) = 0
[KeywordEnum(On, Clip, Dither, Off)] _Shadows ("Shadows", Float) = 0
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend", Float) = 1
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend", Float) = 0
[Enum(Off, 0, On, 1)] _ZWrite ("Z Write", Float) = 1
}
SubShader {
HLSLINCLUDE
#include "../ShaderLibrary/Common.hlsl"
#include "UnlitInput.hlsl"
ENDHLSL
Pass {
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
HLSLPROGRAM
#pragma target 3.5
#pragma shader_feature _CLIPPING
#pragma multi_compile_instancing
#pragma vertex UnlitPassVertex
#pragma fragment UnlitPassFragment
#include "UnlitPass.hlsl"
ENDHLSL
}
Pass {
Tags {
"LightMode" = "ShadowCaster"
}
ColorMask 0
HLSLPROGRAM
#pragma target 3.5
#pragma shader_feature _ _SHADOWS_CLIP _SHADOWS_DITHER
#pragma multi_compile_instancing
#pragma vertex ShadowCasterPassVertex
#pragma fragment ShadowCasterPassFragment
#include "ShadowCasterPass.hlsl"
ENDHLSL
}
Pass {
Tags {
"LightMode" = "Meta"
}
Cull Off
HLSLPROGRAM
#pragma target 3.5
#pragma vertex MetaPassVertex
#pragma fragment MetaPassFragment
#include "MetaPass.hlsl"
ENDHLSL
}
}
CustomEditor "CustomShaderGUI"
}
\ No newline at end of file
fileFormatVersion: 2
guid: f9b6d8c713e140648abcabcb6381316f
guid: f75296bb3d7c54300b1456adfb083c1d
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_LIT_INPUT_INCLUDED
#define CUSTOM_LIT_INPUT_INCLUDED
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
UNITY_INSTANCING_BUFFER_START(UnityPerMaterial)
UNITY_DEFINE_INSTANCED_PROP(float4, _BaseMap_ST)
UNITY_DEFINE_INSTANCED_PROP(float4, _BaseColor)
UNITY_DEFINE_INSTANCED_PROP(float, _Cutoff)
UNITY_INSTANCING_BUFFER_END(UnityPerMaterial)
float2 TransformBaseUV (float2 baseUV) {
float4 baseST = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BaseMap_ST);
return baseUV * baseST.xy + baseST.zw;
}
float4 GetBase (float2 baseUV) {
float4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, baseUV);
float4 baseColor = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _BaseColor);
return baseMap * baseColor;
}
float3 GetEmission (float2 baseUV) {
return GetBase(baseUV).rgb;
}
float GetCutoff (float2 baseUV) {
return UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Cutoff);
}
float GetMetallic (float2 baseUV) {
return 0.0;
}
float GetSmoothness (float2 baseUV) {
return 0.0;
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 526b4f3557307a64ba252a7d6c341b1f
guid: 7220a7076ac0e4d21b578e2f763be344
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
#ifndef CUSTOM_UNLIT_PASS_INCLUDED
#define CUSTOM_UNLIT_PASS_INCLUDED
struct Attributes {
float3 positionOS : POSITION;
float2 baseUV : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings {
float4 positionCS : SV_POSITION;
float2 baseUV : VAR_BASE_UV;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Varyings UnlitPassVertex (Attributes input) {
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
output.baseUV = TransformBaseUV(input.baseUV);
return output;
}
float4 UnlitPassFragment (Varyings input) : SV_TARGET {
UNITY_SETUP_INSTANCE_ID(input);
float4 base = GetBase(input.baseUV);
#if defined(_CLIPPING)
clip(base.a - GetCutoff(input.baseUV));
#endif
return base;
}
#endif
\ No newline at end of file
fileFormatVersion: 2
guid: 4995316860cf375428b5ebb1c0f63386
guid: d2de3310d9f97475ebcd6d8e5fd34489
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e10714eb9eadeae4893bcb2fd9868c80
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 986139d63a4a1de47bc4e16456a0f5f3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 3f9cfd75bf046804da74f14135efcde8
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
%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: Unlit Blue Clip
m_Shader: {fileID: 4800000, guid: f9b6d8c713e140648abcabcb6381316f, type: 3}
m_ShaderKeywords: _CLIPPING _SHADOWS_DITHER
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 2450
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 2800000, guid: 5c8805d759cc642b5845cd761592c0c0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Clipping: 1
- _Cull: 2
- _Cutoff: 0.48
- _DstBlend: 0
- _Shadows: 2
- _SrcBlend: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.011569952, g: 0.17123538, b: 0.49056602, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
%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: Unlit Green Opaque
m_Shader: {fileID: 4800000, guid: f9b6d8c713e140648abcabcb6381316f, type: 3}
m_ShaderKeywords: _SHADOWS_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Clipping: 0
- _Cull: 2
- _Cutoff: 0.5
- _DstBlend: 0
- _Shadows: 0
- _SrcBlend: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.41770938, g: 0.7075472, b: 0.36378607, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
%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: Unlit Instanced Clip
m_Shader: {fileID: 4800000, guid: f9b6d8c713e140648abcabcb6381316f, type: 3}
m_ShaderKeywords: _CLIPPING _SHADOWS_DITHER
m_LightmapFlags: 4
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
m_CustomRenderQueue: 2450
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 2800000, guid: 5c8805d759cc642b5845cd761592c0c0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Clipping: 1
- _Cull: 2
- _Cutoff: 0.271
- _DstBlend: 0
- _Shadows: 2
- _SrcBlend: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
%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: Unlit Red Opaque
m_Shader: {fileID: 4800000, guid: f9b6d8c713e140648abcabcb6381316f, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Clipping: 0
- _Cull: 2
- _Cutoff: 0.5
- _DstBlend: 10
- _Shadows: 0
- _SrcBlend: 5
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 0.8207547, g: 0.18970275, b: 0.18970275, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
fileFormatVersion: 2
guid: b49fb4a37819f4fd1b58ff3e374e7cc1
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
%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: Unlit Yellow Transparent
m_Shader: {fileID: 4800000, guid: f9b6d8c713e140648abcabcb6381316f, type: 3}
m_ShaderKeywords: _SHADOWS_DITHER
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 2800000, guid: 5c8805d759cc642b5845cd761592c0c0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Clipping: 0
- _Cull: 2
- _Cutoff: 0.2
- _DstBlend: 10
- _Shadows: 2
- _SrcBlend: 5
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 1, g: 0.92719114, b: 0, a: 0.49803922}
- _Color: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
fileFormatVersion: 2
guid: f622cecbb39254e169592126596c3ca4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,7 +6,7 @@ LightingSettings:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Baked LightSettings
m_Name: Baked Light Settings
serializedVersion: 3
m_GIWorkflowMode: 1
m_EnableBakedLightmaps: 1
......@@ -18,16 +18,16 @@ LightingSettings:
m_UsingShadowmask: 1
m_BakeBackend: 1
m_LightmapMaxSize: 1024
m_BakeResolution: 20
m_BakeResolution: 40
m_Padding: 2
m_TextureCompression: 0
m_TextureCompression: 1
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAO: 0
m_MixedBakeMode: 2
m_LightmapsBakeMode: 0
m_LightmapsBakeMode: 1
m_FilterMode: 1
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0}
m_ExportTrainingData: 0
......@@ -41,17 +41,17 @@ LightingSettings:
m_PVRCulling: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVREnvironmentSampleCount: 500
m_PVRSampleCount: 512
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_LightProbeSampleCountMultiplier: 4
m_PVRBounces: 2
m_PVRMinBounces: 2
m_PVREnvironmentMIS: 0
m_PVRMinBounces: 1
m_PVREnvironmentMIS: 1
m_PVRFilteringMode: 2
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 0
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
......
fileFormatVersion: 2
guid: b7908db805350004dbfd6481e8c952db
guid: 1556591ee3227314c9a52a04dddc0ddf
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4890085278179872738
......
fileFormatVersion: 2
guid: e2a4b7ede76e4af4fb4257401dcb4f38
guid: 8574b4573e3c34a1ebc1b5d608e35b66
folderAsset: yes
DefaultImporter:
externalObjects: {}
......
此差异已折叠。
fileFormatVersion: 2
guid: b9571aa5227604142af28ef6f1574e67
guid: 8906592143b104fbdb4c313b4ab8132c
DefaultImporter:
externalObjects: {}
userData:
......
fileFormatVersion: 2
guid: 85d916ba4b10e5a439529112c914edd1
guid: 4772e383a675c4016a19a76456116c09
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 112000000
......
fileFormatVersion: 2
guid: d8ba05fd5d927064b8edccb12f092618
guid: eb5027765e9124d74aea8517bc5b5ff7
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 1
......@@ -23,7 +23,6 @@ TextureImporter:
isReadable: 0
streamingMipmaps: 1
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
......@@ -55,13 +54,9 @@ TextureImporter:
textureType: 6
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
......
fileFormatVersion: 2
guid: 8c14825d4452f5b4492c963b62481681
guid: 31afb30c757ea4b828c2f7de72c2dc7e
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 1
......@@ -23,7 +23,6 @@ TextureImporter:
isReadable: 0
streamingMipmaps: 1
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
......@@ -49,19 +48,15 @@ TextureImporter:
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 0
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 11
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
......
fileFormatVersion: 2
guid: d2b4b32fdde91cd48a302e248d09e219
guid: 5c403d4740467403b8e46a1e11e971ad
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 1
......@@ -23,7 +23,6 @@ TextureImporter:
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 1
......@@ -55,13 +54,9 @@ TextureImporter:
textureType: 0
textureShape: 2
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &994350420228217417
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 994350420228217420}
- component: {fileID: 994350420228217421}
- component: {fileID: 994350420228217422}
- component: {fileID: 994350420228217423}
- component: {fileID: 994350420228217416}
m_Layer: 0
m_Name: LOD 0-2 Cube Red
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &994350420228217420
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 994350420228217417}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.25, z: 0}
m_LocalScale: {x: 1, y: 0.5, z: 1}
m_Children: []
m_Father: {fileID: 2535136183800144220}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &994350420228217421
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 994350420228217417}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &994350420228217422
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 994350420228217417}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 3f679c73ce40f49b4922406c03e95520, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &994350420228217423
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 994350420228217417}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &994350420228217416
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 994350420228217417}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12b34fac330b345eea0c6df7126deddc, type: 3}
m_Name:
m_EditorClassIdentifier:
baseColor: {r: 0.7254902, g: 0, b: 0, a: 1}
alphaCutoff: 0.5
metallic: 0
smoothness: 0.5
emissionColor: {r: 0, g: 0, b: 0, a: 1}
--- !u!1 &2141166064219846745
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2535136183800144220}
- component: {fileID: 5089332059524758326}
m_Layer: 0
m_Name: LOD Group Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2535136183800144220
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2141166064219846745}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 8714370529839337139}
- {fileID: 2728862693902475888}
- {fileID: 994350420228217420}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!205 &5089332059524758326
LODGroup:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2141166064219846745}
serializedVersion: 2
m_LocalReferencePoint: {x: 0, y: -0.0625, z: 0}
m_Size: 1
m_FadeMode: 1
m_AnimateCrossFading: 1
m_LastLODIsBillboard: 0
m_LODs:
- screenRelativeHeight: 0.6
fadeTransitionWidth: 1
renderers:
- renderer: {fileID: 3693176207771684284}
- renderer: {fileID: 5101362896890923213}
- renderer: {fileID: 994350420228217422}
- screenRelativeHeight: 0.3
fadeTransitionWidth: 1
renderers:
- renderer: {fileID: 5101362896890923213}
- renderer: {fileID: 994350420228217422}
- screenRelativeHeight: 0.1
fadeTransitionWidth: 1
renderers:
- renderer: {fileID: 994350420228217422}
m_Enabled: 1
--- !u!1 &3688328560882179645
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2728862693902475888}
- component: {fileID: 4117708638078305695}
- component: {fileID: 5101362896890923213}
- component: {fileID: 6552578058566079033}
- component: {fileID: 7817595681931959416}
m_Layer: 0
m_Name: LOD 0-1 Cube Cyan
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2728862693902475888
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3688328560882179645}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.125, z: 0}
m_LocalScale: {x: 0.5, y: 0.25, z: 0.5}
m_Children: []
m_Father: {fileID: 2535136183800144220}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &4117708638078305695
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3688328560882179645}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &5101362896890923213
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3688328560882179645}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 3f679c73ce40f49b4922406c03e95520, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &6552578058566079033
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3688328560882179645}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &7817595681931959416
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3688328560882179645}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12b34fac330b345eea0c6df7126deddc, type: 3}
m_Name:
m_EditorClassIdentifier:
baseColor: {r: 0, g: 0.7921569, b: 0.7921569, a: 1}
alphaCutoff: 0.5
metallic: 0
smoothness: 0.5
emissionColor: {r: 0, g: 0, b: 0, a: 1}
--- !u!1 &8675274081308385985
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8714370529839337139}
- component: {fileID: 6778171592655784463}
- component: {fileID: 3693176207771684284}
- component: {fileID: 5500902755951689310}
- component: {fileID: 7918401428354411016}
m_Layer: 0
m_Name: LOD 0 Cube Yellow
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8714370529839337139
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8675274081308385985}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.3125, z: 0}
m_LocalScale: {x: 0.25, y: 0.125, z: 0.25}
m_Children: []
m_Father: {fileID: 2535136183800144220}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &6778171592655784463
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8675274081308385985}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &3693176207771684284
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8675274081308385985}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 3f679c73ce40f49b4922406c03e95520, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &5500902755951689310
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8675274081308385985}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &7918401428354411016
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8675274081308385985}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12b34fac330b345eea0c6df7126deddc, type: 3}
m_Name:
m_EditorClassIdentifier:
baseColor: {r: 1, g: 1, b: 0.2784314, a: 1}
alphaCutoff: 0.5
metallic: 0
smoothness: 0.5
emissionColor: {r: 0, g: 0, b: 0, a: 1}
fileFormatVersion: 2
guid: 14595156b0dc840aa81a612fd2214d99
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
此差异已折叠。
fileFormatVersion: 2
guid: 2f5e62859100a43eaaeca02977c32a39
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
此差异已折叠。
fileFormatVersion: 2
guid: 49c158928796e4610913f5f1cff12fa8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
此差异已折叠。
fileFormatVersion: 2
guid: f7f2953c9746f194982804f6b5148a7b
guid: 9fc0d4010bbf28b4594072e72b8655ab
DefaultImporter:
externalObjects: {}
userData:
......
此差异已折叠。
using UnityEngine;
using UnityEngine.Rendering;
/// <summary>
/// 生成1023个mesh和小球对象
/// </summary>
public class MeshBall : MonoBehaviour
{
static int baseColorId = Shader.PropertyToID("_BaseColor");
static int metallicId = Shader.PropertyToID("_Metallic");
static int smoothnessId = Shader.PropertyToID("_Smoothness");
[SerializeField]
Mesh mesh = default;
[SerializeField]
Material material = default;
[SerializeField]
LightProbeProxyVolume lightProbeVolume = null;
// 添加金属度和光滑度属性调节参数
Matrix4x4[] matrices = new Matrix4x4[1023];
Vector4[] baseColors = new Vector4[1023];
MaterialPropertyBlock block;
float[] metallic = new float[1023];
float[] smoothness = new float[1023];
void Awake()
{
for (int i = 0; i < matrices.Length; i++)
{
// 创建随机转换矩阵和颜色
matrices[i] = Matrix4x4.TRS(
Random.insideUnitSphere * 10f,
Quaternion.Euler(
Random.value * 360f, Random.value * 360f, Random.value * 360f
),
Vector3.one * Random.Range(0.5f, 1.5f)
);
baseColors[i] = new Vector4(
Random.value, Random.value, Random.value,
Random.Range(0.5f, 1f)
);
// 金属度和光滑度按条件随机
metallic[i] = Random.value < 0.25f ? 1f : 0f;
smoothness[i] = Random.Range(0.05f, 0.95f);
}
}
void Update()
{
if (block == null)
{
// 随机属性发送到着色器
block = new MaterialPropertyBlock();
block.SetVectorArray(baseColorId, baseColors);
block.SetFloatArray(metallicId, metallic);
block.SetFloatArray(smoothnessId, smoothness);
if (!lightProbeVolume)
{
var positions = new Vector3[1023];
for (int i = 0; i < matrices.Length; i++)
{
positions[i] = matrices[i].GetColumn(3);
}
var lightProbes = new SphericalHarmonicsL2[1023];
var occlusionProbes = new Vector4[1023];
LightProbes.CalculateInterpolatedLightAndOcclusionProbes(
positions, lightProbes, occlusionProbes
);
block.CopySHCoefficientArraysFrom(lightProbes);
block.CopyProbeOcclusionArrayFrom(occlusionProbes);
}
}
// 绘制网格实例
Graphics.DrawMeshInstanced(mesh, 0, material, matrices, 1023, block,
ShadowCastingMode.On, true, 0, null, lightProbeVolume ? LightProbeUsage.UseProxyVolume : LightProbeUsage.CustomProvided, lightProbeVolume);
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册