浏览代码

HDREnderLoop: Push misc refactor

/main
sebastienlagarde 8 年前
当前提交
e11a6cc5
共有 16 个文件被更改,包括 588 次插入309 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLit.shader
  2. 261
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/DefaultLit.shader
  3. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitCommon.hlsl
  4. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDebugViewMaterial.hlsl
  5. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForward.hlsl
  6. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForwardUnlit.hlsl
  7. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassGBuffer.hlsl
  8. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassLightTransport.hlsl
  9. 154
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitParams.hlsl
  10. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitParams.hlsl.meta
  11. 135
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitVaryings.hlsl
  12. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitVaryings.hlsl.meta
  13. 19
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDepthOnly.hlsl
  14. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDepthOnly.hlsl.meta
  15. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitCommon.hlsl.meta
  16. 276
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitCommon.hlsl

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLit.shader


#pragma vertex VertDefault
#pragma fragment Frag
#if SHADER_STAGE_FRAGMENT
#ifdef SHADER_STAGE_FRAGMENT
#define SHADERPASS SHADERPASS_GBUFFER
#include "LayeredLitCommon.hlsl"

261
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/DefaultLit.shader


#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
//-------------------------------------------------------------------------------------
// Define
//-------------------------------------------------------------------------------------
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "../../ShaderVariables.hlsl"
#include "../../Debug/DebugViewMaterial.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration

#pragma fragment Frag
#define SHADERPASS SHADERPASS_GBUFFER
#include "LitCommon.hlsl"
#include "../../Lighting/Lighting.hlsl" // This include Material.hlsl
#include "LitVaryings.hlsl"
#include "LitParams.hlsl"
#ifdef SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
GetLitParallaxHeightmap(input, surfaceData);
GetLitBaseColorAlpha(input, surfaceData, builtinData);
GetLitSpecularOcclusion(input, surfaceData);
GetLitNormal(input, surfaceData);
GetLitMask(input, surfaceData);
surfaceData.materialId = 0;
GetLitAnisotropic(input, surfaceData);
surfaceData.specular = 0.04;
GetLitSubSurface(input, surfaceData);
GetLitClearCoat(input, surfaceData);
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
GetLitBuiltinData(input, surfaceData, builtinData);
}
#endif
#include "../../ShaderPass/ShaderPassGBuffer.hlsl"

#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL
#include "LitCommon.hlsl"
#include "../../Material/Material.hlsl"
#include "LitVaryings.hlsl"
#include "LitParams.hlsl"
#ifdef SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
GetLitParallaxHeightmap(input, surfaceData);
GetLitBaseColorAlpha(input, surfaceData, builtinData);
GetLitSpecularOcclusion(input, surfaceData);
GetLitNormal(input, surfaceData);
GetLitMask(input, surfaceData);
surfaceData.materialId = 0;
GetLitAnisotropic(input, surfaceData);
surfaceData.specular = 0.04;
GetLitSubSurface(input, surfaceData);
GetLitClearCoat(input, surfaceData);
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
GetLitBuiltinData(input, surfaceData, builtinData);
}
#endif
void GetVaryingsDataDebug(uint paramId, Varyings input, inout float3 result, inout bool needLinearToSRGB)
{

HLSLPROGRAM
#pragma vertex VertLT
// Lightmap memo
// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light,
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
#pragma vertex Vert
#include "LitCommon.hlsl"
#include "../../Material/Material.hlsl"
#include "LitParams.hlsl"
CBUFFER_START(UnityMetaPass)
// x = use uv1 as raster position

float unity_OneOverOutputBoost;
float unity_MaxOutputValue;
struct VaryingsLT
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 tangentOS : TANGENT;
};
struct Varyings
{
float4 positionHS;
float2 texCoord0;

struct PackedVaryingsLT
struct PackedVaryings
{
float4 positionHS : SV_Position;
float4 interpolators[1] : TEXCOORD0;

PackedVaryingsLT PackVaryings(VaryingsLT input)
PackedVaryings PackVaryings(Varyings input)
PackedVaryingsLT output;
PackedVaryings output;
output.positionHS = input.positionHS;
output.interpolators[0].xy = input.texCoord0;
output.interpolators[0].zw = input.texCoord1;

VaryingsLT UnpackVaryings(PackedVaryingsLT input)
Varyings UnpackVaryings(PackedVaryings input)
VaryingsLT output;
Varyings output;
output.positionHS = input.positionHS;
output.texCoord0 = input.interpolators[0].xy;
output.texCoord1 = input.interpolators[0].zw;

PackedVaryingsLT VertLT(Attributes input)
PackedVaryings Vert(Attributes input)
VaryingsLT output;
Varyings output;
// Output UV coordinate in vertex shader
if (unity_MetaVertexControl.x)

output.positionHS = TransformWorldToHClip(positionWS);
output.texCoord0 = input.uv0;
output.texCoord1 = input.uv1;
#define GetSurfaceAndBuiltinData GetSurfaceAndBuiltinDataLT
#define Varyings VaryingsLT
#define PackedVaryings PackedVaryingsLT
#ifdef SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
GetLitBaseColorAlpha(input, surfaceData, builtinData);
GetLitMask(input, surfaceData);
surfaceData.materialId = 0;
surfaceData.specular = 0.04;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
GetLitBuiltinData(input, surfaceData, builtinData);
}
#endif
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL

// Depth only
Pass
{
Name "DepthOnly" // Name is not used
Tags { "LightMode" = "DepthOnly" } // This will be only for transparent object based on the RenderQueue index
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "../../Material/Material.hlsl"
#include "LitParams.hlsl"
struct Attributes
{
float3 positionOS : POSITION;
float2 uv0 : TEXCOORD0;
#if defined(_HEIGHTMAP) && !defined (_HEIGHTMAP_AS_DISPLACEMENT)
float4 tangentOS : TANGENT;
#endif
};
struct Varyings
{
float4 positionHS;
float2 texCoord0;
#if defined(_HEIGHTMAP) && !defined (_HEIGHTMAP_AS_DISPLACEMENT)
float3 positionWS;
float3 tangentToWorld[3];
#endif
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
#if defined(_HEIGHTMAP) && !defined (_HEIGHTMAP_AS_DISPLACEMENT)
float4 interpolators[4] : TEXCOORD0;
#else
float4 interpolators[1] : TEXCOORD0;
#endif
};
// 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;
#if defined(_HEIGHTMAP) && !defined (_HEIGHTMAP_AS_DISPLACEMENT)
output.interpolators[0].xyz = input.positionWS.xyz;
output.interpolators[1].xyz = input.tangentToWorld[0];
output.interpolators[2].xyz = input.tangentToWorld[1];
output.interpolators[3].xyz = input.tangentToWorld[2];
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1].w = input.texCoord0.y;
#else
output.interpolators[0] = float4(input.texCoord0, 0.0, 0.0);
#endif
return output;
}
Varyings UnpackVaryings(PackedVaryingsLT input)
{
Varyings output;
output.positionHS = input.positionHS;
#if defined(_HEIGHTMAP) && !defined (_HEIGHTMAP_AS_DISPLACEMENT)
output.positionWS.xyz = input.interpolators[0].xyz;
output.tangentToWorld[0] = input.interpolators[1].xyz;
output.tangentToWorld[1] = input.interpolators[2].xyz;
output.tangentToWorld[2] = input.interpolators[3].xyz;
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w);
#else
output.texCoord0.xy = input.interpolators[0].xy;
#endif
}
PackedVaryings Vert(Attributes input)
{
Varyings output;
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(output.positionWS);
output.texCoord0 = input.uv0;
#if defined(_HEIGHTMAP) && !defined (_HEIGHTMAP_AS_DISPLACEMENT)
output.positionWS = positionWS;
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
#endif
return PackVaryings(output);
}
#ifdef SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
GetLitParallaxHeightmap(input, surfaceData);
// Perform alpha testing
GetLitBaseColorAlpha(input, surfaceData, builtinData);
}
#endif
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// forward pass
Pass
{

#pragma fragment Frag
#define SHADERPASS SHADERPASS_FORWARD
#include "LitCommon.hlsl"
#include "../../Lighting/Lighting.hlsl"
#include "LitVaryings.hlsl"
#include "LitParams.hlsl"
#ifdef SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
GetLitParallaxHeightmap(input, surfaceData);
GetLitBaseColorAlpha(input, surfaceData, builtinData);
GetLitSpecularOcclusion(input, surfaceData);
GetLitNormal(input, surfaceData);
GetLitMask(input, surfaceData);
surfaceData.materialId = 0;
GetLitAnisotropic(input, surfaceData);
surfaceData.specular = 0.04;
GetLitSubSurface(input, surfaceData);
GetLitClearCoat(input, surfaceData);
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
GetLitBuiltinData(input, surfaceData, builtinData);
}
#endif
#include "../../ShaderPass/ShaderPassForward.hlsl"

4
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitCommon.hlsl


// Fill SurfaceData/Lighting data function
//-------------------------------------------------------------------------------------
#if SHADER_STAGE_FRAGMENT
#ifdef SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{

}
}
#endif // #if SHADER_STAGE_FRAGMENT
#endif // #ifdef SHADER_STAGE_FRAGMENT

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDebugViewMaterial.hlsl


#error SHADERPASS_is_not_correctly_define
#endif
#if SHADER_STAGE_FRAGMENT
#ifdef SHADER_STAGE_FRAGMENT
#include "Color.hlsl"
int _DebugViewMaterial;

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForward.hlsl


#error SHADERPASS_is_not_correctly_define
#endif
#if SHADER_STAGE_FRAGMENT
#ifdef SHADER_STAGE_FRAGMENT
float4 Frag(PackedVaryings packedInput) : SV_Target
{

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForwardUnlit.hlsl


#error SHADERPASS_is_not_correctly_define
#endif
#if SHADER_STAGE_FRAGMENT
#ifdef SHADER_STAGE_FRAGMENT
float4 Frag(PackedVaryings packedInput) : SV_Target
{

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassGBuffer.hlsl


#error SHADERPASS_is_not_correctly_define
#endif
#if SHADER_STAGE_FRAGMENT
#ifdef SHADER_STAGE_FRAGMENT
void Frag( PackedVaryings packedInput,
OUTPUT_GBUFFER(outGBuffer)

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassLightTransport.hlsl


#include "Color.hlsl"
#if SHADER_STAGE_FRAGMENT
#ifdef SHADER_STAGE_FRAGMENT
// TODO: This is the max value allowed for emissive (bad name - but keep for now to retrieve it) (It is 8^2.2 (gamma) and 8 is the limit of punctual light slider...), comme from UnityCg.cginc. Fix it!
// Ask Jesper if this can be change for HDRenderLoop

154
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitParams.hlsl


// No guard header!
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Lighting data function
//-------------------------------------------------------------------------------------
#ifdef SHADER_STAGE_FRAGMENT
void GetLitParallaxHeightmap(inout Varyings input, inout SurfaceData surfaceData)
{
#if defined(_HEIGHTMAP) && !defined(_HEIGHTMAP_AS_DISPLACEMENT)
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS); // This should be remove by the compiler as we usually cal it before.
float height = UNITY_SAMPLE_TEX2D(_HeightMap, input.texCoord0).r * _HeightScale + _HeightBias;
// Transform view vector in tangent space
TransformWorldToTangent(V, input.tangentToWorld);
float2 offset = ParallaxOffset(viewDirTS, height);
input.texCoord0 += offset;
input.texCoord1 += offset;
#endif
}
void GetLitBaseColorAlpha(Varyings input, inout SurfaceData surfaceData, inout BuiltinData builtinData)
{
surfaceData.baseColor = UNITY_SAMPLE_TEX2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
float alpha = _BaseColor.a;
#else
float alpha = UNITY_SAMPLE_TEX2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a;
#endif
#ifdef _ALPHATEST_ON
clip(alpha - _AlphaCutoff);
#endif
builtinData.opacity = alpha;
}
void GetLitSpecularOcclusion(Varyings input, inout SurfaceData surfaceData)
{
#ifdef _SPECULAROCCLUSIONMAP
// TODO: Do something. For now just take alpha channel
surfaceData.specularOcclusion = UNITY_SAMPLE_TEX2D(_SpecularOcclusionMap, input.texCoord0).a;
#else
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
// smooth it
//surfaceData.specularOcclusion *= surfaceData.specularOcclusion;
surfaceData.specularOcclusion = 1.0;
#endif
}
void GetLitNormal(Varyings input, inout SurfaceData surfaceData)
{
// TODO: think about using BC5
float3 vertexNormalWS = input.tangentToWorld[2].xyz;
#ifdef _NORMALMAP
#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS = UnpackNormalAG(UNITY_SAMPLE_TEX2D(_NormalMap, input.texCoord0));
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
#else // Object space (TODO: We need to apply the world rotation here! - Require to pass world transform)
surfaceData.normalWS = UNITY_SAMPLE_TEX2D(_NormalMap, input.texCoord0).rgb;
#endif
#else
surfaceData.normalWS = vertexNormalWS;
#endif
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
#ifdef _DOUBLESIDED_LIGHTING_FLIP
float3 oppositeNormalWS = -surfaceData.normalWS;
#else
// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS);
#endif
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld();
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS, -GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS);
#endif
}
// Mask is Metalic, Ambient Occlusion, Smoothness
void GetLitMask(Varyings input, inout SurfaceData surfaceData)
{
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
surfaceData.perceptualSmoothness = UNITY_SAMPLE_TEX2D(_BaseColorMap, input.texCoord0).a;
#elif defined(_MASKMAP)
surfaceData.perceptualSmoothness = UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).a;
#else
surfaceData.perceptualSmoothness = 1.0;
#endif
surfaceData.perceptualSmoothness *= _Smoothness;
// MaskMap is Metalic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha)
#ifdef _MASKMAP
surfaceData.metalic = UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).r;
surfaceData.ambientOcclusion = UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).g;
#else
surfaceData.metalic = 1.0;
surfaceData.ambientOcclusion = 1.0;
#endif
surfaceData.metalic *= _Metalic;
}
void GetLitAnisotropic(Varyings input, inout SurfaceData surfaceData)
{
surfaceData.tangentWS = input.tangentToWorld[0].xyz; // TODO: do with tangent same as with normal, sample into texture etc...
surfaceData.anisotropy = 0;
}
void GetLitSubSurface(Varyings input, inout SurfaceData surfaceData)
{
surfaceData.subSurfaceRadius = 1.0;
surfaceData.thickness = 0.0;
surfaceData.subSurfaceProfile = 0;
}
void GetLitClearCoat(Varyings input, inout SurfaceData surfaceData)
{
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;
}
void GetLitBuiltinData(Varyings input, SurfaceData surfaceData, inout BuiltinData builtinData)
{
// Builtin Data
// Alpha is setup earlier
// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
// Note that data input above can be use to sample into lightmap (like normal)
builtinData.bakeDiffuseLighting = UNITY_SAMPLE_TEX2D(_DiffuseLightingMap, input.texCoord1).rgb;
// 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
builtinData.emissiveColor = UNITY_SAMPLE_TEX2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
#elif defined(_MASKMAP) // If we have a MaskMap, use emissive slot as a mask on baseColor
builtinData.emissiveColor = surfaceData.baseColor * UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).bbb;
#else
builtinData.emissiveColor = float3(0.0, 0.0, 0.0);
#endif
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.velocity = float2(0.0, 0.0);
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
}
#endif // #ifdef SHADER_STAGE_FRAGMENT

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitParams.hlsl.meta


fileFormatVersion: 2
guid: da5bd1774f0e4654d8f6655eb1122307
timeCreated: 1476980560
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

135
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitVaryings.hlsl


// No guard header!
#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif
//-------------------------------------------------------------------------------------
// Attribute/Varying
//-------------------------------------------------------------------------------------
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if (DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
float2 uv2 : TEXCOORD2;
#endif
float4 tangentOS : TANGENT; // Always present as we require it also in case of anisotropic lighting
// UNITY_INSTANCE_ID
};
struct Varyings
{
float4 positionHS;
float3 positionWS;
float2 texCoord0;
float2 texCoord1;
#if (DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
float2 texCoord2;
#endif
float3 tangentToWorld[3];
#if defined(SHADER_STAGE_FRAGMENT) && (SHADERPASS != SHADERPASS_LIGHT_TRANSPORT)
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace;
#endif
#endif
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
#if (DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
float4 interpolators[5] : TEXCOORD0;
#else
float4 interpolators[4] : TEXCOORD0;
#endif
#if defined(SHADER_STAGE_FRAGMENT) && (SHADERPASS != SHADERPASS_LIGHT_TRANSPORT)
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#endif
#endif
};
// 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].xyz = input.positionWS.xyz;
output.interpolators[1].xyz = input.tangentToWorld[0];
output.interpolators[2].xyz = input.tangentToWorld[1];
output.interpolators[3].xyz = input.tangentToWorld[2];
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1].w = input.texCoord0.y;
output.interpolators[2].w = input.texCoord1.x;
output.interpolators[3].w = input.texCoord1.y;
#if (DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
output.interpolators[4] = float4(input.texCoord2.xy, 0.0, 0.0);
#endif
return output;
}
Varyings UnpackVaryings(PackedVaryings input)
{
Varyings output;
output.positionHS = input.positionHS;
output.positionWS.xyz = input.interpolators[0].xyz;
output.tangentToWorld[0] = input.interpolators[1].xyz;
output.tangentToWorld[1] = input.interpolators[2].xyz;
output.tangentToWorld[2] = input.interpolators[3].xyz;
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w);
output.texCoord1.xy = float2(input.interpolators[2].w, input.interpolators[3].w);
#if (DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
output.texCoord2 = input.interpolators[4].xy;
#endif
#if defined(SHADER_STAGE_FRAGMENT) && (SHADERPASS != SHADERPASS_LIGHT_TRANSPORT)
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.cullFace = input.cullFace;
#endif
#endif
return output;
}
//-------------------------------------------------------------------------------------
// Vertex shader
//-------------------------------------------------------------------------------------
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16)
PackedVaryings VertDefault(Attributes input)
{
Varyings output;
output.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(output.positionWS);
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
output.texCoord0 = input.uv0;
output.texCoord1 = input.uv1;
#if (DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
output.texCoord2 = input.uv2;
#endif
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
return PackVaryings(output);
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitVaryings.hlsl.meta


fileFormatVersion: 2
guid: e6689284aaade5244989847dfe3c2773
timeCreated: 1476980560
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

19
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDepthOnly.hlsl


#if SHADERPASS != SHADERPASS_DEPTH_ONLY
#error SHADERPASS_is_not_correctly_define
#endif
#ifdef SHADER_STAGE_FRAGMENT
float4 Frag(PackedVaryings packedInput) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
// TODO: handle cubemap shadow
return float4(0.0, 0.0, 0.0, 0.0);
}
#endif

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDepthOnly.hlsl.meta


fileFormatVersion: 2
guid: d2b018587e99fd248bcbab551f0151a1
timeCreated: 1476981737
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitCommon.hlsl.meta


fileFormatVersion: 2
guid: 8378596fcd29cf2459998acc0b0b5b8a
timeCreated: 1476885564
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

276
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitCommon.hlsl


// No guard header!
#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "../../Lighting/Lighting.hlsl" // This include Material.hlsl
#include "../../ShaderVariables.hlsl"
#include "../../Debug/DebugViewMaterial.hlsl"
//-------------------------------------------------------------------------------------
// Attribute/Varying
//-------------------------------------------------------------------------------------
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
float2 uv2 : TEXCOORD2;
#endif
float4 tangentOS : TANGENT; // Always present as we require it also in case of anisotropic lighting
// UNITY_INSTANCE_ID
};
struct Varyings
{
float4 positionHS;
float3 positionWS;
float2 texCoord0;
float2 texCoord1;
#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
float2 texCoord2;
#endif
float3 tangentToWorld[3];
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace;
#endif
#endif
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
float4 interpolators[5] : TEXCOORD0;
#else
float4 interpolators[4] : TEXCOORD0;
#endif
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#endif
#endif
};
// 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].xyz = input.positionWS.xyz;
output.interpolators[1].xyz = input.tangentToWorld[0];
output.interpolators[2].xyz = input.tangentToWorld[1];
output.interpolators[3].xyz = input.tangentToWorld[2];
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1].w = input.texCoord0.y;
output.interpolators[2].w = input.texCoord1.x;
output.interpolators[3].w = input.texCoord1.y;
#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
output.interpolators[4] = float4(input.texCoord2.xy, 0.0, 0.0);
#endif
return output;
}
Varyings UnpackVaryings(PackedVaryings input)
{
Varyings output;
output.positionHS = input.positionHS;
output.positionWS.xyz = input.interpolators[0].xyz;
output.tangentToWorld[0] = input.interpolators[1].xyz;
output.tangentToWorld[1] = input.interpolators[2].xyz;
output.tangentToWorld[2] = input.interpolators[3].xyz;
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w);
output.texCoord1.xy = float2(input.interpolators[2].w, input.interpolators[3].w);
#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
output.texCoord2 = input.interpolators[4].xy;
#endif
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.cullFace = input.cullFace;
#endif
#endif
return output;
}
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16)
PackedVaryings VertDefault(Attributes input)
{
Varyings output;
output.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(output.positionWS);
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
output.texCoord0 = input.uv0;
output.texCoord1 = input.uv1;
#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
output.texCoord2 = input.uv2;
#endif
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
return PackVaryings(output);
}
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Lighting data function
//-------------------------------------------------------------------------------------
#if SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
#ifdef _HEIGHTMAP
#ifdef _HEIGHTMAP_AS_DISPLACEMENT
// TODO
#else
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS); // This should be remove by the compiler as we usually cal it before.
float height = UNITY_SAMPLE_TEX2D(_HeightMap, input.texCoord0).r * _HeightScale + _HeightBias;
// Transform view vector in tangent space
TransformWorldToTangent(V, input.tangentToWorld);
float2 offset = ParallaxOffset(viewDirTS, height);
input.texCoord0 += offset;
input.texCoord1 += offset;
#endif
#endif
surfaceData.baseColor = UNITY_SAMPLE_TEX2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
float alpha = _BaseColor.a;
#else
float alpha = UNITY_SAMPLE_TEX2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a;
#endif
#ifdef _ALPHATEST_ON
clip(alpha - _AlphaCutoff);
#endif
#ifdef _SPECULAROCCLUSIONMAP
// TODO: Do something. For now just take alpha channel
surfaceData.specularOcclusion = UNITY_SAMPLE_TEX2D(_SpecularOcclusionMap, input.texCoord0).a;
#else
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
// smooth it
//surfaceData.specularOcclusion *= surfaceData.specularOcclusion;
surfaceData.specularOcclusion = 1.0;
#endif
// TODO: think about using BC5
float3 vertexNormalWS = input.tangentToWorld[2].xyz;
#ifdef _NORMALMAP
#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS = UnpackNormalAG(UNITY_SAMPLE_TEX2D(_NormalMap, input.texCoord0));
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
#else // Object space (TODO: We need to apply the world rotation here! - Require to pass world transform)
surfaceData.normalWS = UNITY_SAMPLE_TEX2D(_NormalMap, input.texCoord0).rgb;
#endif
#else
surfaceData.normalWS = vertexNormalWS;
#endif
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
#ifdef _DOUBLESIDED_LIGHTING_FLIP
float3 oppositeNormalWS = -surfaceData.normalWS;
#else
// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS);
#endif
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld();
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS, -GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS);
#endif
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
surfaceData.perceptualSmoothness = UNITY_SAMPLE_TEX2D(_BaseColorMap, input.texCoord0).a;
#elif defined(_MASKMAP)
surfaceData.perceptualSmoothness = UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).a;
#else
surfaceData.perceptualSmoothness = 1.0;
#endif
surfaceData.perceptualSmoothness *= _Smoothness;
surfaceData.materialId = 0;
// MaskMap is Metalic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha)
#ifdef _MASKMAP
surfaceData.metalic = UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).r;
surfaceData.ambientOcclusion = UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).g;
#else
surfaceData.metalic = 1.0;
surfaceData.ambientOcclusion = 1.0;
#endif
surfaceData.metalic *= _Metalic;
surfaceData.tangentWS = input.tangentToWorld[0].xyz; // TODO: do with tangent same as with normal, sample into texture etc...
surfaceData.anisotropy = 0;
surfaceData.specular = 0.04;
surfaceData.subSurfaceRadius = 1.0;
surfaceData.thickness = 0.0;
surfaceData.subSurfaceProfile = 0;
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
// Builtin Data
builtinData.opacity = alpha;
// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
// Note that data input above can be use to sample into lightmap (like normal)
builtinData.bakeDiffuseLighting = UNITY_SAMPLE_TEX2D(_DiffuseLightingMap, input.texCoord0).rgb;
// 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
builtinData.emissiveColor = UNITY_SAMPLE_TEX2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
#elif defined(_MASKMAP) // If we have a MaskMap, use emissive slot as a mask on baseColor
builtinData.emissiveColor = surfaceData.baseColor * UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).bbb;
#else
builtinData.emissiveColor = float3(0.0, 0.0, 0.0);
#endif
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.velocity = float2(0.0, 0.0);
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
}
#endif // #if SHADER_STAGE_FRAGMENT
正在加载...
取消
保存