浏览代码

Added LightweightKeywords and ShaderPreprocessor. Stripping Meta pass from build.

/main
Felipe Lira 7 年前
当前提交
bbeadae5
共有 4 个文件被更改,包括 96 次插入0 次删除
  1. 56
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs
  2. 11
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs.meta
  3. 18
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightKeywords.cs
  4. 11
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightKeywords.cs.meta

56
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs


using System.Collections.Generic;
using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Rendering;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
class ShaderPreprocessor : IPreprocessShaders
{
int totalVariantsInputCount = 0;
int totalVariantsOutputCount = 0;
// Multiple callback may be implemented.
// The first one executed is the one where callbackOrder is returning the smallest number.
public int callbackOrder { get { return 0; } }
private bool StripUnusedVariant(ShaderSnippetData snippetData, ShaderCompilerData compilerData)
{
if (snippetData.passName == "Meta")
return true;
return false;
}
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
{
int initDataCount = data.Count;
for (int i = 0; i < data.Count; ++i)
{
if (StripUnusedVariant(snippet, data[i]))
{
data.RemoveAt(i);
--i;
}
}
totalVariantsInputCount += initDataCount;
totalVariantsOutputCount += data.Count;
if (shader.name.Contains("LightweightPipeline/Standard (Physically Based)") || shader.name.Contains("LightweightPipeline/Standard (Simple Lighting)"))
{
float percentageCurrent = (float) data.Count / (float) initDataCount * 100f;
float percentageTotal = (float) totalVariantsOutputCount / (float) totalVariantsInputCount * 100f;
string result = "STRIPPING: " + shader.name + "(" + snippet.passName + " pass)" + "(" + snippet.shaderType.ToString() +
") - Remaining shader variants = " + data.Count + " / " + initDataCount + " = " +
percentageCurrent + "% - Total = " + totalVariantsOutputCount + " / " +
totalVariantsInputCount + " = " + percentageTotal + "%";
Debug.Log(result);
}
}
}
}

11
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs.meta


fileFormatVersion: 2
guid: 9f7bf504ded5bcb48835f194831914c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

18
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightKeywords.cs


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class LightweightKeywords : MonoBehaviour
{
// Pipeline specific keywords
public static readonly ShaderKeyword AdditionalLights = new ShaderKeyword("_ADDITIONAL_LIGHTS");
public static readonly ShaderKeyword VertexLights = new ShaderKeyword("_VERTEX_LIGHTS");
public static readonly ShaderKeyword SubtractiveLight = new ShaderKeyword("_MIXED_LIGHTING_SUBTRACTIVE");
public static readonly ShaderKeyword DirectionalShadows = new ShaderKeyword("_SHADOWS_ENABLED");
public static readonly ShaderKeyword LocalShadows = new ShaderKeyword("_LOCAL_SHADOWS_ENABLED");
public static readonly ShaderKeyword Lightmap = new ShaderKeyword("DIRLIGHTMAP_COMBINED");
public static readonly ShaderKeyword DirectionalLightmap = new ShaderKeyword("LIGHTMAP_ON");
}
}

11
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightKeywords.cs.meta


fileFormatVersion: 2
guid: d973de1eba2f6934e9c31429e8e40c09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存