浏览代码
HDRenderloop: Update Parameters of lit material and update GBuffer layout + add aniso function
/main
HDRenderloop: Update Parameters of lit material and update GBuffer layout + add aniso function
/main
sebastienlagarde
8 年前
当前提交
6d8ef108
共有 21 个文件被更改,包括 862 次插入 和 403 次删除
-
6Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader
-
221Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl
-
56Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
-
25Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
-
3Assets/TestScenes/HDTest/HDRenderLoopTest.unity
-
5Assets/TestScenes/HDTest/Leaf/GroundLeaf/Materials/GroundLeaf_Albedo.mat
-
14Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Blue_Alpha.mat
-
14Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Gray.mat
-
14Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Green.mat
-
14Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Red.mat
-
14Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Terrain.mat
-
13Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-alpha.mat
-
10Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-transparent.mat
-
9Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-twosidedLighting.mat
-
8Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test.mat
-
284Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl.meta
-
239Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/CubeTransparent.mat
-
8Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/CubeTransparent.mat.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl.meta
-
290Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl
|
|||
// 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" |
|||
|
|||
// 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; |
|||
sampler2D _BaseColorMap; |
|||
|
|||
float _Metalic; |
|||
float _Smoothness; |
|||
sampler2D _MaskMap; |
|||
sampler2D _SpecularOcclusionMap; |
|||
|
|||
sampler2D _NormalMap; |
|||
sampler2D _Heightmap; |
|||
float _HeightScale; |
|||
float _HeightBias; |
|||
|
|||
sampler2D _DiffuseLightingMap; |
|||
float4 _EmissiveColor; |
|||
sampler2D _EmissiveColorMap; |
|||
float _EmissiveIntensity; |
|||
|
|||
float _SubSurfaceRadius; |
|||
sampler2D _SubSurfaceRadiusMap; |
|||
// float _Thickness; |
|||
// sampler2D _ThicknessMap; |
|||
|
|||
// float _CoatCoverage; |
|||
// sampler2D _CoatCoverageMap; |
|||
|
|||
// float _CoatRoughness; |
|||
// sampler2D _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 = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb; |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
float alpha = _BaseColor.a; |
|||
#else |
|||
float alpha = tex2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a; |
|||
#endif |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(alpha - _AlphaCutoff); |
|||
#endif |
|||
|
|||
builtinData.opacity = alpha; |
|||
|
|||
#ifdef _SPECULAROCCLUSIONMAP |
|||
// TODO: Do something. For now just take alpha channel |
|||
surfaceData.specularOcclusion = 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 = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0)); |
|||
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld); |
|||
#else // Object space (TODO: We need to apply the world rotation here!) |
|||
surfaceData.normalWS = 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 = tex2D(_BaseColorMap, input.texCoord0).a; |
|||
#elif defined(_MASKMAP) |
|||
surfaceData.perceptualSmoothness = 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 = tex2D(_MaskMap, input.texCoord0).r; |
|||
surfaceData.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g; |
|||
#else |
|||
surfaceData.metalic = 1.0; |
|||
surfaceData.ambientOcclusion = 1.0; |
|||
#endif |
|||
surfaceData.metalic *= _Metalic; |
|||
|
|||
|
|||
surfaceData.tangentWS = float3(1.0, 0.0, 0.0); |
|||
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 |
|||
|
|||
// 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 = 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 = 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 * 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 |
|
|||
fileFormatVersion: 2 |
|||
guid: dda3abfe43d26f84c9255796cfad662a |
|||
timeCreated: 1475859326 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: CubeTransparent |
|||
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3} |
|||
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF |
|||
_EMISSION _NORMALMAP_TANGENT_SPACE |
|||
m_LightmapFlags: 1 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
m_SavedProperties: |
|||
serializedVersion: 2 |
|||
m_TexEnvs: |
|||
- first: |
|||
name: _BaseColorMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _BumpMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _DetailAlbedoMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _DetailMask |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _DetailNormalMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _DiffuseLightingMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _EmissionMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _EmissiveColorMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _HeightMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _MainTex |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _MaskMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _MetallicGlossMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _NormalMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _OcclusionMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _ParallaxMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _SpecularOcclusionMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- first: |
|||
name: _SubSurfaceRadiusMap |
|||
second: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- first: |
|||
name: _AlphaCutoff |
|||
second: 0.5 |
|||
- first: |
|||
name: _AlphaCutoffEnable |
|||
second: 0 |
|||
- first: |
|||
name: _BlendMode |
|||
second: 0 |
|||
- first: |
|||
name: _BumpScale |
|||
second: 1 |
|||
- first: |
|||
name: _CullMode |
|||
second: 0 |
|||
- first: |
|||
name: _Cutoff |
|||
second: 0.5 |
|||
- first: |
|||
name: _DetailNormalMapScale |
|||
second: 1 |
|||
- first: |
|||
name: _DistortionDepthTest |
|||
second: 0 |
|||
- first: |
|||
name: _DistortionOnly |
|||
second: 0 |
|||
- first: |
|||
name: _DoubleSidedMode |
|||
second: 0 |
|||
- first: |
|||
name: _DstBlend |
|||
second: 10 |
|||
- first: |
|||
name: _EmissiveColorMode |
|||
second: 1 |
|||
- first: |
|||
name: _EmissiveIntensity |
|||
second: 0 |
|||
- first: |
|||
name: _GlossMapScale |
|||
second: 1 |
|||
- first: |
|||
name: _Glossiness |
|||
second: 0.5 |
|||
- first: |
|||
name: _GlossyReflections |
|||
second: 1 |
|||
- first: |
|||
name: _HeightBias |
|||
second: 0 |
|||
- first: |
|||
name: _HeightMapMode |
|||
second: 0 |
|||
- first: |
|||
name: _HeightScale |
|||
second: 1 |
|||
- first: |
|||
name: _MaterialId |
|||
second: 0 |
|||
- first: |
|||
name: _Metalic |
|||
second: 0 |
|||
- first: |
|||
name: _Metallic |
|||
second: 0 |
|||
- first: |
|||
name: _Mettalic |
|||
second: 0 |
|||
- first: |
|||
name: _Mode |
|||
second: 0 |
|||
- first: |
|||
name: _NormalMapSpace |
|||
second: 0 |
|||
- first: |
|||
name: _OcclusionStrength |
|||
second: 1 |
|||
- first: |
|||
name: _Parallax |
|||
second: 0.02 |
|||
- first: |
|||
name: _Smoothness |
|||
second: 0.5 |
|||
- first: |
|||
name: _SmoothnessTextureChannel |
|||
second: 0 |
|||
- first: |
|||
name: _SpecularHighlights |
|||
second: 1 |
|||
- first: |
|||
name: _SrcBlend |
|||
second: 5 |
|||
- first: |
|||
name: _SubSurfaceRadius |
|||
second: 0 |
|||
- first: |
|||
name: _SurfaceType |
|||
second: 1 |
|||
- first: |
|||
name: _UVSec |
|||
second: 0 |
|||
- first: |
|||
name: _ZWrite |
|||
second: 0 |
|||
m_Colors: |
|||
- first: |
|||
name: _BaseColor |
|||
second: {r: 0.9117647, g: 0.1273789, b: 0.1273789, a: 0.566} |
|||
- first: |
|||
name: _Color |
|||
second: {r: 1, g: 1, b: 1, a: 1} |
|||
- first: |
|||
name: _EmissionColor |
|||
second: {r: 0, g: 0, b: 0, a: 1} |
|||
- first: |
|||
name: _EmissiveColor |
|||
second: {r: 0, g: 0, b: 0, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: 53db393fa1a97b244b8f7e9d8f0bbdba |
|||
timeCreated: 1475760437 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f69e98902bfd77a48ab69e05b54c09a5 |
|||
timeCreated: 1475845771 |
|||
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" |
|||
|
|||
// 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; |
|||
sampler2D _BaseColorMap; |
|||
|
|||
float _Metalic; |
|||
float _Smoothness; |
|||
sampler2D _MaskMap; |
|||
sampler2D _SpecularOcclusionMap; |
|||
|
|||
sampler2D _NormalMap; |
|||
sampler2D _Heightmap; |
|||
float _HeightScale; |
|||
float _HeightBias; |
|||
|
|||
sampler2D _DiffuseLightingMap; |
|||
float4 _EmissiveColor; |
|||
sampler2D _EmissiveColorMap; |
|||
float _EmissiveIntensity; |
|||
|
|||
float _SubSurfaceRadius; |
|||
sampler2D _SubSurfaceRadiusMap; |
|||
// float _Thickness; |
|||
// sampler2D _ThicknessMap; |
|||
|
|||
// float _CoatCoverage; |
|||
// sampler2D _CoatCoverageMap; |
|||
|
|||
// float _CoatRoughness; |
|||
// sampler2D _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) |
|||
{ |
|||
float3 baseColor = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb; |
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
float alpha = _BaseColor.a; |
|||
#else |
|||
float alpha = tex2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a; |
|||
#endif |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
clip(alpha - _AlphaCutoff); |
|||
#endif |
|||
|
|||
builtinData.opacity = alpha; |
|||
|
|||
// MaskMap is Metalic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha) |
|||
#ifdef _MASKMAP |
|||
float metalic = tex2D(_MaskMap, input.texCoord0).r; |
|||
surfaceData.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g; |
|||
#else |
|||
float metalic = 1.0; |
|||
surfaceData.ambientOcclusion = 1.0; |
|||
#endif |
|||
metalic *= _Metalic; |
|||
|
|||
surfaceData.diffuseColor = baseColor * (1.0 - metalic); |
|||
float f0_dieletric = 0.04; |
|||
surfaceData.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, metalic); |
|||
|
|||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|||
surfaceData.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a; |
|||
#elif defined(_MASKMAP) |
|||
surfaceData.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a; |
|||
#else |
|||
surfaceData.perceptualSmoothness = 1.0; |
|||
#endif |
|||
surfaceData.perceptualSmoothness *= _Smoothness; |
|||
|
|||
#ifdef _SPECULAROCCLUSIONMAP |
|||
// TODO: Do something. For now just take alpha channel |
|||
surfaceData.specularOcclusion = 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 = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0)); |
|||
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld); |
|||
#else // Object space (TODO: We need to apply the world rotation here!) |
|||
surfaceData.normalWS = 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 |
|||
|
|||
surfaceData.materialId = 0; |
|||
|
|||
surfaceData.subSurfaceRadius = 1.0; // tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius; |
|||
|
|||
// TODO |
|||
/* |
|||
float _SubSurfaceRadius; |
|||
sampler2D _SubSurfaceRadiusMap; |
|||
float _Thickness; |
|||
sampler2D _ThicknessMap; |
|||
|
|||
float _CoatCoverage; |
|||
sampler2D _CoatCoverageMap; |
|||
|
|||
float _CoatRoughness; |
|||
sampler2D _CoatRoughnessMap; |
|||
*/ |
|||
|
|||
// Builtin Data |
|||
|
|||
// 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 = 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 = 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 = baseColor * 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 |
撰写
预览
正在加载...
取消
保存
Reference in new issue