浏览代码

Merge branch 'master' into DebugShader

/main
Julien Ignace 8 年前
当前提交
d45894b6
共有 9 个文件被更改,包括 294 次插入27 次删除
  1. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.cs
  2. 34
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
  3. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit.hlsl
  4. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader
  5. 6
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl
  6. 81
      Assets/TestScenes/HDTest/HDRenderLoopTest.unity
  7. 2
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-twosidedLighting.mat
  8. 172
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Unlit.shader
  9. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Unlit.shader.meta

7
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.cs


}
}
if (doubleSidedMode != DoubleSidedMode.None || surfaceType == SurfaceType.Transparent)
if (doubleSidedMode == DoubleSidedMode.None)
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Back);
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Back);
material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
}
if (doubleSidedMode == DoubleSidedMode.DoubleSidedLightingFlip)

SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture("_SpecularOcclusionMap"));
SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", ((SmoothnessMapChannel)material.GetFloat("_SmoothnessTextureChannel")) == SmoothnessMapChannel.AlbedoAlpha);
SetKeyword(material, "_EMISSIVE_COLOR", ((EmissiveColorMode)material.GetFloat("_EmissiveColorMode")) == EmissiveColorMode.UseEmissiveColor);
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture("_EmissiveColorMap"));
SetKeyword(material, "_HEIGHTMAP", material.GetTexture("_HeightMap"));
SetKeyword(material, "_HEIGHTMAP_AS_DISPLACEMENT", (HeightmapMode)material.GetFloat("_HeightMapMode") == HeightmapMode.Displacement);

34
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader


_HeightBias("Height Bias", Float) = 0
[Enum(Parallax, 0, Displacement, 1)] _HeightMapMode("Heightmap usage", Float) = 0
_DiffuseLightingMap("DiffuseLightingMap", 2D) = "black" {}
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0

// _DistortionBlur("DistortionBlur", Range(0.0, 1.0)) = 0
// Following options are for the GUI inspector and different from the input parameters above
// These option below will cause different compilation flag.
// These option below will cause different compilation flag.
_DiffuseLightingMap("DiffuseLightingMap", 2D) = "black" {}
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0

[HideInInspector] _SrcBlend ("__src", Float) = 1.0
[HideInInspector] _DstBlend ("__dst", Float) = 0.0
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
[HideInInspector] _CullMode("__cullmode", Float) = 2.0 // Back by default: MEGA WARNING - if we override this, how it work with reflection plane ? (to check if the engine correctly flip stuff)
[HideInInspector] _CullMode("__cullmode", Float) = 2.0
// Material Id
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0

}
HLSLINCLUDE
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR

#pragma shader_feature _SPECULAROCCLUSIONMAP
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _EMISSIVE_COLOR_MAP
#include "TemplateDisneyGGX.hlsl"
ENDHLSL

Cull [_CullMode]
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma fragment FragForward
#include "TemplateDisneyGGX.hlsl"
#pragma fragment FragForward
#if SHADER_STAGE_FRAGMENT

Cull [_CullMode]
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
HLSLPROGRAM
#include "TemplateDisneyGGX.hlsl"
#if SHADER_STAGE_FRAGMENT

3
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit.hlsl


struct SurfaceData
{
float3 color;
BuiltinData builtin;
};
struct BSDFData

{
BSDFData output;
output.color = data.color;
return output;
}
//-----------------------------------------------------------------------------

7
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader


_ToneMapCoeffs1("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0)
_ToneMapCoeffs2("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0)
_Exposure("Exposure", Range(-32.0, 32.0)) = 0
[ToggleOff] _EnableToneMap("Enable Tone Map", Float) = 0
}
SubShader {

#pragma fragment Frag
#pragma target 5.0
#include "../../../ShaderLibrary/Common.hlsl"
#include "../../../ShaderLibrary/Color.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
#include "../ShaderVariables.hlsl"
sampler2D _MainTex;

// So we must not correct the sRGB here else it will be done two time.
// To fix!
c.rgb = ApplyToneMap(c.rgb * pow(2.0, _Exposure));
c.rgb = ApplyToneMap(c.rgb * exp2(_Exposure));
// return LinearToSRGB(c);
return c;

6
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl


// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap
#ifdef _EMISSIVE_COLOR
#ifdef _EMISSIVE_COLOR_MAP
#elif _MASKMAP // If we have a MaskMap, use emissive slot as a mask on baseColor
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
#elif defined(_MASKMAP) // If we have a MaskMap, use emissive slot as a mask on baseColor
builtinData.emissiveColor = baseColor * tex2D(_MaskMap, input.texCoord0).bbb;
#else
builtinData.emissiveColor = float3(0.0, 0.0, 0.0);

81
Assets/TestScenes/HDTest/HDRenderLoopTest.unity


m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 142.28, y: 106.256996, z: -160.70999}
--- !u!1 &609148480
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 609148484}
- component: {fileID: 609148483}
- component: {fileID: 609148482}
- component: {fileID: 609148481}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &609148481
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 609148480}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: 53db393fa1a97b244b8f7e9d8f0bbdba, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!65 &609148482
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 609148480}
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!33 &609148483
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 609148480}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &609148484
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 609148480}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 3.4166343, y: 1.4560829, z: -3.79}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &653798720
Prefab:
m_ObjectHideFlags: 0

2
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-twosidedLighting.mat


m_Floats:
- first:
name: _AlphaCutoff
second: 0.5
second: 0.216
- first:
name: _AlphaCutoffEnable
second: 0

172
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Unlit.shader


Shader "Unity/Unlit"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_ColorMap("ColorMap", 2D) = "white" {}
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// Blending state
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0
[HideInInspector] _BlendMode ("__blendmode", Float) = 0.0
[HideInInspector] _SrcBlend ("__src", Float) = 1.0
[HideInInspector] _DstBlend ("__dst", Float) = 0.0
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
[HideInInspector] _CullMode("__cullmode", Float) = 2.0
[Enum(None, 0, DoubleSided)] _DoubleSidedMode("Double sided mode", Float) = 0
}
HLSLINCLUDE
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _EMISSIVE_COLOR_MAP
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl"
#define UNITY_MATERIAL_UNLIT
#include "Material/Material.hlsl"
#include "ShaderVariables.hlsl"
float4 _Color;
sampler2D _ColorMap;
float4 _EmissiveColor;
sampler2D _EmissiveColorMap;
float _EmissiveIntensity;
ENDHLSL
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
// ------------------------------------------------------------------
// forward pass
Pass
{
Name "Forward" // Name is not used
Tags { "LightMode" = "ForwardUnlit" } // This will be only for transparent object based on the RenderQueue index
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragForward
// Forward
struct Attributes
{
float3 positionOS : POSITION;
float2 uv0 : TEXCOORD0;
};
struct Varyings
{
float4 positionHS;
float2 texCoord0;
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
float4 interpolators[1] : TEXCOORD0;
};
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionHS = input.positionHS;
output.interpolators[0].xy = input.texCoord0.xy;
output.interpolators[0].zw = float2(0.0, 0.0);
return output;
}
Varyings UnpackVaryings(PackedVaryings input)
{
Varyings output;
output.positionHS = input.positionHS;
output.texCoord0.xy = input.interpolators[0].xy;
return output;
}
PackedVaryings VertDefault(Attributes input)
{
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionHS = TransformWorldToHClip(positionWS);
output.texCoord0 = input.uv0;
return PackVaryings(output);
}
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
surfaceData.color = tex2D(_ColorMap, input.texCoord0).rgb * _Color.rgb;
float alpha = tex2D(_ColorMap, input.texCoord0).a * _Color.rgb;
#ifdef _ALPHATEST_ON
clip(alpha - _AlphaCutoff);
#endif
builtinData.opacity = alpha;
// Builtin Data
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0);
#ifdef _EMISSIVE_COLOR_MAP
builtinData.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.velocity = float2(0.0, 0.0);
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
}
#if SHADER_STAGE_FRAGMENT
float4 FragForward(PackedVaryings packedInput) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
return float4(bsdfData.color, builtinData.opacity);
}
#endif
ENDHLSL
}
}
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Unlit.shader.meta


fileFormatVersion: 2
guid: 1972af2d7b732904ab1f3d5d0f1f2ab0
timeCreated: 1475766656
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存