浏览代码
Merge pull request #5 from Unity-Technologies/LightmapSupport
Merge pull request #5 from Unity-Technologies/LightmapSupport
Add Meta pass + Depth pass support/main
GitHub
8 年前
当前提交
ca67bebf
共有 96 个文件被更改,包括 1864 次插入 和 1218 次删除
-
14Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
14Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl
-
20Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs.hlsl
-
7Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl
-
5Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward/LightingForward.hlsl
-
11Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Builtin/BuiltinData.cs
-
18Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Builtin/BuiltinData.cs.hlsl
-
15Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Builtin/BuiltinData.hlsl
-
115Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLit.shader
-
40Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitCommon.hlsl
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.cs
-
16Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.cs.hlsl
-
295Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitUI.cs
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.cs.hlsl
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDebugViewMaterial.hlsl
-
7Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForward.hlsl
-
7Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForwardUnlit.hlsl
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassGBuffer.hlsl
-
18Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl
-
4Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
-
2Assets/ScriptableRenderLoop/ShaderLibrary/API/Validate.hlsl
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl
-
11Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
-
2Assets/TestScenes/HDTest/Leaf/GroundLeaf/Materials/GroundLeaf_Albedo.mat
-
7Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Blue_Alpha.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/CubeTransparent.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Gray.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Green.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Ground/Ground_01_2x2.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Ground/Needle_Moss_1x1.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Ground/Sand_02_2x2_02.mat
-
74Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Red.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Terrain.mat
-
7Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-alpha.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-transparent.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-twosidedLighting.mat
-
2Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test.mat
-
47Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/unlitTest.mat
-
2Assets/TestScenes/HDTest/Rock/rcgRock012/Materials/rcgRock012Material.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_0.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_1.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_2.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_3.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_4.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_5.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_6.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_7.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_8.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth0_9.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smooth1_1.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_0.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_1.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_2.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_3.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_4.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_5.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_6.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_7.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_8.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric0_9.mat
-
2Assets/TestScenes/HDTest/Spheres/Mat_smoothdielectric1_0.mat
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitCommon.hlsl.meta
-
149Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.hlsl.meta
-
494Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDefault.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDefault.shader.meta
-
238Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitEnvTemplate.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitEnvTemplate.hlsl.meta
-
131Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitShare.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitShare.hlsl.meta
-
45Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitData.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitData.hlsl.meta
-
142Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitDefault.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitDefault.shader.meta
-
63Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitShare.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitShare.hlsl.meta
-
22Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPass.cs
-
17Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPass.cs.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPass.cs.hlsl.meta
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPass.cs.meta
-
16Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDepthOnly.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassDepthOnly.hlsl.meta
-
43Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassLightTransport.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassLightTransport.hlsl.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitTemplate.hlsl.meta
-
157Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/DefaultLit.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/DefaultLit.shader.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitCommon.hlsl.meta
-
309Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitCommon.hlsl
-
88Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/DefaultUnlit.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/DefaultUnlit.shader.meta
-
143Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitCommon.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitCommon.hlsl.meta
-
0/Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/LayeredLit/LayeredLitCommon.hlsl
|
|||
fileFormatVersion: 2 |
|||
guid: 4475f12491047e54d9ddd0a61e36ead2 |
|||
timeCreated: 1476924487 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// No guard header! |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// FragInput |
|||
// This structure gather all possible varying/interpolator for this shader. |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
struct FragInput |
|||
{ |
|||
float4 positionHS; |
|||
float3 positionWS; |
|||
float2 texCoord0; |
|||
float2 texCoord1; |
|||
float2 texCoord2; |
|||
float3 tangentToWorld[3]; |
|||
bool isFrontFace; |
|||
}; |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInput input, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
#ifdef _HEIGHTMAP |
|||
// TODO: in case of shader graph, a node like parallax must be nullify if use to generate code for Meta pass |
|||
#ifndef _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 |
|||
#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 = input.isFrontFace ? |
|||
(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 Metallic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha) |
|||
#ifdef _MASKMAP |
|||
surfaceData.metallic = UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).r; |
|||
surfaceData.ambientOcclusion = UNITY_SAMPLE_TEX2D(_MaskMap, input.texCoord0).g; |
|||
#else |
|||
surfaceData.metallic = 1.0; |
|||
surfaceData.ambientOcclusion = 1.0; |
|||
#endif |
|||
surfaceData.metallic *= _Metallic; |
|||
|
|||
|
|||
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.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; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c4a6d6f92d4f44d47b369e7a13250e0a |
|||
timeCreated: 1477003836 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Unity/Lit" |
|||
{ |
|||
Properties |
|||
{ |
|||
// Following set of parameters represent the parameters node inside the MaterialGraph. |
|||
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist. |
|||
|
|||
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear |
|||
_BaseColor("BaseColor", Color) = (1,1,1,1) |
|||
_BaseColorMap("BaseColorMap", 2D) = "white" {} |
|||
|
|||
_Metallic("_Metallic", Range(0.0, 1.0)) = 0 |
|||
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5 |
|||
_MaskMap("MaskMap", 2D) = "white" {} |
|||
|
|||
_SpecularOcclusionMap("SpecularOcclusion", 2D) = "white" {} |
|||
|
|||
_NormalMap("NormalMap", 2D) = "bump" {} |
|||
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0 |
|||
|
|||
_HeightMap("HeightMap", 2D) = "black" {} |
|||
_HeightScale("Height Scale", Float) = 1 |
|||
_HeightBias("Height Bias", Float) = 0 |
|||
[Enum(Parallax, 0, Displacement, 1)] _HeightMapMode("Heightmap usage", Float) = 0 |
|||
|
|||
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0 |
|||
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {} |
|||
//_Thickness("Thickness", Range(0.0, 1.0)) = 0 |
|||
//_ThicknessMap("ThicknessMap", 2D) = "white" {} |
|||
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0 |
|||
|
|||
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0 |
|||
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {} |
|||
|
|||
//_CoatRoughness("CoatRoughness", Range(0.0, 1.0)) = 0 |
|||
//_CoatRoughnessMap("CoatRoughnessMap", 2D) = "white" {} |
|||
|
|||
// _DistortionVectorMap("DistortionVectorMap", 2D) = "white" {} |
|||
// _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. |
|||
|
|||
_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 |
|||
|
|||
[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 |
|||
// Material Id |
|||
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0 |
|||
|
|||
[Enum(Mask Alpha, 0, BaseColor Alpha, 1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 1 |
|||
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1 |
|||
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _DoubleSidedMode("Double sided mode", Float) = 0 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Variant |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR |
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _NORMALMAP_TANGENT_SPACE |
|||
#pragma shader_feature _MASKMAP |
|||
#pragma shader_feature _SPECULAROCCLUSIONMAP |
|||
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
#pragma shader_feature _EMISSIVE_COLOR |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
#pragma shader_feature _HEIGHTMAP |
|||
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT |
|||
|
|||
#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 |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "common.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Debug/DebugViewMaterial.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// Set of users variables |
|||
float4 _BaseColor; |
|||
UNITY_DECLARE_TEX2D(_BaseColorMap); |
|||
|
|||
float _Metallic; |
|||
float _Smoothness; |
|||
UNITY_DECLARE_TEX2D(_MaskMap); |
|||
UNITY_DECLARE_TEX2D(_SpecularOcclusionMap); |
|||
|
|||
UNITY_DECLARE_TEX2D(_NormalMap); |
|||
UNITY_DECLARE_TEX2D(_Heightmap); |
|||
float _HeightScale; |
|||
float _HeightBias; |
|||
|
|||
UNITY_DECLARE_TEX2D(_DiffuseLightingMap); |
|||
float4 _EmissiveColor; |
|||
UNITY_DECLARE_TEX2D(_EmissiveColorMap); |
|||
float _EmissiveIntensity; |
|||
|
|||
float _SubSurfaceRadius; |
|||
UNITY_DECLARE_TEX2D(_SubSurfaceRadiusMap); |
|||
// float _Thickness; |
|||
// UNITY_DECLARE_TEX2D(_ThicknessMap); |
|||
|
|||
// float _CoatCoverage; |
|||
// UNITY_DECLARE_TEX2D(_CoatCoverageMap); |
|||
|
|||
// float _CoatRoughness; |
|||
// UNITY_DECLARE_TEX2D(_CoatRoughnessMap); |
|||
|
|||
float _AlphaCutoff; |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Deferred pass |
|||
Pass |
|||
{ |
|||
Name "GBuffer" // Name is not used |
|||
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index |
|||
|
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_GBUFFER |
|||
#include "../../Lighting/Lighting.hlsl" // This include Material.hlsl |
|||
#include "LitData.hlsl" |
|||
#include "LitShare.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassGBuffer.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Debug pass |
|||
Pass |
|||
{ |
|||
Name "Debug" |
|||
Tags { "LightMode" = "DebugViewMaterial" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL |
|||
#include "../../Material/Material.hlsl" |
|||
#include "LitData.hlsl" |
|||
#include "LitShare.hlsl" |
|||
|
|||
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_VARYING_DEPTH: |
|||
// TODO: provide a customize parameter (like a slider) |
|||
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1); |
|||
result = linearDepth.xxx; |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD0: |
|||
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0); |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD1: |
|||
result = float3(input.texCoord1 * 0.5 + 0.5, 0.0); |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD2: |
|||
result = float3(input.texCoord2 * 0.5 + 0.5, 0.0); |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXTANGENTWS: |
|||
result = input.tangentToWorld[0].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXBITANGENTWS: |
|||
result = input.tangentToWorld[1].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXNORMALWS: |
|||
result = input.tangentToWorld[2].xyz * 0.5 + 0.5; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Extracts information for lightmapping, GI (emission, albedo, ...) |
|||
// This pass it not used during regular rendering. |
|||
Pass |
|||
{ |
|||
Name "META" |
|||
Tags{ "LightMode" = "Meta" } |
|||
|
|||
Cull Off |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
// 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 |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT |
|||
#include "../../Material/Material.hlsl" |
|||
#include "LitData.hlsl" |
|||
|
|||
CBUFFER_START(UnityMetaPass) |
|||
// x = use uv1 as raster position |
|||
// y = use uv2 as raster position |
|||
bool4 unity_MetaVertexControl; |
|||
|
|||
// x = return albedo |
|||
// y = return normal |
|||
bool4 unity_MetaFragmentControl; |
|||
|
|||
CBUFFER_END |
|||
|
|||
// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency |
|||
float unity_OneOverOutputBoost; |
|||
float unity_MaxOutputValue; |
|||
|
|||
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; |
|||
float2 texCoord1; |
|||
}; |
|||
|
|||
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; |
|||
output.interpolators[0].zw = input.texCoord1; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInput UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInput output; |
|||
ZERO_INITIALIZE(FragInput, output); |
|||
|
|||
output.positionHS = input.positionHS; |
|||
output.texCoord0 = input.interpolators[0].xy; |
|||
output.texCoord1 = input.interpolators[0].zw; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
// Output UV coordinate in vertex shader |
|||
if (unity_MetaVertexControl.x) |
|||
{ |
|||
input.positionOS.xy = input.uv1 * unity_LightmapST.xy + unity_LightmapST.zw; |
|||
// OpenGL right now needs to actually use incoming vertex position, |
|||
// so use it in a very dummy way |
|||
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f; |
|||
} |
|||
if (unity_MetaVertexControl.y) |
|||
{ |
|||
input.positionOS.xy = input.uv2 * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; |
|||
// OpenGL right now needs to actually use incoming vertex position, |
|||
// so use it in a very dummy way |
|||
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f; |
|||
} |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionHS = TransformWorldToHClip(positionWS); |
|||
output.texCoord0 = input.uv0; |
|||
output.texCoord1 = input.uv1; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|||
|
|||
#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 "LitData.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; |
|||
} |
|||
|
|||
FragInput UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInput output; |
|||
ZERO_INITIALIZE(FragInput, 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 |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionHS = TransformWorldToHClip(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); |
|||
} |
|||
|
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
Pass |
|||
{ |
|||
Name "Forward" // Name is not used |
|||
Tags { "LightMode" = "Forward" } // 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 Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD |
|||
#include "../../Lighting/Lighting.hlsl" |
|||
#include "LitData.hlsl" |
|||
#include "LitShare.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
CustomEditor "LitGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6e4ae4064600d784cac1e41a9e6f2e59 |
|||
timeCreated: 1477003836 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// No guard header! |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Env - Reference |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
// Ref: Moving Frostbite to PBR (Appendix A) |
|||
float3 IntegrateLambertIBLRef( EnvLightData lightData, BSDFData bsdfData, |
|||
UNITY_ARGS_ENV(_EnvTextures), |
|||
uint sampleCount = 2048) |
|||
{ |
|||
float3 N = bsdfData.normalWS; |
|||
float3 acc = float3(0.0, 0.0, 0.0); |
|||
// Add some jittering on Hammersley2d |
|||
float2 randNum = InitRandom(N.xy * 0.5 + 0.5); |
|||
|
|||
float3 tangentX, tangentY; |
|||
GetLocalFrame(N, tangentX, tangentY); |
|||
|
|||
for (uint i = 0; i < sampleCount; ++i) |
|||
{ |
|||
float2 u = Hammersley2d(i, sampleCount); |
|||
u = frac(u + randNum + 0.5); |
|||
|
|||
float3 L; |
|||
float NdotL; |
|||
float weightOverPdf; |
|||
ImportanceSampleLambert(u, N, tangentX, tangentY, L, NdotL, weightOverPdf); |
|||
|
|||
if (NdotL > 0.0) |
|||
{ |
|||
float4 val = UNITY_SAMPLE_ENV_LOD(_EnvTextures, L, lightData, 0); |
|||
|
|||
// diffuse Albedo is apply here as describe in ImportanceSampleLambert function |
|||
acc += bsdfData.diffuseColor * Lambert() * weightOverPdf * val.rgb; |
|||
} |
|||
} |
|||
|
|||
return acc / sampleCount; |
|||
} |
|||
|
|||
float3 IntegrateDisneyDiffuseIBLRef(float3 V, EnvLightData lightData, BSDFData bsdfData, |
|||
UNITY_ARGS_ENV(_EnvTextures), |
|||
uint sampleCount = 2048) |
|||
{ |
|||
float3 N = bsdfData.normalWS; |
|||
float NdotV = dot(N, V); |
|||
float3 acc = float3(0.0, 0.0, 0.0); |
|||
// Add some jittering on Hammersley2d |
|||
float2 randNum = InitRandom(N.xy * 0.5 + 0.5); |
|||
|
|||
float3 tangentX, tangentY; |
|||
GetLocalFrame(N, tangentX, tangentY); |
|||
|
|||
for (uint i = 0; i < sampleCount; ++i) |
|||
{ |
|||
float2 u = Hammersley2d(i, sampleCount); |
|||
u = frac(u + randNum + 0.5); |
|||
|
|||
float3 L; |
|||
float NdotL; |
|||
float weightOverPdf; |
|||
// for Disney we still use a Cosine importance sampling, true Disney importance sampling imply a look up table |
|||
ImportanceSampleLambert(u, N, tangentX, tangentY, L, NdotL, weightOverPdf); |
|||
|
|||
if (NdotL > 0.0) |
|||
{ |
|||
float3 H = normalize(L + V); |
|||
float LdotH = dot(L, H); |
|||
// Note: we call DisneyDiffuse that require to multiply by Albedo / PI. Divide by PI is already taken into account |
|||
// in weightOverPdf of ImportanceSampleLambert call. |
|||
float disneyDiffuse = DisneyDiffuse(NdotV, NdotL, LdotH, bsdfData.perceptualRoughness); |
|||
|
|||
// diffuse Albedo is apply here as describe in ImportanceSampleLambert function |
|||
float4 val = UNITY_SAMPLE_ENV_LOD(_EnvTextures, L, lightData, 0); |
|||
acc += bsdfData.diffuseColor * disneyDiffuse * weightOverPdf * val.rgb; |
|||
} |
|||
} |
|||
|
|||
return acc / sampleCount; |
|||
} |
|||
|
|||
// Ref: Moving Frostbite to PBR (Appendix A) |
|||
float3 IntegrateSpecularGGXIBLRef( float3 V, EnvLightData lightData, BSDFData bsdfData, |
|||
UNITY_ARGS_ENV(_EnvTextures), |
|||
uint sampleCount = 2048) |
|||
{ |
|||
float3 N = bsdfData.normalWS; |
|||
float NdotV = saturate(dot(N, V)); |
|||
float3 acc = float3(0.0, 0.0, 0.0); |
|||
|
|||
// Add some jittering on Hammersley2d |
|||
float2 randNum = InitRandom(V.xy * 0.5 + 0.5); |
|||
|
|||
float3 tangentX, tangentY; |
|||
GetLocalFrame(N, tangentX, tangentY); |
|||
|
|||
for (uint i = 0; i < sampleCount; ++i) |
|||
{ |
|||
float2 u = Hammersley2d(i, sampleCount); |
|||
u = frac(u + randNum + 0.5); |
|||
|
|||
float VdotH; |
|||
float NdotL; |
|||
float3 L; |
|||
float weightOverPdf; |
|||
|
|||
// GGX BRDF |
|||
ImportanceSampleGGX(u, V, N, tangentX, tangentY, bsdfData.roughness, NdotV, |
|||
L, VdotH, NdotL, weightOverPdf); |
|||
|
|||
if (NdotL > 0.0) |
|||
{ |
|||
// Fresnel component is apply here as describe in ImportanceSampleGGX function |
|||
float3 FweightOverPdf = F_Schlick(bsdfData.fresnel0, VdotH) * weightOverPdf; |
|||
|
|||
float4 val = UNITY_SAMPLE_ENV_LOD(_EnvTextures, L, lightData, 0); |
|||
|
|||
acc += FweightOverPdf * val.rgb; |
|||
} |
|||
} |
|||
|
|||
return acc / sampleCount; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Env |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
// _preIntegratedFGD and _CubemapLD are unique for each BRDF |
|||
void EvaluateBSDF_Env( float3 V, float3 positionWS, PreLightData prelightData, EnvLightData lightData, BSDFData bsdfData, |
|||
UNITY_ARGS_ENV(_EnvTextures), |
|||
out float4 diffuseLighting, |
|||
out float4 specularLighting) |
|||
{ |
|||
#ifdef LIT_DISPLAY_REFERENCE |
|||
|
|||
specularLighting.rgb = IntegrateSpecularGGXIBLRef(V, lightData, bsdfData, UNITY_PASS_ENV(_EnvTextures)); |
|||
specularLighting.a = 1.0; |
|||
|
|||
/* |
|||
#ifdef DIFFUSE_LAMBERT_BRDF |
|||
diffuseLighting.rgb = IntegrateLambertIBLRef(lightData, bsdfData, UNITY_PASS_ENV(_EnvTextures)); |
|||
#else |
|||
diffuseLighting.rgb = IntegrateDisneyDiffuseIBLRef(V, lightData, bsdfData, UNITY_PASS_ENV(_EnvTextures)); |
|||
#endif |
|||
diffuseLighting.a = 1.0; |
|||
*/ |
|||
diffuseLighting = float4(0.0, 0.0, 0.0, 0.0); |
|||
|
|||
#else |
|||
// TODO: factor this code in common, so other material authoring don't require to rewrite everything, |
|||
// also think about how such a loop can handle 2 cubemap at the same time as old unity. Macro can allow to do that |
|||
// but we need to have UNITY_SAMPLE_ENV_LOD replace by a true function instead that is define by the lighting arcitecture. |
|||
// Also not sure how to deal with 2 intersection.... |
|||
// Box and sphere are related to light property (but we have also distance based roughness etc...) |
|||
|
|||
// TODO: test the strech from Tomasz |
|||
// float shrinkedRoughness = AnisotropicStrechAtGrazingAngle(bsdfData.roughness, bsdfData.perceptualRoughness, NdotV); |
|||
|
|||
// Note: As explain in GetPreLightData we use normalWS and not iblNormalWS here (in case of anisotropy) |
|||
float3 rayWS = GetSpecularDominantDir(bsdfData.normalWS, prelightData.iblR, bsdfData.roughness); |
|||
|
|||
float3 R = rayWS; |
|||
float weight = 1.0; |
|||
|
|||
// In this code we redefine a bit the behavior of the reflcetion proble. We separate the projection volume (the proxy of the scene) form the influence volume (what pixel on the screen is affected) |
|||
|
|||
// 1. First determine the projection volume |
|||
|
|||
// In Unity the cubemaps are capture with the localToWorld transform of the component. |
|||
// This mean that location and oritention matter. So after intersection of proxy volume we need to convert back to world. |
|||
|
|||
// CAUTION: localToWorld is the transform use to convert the cubemap capture point to world space (mean it include the offset) |
|||
// the center of the bounding box is thus in locals space: positionLS - offsetLS |
|||
// We use this formulation as it is the one of legacy unity that was using only AABB box. |
|||
|
|||
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling |
|||
float3 positionLS = positionWS - lightData.positionWS; |
|||
positionLS = mul(positionLS, worldToLocal).xyz - lightData.offsetLS; // We want to calculate the intersection from the center of the bounding box. |
|||
|
|||
if (lightData.envShapeType == ENVSHAPETYPE_BOX) |
|||
{ |
|||
float3 rayLS = mul(rayWS, worldToLocal); |
|||
float3 boxOuterDistance = lightData.innerDistance + float3(lightData.blendDistance, lightData.blendDistance, lightData.blendDistance); |
|||
float dist = BoxRayIntersectSimple(positionLS, rayLS, -boxOuterDistance, boxOuterDistance); |
|||
|
|||
// No need to normalize for fetching cubemap |
|||
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.positionWS |
|||
R = (positionWS + dist * rayWS) - lightData.positionWS; |
|||
|
|||
// TODO: add distance based roughness |
|||
} |
|||
else if (lightData.envShapeType == ENVSHAPETYPE_SPHERE) |
|||
{ |
|||
float3 rayLS = mul(rayWS, worldToLocal); |
|||
float sphereOuterDistance = lightData.innerDistance.x + lightData.blendDistance; |
|||
float dist = SphereRayIntersectSimple(positionLS, rayLS, sphereOuterDistance); |
|||
|
|||
R = (positionWS + dist * rayWS) - lightData.positionWS; |
|||
} |
|||
|
|||
// 2. Apply the influence volume (Box volume is used for culling whatever the influence shape) |
|||
// TODO: In the future we could have an influence volume inside the projection volume (so with a different transform, in this case we will need another transform) |
|||
if (lightData.envShapeType == ENVSHAPETYPE_SPHERE) |
|||
{ |
|||
float distFade = max(length(positionLS) - lightData.innerDistance.x, 0.0); |
|||
weight = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero |
|||
} |
|||
else // ENVSHAPETYPE_BOX or ENVSHAPETYPE_NONE |
|||
{ |
|||
// Calculate falloff value, so reflections on the edges of the volume would gradually blend to previous reflection. |
|||
float distFade = DistancePointBox(positionLS, -lightData.innerDistance, lightData.innerDistance); |
|||
weight = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero |
|||
} |
|||
|
|||
// Smooth weighting |
|||
weight = smoothstep01(weight); |
|||
|
|||
// TODO: we must always perform a weight calculation as due to tiled rendering we need to smooth out cubemap at boundaries. |
|||
// So goal is to split into two category and have an option to say if we parallax correct or not. |
|||
|
|||
// TODO: compare current Morten version: offline cubemap with a particular remap + the bias in perceptualRoughnessToMipmapLevel |
|||
// to classic remap like unreal/Frobiste. The function GetSpecularDominantDir can result in a better matching in this case |
|||
// We let GetSpecularDominantDir currently as it still an improvement but not as good as it could be |
|||
float mip = perceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness); |
|||
float4 preLD = UNITY_SAMPLE_ENV_LOD(_EnvTextures, R, lightData, mip); |
|||
specularLighting.rgb = preLD.rgb * prelightData.specularFGD; |
|||
|
|||
// Apply specular occlusion on it |
|||
specularLighting.rgb *= bsdfData.specularOcclusion; |
|||
specularLighting.a = weight; |
|||
|
|||
diffuseLighting = float4(0.0, 0.0, 0.0, 0.0); |
|||
|
|||
#endif |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 22c20a34a48ade04daa95ffdc51ac052 |
|||
timeCreated: 1476997917 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// 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_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]; |
|||
}; |
|||
|
|||
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 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 (DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL) |
|||
output.interpolators[4] = float4(input.texCoord2.xy, 0.0, 0.0); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInput UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInput output; |
|||
ZERO_INITIALIZE(FragInput, 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 SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false); |
|||
#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); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9e1065b7612f2bd4c918d79e8a7ea8a3 |
|||
timeCreated: 1477003836 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// No guard header! |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// FragInput |
|||
// This structure gather all possible varying/interpolator for this shader. |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
struct FragInput |
|||
{ |
|||
float4 positionHS; |
|||
float2 texCoord0; |
|||
}; |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInput input, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
surfaceData.color = UNITY_SAMPLE_TEX2D(_ColorMap, input.texCoord0).rgb * _Color.rgb; |
|||
float alpha = UNITY_SAMPLE_TEX2D(_ColorMap, input.texCoord0).a * _Color.a; |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(alpha - _AlphaCutoff); |
|||
#endif |
|||
|
|||
// Builtin Data |
|||
builtinData.opacity = alpha; |
|||
|
|||
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
#ifdef _EMISSIVE_COLOR_MAP |
|||
builtinData.emissiveColor = UNITY_SAMPLE_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; |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: d0259a31ef8b78e47b18e07b4ed40762 |
|||
timeCreated: 1477005871 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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, 1)] _DoubleSidedMode("Double sided mode", Float) = 0 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Variant |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Define |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#define UNITY_MATERIAL_UNLIT // Need to be define before including Material.hlsl |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "common.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Debug/DebugViewMaterial.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
float4 _Color; |
|||
UNITY_DECLARE_TEX2D(_ColorMap); |
|||
float3 _EmissiveColor; |
|||
UNITY_DECLARE_TEX2D(_EmissiveColorMap); |
|||
float _EmissiveIntensity; |
|||
|
|||
float _AlphaCutoff; |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Debug pass |
|||
Pass |
|||
{ |
|||
Name "Debug" |
|||
Tags { "LightMode" = "DebugViewMaterial" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL |
|||
#include "../../Material/Material.hlsl" |
|||
#include "UnlitData.hlsl" |
|||
#include "UnlitShare.hlsl" |
|||
|
|||
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_VARYING_DEPTH: |
|||
// TODO: provide a customize parameter (like a slider) |
|||
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1); |
|||
result = linearDepth.xxx; |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD0: |
|||
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
Pass |
|||
{ |
|||
Name "ForwardUnlit" |
|||
Tags { "LightMode" = "ForwardUnlit" } |
|||
|
|||
Blend [_SrcBlend] [_DstBlend] |
|||
ZWrite [_ZWrite] |
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD_UNLIT |
|||
#include "../../Material/Material.hlsl" |
|||
#include "UnlitData.hlsl" |
|||
#include "UnlitShare.hlsl" |
|||
|
|||
#include "../../ShaderPass/ShaderPassForwardUnlit.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
CustomEditor "UnlitGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c4edd00ff2db5b24391a4fcb1762e459 |
|||
timeCreated: 1477005432 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// No guard header! |
|||
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Attribute/Varying |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float2 uv0 : TEXCOORD0; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionHS; |
|||
float2 texCoord0; |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionHS : SV_Position; |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
}; |
|||
|
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionHS = input.positionHS; |
|||
output.interpolators[0] = float4(input.texCoord0.xy, 0.0, 0.0); |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInput UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInput output; |
|||
ZERO_INITIALIZE(FragInput, output); |
|||
|
|||
output.positionHS = input.positionHS; |
|||
output.texCoord0.xy = input.interpolators[0].xy; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Vertex shader |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
PackedVaryings VertDefault(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionHS = TransformWorldToHClip(positionWS); |
|||
|
|||
output.texCoord0 = input.uv0; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dde56582e54a7624f9768780b89f9c46 |
|||
timeCreated: 1477005849 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using System; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// structure definition
|
|||
//-----------------------------------------------------------------------------
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
[GenerateHLSL(PackingRules.Exact)] |
|||
public enum ShaderPass |
|||
{ |
|||
GBuffer, |
|||
Forward, |
|||
ForwardUnlit, |
|||
DepthOnly, |
|||
Velocity, |
|||
Distortion, |
|||
LightTransport, |
|||
DebugViewMaterial |
|||
} |
|||
} |
|
|||
// |
|||
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPass.cs. Please don't edit by hand. |
|||
// |
|||
|
|||
// |
|||
// UnityEngine.Experimental.ScriptableRenderLoop.ShaderPass: static fields |
|||
// |
|||
#define SHADERPASS_GBUFFER (0) |
|||
#define SHADERPASS_FORWARD (1) |
|||
#define SHADERPASS_FORWARD_UNLIT (2) |
|||
#define SHADERPASS_DEPTH_ONLY (3) |
|||
#define SHADERPASS_VELOCITY (4) |
|||
#define SHADERPASS_DISTORTION (5) |
|||
#define SHADERPASS_LIGHT_TRANSPORT (6) |
|||
#define SHADERPASS_DEBUG_VIEW_MATERIAL (7) |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 2c2d7b256f4650943b60cc4ef1c7aeaa |
|||
timeCreated: 1476916342 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 974f8c2dd0fe55a4d9f840490fcfa252 |
|||
timeCreated: 1476916273 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if SHADERPASS != SHADERPASS_DEPTH_ONLY |
|||
#error SHADERPASS_is_not_correctly_define |
|||
#endif |
|||
|
|||
float4 Frag(PackedVaryings packedInput) : SV_Target |
|||
{ |
|||
FragInput 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); |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: d2b018587e99fd248bcbab551f0151a1 |
|||
timeCreated: 1476981737 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if SHADERPASS != SHADERPASS_LIGHT_TRANSPORT |
|||
#error SHADERPASS_is_not_correctly_define |
|||
#endif |
|||
|
|||
#include "Color.hlsl" |
|||
|
|||
// 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 |
|||
#define EMISSIVE_RGBM_SCALE 97.0 |
|||
|
|||
float4 Frag(PackedVaryings packedInput) : SV_Target |
|||
{ |
|||
FragInput input = UnpackVaryings(packedInput); |
|||
|
|||
SurfaceData surfaceData; |
|||
BuiltinData builtinData; |
|||
GetSurfaceAndBuiltinData(input, surfaceData, builtinData); |
|||
|
|||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData); |
|||
LighTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); |
|||
|
|||
// This shader is call two time. Once for getting emissiveColor, the other time to get diffuseColor |
|||
// We use unity_MetaFragmentControl to make the distinction. |
|||
|
|||
float4 res = float4(0.0, 0.0, 0.0, 1.0); |
|||
|
|||
// TODO: No if / else in original code from Unity, why ? keep like original code but should be either diffuse or emissive |
|||
if (unity_MetaFragmentControl.x) |
|||
{ |
|||
// Apply diffuseColor Boost from LightmapSettings. |
|||
// put abs here to silent a warning, no cost, no impact as color is assume to be positive. |
|||
res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); |
|||
} |
|||
|
|||
if (unity_MetaFragmentControl.y) |
|||
{ |
|||
// TODO: THIS LIMIT MUST BE REMOVE, IT IS NOT HDR, change when RGB9e5 is here. |
|||
// Do we assume here that emission is [0..1] ? |
|||
res = PackRGBM(lightTransportData.emissiveColor, EMISSIVE_RGBM_SCALE); |
|||
} |
|||
|
|||
return res; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5fd11cedfe7e32f428a5b3ee47a077f7 |
|||
timeCreated: 1476909403 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f32b62aaa1f885a4d9aceab2b86206cb |
|||
timeCreated: 1475846632 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Unity/Lit" |
|||
{ |
|||
Properties |
|||
{ |
|||
// Following set of parameters represent the parameters node inside the MaterialGraph. |
|||
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist. |
|||
|
|||
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear |
|||
_BaseColor("BaseColor", Color) = (1,1,1,1) |
|||
_BaseColorMap("BaseColorMap", 2D) = "white" {} |
|||
|
|||
_Metalic("_Metalic", Range(0.0, 1.0)) = 0 |
|||
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5 |
|||
_MaskMap("MaskMap", 2D) = "white" {} |
|||
|
|||
_SpecularOcclusionMap("SpecularOcclusion", 2D) = "white" {} |
|||
|
|||
_NormalMap("NormalMap", 2D) = "bump" {} |
|||
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0 |
|||
|
|||
_HeightMap("HeightMap", 2D) = "black" {} |
|||
_HeightScale("Height Scale", Float) = 1 |
|||
_HeightBias("Height Bias", Float) = 0 |
|||
[Enum(Parallax, 0, Displacement, 1)] _HeightMapMode("Heightmap usage", Float) = 0 |
|||
|
|||
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0 |
|||
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {} |
|||
//_Thickness("Thickness", Range(0.0, 1.0)) = 0 |
|||
//_ThicknessMap("ThicknessMap", 2D) = "white" {} |
|||
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0 |
|||
|
|||
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0 |
|||
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {} |
|||
|
|||
//_CoatRoughness("CoatRoughness", Range(0.0, 1.0)) = 0 |
|||
//_CoatRoughnessMap("CoatRoughnessMap", 2D) = "white" {} |
|||
|
|||
// _DistortionVectorMap("DistortionVectorMap", 2D) = "white" {} |
|||
// _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. |
|||
|
|||
_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 |
|||
|
|||
[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 |
|||
// Material Id |
|||
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0 |
|||
|
|||
[Enum(Mask Alpha, 0, BaseColor Alpha, 1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 1 |
|||
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1 |
|||
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _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 _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR |
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _NORMALMAP_TANGENT_SPACE |
|||
#pragma shader_feature _MASKMAP |
|||
#pragma shader_feature _SPECULAROCCLUSIONMAP |
|||
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
#pragma shader_feature _EMISSIVE_COLOR |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
#pragma shader_feature _HEIGHTMAP |
|||
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT |
|||
|
|||
#include "LitCommon.hlsl" |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Deferred pass |
|||
Pass |
|||
{ |
|||
Name "GBuffer" // Name is not used |
|||
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index |
|||
|
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#include "../../ShaderPass/ShaderPassGBuffer.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Debug pass |
|||
Pass |
|||
{ |
|||
Name "Debug" |
|||
Tags { "LightMode" = "DebugViewMaterial" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
Pass |
|||
{ |
|||
Name "Forward" // Name is not used |
|||
Tags { "LightMode" = "Forward" } // 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 Frag |
|||
|
|||
#include "../../ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
CustomEditor "LitGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ef966ed93e262964781047eaf96991db |
|||
timeCreated: 1476885564 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8378596fcd29cf2459998acc0b0b5b8a |
|||
timeCreated: 1476885564 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// GENERATED BY SHADER GRAPH |
|||
// Question for shader graph: how to handle dynamic parameter data like matData0 that can change name |
|||
|
|||
// No guard header! |
|||
|
|||
#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" |
|||
|
|||
// This files is generated by the ShaderGraph or written by hand |
|||
|
|||
// Note for ShaderGraph: |
|||
// ShaderGraph should generate the vertex shader output to add the variable that may be required |
|||
// For example if we require view vector in shader graph, the output must contain positionWS and we calcualte the view vector with it. |
|||
// Still some input are mandatory depends on the type of loop. positionWS is mandatory in this current framework. So the ShaderGraph should always generate it. |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// Set of users variables |
|||
float4 _BaseColor; |
|||
UNITY_DECLARE_TEX2D(_BaseColorMap); |
|||
|
|||
float _Metalic; |
|||
float _Smoothness; |
|||
UNITY_DECLARE_TEX2D(_MaskMap); |
|||
UNITY_DECLARE_TEX2D(_SpecularOcclusionMap); |
|||
|
|||
UNITY_DECLARE_TEX2D(_NormalMap); |
|||
UNITY_DECLARE_TEX2D(_Heightmap); |
|||
float _HeightScale; |
|||
float _HeightBias; |
|||
|
|||
UNITY_DECLARE_TEX2D(_DiffuseLightingMap); |
|||
float4 _EmissiveColor; |
|||
UNITY_DECLARE_TEX2D(_EmissiveColorMap); |
|||
float _EmissiveIntensity; |
|||
|
|||
float _SubSurfaceRadius; |
|||
UNITY_DECLARE_TEX2D(_SubSurfaceRadiusMap); |
|||
// float _Thickness; |
|||
// UNITY_DECLARE_TEX2D(_ThicknessMap); |
|||
|
|||
// float _CoatCoverage; |
|||
// UNITY_DECLARE_TEX2D(_CoatCoverageMap); |
|||
|
|||
// float _CoatRoughness; |
|||
// UNITY_DECLARE_TEX2D(_CoatRoughnessMap); |
|||
|
|||
float _AlphaCutoff; |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Lighting architecture |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// TODO: Check if we will have different Varyings based on different pass, not sure about that... |
|||
|
|||
// Forward |
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float3 normalOS : NORMAL; |
|||
float2 uv0 : TEXCOORD0; |
|||
float4 tangentOS : TANGENT; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionHS; |
|||
float3 positionWS; |
|||
float2 texCoord0; |
|||
float4 tangentToWorld[3]; // [3x3:tangentToWorld | 1x3:viewDirForParallax] |
|||
|
|||
#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; |
|||
float4 interpolators[5] : TEXCOORD0; |
|||
|
|||
#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[0].w = input.texCoord0.x; |
|||
output.interpolators[1] = input.tangentToWorld[0]; |
|||
output.interpolators[2] = input.tangentToWorld[1]; |
|||
output.interpolators[3] = input.tangentToWorld[2]; |
|||
output.interpolators[4].x = input.texCoord0.y; |
|||
output.interpolators[4].yzw = float3(0.0, 0.0, 0.0); |
|||
|
|||
return output; |
|||
} |
|||
|
|||
Varyings UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
Varyings output; |
|||
output.positionHS = input.positionHS; |
|||
output.positionWS.xyz = input.interpolators[0].xyz; |
|||
output.texCoord0.x = input.interpolators[0].w; |
|||
output.texCoord0.y = input.interpolators[4].x; |
|||
output.tangentToWorld[0] = input.interpolators[1]; |
|||
output.tangentToWorld[1] = input.interpolators[2]; |
|||
output.tangentToWorld[2] = input.interpolators[3]; |
|||
|
|||
#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; |
|||
|
|||
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w); |
|||
|
|||
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w); |
|||
output.tangentToWorld[0].xyz = tangentToWorld[0]; |
|||
output.tangentToWorld[1].xyz = tangentToWorld[1]; |
|||
output.tangentToWorld[2].xyz = tangentToWorld[2]; |
|||
|
|||
output.tangentToWorld[0].w = 0; |
|||
output.tangentToWorld[1].w = 0; |
|||
output.tangentToWorld[2].w = 0; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|||
|
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Lighting data function |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
float3 TransformTangentToWorld(float3 normalTS, float4 tangentToWorld[3]) |
|||
{ |
|||
// TODO check: do we need to normalize ? |
|||
return normalize(mul(normalTS, float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz))); |
|||
} |
|||
|
|||
#if SHADER_STAGE_FRAGMENT |
|||
|
|||
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out 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 |
|||
|
|||
#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!) |
|||
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; |
|||
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; |
|||
} |
|||
|
|||
void GetVaryingsDataDebug(uint paramId, Varyings input, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_VARYING_DEPTH: |
|||
// TODO: provide a customize parameter (like a slider) |
|||
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1); |
|||
result = linearDepth.xxx; |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD0: |
|||
// TODO: require a remap |
|||
result = float3(input.texCoord0, 0.0); |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXNORMALWS: |
|||
result = input.tangentToWorld[2].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXTANGENTWS: |
|||
result = input.tangentToWorld[0].xyz * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_VARYING_VERTEXBITANGENTWS: |
|||
result = input.tangentToWorld[1].xyz * 0.5 + 0.5; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
#endif // #if SHADER_STAGE_FRAGMENT |
|
|||
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, 1)] _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 "UnlitCommon.hlsl" |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Debug pass |
|||
Pass |
|||
{ |
|||
Name "Debug" |
|||
Tags { "LightMode" = "DebugViewMaterial" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
Pass |
|||
{ |
|||
Name "ForwardUnlit" |
|||
Tags { "LightMode" = "ForwardUnlit" } |
|||
|
|||
Blend [_SrcBlend] [_DstBlend] |
|||
ZWrite [_ZWrite] |
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma vertex VertDefault |
|||
#pragma fragment Frag |
|||
|
|||
#include "../../ShaderPass/ShaderPassForwardUnlit.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
|
|||
CustomEditor "UnlitGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ce56194c2cab0bd4fbab7a7aba4f160d |
|||
timeCreated: 1476887321 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#define UNITY_MATERIAL_UNLIT // Need to be define before including Material.hlsl |
|||
// no need to include lighting |
|||
#include "../Material.hlsl" |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Debug/DebugViewMaterial.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
float4 _Color; |
|||
UNITY_DECLARE_TEX2D(_ColorMap); |
|||
float3 _EmissiveColor; |
|||
UNITY_DECLARE_TEX2D(_EmissiveColorMap); |
|||
float _EmissiveIntensity; |
|||
|
|||
float _AlphaCutoff; |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Lighting architecture |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// TODO: Check if we will have different Varyings based on different pass, not sure about that... |
|||
|
|||
// Forward |
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float2 uv0 : TEXCOORD0; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionHS; |
|||
float2 texCoord0; |
|||
|
|||
#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; |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC; |
|||
#endif |
|||
#endif |
|||
}; |
|||
|
|||
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; |
|||
|
|||
#ifdef SHADER_STAGE_FRAGMENT |
|||
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR) |
|||
output.cullFace = input.cullFace; |
|||
#endif |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings VertDefault(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionHS = TransformWorldToHClip(positionWS); |
|||
|
|||
output.texCoord0 = input.uv0; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Lighting data function |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#if SHADER_STAGE_FRAGMENT |
|||
|
|||
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
surfaceData.color = UNITY_SAMPLE_TEX2D(_ColorMap, input.texCoord0).rgb * _Color.rgb; |
|||
float alpha = UNITY_SAMPLE_TEX2D(_ColorMap, input.texCoord0).a * _Color.a; |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(alpha - _AlphaCutoff); |
|||
#endif |
|||
|
|||
// Builtin Data |
|||
builtinData.opacity = alpha; |
|||
|
|||
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
#ifdef _EMISSIVE_COLOR_MAP |
|||
builtinData.emissiveColor = UNITY_SAMPLE_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; |
|||
} |
|||
|
|||
void GetVaryingsDataDebug(uint paramId, Varyings input, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_VARYING_DEPTH: |
|||
// TODO: provide a customize parameter (like a slider) |
|||
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1); |
|||
result = linearDepth.xxx; |
|||
break; |
|||
case DEBUGVIEW_VARYING_TEXCOORD0: |
|||
// TODO: require a remap |
|||
result = float3(input.texCoord0, 0.0); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
#endif // #if SHADER_STAGE_FRAGMENT |
|
|||
fileFormatVersion: 2 |
|||
guid: aef2222e32b780144af8d7e9fd2176a2 |
|||
timeCreated: 1476887321 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue