Peter Bay Bastian
7 年前
当前提交
ba0ce030
共有 85 个文件被更改,包括 1604 次插入 和 412 次删除
-
8README.md
-
2ScriptableRenderPipeline/Core/CoreRP/CoreResources/EncodeBC6H.compute
-
2ScriptableRenderPipeline/Core/CoreRP/CoreResources/GPUCopy.compute
-
9ScriptableRenderPipeline/Core/CoreRP/Debugging/DebugUI.Fields.cs
-
9ScriptableRenderPipeline/Core/CoreRP/Editor/MaterialUpgrader.cs
-
2ScriptableRenderPipeline/Core/CoreRP/Editor/Volume/VolumeProfileFactory.cs
-
19ScriptableRenderPipeline/Core/CoreRP/Inputs/InputRegistering.cs
-
10ScriptableRenderPipeline/Core/CoreRP/Shadow/AdditionalShadowData.cs
-
19ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs
-
2ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute
-
12ScriptableRenderPipeline/Core/CoreRP/TextureCache.cs
-
4ScriptableRenderPipeline/Core/package.json
-
96ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
-
31ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs
-
46ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineMenuItems.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
-
136ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/ProceduralSky/ProceduralSkyEditor.cs
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/SkySettingsEditor.cs
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/UpgradeStandardShaderMaterials.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/DeferredDirectionalShadow.compute
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Light/HDAdditionalLightData.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Light/HDLightEditorUtilities.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/Deferred.compute
-
234ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/builddispatchindirect.compute
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/cleardispatchindirect.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild-bigtile.compute
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild-clustered.compute
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/lightlistbuild.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/materialflags.compute
-
26ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/scrbound.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/Resources/VolumetricLighting.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/GGXConvolution/BuildProbabilityTables.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/GGXConvolution/ComputeGgxIblSampleData.compute
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/ApplyDistorsion.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/ColorPyramid.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/DepthPyramid.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariablesMatrixDefsHDCamera.hlsl
-
46ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/HDShadowSettings.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/HDRISky/HDRISkyRenderer.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/ProceduralSky/ProceduralSkyRenderer.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyManager.cs
-
6ScriptableRenderPipeline/HDRenderPipeline/package.json
-
11ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs
-
21ScriptableRenderPipeline/LightweightPipeline/LWRP/Materials/Lightweight-DefaultParticle.mat
-
10ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardUnlit.shader
-
6ScriptableRenderPipeline/LightweightPipeline/package.json
-
4ScriptableRenderPipeline/master-package.json
-
8ScriptableRenderPipeline/Core/CoreRP/Editor/TextureCombiner.meta
-
208ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/StandardsToHDLitMaterialUpgrader.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/StandardsToHDLitMaterialUpgrader.cs.meta
-
44ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Unlit/UnlitsToHDUnlitUpgrader.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Unlit/UnlitsToHDUnlitUpgrader.cs.meta
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Shadows.meta
-
67ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtils.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtils.cs.meta
-
16ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/ContactShadows.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/ContactShadows.cs.meta
-
11ScriptableRenderPipeline/Core/CoreRP/Editor/TextureCombiner/TextureCombiner.cs.meta
-
9ScriptableRenderPipeline/Core/CoreRP/Editor/TextureCombiner/TextureCombiner.shader.meta
-
282ScriptableRenderPipeline/Core/CoreRP/Editor/TextureCombiner/TextureCombiner.cs
-
98ScriptableRenderPipeline/Core/CoreRP/Editor/TextureCombiner/TextureCombiner.shader
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Shadows/HDShadowSettingsEditor.cs.meta
-
66ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Shadows/HDShadowSettingsEditor.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Shadows/ContactShadowsEditor.cs.meta
-
57ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Shadows/ContactShadowsEditor.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/StandardSpecularToHDLitMaterialUpgrader.cs.meta
-
12ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/StandardToHDLitMaterialUpgrader.cs.meta
-
45ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/StandardToHDLitMaterialUpgrader.cs
-
43ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/StandardSpecularToHDLitMaterialUpgrader.cs
-
3Tests/Scripts/Editor/MaterialUpgraderTests.cs.meta
-
61Tests/Scripts/Editor/MaterialUpgraderTests.cs
|
|||
{ |
|||
"name": "com.unity.render-pipelines.core", |
|||
"description": "Core library for Unity render pipelines.", |
|||
"version": "0.1.32", |
|||
"version": "0.1.33", |
|||
"com.unity.postprocessing": "0.1.8" |
|||
"com.unity.postprocessing": "0.2.0" |
|||
} |
|||
} |
|
|||
{ |
|||
"name": "com.unity.render-pipelines.high-definition", |
|||
"description": "HD Render Pipeline for Unity.", |
|||
"version": "0.1.32", |
|||
"version": "0.1.33", |
|||
"com.unity.postprocessing": "0.1.8", |
|||
"com.unity.render-pipelines.core": "0.1.32" |
|||
"com.unity.postprocessing": "0.2.0", |
|||
"com.unity.render-pipelines.core": "0.1.33" |
|||
} |
|||
} |
|
|||
{ |
|||
"name": "com.unity.render-pipelines.lightweight", |
|||
"description": "Lightweight Render Pipeline for Unity.", |
|||
"version": "0.1.32", |
|||
"version": "0.1.33", |
|||
"com.unity.postprocessing": "0.1.8", |
|||
"com.unity.render-pipelines.core": "0.1.32" |
|||
"com.unity.postprocessing": "0.2.0", |
|||
"com.unity.render-pipelines.core": "0.1.33" |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 87845c683f4fa7546a3910e641768da8 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class StandardsToHDLitMaterialUpgrader : MaterialUpgrader |
|||
{ |
|||
static readonly string Standard = "Standard"; |
|||
static readonly string Standard_Spec = "Standard (Specular setup)"; |
|||
static readonly string Standard_Rough = "Standard (Roughness setup)"; |
|||
|
|||
public StandardsToHDLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null) |
|||
{ |
|||
RenameShader(sourceShaderName, destShaderName, finalizer); |
|||
|
|||
RenameTexture("_MainTex", "_BaseColorMap"); |
|||
RenameColor("_Color", "_BaseColor"); |
|||
RenameFloat("_Glossiness", "_Smoothness"); |
|||
RenameTexture("_BumpMap", "_NormalMap"); |
|||
RenameFloat("_BumpScale", "_NormalScale"); |
|||
RenameTexture("_ParallaxMap", "_HeightMap"); |
|||
RenameTexture("_EmissionMap", "_EmissiveColorMap"); |
|||
RenameTexture("_DetailAlbedoMap", "_DetailMap"); |
|||
RenameFloat("_UVSec", "_UVDetail"); |
|||
SetFloat("_LinkDetailsWithBase", 0); |
|||
RenameFloat("_DetailNormalMapScale", "_DetailNormalScale"); |
|||
RenameFloat("_Cutoff", "_AlphaCutoff"); |
|||
RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f); |
|||
|
|||
|
|||
if (sourceShaderName == Standard) |
|||
{ |
|||
SetFloat("_MaterialID", 1f); |
|||
} |
|||
|
|||
if (sourceShaderName == Standard_Spec) |
|||
{ |
|||
SetFloat("_MaterialID", 4f); |
|||
|
|||
RenameColor("_SpecColor", "_SpecularColor"); |
|||
RenameTexture("_SpecGlossMap", "_SpecularColorMap"); |
|||
} |
|||
} |
|||
|
|||
public override void Convert(Material srcMaterial, Material dstMaterial) |
|||
{ |
|||
dstMaterial.hideFlags = HideFlags.DontUnloadUnusedAsset; |
|||
|
|||
base.Convert(srcMaterial, dstMaterial); |
|||
|
|||
// ---------- Mask Map ----------
|
|||
|
|||
// Metallic
|
|||
bool hasMetallic = false; |
|||
Texture metallicMap; |
|||
if ( (srcMaterial.shader.name == Standard) || (srcMaterial.shader.name == Standard_Rough) ) |
|||
{ |
|||
hasMetallic = srcMaterial.GetTexture("_MetallicGlossMap") != null; |
|||
if (hasMetallic) metallicMap = TextureCombiner.GetTextureSafe(srcMaterial, "_MetallicGlossMap", Color.white); |
|||
} |
|||
else |
|||
metallicMap = Texture2D.blackTexture; |
|||
|
|||
// Occlusion
|
|||
bool hasOcclusion = srcMaterial.GetTexture("_OcclusionMap") != null; |
|||
Texture occlusionMap; |
|||
if (hasOcclusion) occlusionMap = TextureCombiner.GetTextureSafe(srcMaterial, "_OcclusionMap", Color.white); |
|||
|
|||
// Detail Mask
|
|||
bool hasDetailMask = srcMaterial.GetTexture("_DetailMask") != null; |
|||
Texture detailMaskMap; |
|||
if (hasDetailMask) detailMaskMap = TextureCombiner.GetTextureSafe(srcMaterial, "_DetailMask", Color.white); |
|||
|
|||
// Smoothness
|
|||
bool hasSmoothness = false; |
|||
Texture2D smoothnessMap = TextureCombiner.TextureFromColor(Color.grey); |
|||
|
|||
if (srcMaterial.shader.name == Standard_Rough) |
|||
hasSmoothness = srcMaterial.GetTexture("_SpecGlossMap")!=null; |
|||
else |
|||
{ |
|||
string smoothnessTextureChannel = "_MainTex"; |
|||
|
|||
if (srcMaterial.shader.name == Standard_Rough) |
|||
smoothnessMap = (Texture2D) TextureCombiner.GetTextureSafe(srcMaterial, "_SpecGlossMap", Color.grey); |
|||
else |
|||
{ |
|||
if ( srcMaterial.GetFloat("_SmoothnessTextureChannel") == 0 ) |
|||
{ |
|||
if (srcMaterial.shader.name == Standard) smoothnessTextureChannel = "_MetallicGlossMap"; |
|||
if (srcMaterial.shader.name == Standard_Spec) smoothnessTextureChannel = "_SpecGlossMap"; |
|||
} |
|||
|
|||
smoothnessMap = (Texture2D) srcMaterial.GetTexture( smoothnessTextureChannel ); |
|||
if (smoothnessMap == null || !TextureCombiner.TextureHasAlpha(smoothnessMap)) |
|||
{ |
|||
hasSmoothness = true; |
|||
smoothnessMap = TextureCombiner.TextureFromColor(Color.white * srcMaterial.GetFloat("_Glossiness")); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Build the mask map
|
|||
if ( hasMetallic || hasOcclusion || hasDetailMask || hasSmoothness ) |
|||
{ |
|||
Texture2D maskMap; |
|||
|
|||
TextureCombiner maskMapCombiner = new TextureCombiner( |
|||
TextureCombiner.GetTextureSafe(srcMaterial, "_MetallicGlossMap", Color.white), 4, // Metallic
|
|||
TextureCombiner.GetTextureSafe(srcMaterial, "_OcclusionMap", Color.white), 4, // Occlusion
|
|||
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailMask", Color.white), 4, // Detail Mask
|
|||
smoothnessMap, (srcMaterial.shader.name == Standard_Rough)?-4:3 // Smoothness Texture
|
|||
); |
|||
|
|||
string maskMapPath = AssetDatabase.GetAssetPath(srcMaterial); |
|||
maskMapPath = maskMapPath.Remove(maskMapPath.Length-4) + "_MaskMap.png"; |
|||
maskMap = maskMapCombiner.Combine( maskMapPath ); |
|||
dstMaterial.SetTexture("_MaskMap", maskMap); |
|||
} |
|||
|
|||
dstMaterial.SetFloat("_AORemapMin", 1f - srcMaterial.GetFloat("_OcclusionStrength")); |
|||
|
|||
// Specular Setup Specific
|
|||
if (srcMaterial.shader.name == Standard_Spec) |
|||
{ |
|||
// if there is a specular map, change the specular color to white
|
|||
if (srcMaterial.GetTexture("_SpecGlossMap") != null ) dstMaterial.SetColor("_SpecularColor", Color.white); |
|||
} |
|||
|
|||
// ---------- Height Map ----------
|
|||
bool hasHeightMap = srcMaterial.GetTexture("_ParallaxMap") != null; |
|||
if (hasHeightMap) // Enable Parallax Occlusion Mapping
|
|||
{ |
|||
dstMaterial.SetFloat("_DisplacementMode", 2); |
|||
dstMaterial.SetFloat("_HeightPoMAmplitude", srcMaterial.GetFloat("_Parallax") * 2f); |
|||
} |
|||
|
|||
// ---------- Detail Map ----------
|
|||
bool hasDetailAlbedo = srcMaterial.GetTexture("_DetailAlbedoMap") != null; |
|||
bool hasDetailNormal = srcMaterial.GetTexture("_DetailNormalMap") != null; |
|||
if ( hasDetailAlbedo || hasDetailNormal ) |
|||
{ |
|||
Texture2D detailMap; |
|||
TextureCombiner detailCombiner = new TextureCombiner( |
|||
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailAlbedoMap", Color.grey), 4, // Albedo (overlay)
|
|||
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailNormalMap", Color.grey), 1, // Normal Y
|
|||
TextureCombiner.midGrey, 1, // Smoothness
|
|||
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailNormalMap", Color.grey), 0 // Normal X
|
|||
); |
|||
string detailMapPath = AssetDatabase.GetAssetPath(srcMaterial); |
|||
detailMapPath = detailMapPath.Remove(detailMapPath.Length-4) + "_DetailMap.png"; |
|||
detailMap = detailCombiner.Combine( detailMapPath ); |
|||
dstMaterial.SetTexture("_DetailMap", detailMap); |
|||
} |
|||
|
|||
|
|||
// Blend Mode
|
|||
int previousBlendMode = srcMaterial.GetInt("_Mode"); |
|||
switch (previousBlendMode) |
|||
{ |
|||
case 0: // Opaque
|
|||
dstMaterial.SetFloat("_SurfaceType", 0); |
|||
dstMaterial.SetFloat("_BlendMode", 0); |
|||
dstMaterial.SetFloat("_AlphaCutoffEnable", 0); |
|||
dstMaterial.SetFloat("_EnableBlendModePreserveSpecularLighting", 1); |
|||
break; |
|||
case 1: // Cutout
|
|||
dstMaterial.SetFloat("_SurfaceType", 0); |
|||
dstMaterial.SetFloat("_BlendMode", 0); |
|||
dstMaterial.SetFloat("_AlphaCutoffEnable", 1); |
|||
dstMaterial.SetFloat("_EnableBlendModePreserveSpecularLighting", 1); |
|||
break; |
|||
case 2: // Fade -> Alpha + Disable preserve specular
|
|||
dstMaterial.SetFloat("_SurfaceType", 1); |
|||
dstMaterial.SetFloat("_BlendMode", 0); |
|||
dstMaterial.SetFloat("_AlphaCutoffEnable", 0); |
|||
dstMaterial.SetFloat("_EnableBlendModePreserveSpecularLighting", 0); |
|||
break; |
|||
case 3: // Transparent -> Alpha
|
|||
dstMaterial.SetFloat("_SurfaceType", 1); |
|||
dstMaterial.SetFloat("_BlendMode", 0); |
|||
dstMaterial.SetFloat("_AlphaCutoffEnable", 0); |
|||
dstMaterial.SetFloat("_EnableBlendModePreserveSpecularLighting", 1); |
|||
break; |
|||
} |
|||
|
|||
// Emission: Convert the HDR emissive color to ldr color + intensity
|
|||
Color hdrEmission = srcMaterial.GetColor("_EmissionColor"); |
|||
float intensity = Mathf.Max(hdrEmission.r, Mathf.Max(hdrEmission.g, hdrEmission.b)); |
|||
|
|||
if (intensity > 1f) |
|||
{ |
|||
hdrEmission.r /= intensity; |
|||
hdrEmission.g /= intensity; |
|||
hdrEmission.b /= intensity; |
|||
} |
|||
else |
|||
intensity = 1f; |
|||
|
|||
intensity = Mathf.Pow(intensity, 2.2f); // Gamma to Linear conversion
|
|||
|
|||
dstMaterial.SetColor("_EmissiveColor", hdrEmission); |
|||
dstMaterial.SetFloat("_EmissiveIntensity", intensity); |
|||
|
|||
HDEditorUtils.ResetMaterialKeywords(dstMaterial); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3892a7f1ec73e554fb1bd8be6a6d3400 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class UnlitsToHDUnlitUpgrader : MaterialUpgrader |
|||
{ |
|||
string Unlit_Color = "Unlit/Color"; |
|||
string Unlit_Texture = "Unlit/Texture"; |
|||
string Unlit_Transparent = "Unlit/Transparent"; |
|||
string Unlit_Cutout = "Unlit/Transparent Cutout"; |
|||
|
|||
public UnlitsToHDUnlitUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null) |
|||
{ |
|||
RenameShader(sourceShaderName, destShaderName, finalizer); |
|||
|
|||
if (sourceShaderName == Unlit_Color) |
|||
RenameColor("_Color", "_UnlitColor"); |
|||
else // all other unlit have a texture
|
|||
RenameTexture("_MainTex", "_UnlitColorMap"); |
|||
|
|||
if (sourceShaderName == Unlit_Cutout) |
|||
{ |
|||
RenameFloat("_Cutoff", "_AlphaCutoff"); |
|||
SetFloat("_AlphaCutoffEnable", 1f); |
|||
} |
|||
else |
|||
SetFloat("_AlphaCutoffEnable", 0f); |
|||
|
|||
|
|||
SetFloat("_SurfaceType", (sourceShaderName == Unlit_Transparent)? 1f : 0f ); |
|||
|
|||
} |
|||
|
|||
public override void Convert(Material srcMaterial, Material dstMaterial) |
|||
{ |
|||
//dstMaterial.hideFlags = HideFlags.DontUnloadUnusedAsset;
|
|||
|
|||
base.Convert(srcMaterial, dstMaterial); |
|||
|
|||
HDEditorUtils.ResetMaterialKeywords(dstMaterial); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b6a8dfccb93f0a946a7bc1521ab32f43 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c5d39f83747e41446b413632dde29652 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class LightUtils |
|||
{ |
|||
// Physical light unit helper
|
|||
// All light unit are in lumen (Luminous power)
|
|||
// Punctual light (point, spot) are convert to candela (cd = lumens / steradian)
|
|||
// Area light are convert to luminance (cd/(m^2*steradian)) with the following formulation: Luminous Power / (Area * PI * steradian)
|
|||
|
|||
// Ref: Moving Frostbite to PBR
|
|||
// Also good ref: https://www.radiance-online.org/community/workshops/2004-fribourg/presentations/Wandachowicz_paper.pdf
|
|||
|
|||
// convert intensity (lumen) to candela
|
|||
public static float ConvertPointLightIntensity(float intensity) |
|||
{ |
|||
return intensity / (4.0f * Mathf.PI); |
|||
} |
|||
|
|||
// angle is the full angle, not the half angle in radiant
|
|||
// convert intensity (lumen) to candela
|
|||
public static float ConvertSpotLightIntensity(float intensity, float angle, bool exact) |
|||
{ |
|||
return exact ? intensity / (2.0f * (1.0f - Mathf.Cos(angle / 2.0f)) * Mathf.PI) : intensity / Mathf.PI; |
|||
} |
|||
|
|||
// angleA and angleB are the full opening angle, not half angle
|
|||
// convert intensity (lumen) to candela
|
|||
public static float ConvertFrustrumLightIntensity(float intensity, float angleA, float angleB) |
|||
{ |
|||
return intensity / (4.0f * Mathf.Asin(Mathf.Sin(angleA / 2.0f) * Mathf.Sin(angleB / 2.0f))); |
|||
} |
|||
|
|||
// convert intensity (lumen) to nits
|
|||
public static float ConvertSphereLightIntensity(float intensity, float sphereRadius) |
|||
{ |
|||
return intensity / ((4.0f * Mathf.PI * sphereRadius * sphereRadius) * Mathf.PI); |
|||
} |
|||
|
|||
// convert intensity (lumen) to nits
|
|||
public static float ConvertDiscLightIntensity(float intensity, float discRadius) |
|||
{ |
|||
return intensity / ((discRadius * discRadius * Mathf.PI) * Mathf.PI); |
|||
} |
|||
|
|||
// convert intensity (lumen) to nits
|
|||
public static float ConvertRectLightIntensity(float intensity, float width, float height) |
|||
{ |
|||
return intensity / ((width * height) * Mathf.PI); |
|||
} |
|||
|
|||
// convert intensity (lumen) to nits
|
|||
public static float calculateLineLightArea(float intensity, float lineWidth) |
|||
{ |
|||
// The area of a cylinder is this:
|
|||
// float lineRadius = 0.01f; // 1cm
|
|||
//return intensity / (2.0f * Mathf.PI * lineRadius * lineWidth * Mathf.PI);
|
|||
// But with our current line light algorithm we get an insane gap in intensity
|
|||
// following formula (fully empirical) give a better match to a rect light of 1cm of width.
|
|||
// It is basically point light intensity / line width.
|
|||
return intensity / (4.0f * Mathf.PI * lineWidth); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 04acc467a6eef0b45b027f43ed25662b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[Serializable] |
|||
public class ContactShadows : VolumeComponent |
|||
{ |
|||
// Contact shadows
|
|||
public BoolParameter enable = new BoolParameter(false); |
|||
public ClampedFloatParameter length = new ClampedFloatParameter(0.15f, 0.0f, 1.0f); |
|||
public ClampedFloatParameter distanceScaleFactor = new ClampedFloatParameter(0.5f, 0.0f, 1.0f); |
|||
public MinFloatParameter maxDistance = new MinFloatParameter(50.0f, 0.0f); |
|||
public MinFloatParameter fadeDistance = new MinFloatParameter(5.0f, 0.0f); |
|||
public NoInterpClampedIntParameter sampleCount = new NoInterpClampedIntParameter(8, 4, 64); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 56b145d2b9ee1ac4f846968484e7485a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1a9d1eab24683cb42a7c52b9d850d154 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8486e1ca5cc45c34c94df540d5676ec3 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System.IO; |
|||
|
|||
public class TextureCombiner |
|||
{ |
|||
public static Texture2D _midGrey; |
|||
public static Texture2D midGrey |
|||
{ |
|||
get |
|||
{ |
|||
if (_midGrey == null) |
|||
_midGrey = TextureFromColor(Color.grey); |
|||
|
|||
return _midGrey; |
|||
} |
|||
} |
|||
|
|||
private static Dictionary<Color, Texture2D> singleColorTextures = new Dictionary<Color, Texture2D>(); |
|||
|
|||
public static Texture2D TextureFromColor(Color color) |
|||
{ |
|||
if (color == Color.white) return Texture2D.whiteTexture; |
|||
if (color == Color.black) return Texture2D.blackTexture; |
|||
|
|||
bool makeTexture = !singleColorTextures.ContainsKey(color); |
|||
if (!makeTexture) |
|||
makeTexture = (singleColorTextures[color] == null); |
|||
|
|||
if (makeTexture) |
|||
{ |
|||
Texture2D tex = new Texture2D(1,1, TextureFormat.ARGB32, false, true); |
|||
tex.SetPixel(0,0,color); |
|||
tex.Apply(); |
|||
|
|||
singleColorTextures[color] = tex; |
|||
} |
|||
|
|||
return singleColorTextures[color]; |
|||
} |
|||
|
|||
public static Texture GetTextureSafe( Material srcMaterial, string propertyName, Color fallback) |
|||
{ |
|||
return GetTextureSafe( srcMaterial, propertyName, TextureFromColor(fallback) ); |
|||
} |
|||
|
|||
public static Texture GetTextureSafe( Material srcMaterial, string propertyName, Texture fallback) |
|||
{ |
|||
if (!srcMaterial.HasProperty(propertyName)) |
|||
return fallback; |
|||
|
|||
Texture tex = srcMaterial.GetTexture(propertyName); |
|||
if (tex == null) |
|||
return fallback; |
|||
else |
|||
return tex; |
|||
} |
|||
|
|||
public static TextureFormat[] TextureFormatsWithouthAlpha = new TextureFormat[]{ |
|||
TextureFormat.ASTC_RGB_10x10 , |
|||
TextureFormat.ASTC_RGB_12x12 , |
|||
TextureFormat.ASTC_RGB_4x4 , |
|||
TextureFormat.ASTC_RGB_5x5 , |
|||
TextureFormat.ASTC_RGB_6x6 , |
|||
TextureFormat.ASTC_RGB_8x8 , |
|||
TextureFormat.BC4 , |
|||
TextureFormat.BC5 , |
|||
TextureFormat.DXT1 , |
|||
TextureFormat.DXT1Crunched , |
|||
TextureFormat.EAC_R , |
|||
TextureFormat.EAC_R_SIGNED , |
|||
TextureFormat.EAC_RG , |
|||
TextureFormat.EAC_RG_SIGNED , |
|||
TextureFormat.ETC2_RGB , |
|||
TextureFormat.ETC_RGB4 , |
|||
TextureFormat.ETC_RGB4_3DS , |
|||
TextureFormat.ETC_RGB4Crunched , |
|||
TextureFormat.PVRTC_RGB2 , |
|||
TextureFormat.PVRTC_RGB4 , |
|||
TextureFormat.R16 , |
|||
TextureFormat.R8 , |
|||
TextureFormat.RFloat , |
|||
TextureFormat.RG16 , |
|||
TextureFormat.RGB24 , |
|||
TextureFormat.RGB565 , |
|||
TextureFormat.RGB9e5Float , |
|||
TextureFormat.RGFloat , |
|||
TextureFormat.RGHalf , |
|||
TextureFormat.RHalf , |
|||
TextureFormat.YUY2 |
|||
}; |
|||
|
|||
public static bool TextureHasAlpha ( Texture2D tex ) |
|||
{ |
|||
if (tex == null) return false; |
|||
|
|||
bool o = true; |
|||
int i=0; |
|||
|
|||
while ( i < TextureFormatsWithouthAlpha.Length && o) |
|||
{ |
|||
o = tex.format != TextureFormatsWithouthAlpha[i]; |
|||
++i; |
|||
} |
|||
|
|||
return o; |
|||
} |
|||
|
|||
private Texture m_rSource; |
|||
private Texture m_gSource; |
|||
private Texture m_bSource; |
|||
private Texture m_aSource; |
|||
|
|||
// Chanels are : r=0, g=1, b=2, a=3, greyscale from rgb = 4
|
|||
// If negative, the chanel is inverted
|
|||
private int m_rChanel; |
|||
private int m_gChanel; |
|||
private int m_bChanel; |
|||
private int m_aChanel; |
|||
|
|||
// Chanels remaping
|
|||
private Vector4[] m_remapings = new Vector4[]{ |
|||
new Vector4(0f, 1f, 0f, 0f), |
|||
new Vector4(0f, 1f, 0f, 0f), |
|||
new Vector4(0f, 1f, 0f, 0f), |
|||
new Vector4(0f, 1f, 0f, 0f) |
|||
}; |
|||
|
|||
private bool m_bilinearFilter; |
|||
|
|||
private Dictionary<Texture, Texture> m_RawTextures; |
|||
|
|||
public TextureCombiner( Texture rSource, int rChanel, Texture gSource, int gChanel, Texture bSource, int bChanel, Texture aSource, int aChanel, bool bilinearFilter = true ) |
|||
{ |
|||
m_rSource = rSource; |
|||
m_gSource = gSource; |
|||
m_bSource = bSource; |
|||
m_aSource = aSource; |
|||
m_rChanel = rChanel; |
|||
m_gChanel = gChanel; |
|||
m_bChanel = bChanel; |
|||
m_aChanel = aChanel; |
|||
m_bilinearFilter = bilinearFilter; |
|||
} |
|||
|
|||
public void SetRemapping( int channel, float min, float max) |
|||
{ |
|||
if (channel > 3 || channel < 0) return; |
|||
|
|||
m_remapings[channel].x = min; |
|||
m_remapings[channel].y = max; |
|||
} |
|||
|
|||
public Texture2D Combine( string savePath ) |
|||
{ |
|||
int xMin = int.MaxValue; |
|||
int yMin = int.MaxValue; |
|||
|
|||
if (m_rSource.width > 4 && m_rSource.width < xMin) xMin = m_rSource.width; |
|||
if (m_gSource.width > 4 && m_gSource.width < xMin) xMin = m_gSource.width; |
|||
if (m_bSource.width > 4 && m_bSource.width < xMin) xMin = m_bSource.width; |
|||
if (m_aSource.width > 4 && m_aSource.width < xMin) xMin = m_aSource.width; |
|||
if (xMin == int.MaxValue) xMin = 4; |
|||
|
|||
if (m_rSource.height > 4 && m_rSource.height < yMin) yMin = m_rSource.height; |
|||
if (m_gSource.height > 4 && m_gSource.height < yMin) yMin = m_gSource.height; |
|||
if (m_bSource.height > 4 && m_bSource.height < yMin) yMin = m_bSource.height; |
|||
if (m_aSource.height > 4 && m_aSource.height < yMin) yMin = m_aSource.height; |
|||
if (yMin == int.MaxValue) yMin = 4; |
|||
|
|||
Texture2D combined = new Texture2D(xMin, yMin, TextureFormat.RGBAFloat, true, true); |
|||
combined.hideFlags = HideFlags.DontUnloadUnusedAsset; |
|||
|
|||
Material combinerMaterial = new Material(Shader.Find("Hidden/SRP_Core/TextureCombiner")); |
|||
combinerMaterial.hideFlags = HideFlags.DontUnloadUnusedAsset; |
|||
|
|||
combinerMaterial.SetTexture("_RSource", GetRawTexture(m_rSource)); |
|||
combinerMaterial.SetTexture("_GSource", GetRawTexture(m_gSource)); |
|||
combinerMaterial.SetTexture("_BSource", GetRawTexture(m_bSource)); |
|||
combinerMaterial.SetTexture("_ASource", GetRawTexture(m_aSource)); |
|||
|
|||
combinerMaterial.SetFloat("_RChannel", m_rChanel); |
|||
combinerMaterial.SetFloat("_GChannel", m_gChanel); |
|||
combinerMaterial.SetFloat("_BChannel", m_bChanel); |
|||
combinerMaterial.SetFloat("_AChannel", m_aChanel); |
|||
|
|||
combinerMaterial.SetVector("_RRemap", m_remapings[0]); |
|||
combinerMaterial.SetVector("_GRemap", m_remapings[1]); |
|||
combinerMaterial.SetVector("_BRemap", m_remapings[2]); |
|||
combinerMaterial.SetVector("_ARemap", m_remapings[3]); |
|||
|
|||
RenderTexture combinedRT = new RenderTexture(xMin, yMin, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.sRGB); |
|||
|
|||
Graphics.Blit(Texture2D.whiteTexture, combinedRT, combinerMaterial); |
|||
|
|||
// Readback the render texture
|
|||
RenderTexture previousActive = RenderTexture.active; |
|||
RenderTexture.active = combinedRT; |
|||
combined.ReadPixels(new Rect(0, 0, xMin, yMin), 0, 0, false); |
|||
combined.Apply(); |
|||
RenderTexture.active = previousActive; |
|||
|
|||
byte[] bytes = new byte[0]; |
|||
|
|||
if (savePath.EndsWith("png")) |
|||
bytes = ImageConversion.EncodeToPNG(combined); |
|||
if (savePath.EndsWith("exr")) |
|||
bytes = ImageConversion.EncodeToEXR(combined); |
|||
if (savePath.EndsWith("jpg")) |
|||
bytes = ImageConversion.EncodeToJPG(combined); |
|||
|
|||
string systemPath = Path.Combine(Application.dataPath.Remove(Application.dataPath.Length-6), savePath); |
|||
File.WriteAllBytes(systemPath, bytes); |
|||
|
|||
Object.DestroyImmediate(combined); |
|||
|
|||
AssetDatabase.ImportAsset(savePath); |
|||
|
|||
TextureImporter combinedImporter = (TextureImporter) AssetImporter.GetAtPath(savePath); |
|||
combinedImporter.sRGBTexture = false; |
|||
combinedImporter.SaveAndReimport(); |
|||
|
|||
if (savePath.EndsWith("exr")) |
|||
{ |
|||
// The options for the platform string are: "Standalone", "iPhone", "Android", "WebGL", "Windows Store Apps", "PSP2", "PS4", "XboxOne", "Nintendo 3DS", "WiiU", "tvOS".
|
|||
combinedImporter.SetPlatformTextureSettings(new TextureImporterPlatformSettings(){name = "Standalone", format = TextureImporterFormat.DXT5, overridden = true }); |
|||
} |
|||
|
|||
combined = AssetDatabase.LoadAssetAtPath<Texture2D>(savePath); |
|||
|
|||
//cleanup "raw" textures
|
|||
foreach( KeyValuePair<Texture, Texture> prop in m_RawTextures ) |
|||
{ |
|||
if (AssetDatabase.Contains(prop.Value)) |
|||
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(prop.Value)); |
|||
} |
|||
Object.DestroyImmediate(combinerMaterial); |
|||
|
|||
m_RawTextures.Clear(); |
|||
|
|||
return combined; |
|||
} |
|||
|
|||
private Texture GetRawTexture (Texture original, bool sRGB = false) |
|||
{ |
|||
if (m_RawTextures == null) m_RawTextures = new Dictionary<Texture, Texture>(); |
|||
if (!m_RawTextures.ContainsKey(original)) |
|||
{ |
|||
if ( AssetDatabase.Contains(original)) |
|||
{ |
|||
string path = AssetDatabase.GetAssetPath(original); |
|||
string rawPath = "Assets/raw_"+Path.GetFileName(path); |
|||
|
|||
AssetDatabase.CopyAsset(path, rawPath); |
|||
|
|||
AssetDatabase.ImportAsset(rawPath); |
|||
|
|||
TextureImporter rawImporter = (TextureImporter) TextureImporter.GetAtPath(rawPath); |
|||
rawImporter.textureType = TextureImporterType.Default; |
|||
rawImporter.mipmapEnabled = false; |
|||
rawImporter.isReadable = true; |
|||
rawImporter.filterMode = m_bilinearFilter? FilterMode.Bilinear : FilterMode.Point; |
|||
rawImporter.npotScale = TextureImporterNPOTScale.None; |
|||
rawImporter.wrapMode = TextureWrapMode.Clamp; |
|||
rawImporter.sRGBTexture = sRGB; |
|||
rawImporter.maxTextureSize = 8192; |
|||
|
|||
rawImporter.textureCompression = TextureImporterCompression.Uncompressed; |
|||
|
|||
rawImporter.SaveAndReimport(); |
|||
|
|||
m_RawTextures.Add(original, AssetDatabase.LoadAssetAtPath<Texture>(rawPath)); |
|||
} |
|||
else |
|||
m_RawTextures.Add(original, original); |
|||
} |
|||
|
|||
return m_RawTextures[original]; |
|||
} |
|||
} |
|
|||
Shader "Hidden/SRP_Core/TextureCombiner" |
|||
{ |
|||
Properties |
|||
{ |
|||
// Chanels are : r=0, g=1, b=2, a=3, greyscale from rgb = 4 |
|||
// If the chanel value is negative, we invert the value |
|||
|
|||
[Linear][NoScaleOffset] _RSource ("R Source", 2D) = "white" {} |
|||
_RChannel ("R Channel", float) = 0 |
|||
_RRemap ("R Remap", Vector) = (0, 1, 0, 0) |
|||
|
|||
[Linear][NoScaleOffset] _GSource ("G Source", 2D) = "white" {} |
|||
_GChannel ("G Channel", float) = 1 |
|||
_GRemap ("G Remap", Vector) = (0, 1, 0, 0) |
|||
|
|||
[Linear][NoScaleOffset] _BSource ("B Source", 2D) = "white" {} |
|||
_BChannel ("B Channel", float) = 2 |
|||
_BRemap ("B Remap", Vector) = (0, 1, 0, 0) |
|||
|
|||
[Linear][NoScaleOffset] _ASource ("A Source", 2D) = "white" {} |
|||
_AChannel ("A Channel", float) = 3 |
|||
_ARemap ("A Remap", Vector) = (0, 1, 0, 0) |
|||
} |
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" } |
|||
LOD 100 |
|||
|
|||
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; |
|||
}; |
|||
|
|||
sampler2D _RSource, _GSource, _BSource, _ASource; |
|||
float _RChannel, _GChannel, _BChannel, _AChannel; |
|||
float4 _RRemap, _GRemap, _BRemap, _ARemap; |
|||
|
|||
v2f vert (appdata v) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.uv; |
|||
return o; |
|||
} |
|||
|
|||
float PlotSourcetoChanel(float4 source, float param, float2 remap) |
|||
{ |
|||
if (param < 0 ) |
|||
{ |
|||
param = -param; |
|||
source = float4(1,1,1,1) - source; |
|||
} |
|||
|
|||
float o; |
|||
|
|||
if (param >= 4) |
|||
o = source.r * 0.3 + source.g * 0.59 + source.b * 0.11; // Photoshop desaturation : G*.59+R*.3+B*.11 |
|||
else |
|||
o = source[param]; |
|||
|
|||
return o * ( remap.y - remap.x) + remap.x ; |
|||
} |
|||
|
|||
float PlotSourcetoChanel(float4 source, float param) |
|||
{ |
|||
return PlotSourcetoChanel(source, param, float2(0,1) ); |
|||
} |
|||
|
|||
float4 frag (v2f i) : SV_Target |
|||
{ |
|||
float4 col = float4(0,0,0,0); |
|||
|
|||
col.r = PlotSourcetoChanel( tex2D(_RSource, i.uv), _RChannel, _RRemap ); |
|||
col.g = PlotSourcetoChanel( tex2D(_GSource, i.uv), _GChannel, _GRemap ); |
|||
col.b = PlotSourcetoChanel( tex2D(_BSource, i.uv), _BChannel, _BRemap ); |
|||
col.a = PlotSourcetoChanel( tex2D(_ASource, i.uv), _AChannel, _ARemap ); |
|||
|
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d8efece7d7ee34048a4b794bf3234ca3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.Experimental.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CanEditMultipleObjects] |
|||
[VolumeComponentEditor(typeof(HDShadowSettings))] |
|||
public class HDShadowSettingsEditor : VolumeComponentEditor |
|||
{ |
|||
SerializedDataParameter m_MaxShadowDistance; |
|||
|
|||
SerializedDataParameter m_CascadeShadowSplitCount; |
|||
|
|||
SerializedDataParameter[] m_CascadeShadowSplits = new SerializedDataParameter[3]; |
|||
SerializedDataParameter[] m_CascadeShadowBorders = new SerializedDataParameter[4]; |
|||
|
|||
// For now we don't use borders so we hide the UI.
|
|||
bool m_bShowBorders = false; |
|||
|
|||
public override void OnEnable() |
|||
{ |
|||
var o = new PropertyFetcher<HDShadowSettings>(serializedObject); |
|||
|
|||
m_MaxShadowDistance = Unpack(o.Find(x => x.maxShadowDistance)); |
|||
m_CascadeShadowSplitCount = Unpack(o.Find(x => x.cascadeShadowSplitCount)); |
|||
m_CascadeShadowSplits[0] = Unpack(o.Find(x => x.cascadeShadowSplit0)); |
|||
m_CascadeShadowSplits[1] = Unpack(o.Find(x => x.cascadeShadowSplit1)); |
|||
m_CascadeShadowSplits[2] = Unpack(o.Find(x => x.cascadeShadowSplit2)); |
|||
m_CascadeShadowBorders[0] = Unpack(o.Find(x => x.cascadeShadowBorder0)); |
|||
m_CascadeShadowBorders[1] = Unpack(o.Find(x => x.cascadeShadowBorder1)); |
|||
m_CascadeShadowBorders[2] = Unpack(o.Find(x => x.cascadeShadowBorder2)); |
|||
m_CascadeShadowBorders[3] = Unpack(o.Find(x => x.cascadeShadowBorder3)); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
PropertyField(m_MaxShadowDistance, CoreEditorUtils.GetContent("Max Distance")); |
|||
|
|||
EditorGUILayout.Space(); |
|||
PropertyField(m_CascadeShadowSplitCount, CoreEditorUtils.GetContent("Cascade Count")); |
|||
|
|||
if (!m_CascadeShadowSplitCount.value.hasMultipleDifferentValues) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
int splitCount = m_CascadeShadowSplitCount.value.intValue; |
|||
for (int i = 0; i < splitCount - 1; i++) |
|||
{ |
|||
PropertyField(m_CascadeShadowSplits[i], CoreEditorUtils.GetContent(string.Format("Split {0}", i + 1))); |
|||
} |
|||
|
|||
if(m_bShowBorders) |
|||
{ |
|||
EditorGUILayout.Space(); |
|||
|
|||
for (int i = 0; i < splitCount; i++) |
|||
{ |
|||
PropertyField(m_CascadeShadowBorders[i], CoreEditorUtils.GetContent(string.Format("Border {0}", i + 1))); |
|||
} |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f5a268c81ffd7634db3a9a0cb30af239 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.Experimental.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CanEditMultipleObjects] |
|||
[VolumeComponentEditor(typeof(ContactShadows))] |
|||
public class ContactShadowsEditor : VolumeComponentEditor |
|||
{ |
|||
public readonly GUIContent contactShadow = new GUIContent("Contact Shadows"); |
|||
public readonly GUIContent contactShadowLength = new GUIContent("Length", "Length of rays used to gather contact shadows in world units.\nZero will disable the feature."); |
|||
public readonly GUIContent contactShadowDistanceScaleFactor = new GUIContent("Distance Scale Factor", "Contact Shadows are scaled up with distance. Use this parameter to dampen this effect."); |
|||
public readonly GUIContent contactShadowMaxDistance = new GUIContent("Max Distance", "Distance from the camera in world units at which contact shadows are faded out to zero."); |
|||
public readonly GUIContent contactShadowFadeDistance = new GUIContent("Fade Distance", "Distance in world units over which the contact shadows are faded out (see Max Distance)."); |
|||
public readonly GUIContent contactShadowSampleCount = new GUIContent("Sample Count", "Number of samples when ray casting."); |
|||
|
|||
|
|||
SerializedDataParameter m_Enable; |
|||
SerializedDataParameter m_Length; |
|||
SerializedDataParameter m_DistanceScaleFactor; |
|||
SerializedDataParameter m_MaxDistance; |
|||
SerializedDataParameter m_FadeDistance; |
|||
SerializedDataParameter m_SampleCount; |
|||
|
|||
|
|||
public override void OnEnable() |
|||
{ |
|||
var o = new PropertyFetcher<ContactShadows>(serializedObject); |
|||
|
|||
m_Enable = Unpack(o.Find(x => x.enable)); |
|||
m_Length = Unpack(o.Find(x => x.length)); |
|||
m_DistanceScaleFactor = Unpack(o.Find(x => x.distanceScaleFactor)); |
|||
m_MaxDistance = Unpack(o.Find(x => x.maxDistance)); |
|||
m_FadeDistance = Unpack(o.Find(x => x.fadeDistance)); |
|||
m_SampleCount = Unpack(o.Find(x => x.sampleCount)); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
PropertyField(m_Enable, CoreEditorUtils.GetContent("Enable")); |
|||
|
|||
if (!m_Enable.value.hasMultipleDifferentValues) |
|||
{ |
|||
using (new EditorGUI.DisabledGroupScope(!m_Enable.value.boolValue)) |
|||
{ |
|||
PropertyField(m_Length, CoreEditorUtils.GetContent("Length|Length of rays used to gather contact shadows in world units.")); |
|||
PropertyField(m_DistanceScaleFactor, CoreEditorUtils.GetContent("Distance Scale Factor|Contact Shadows are scaled up with distance. Use this parameter to dampen this effect.")); |
|||
PropertyField(m_MaxDistance, CoreEditorUtils.GetContent("Max Distance|Distance from the camera in world units at which contact shadows are faded out to zero.")); |
|||
PropertyField(m_FadeDistance, CoreEditorUtils.GetContent("Fade Distance|Distance in world units over which the contact shadows fade out (see Max Distance).")); |
|||
PropertyField(m_SampleCount, CoreEditorUtils.GetContent("Sample Count|Number of samples when ray casting.")); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 775bef174b1e2ed47972a143845e1191 |
|||
timeCreated: 1479911618 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: fedbd6bc5d95f4d768cb8077e8454b4e |
|||
timeCreated: 1479851295 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class StandardToHDLitMaterialUpgrader : MaterialUpgrader |
|||
{ |
|||
public StandardToHDLitMaterialUpgrader() : this("Standard", "HDRenderPipeline/Lit", LitGUI.SetupMaterialKeywordsAndPass) {} |
|||
|
|||
public StandardToHDLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer) |
|||
{ |
|||
RenameShader(sourceShaderName, destShaderName, finalizer); |
|||
|
|||
RenameTexture("_MainTex", "_BaseColorMap"); |
|||
RenameColor("_Color", "_BaseColor"); |
|||
RenameFloat("_Glossiness", "_Smoothness"); |
|||
RenameTexture("_BumpMap", "_NormalMap"); |
|||
RenameFloat("_BumpScale", "_NormalScale"); |
|||
RenameColor("_EmissionColor", "_EmissiveColor"); |
|||
RenameFloat("_DetailNormalMapScale", "_DetailNormalScale"); |
|||
RenameFloat("_Cutoff", "_AlphaCutoff"); |
|||
RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f); |
|||
|
|||
// the HD renderloop packs detail albedo and detail normals into a single texture.
|
|||
// mapping the detail normal map, if any, to the detail map, should do the right thing if
|
|||
// there is no detail albedo.
|
|||
RenameTexture("_DetailNormalMap", "_DetailMap"); |
|||
|
|||
// Metallic uses [Gamma] attribute in standard shader but not in Lit.
|
|||
// @Seb: Should we convert?
|
|||
RenameFloat("_Metallic", "_Metallic"); |
|||
|
|||
//@TODO: Seb. Why do we multiply color by intensity
|
|||
// in shader when we can just store a color?
|
|||
// builtinData.emissiveColor * builtinData.emissiveIntensity
|
|||
} |
|||
|
|||
public override void Convert(Material srcMaterial, Material dstMaterial) |
|||
{ |
|||
base.Convert(srcMaterial, dstMaterial); |
|||
//@TODO: Find a good way of setting up keywords etc from properties.
|
|||
// Code should be shared with material UI code.
|
|||
} |
|||
|
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class StandardSpecularToHDLitMaterialUpgrader : MaterialUpgrader |
|||
{ |
|||
public StandardSpecularToHDLitMaterialUpgrader() : this("Standard (Specular setup)", "HDRenderPipeline/Lit", LitGUI.SetupMaterialKeywordsAndPass) {} |
|||
|
|||
public StandardSpecularToHDLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer) |
|||
{ |
|||
RenameShader(sourceShaderName, destShaderName, finalizer); |
|||
|
|||
RenameTexture("_MainTex", "_BaseColorMap"); |
|||
RenameColor("_Color", "_BaseColor"); |
|||
RenameFloat("_Glossiness", "_Smoothness"); |
|||
RenameTexture("_BumpMap", "_NormalMap"); |
|||
RenameFloat("_BumpScale", "_NormalScale"); |
|||
RenameColor("_EmissionColor", "_EmissiveColor"); |
|||
RenameFloat("_DetailNormalMapScale", "_DetailNormalScale"); |
|||
RenameFloat("_Cutoff", "_AlphaCutoff"); |
|||
RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f); |
|||
|
|||
// the HD renderloop packs detail albedo and detail normals into a single texture.
|
|||
// mapping the detail normal map, if any, to the detail map, should do the right thing if
|
|||
// there is no detail albedo.
|
|||
RenameTexture("_DetailNormalMap", "_DetailMap"); |
|||
|
|||
// Anything reasonable that can be done here?
|
|||
//RenameFloat("_SpecColor", ...);
|
|||
|
|||
//@TODO: Seb. Why do we multiply color by intensity
|
|||
// in shader when we can just store a color?
|
|||
// builtinData.emissiveColor * builtinData.emissiveIntensity
|
|||
} |
|||
|
|||
public override void Convert(Material srcMaterial, Material dstMaterial) |
|||
{ |
|||
base.Convert(srcMaterial, dstMaterial); |
|||
//@TODO: Find a good way of setting up keywords etc from properties.
|
|||
// Code should be shared with material UI code.
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 20d5442c0aea41919653fbc75ca174d1 |
|||
timeCreated: 1512986339 |
|
|||
using NUnit.Framework; |
|||
using UnityEditor.Experimental.Rendering; |
|||
using UnityEditor.Experimental.Rendering.HDPipeline; |
|||
using UnityEngine; |
|||
|
|||
namespace ScriptableRenderPipeline.Tests.Editor |
|||
{ |
|||
public class MaterialUpgraderTests |
|||
{ |
|||
[Test] |
|||
public void UpgradeStandardSpecularToHDLitMaterial() |
|||
{ |
|||
var newShader = Shader.Find("HDRenderPipeline/Lit"); |
|||
var mat = new Material(Shader.Find("Standard (Specular setup)")); |
|||
var albedo = new Texture2D(1, 1); |
|||
var normals = new Texture2D(1, 1); |
|||
var baseScale = new Vector2(1, 1); |
|||
var color = Color.red; |
|||
mat.mainTexture = albedo; |
|||
mat.SetTexture("_BumpMap", normals); |
|||
mat.color = color; |
|||
mat.SetTextureScale("_MainTex", baseScale); |
|||
|
|||
var upgrader = new StandardSpecularToHDLitMaterialUpgrader(); |
|||
MaterialUpgrader.Upgrade(mat, upgrader, MaterialUpgrader.UpgradeFlags.CleanupNonUpgradedProperties); |
|||
|
|||
Assert.AreEqual(newShader, mat.shader); |
|||
Assert.AreEqual(albedo, mat.GetTexture("_BaseColorMap")); |
|||
Assert.AreEqual(color, mat.GetColor("_BaseColor")); |
|||
Assert.AreEqual(baseScale, mat.GetTextureScale("_BaseColorMap")); |
|||
Assert.AreEqual(normals, mat.GetTexture("_NormalMap")); |
|||
Assert.IsTrue(mat.IsKeywordEnabled("_NORMALMAP")); |
|||
} |
|||
|
|||
[Test] |
|||
public void UpgradeStandardToHDLitMaterialUpgrader() |
|||
{ |
|||
var newShader = Shader.Find("HDRenderPipeline/Lit"); |
|||
var mat = new Material(Shader.Find("Standard")); |
|||
var albedo = new Texture2D(1, 1); |
|||
var normals = new Texture2D(1, 1); |
|||
var baseScale = new Vector2(1, 1); |
|||
var color = Color.red; |
|||
mat.mainTexture = albedo; |
|||
mat.SetTexture("_BumpMap", normals); |
|||
mat.color = color; |
|||
mat.SetTextureScale("_MainTex", baseScale); |
|||
|
|||
var upgrader = new StandardToHDLitMaterialUpgrader(); |
|||
MaterialUpgrader.Upgrade(mat, upgrader, MaterialUpgrader.UpgradeFlags.CleanupNonUpgradedProperties); |
|||
|
|||
Assert.AreEqual(newShader, mat.shader); |
|||
Assert.AreEqual(albedo, mat.GetTexture("_BaseColorMap")); |
|||
Assert.AreEqual(color, mat.GetColor("_BaseColor")); |
|||
Assert.AreEqual(baseScale, mat.GetTextureScale("_BaseColorMap")); |
|||
Assert.AreEqual(normals, mat.GetTexture("_NormalMap")); |
|||
Assert.IsTrue(mat.IsKeywordEnabled("_NORMALMAP")); |
|||
} |
|||
|
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue