sebastienlagarde
8 年前
当前提交
3b0e1c97
共有 40 个文件被更改,包括 1050 次插入 和 943 次删除
-
10Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
-
3Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
-
14Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
-
10Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
-
35Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
-
35Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
-
57Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitMetaPass.hlsl
-
46Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
-
133Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
-
111Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDebugViewMaterial.hlsl
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
-
49Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl
-
112Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl
-
13Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl.meta
-
59Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl.meta
-
363Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
-
174Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl.meta
-
13Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitMetaPass.hlsl
-
10Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl
-
83Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl.meta
-
392Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitAttributesVarying.hlsl
-
61Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitSharePass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl.meta
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl
|
|||
fileFormatVersion: 2 |
|||
guid: 1e29a17691259ac4e9de48d4cfd72d06 |
|||
timeCreated: 1484313687 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
struct TessellationFactors |
|||
{ |
|||
float edge[3] : SV_TessFactor; |
|||
float inside : SV_InsideTessFactor; |
|||
}; |
|||
|
|||
TessellationFactors HullConstant(InputPatch<PackedVaryingsToDS, 3> input) |
|||
{ |
|||
VaryingsToDS varying0 = UnpackVaryingsToDS(input[0]); |
|||
VaryingsToDS varying1 = UnpackVaryingsToDS(input[1]); |
|||
VaryingsToDS varying2 = UnpackVaryingsToDS(input[2]); |
|||
|
|||
float4 tf = TessellationEdge( varying0.vmesh.positionWS, varying1.vmesh.positionWS, varying2.vmesh.positionWS, |
|||
varying0.vmesh.normalWS, varying1.vmesh.normalWS, varying2.vmesh.normalWS); |
|||
|
|||
TessellationFactors ouput; |
|||
ouput.edge[0] = tf.x; |
|||
ouput.edge[1] = tf.y; |
|||
ouput.edge[2] = tf.z; |
|||
ouput.inside = tf.w; |
|||
|
|||
return ouput; |
|||
} |
|||
|
|||
[maxtessfactor(15.0)] // AMD recommand this value for GCN http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/05/GCNPerformanceTweets.pdf |
|||
[domain("tri")] |
|||
[partitioning("fractional_odd")] |
|||
[outputtopology("triangle_cw")] |
|||
[patchconstantfunc("HullConstant")] |
|||
[outputcontrolpoints(3)] |
|||
PackedVaryingsToDS Hull(InputPatch<PackedVaryingsToDS, 3> input, uint id : SV_OutputControlPointID) |
|||
{ |
|||
// Pass-through |
|||
return input[id]; |
|||
} |
|||
|
|||
[domain("tri")] |
|||
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<PackedVaryingsToDS, 3> input, float3 baryCoords : SV_DomainLocation) |
|||
{ |
|||
VaryingsToDS varying0 = UnpackVaryingsToDS(input[0]); |
|||
VaryingsToDS varying1 = UnpackVaryingsToDS(input[1]); |
|||
VaryingsToDS varying2 = UnpackVaryingsToDS(input[2]); |
|||
|
|||
VaryingsToDS varying = InterpolateWithBaryCoords(varying0, varying1, varying2, baryCoords); |
|||
|
|||
// We have Phong tessellation in all case where we don't have displacement only |
|||
#ifndef _TESSELLATION_DISPLACEMENT |
|||
varying.vmesh.positionWS = PhongTessellation( varying.positionWS, |
|||
varying0.vmesh.positionWS, varying1.vmesh.positionWS, varying2.vmesh.positionWS, |
|||
varying0.vmesh.normalWS, varying1.vmesh.normalWS, varying2.vmesh.normalWS, |
|||
baryCoords, _TessellationShapeFactor); |
|||
#endif |
|||
|
|||
#if defined(_TESSELLATION_DISPLACEMENT) || defined(_TESSELLATION_DISPLACEMENT_PHONG) |
|||
varying.vmesh.positionWS = GetDisplacement(varying.vmesh); |
|||
#endif |
|||
|
|||
return VertTesselation(varying); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7a951f9236225024eb694af870ee4efe |
|||
timeCreated: 1484313687 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
struct AttributesMesh |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
#ifdef ATTRIBUTES_NEED_NORMAL |
|||
float3 normalOS : NORMAL; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TANGENT |
|||
float4 tangentOS : TANGENT; // Store sign in w |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD0 |
|||
float2 uv0 : TEXCOORD0; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD1 |
|||
float2 uv1 : TEXCOORD1; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD2 |
|||
float2 uv2 : TEXCOORD2; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD3 |
|||
float2 uv3 : TEXCOORD3; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_COLOR |
|||
float4 color : COLOR; |
|||
#endif |
|||
|
|||
// UNITY_INSTANCE_ID |
|||
}; |
|||
|
|||
struct VaryingsMeshToPS |
|||
{ |
|||
float4 positionCS; |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
float3 positionWS; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
float3 tangentToWorld[3]; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD0 |
|||
float2 texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
float2 texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD2 |
|||
float2 texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
float2 texCoord3; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_COLOR |
|||
float4 color; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsMeshToPS |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
|
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
// if present, pack positionWS |
|||
float4 interpolators1 : TEXCOORD1; |
|||
float4 interpolators2 : TEXCOORD2; |
|||
float4 interpolators3 : TEXCOORD3; |
|||
#else |
|||
float3 interpolators1 : TEXCOORD1; |
|||
float3 interpolators2 : TEXCOORD2; |
|||
float3 interpolators3 : TEXCOORD3; |
|||
#endif |
|||
#else |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
float3 interpolators0 : TEXCOORD0; |
|||
#endif |
|||
#endif |
|||
|
|||
// Allocate only necessary space if shader compiler in the future are able to automatically pack |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
float4 interpolators4 : TEXCOORD4; |
|||
#elif defined(VARYINGS_NEED_TEXCOORD0) |
|||
float2 interpolators4 : TEXCOORD4; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
float4 interpolators5 : TEXCOORD5; |
|||
#elif defined(VARYINGS_NEED_TEXCOORD2) |
|||
float2 interpolators5 : TEXCOORD5; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_COLOR |
|||
float4 interpolators6 : TEXCOORD6; |
|||
#endif |
|||
|
|||
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT |
|||
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC; |
|||
#endif |
|||
}; |
|||
|
|||
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryingsMeshToPS PackVaryingsMeshToPS(VaryingsMeshToPS input) |
|||
{ |
|||
PackedVaryingsMeshToPS output; |
|||
|
|||
output.positionCS = input.positionCS; |
|||
|
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
output.interpolators1.xyz = input.tangentToWorld[0]; |
|||
output.interpolators2.xyz = input.tangentToWorld[1]; |
|||
output.interpolators3.xyz = input.tangentToWorld[2]; |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.interpolators1.w = input.positionWS.x; |
|||
output.interpolators2.w = input.positionWS.y; |
|||
output.interpolators3.w = input.positionWS.z; |
|||
#else |
|||
output.interpolators1.w = 0.0; |
|||
output.interpolators2.w = 0.0; |
|||
output.interpolators3.w = 0.0; |
|||
#endif |
|||
#else |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.interpolators0.xyz = input.positionWS; |
|||
output.interpolators0.w = 0.0; |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_TEXCOORD0 |
|||
output.interpolators4.xy = input.texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
output.interpolators4.zw = input.texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD2 |
|||
output.interpolators5.xy = input.texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
output.interpolators5.zw = input.texCoord3; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_COLOR |
|||
output.interpolators6 = input.color; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInputs UnpackVaryingsMeshToPS(PackedVaryingsMeshToPS input) |
|||
{ |
|||
FragInputs output; |
|||
ZERO_INITIALIZE(FragInputs, output); |
|||
|
|||
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position |
|||
|
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
output.tangentToWorld[0] = input.interpolators1.xyz; |
|||
output.tangentToWorld[1] = input.interpolators2.xyz; |
|||
output.tangentToWorld[2] = input.interpolators3.xyz; |
|||
#ifdef WANT_PER_PIXEL_WORLDPOS |
|||
output.positionWS.xyz = float3(input.interpolators1.w, input.interpolators2.w, input.interpolators3.w); |
|||
#endif |
|||
#else |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.positionWS.xyz = input.interpolators0.xyz; |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_TEXCOORD0 |
|||
output.texCoord0 = input.interpolators4.xy; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
output.texCoord1 = input.interpolators4.zw; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD2 |
|||
output.texCoord2 = input.interpolators5.xy; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
output.texCoord3 = input.interpolators5.zw; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_COLOR |
|||
output.color = input.interpolators6; |
|||
#endif |
|||
|
|||
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT |
|||
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
|
|||
// Varying DS - use for domain shader |
|||
// We can deduce these defines from the other defines |
|||
// We need to pass to DS any varying required by pixel shader |
|||
// If we have required an attributes that is not present in varyings it mean we will be for DS |
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
#define VARYINGS_DS_NEED_NORMAL |
|||
#define VARYINGS_DS_NEED_TANGENT |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD0) || defined(ATTRIBUTES_NEED_TEXCOORD0) |
|||
#define VARYINGS_DS_NEED_TEXCOORD0 |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD1) || defined(ATTRIBUTES_NEED_TEXCOORD1) |
|||
#define VARYINGS_DS_NEED_TEXCOORD1 |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD2) || defined(ATTRIBUTES_NEED_TEXCOORD2) |
|||
#define VARYINGS_DS_NEED_TEXCOORD2 |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD3) || defined(ATTRIBUTES_NEED_TEXCOORD3) |
|||
#define VARYINGS_DS_NEED_TEXCOORD3 |
|||
#endif |
|||
#if defined(VARYINGS_NEED_COLOR) || defined(ATTRIBUTES_NEED_COLOR) |
|||
float4 VARYINGS_DS_NEED_COLOR; |
|||
#endif |
|||
|
|||
// Varying for domain shader |
|||
// Position and normal are always present (for tessellation) and in world space |
|||
struct VaryingsMeshToDS |
|||
{ |
|||
float3 positionWS; |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
float3 normalWS; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
float4 tangentWS; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
float2 texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
float2 texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
float2 texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
float2 texCoord3; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
float4 color; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsMeshToDS |
|||
{ |
|||
float3 interpolators0 : INTERNALTESSPOS; // positionWS |
|||
|
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
float3 interpolators1 : NORMAL; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
float4 interpolators2 : TANGENT; |
|||
#endif |
|||
|
|||
// Allocate only necessary space if shader compiler in the future are able to automatically pack |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
float4 interpolators3 : TEXCOORD0; |
|||
#elif defined(VARYINGS_DS_NEED_TEXCOORD0) |
|||
float2 interpolators3 : TEXCOORD0; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
float4 interpolators4 : TEXCOORD1; |
|||
#elif defined(VARYINGS_DS_NEED_TEXCOORD2) |
|||
float2 interpolators4 : TEXCOORD1; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
float4 interpolators5 : TEXCOORD2; |
|||
#endif |
|||
}; |
|||
|
|||
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryingsMeshToDS PackVaryingsMeshToDS(VaryingsDS input) |
|||
{ |
|||
PackedVaryingsMeshToDS output; |
|||
|
|||
output.interpolators0 = input.positionWS; |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
output.interpolators1 = input.normalWS; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
output.interpolators2 = input.tangentWS; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
output.interpolators3.xy = input.texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
output.interpolators3.zw = input.texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
output.interpolators4.xy = input.texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
output.interpolators4.zw = input.texCoord3; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
output.interpolators5 = input.color; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
VaryingsMeshToDS UnpackVaryingsMeshToDS(PackedVaryingsMeshToDS input) |
|||
{ |
|||
VaryingsDS output; |
|||
|
|||
output.positionWS = input.interpolators0; |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
output.normalWS = input.interpolators1; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
output.tangentWS = input.interpolators2; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
output.texCoord0 = input.interpolators3.xy; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
output.texCoord1 = input.interpolators3.zw; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
output.texCoord2 = input.interpolators4.xy; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
output.texCoord3 = input.interpolators4.zw; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
output.color = input.interpolators5; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
VaryingsMeshToDS InterpolateWithBaryCoordsMeshToDS(VaryingsMeshToDS input0, VaryingsMeshToDS input1, VaryingsMeshToDS input2, float3 baryCoords) |
|||
{ |
|||
VaryingsMeshToDS ouput; |
|||
|
|||
TESSELLATION_INTERPOLATE_BARY(positionWS, baryCoords); |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
TESSELLATION_INTERPOLATE_BARY(normalWS, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
// This will interpolate the sign but should be ok in practice as we may expect a triangle to have same sign (? TO CHECK) |
|||
TESSELLATION_INTERPOLATE_BARY(tangentWS, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord0, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord1, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord2, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord3, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
TESSELLATION_INTERPOLATE_BARY(color, baryCoords); |
|||
#endif |
|||
|
|||
return ouput; |
|||
} |
|||
|
|||
#endif // TESSELLATION_ON |
|
|||
struct VaryingsToPS |
|||
{ |
|||
VaryingsMeshToPS vmesh; |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
VaryingsPassToPS vpass; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsToPS |
|||
{ |
|||
PackedVaryingsMeshToPS vmesh; |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
PackedVaryingsPassToPS vpass; |
|||
#endif |
|||
}; |
|||
|
|||
PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) |
|||
{ |
|||
PackedVaryingsToPS output; |
|||
output.vmesh = PackVaryingsMeshToPS(input.vmesh); |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
output.vpass = PackVaryingsPassToPS(input.vpass); |
|||
#endif |
|||
} |
|||
|
|||
VaryingsToPS UnpackVaryingsToPS(PackedVaryingsToPS input) |
|||
{ |
|||
VaryingsToDS output; |
|||
output.vmesh = UnpackVaryingsMeshToPS(input.vmesh); |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
output.vpass = UnpackVaryingsPassToPS(input.vpass); |
|||
#endif |
|||
} |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
|
|||
struct VaryingsToDS |
|||
{ |
|||
VaryingsMeshToDS vmesh; |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
VaryingsPassToDS vpass; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsToDS |
|||
{ |
|||
PackedVaryingsDS vmesh; |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
PackedVaryingsPassDS vpass; |
|||
#endif |
|||
}; |
|||
|
|||
PackedVaryingsToDS PackVaryingsToDS(VaryingsToDS input) |
|||
{ |
|||
PackedVaryingsToDS output; |
|||
output.vmesh = PackVaryingsMeshToDS(input.vmesh); |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
output.vpass = PackVaryingsPassToDS(input.vpass); |
|||
#endif |
|||
} |
|||
|
|||
VaryingsToDS UnpackVaryingsToDS(PackedVaryingsToDS input) |
|||
{ |
|||
VaryingsToDS output; |
|||
output.vmesh = UnpackVaryingsMeshToDS(input.vmesh); |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
output.vpass = UnpackVaryingsPassToDS(input.vpass); |
|||
#endif |
|||
} |
|||
|
|||
VaryingsToDS InterpolateWithBaryCoordsToDS(VaryingsToDS input0, VaryingsToDS input1, VaryingsToDS input2, float3 baryCoords) |
|||
{ |
|||
VaryingsToDS ouput; |
|||
|
|||
ouput.vmesh = InterpolateWithBaryCoordsMeshToDS(input0.vmesh, input1.vmesh, input2.vmesh, baryCoords); |
|||
#ifdef VARYINGS_DS_NEED_PASS |
|||
ouput.vpass = InterpolateWithBaryCoordsPassToDS(input0.vpass, input1.vpass, input2.vpass, baryCoords); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#endif // TESSELLATION_ON |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
#define VaryingsType VaryingsToDS |
|||
#define PackedVaryingsType PackedVaryingsToDS |
|||
#define PackVaryingsType PackVaryingsToDS |
|||
#else |
|||
#define VaryingsType VaryingsToPS |
|||
#define PackedVaryingsType PackedVaryingsToPS |
|||
#define PackVaryingsType PackVaryingsToPS |
|||
#endif |
|||
|
|||
// 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) |
|||
VaryingsType VertMesh(AttributesMesh input) |
|||
{ |
|||
VaryingsType output; |
|||
|
|||
#if defined(TESSELLATION_ON) |
|||
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) |
|||
#if defined(VARYING_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_NORMAL) |
|||
output.normalWS = TransformObjectToWorldNormal(input.normalOS); |
|||
#endif |
|||
#if defined(VARYING_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_TANGENT) |
|||
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w); |
|||
#endif |
|||
#else |
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix) |
|||
output.positionCS = TransformWorldToHClip(positionWS); |
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
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 |
|||
#endif |
|||
|
|||
#if defined(VARYINGS_NEED_TEXCOORD0) || defined(VARYINGS_DS_NEED_TEXCOORD0) |
|||
output.texCoord0 = input.uv0; |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD1) || defined(VARYINGS_DS_NEED_TEXCOORD1) |
|||
output.texCoord1 = input.uv1; |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD2) || defined(VARYINGS_DS_NEED_TEXCOORD2) |
|||
output.texCoord2 = input.uv2; |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD3) || defined(VARYINGS_DS_NEED_TEXCOORD3) |
|||
output.texCoord3 = input.uv3; |
|||
#endif |
|||
#if defined(VARYINGS_NEED_COLOR) || defined(VARYINGS_DS_NEED_COLOR) |
|||
output.color = input.color; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
|
|||
VaryingMeshToPS VertMeshTesselation(VaryingMeshToDS input) |
|||
{ |
|||
VaryingMeshToPS output; |
|||
|
|||
output.positionCS = TransformWorldToHClip(input.positionWS); |
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
float3x3 tangentToWorld = CreateTangentToWorld(input.normalWS, input.tangentWS.xyz, input.tangentWS.w); |
|||
output.tangentToWorld[0] = tangentToWorld[0]; |
|||
output.tangentToWorld[1] = tangentToWorld[1]; |
|||
output.tangentToWorld[2] = tangentToWorld[2]; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_TEXCOORD0 |
|||
output.texCoord0 = input.uv0; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
output.texCoord1 = input.uv1; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD2 |
|||
output.texCoord2 = input.uv2; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
output.texCoord3 = input.uv3; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_COLOR |
|||
output.color = input.color; |
|||
#endif |
|||
} |
|||
|
|||
#endif // TESSELLATION_ON |
|
|||
fileFormatVersion: 2 |
|||
guid: 5f7d62bf425b54942b9b212cad7efb1a |
|||
timeCreated: 1484313687 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
#define ATTRIBUTES_NEED_TEXCOORD1 |
|||
#define ATTRIBUTES_NEED_TEXCOORD2 |
|||
|
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
#define VARYINGS_NEED_TEXCOORD1 |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
|
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|
|||
|
|||
// 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) |
|||
PackedVaryingsType Vert(Attributes input) |
|||
{ |
|||
VaryingsType output; |
|||
|
|||
#if defined(TESSELLATION_ON) |
|||
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) |
|||
#if defined(VARYING_DS_WANT_TANGENT_TO_WORLD) || defined(VARYING_DS_WANT_NORMAL) |
|||
output.normalWS = TransformObjectToWorldNormal(input.normalOS); |
|||
#endif |
|||
#if defined(VARYING_DS_WANT_TANGENT_TO_WORLD) || defined(VARYING_DS_WANT_TANGENT) |
|||
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w); |
|||
#endif |
|||
#else |
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix) |
|||
output.positionCS = TransformWorldToHClip(positionWS); |
|||
#ifdef VARYING_WANT_TANGENT_TO_WORLD |
|||
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 |
|||
#endif |
|||
|
|||
#if defined(VARYING_WANT_TEXCOORD0) || defined(VARYING_DS_WANT_TEXCOORD0) |
|||
output.texCoord0 = input.uv0; |
|||
#endif |
|||
#if defined(VARYING_WANT_TEXCOORD1) || defined(VARYING_DS_WANT_TEXCOORD1) |
|||
output.texCoord1 = input.uv1; |
|||
#endif |
|||
#if defined(VARYING_WANT_TEXCOORD2) || defined(VARYING_DS_WANT_TEXCOORD2) |
|||
output.texCoord2 = input.uv2; |
|||
#endif |
|||
#if defined(VARYING_WANT_TEXCOORD3) || defined(VARYING_DS_WANT_TEXCOORD3) |
|||
output.texCoord3 = input.uv3; |
|||
#endif |
|||
#if defined(VARYING_WANT_COLOR) || defined(VARYING_DS_WANT_COLOR) |
|||
output.color = input.color; |
|||
#endif |
|||
|
|||
return PackVaryingsType(output); |
|||
} |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
|
|||
PackedVaryings VertTesselation(VaryingDS input) |
|||
{ |
|||
VaryingsType output; |
|||
|
|||
output.positionCS = TransformWorldToHClip(input.positionWS); |
|||
#ifdef VARYING_WANT_TANGENT_TO_WORLD |
|||
float3x3 tangentToWorld = CreateTangentToWorld(input.normalWS, input.tangentWS.xyz, input.tangentWS.w); |
|||
output.tangentToWorld[0] = tangentToWorld[0]; |
|||
output.tangentToWorld[1] = tangentToWorld[1]; |
|||
output.tangentToWorld[2] = tangentToWorld[2]; |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_TEXCOORD0 |
|||
output.texCoord0 = input.uv0; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD1 |
|||
output.texCoord1 = input.uv1; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD2 |
|||
output.texCoord2 = input.uv2; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD3 |
|||
output.texCoord3 = input.uv3; |
|||
#endif |
|||
#ifdef VARYING_WANT_COLOR |
|||
output.color = input.color; |
|||
#endif |
|||
|
|||
return PackVaryingsType(output); |
|||
} |
|||
|
|||
#endif // TESSELLATION_ON |
|
|||
fileFormatVersion: 2 |
|||
guid: a09588881dc3d264188b6d25d553717c |
|||
timeCreated: 1484258505 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
#ifdef ATTRIBUTES_WANT_NORMAL |
|||
float3 normalOS : NORMAL; |
|||
#endif |
|||
#ifdef ATTRIBUTES_WANT_TANGENT |
|||
float4 tangentOS : TANGENT; // Store sign in w |
|||
#endif |
|||
#ifdef ATTRIBUTES_WANT_UV0 |
|||
float2 uv0 : TEXCOORD0; |
|||
#endif |
|||
#ifdef ATTRIBUTES_WANT_UV1 |
|||
float2 uv1 : TEXCOORD1; |
|||
#endif |
|||
#ifdef ATTRIBUTES_WANT_UV2 |
|||
float2 uv2 : TEXCOORD2; |
|||
#endif |
|||
#ifdef ATTRIBUTES_WANT_UV3 |
|||
float2 uv3 : TEXCOORD3; |
|||
#endif |
|||
#ifdef ATTRIBUTES_WANT_COLOR |
|||
float4 color : COLOR; |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_PASS_SPECIFIC |
|||
AttributesPass attributesPass; |
|||
#endif |
|||
|
|||
// UNITY_INSTANCE_ID |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS; |
|||
#ifdef VARYING_WANT_POSITION_WS |
|||
float3 positionWS; |
|||
#endif |
|||
#ifdef VARYING_WANT_TANGENT_TO_WORLD |
|||
float3 tangentToWorld[3]; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD0 |
|||
float2 texCoord0; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD1 |
|||
float2 texCoord1; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD2 |
|||
float2 texCoord2; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD3 |
|||
float2 texCoord3; |
|||
#endif |
|||
#ifdef VARYING_WANT_COLOR |
|||
float4 color; |
|||
#endif |
|||
#ifdef VARYING_WANT_PASS_SPECIFIC |
|||
VaryingsPass varyingPass; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
|
|||
#ifdef VARYING_WANT_TANGENT_TO_WORLD |
|||
#ifdef VARYING_WANT_POSITION_WS |
|||
// if present, pack positionWS |
|||
float4 interpolators1 : TEXCOORD1; |
|||
float4 interpolators2 : TEXCOORD2; |
|||
float4 interpolators3 : TEXCOORD3; |
|||
#else |
|||
float3 interpolators1 : TEXCOORD1; |
|||
float3 interpolators2 : TEXCOORD2; |
|||
float3 interpolators3 : TEXCOORD3; |
|||
#endif |
|||
#else |
|||
#ifdef VARYING_WANT_POSITION_WS |
|||
float3 interpolators0 : TEXCOORD0; |
|||
#endif |
|||
#endif |
|||
|
|||
// Allocate only necessary space if shader compiler in the future are able to automatically pack |
|||
#ifdef VARYING_WANT_TEXCOORD1 |
|||
float4 interpolators4 : TEXCOORD4; |
|||
#elif defined(VARYING_WANT_TEXCOORD0) |
|||
float2 interpolators4 : TEXCOORD4; |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_TEXCOORD3 |
|||
float4 interpolators5 : TEXCOORD5; |
|||
#elif defined(VARYING_WANT_TEXCOORD2) |
|||
float2 interpolators5 : TEXCOORD5; |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_COLOR |
|||
float4 interpolators6 : TEXCOORD6; |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_PASS_SPECIFIC |
|||
PackedVaryingsPass packedVaryingsPass; |
|||
#endif |
|||
|
|||
#if defined(VARYING_WANT_CULLFACE) && SHADER_STAGE_FRAGMENT |
|||
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC; |
|||
#endif |
|||
}; |
|||
|
|||
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
|
|||
output.positionCS = input.positionCS; |
|||
|
|||
#ifdef VARYING_WANT_TANGENT_TO_WORLD |
|||
output.interpolators1.xyz = input.tangentToWorld[0]; |
|||
output.interpolators2.xyz = input.tangentToWorld[1]; |
|||
output.interpolators3.xyz = input.tangentToWorld[2]; |
|||
#ifdef VARYING_WANT_POSITION_WS |
|||
output.interpolators1.w = input.positionWS.x; |
|||
output.interpolators2.w = input.positionWS.y; |
|||
output.interpolators3.w = input.positionWS.z; |
|||
#else |
|||
output.interpolators1.w = 0.0; |
|||
output.interpolators2.w = 0.0; |
|||
output.interpolators3.w = 0.0; |
|||
#endif |
|||
#else |
|||
#ifdef VARYING_WANT_POSITION_WS |
|||
output.interpolators0.xyz = input.positionWS; |
|||
output.interpolators0.w = 0.0; |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_TEXCOORD0 |
|||
output.interpolators4.xy = input.texCoord0; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD1 |
|||
output.interpolators4.zw = input.texCoord1; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD2 |
|||
output.interpolators5.xy = input.texCoord2; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD3 |
|||
output.interpolators5.zw = input.texCoord3; |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_COLOR |
|||
output.interpolators6 = input.color; |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_PASS_SPECIFIC |
|||
output.packedVaryingsPass = PackVaryingsPass(input.varyingPass); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInputs UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInputs output; |
|||
ZERO_INITIALIZE(FragInputs, output); |
|||
|
|||
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position |
|||
|
|||
#ifdef VARYING_WANT_TANGENT_TO_WORLD |
|||
output.tangentToWorld[0] = input.interpolators1.xyz; |
|||
output.tangentToWorld[1] = input.interpolators2.xyz; |
|||
output.tangentToWorld[2] = input.interpolators3.xyz; |
|||
#ifdef WANT_PER_PIXEL_WORLDPOS |
|||
output.positionWS.xyz = float3(input.interpolators1.w, input.interpolators2.w, input.interpolators3.w); |
|||
#endif |
|||
#else |
|||
#ifdef VARYING_WANT_POSITION_WS |
|||
output.positionWS.xyz = input.interpolators0.xyz; |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_TEXCOORD0 |
|||
output.texCoord0 = input.interpolators4.xy; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD1 |
|||
output.texCoord1 = input.interpolators4.zw; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD2 |
|||
output.texCoord2 = input.interpolators5.xy; |
|||
#endif |
|||
#ifdef VARYING_WANT_TEXCOORD3 |
|||
output.texCoord3 = input.interpolators5.zw; |
|||
#endif |
|||
#ifdef VARYING_WANT_COLOR |
|||
output.color = input.interpolators6; |
|||
#endif |
|||
|
|||
#ifdef VARYING_WANT_PASS_SPECIFIC |
|||
output.varyingPass = UnpackVaryingsPass(input.packedVaryingsPass); |
|||
#endif |
|||
|
|||
#if defined(VARYING_WANT_CULLFACE) && SHADER_STAGE_FRAGMENT |
|||
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
|
|||
// Varying DS - use for domain shader |
|||
// We can deduce these define from the other define |
|||
// We need to pass to DS any varying required by pixel shader |
|||
// If we have required an attribute it mean we will use it at least for DS |
|||
#ifdef VARYING_WANT_TANGENT_TO_WORLD |
|||
#define VARYING_DS_WANT_NORMAL |
|||
#define VARYING_DS_WANT_TANGENT |
|||
#endif |
|||
#if defined(VARYING_WANT_TEXCOORD0) || defined(ATTRIBUTES_WANT_UV0) |
|||
#define VARYING_DS_WANT_TEXCOORD0 |
|||
#endif |
|||
#if defined(VARYING_WANT_TEXCOORD1) || defined(ATTRIBUTES_WANT_UV1) |
|||
#define VARYING_DS_WANT_TEXCOORD1 |
|||
#endif |
|||
#if defined(VARYING_WANT_TEXCOORD2) || defined(ATTRIBUTES_WANT_UV2) |
|||
#define VARYING_DS_WANT_TEXCOORD2 |
|||
#endif |
|||
#if defined(VARYING_WANT_TEXCOORD3) || defined(ATTRIBUTES_WANT_UV3) |
|||
#define VARYING_DS_WANT_TEXCOORD3 |
|||
#endif |
|||
#if defined(VARYING_WANT_COLOR) || defined(ATTRIBUTES_WANT_COLOR) |
|||
float4 VARYING_DS_WANT_COLOR; |
|||
#endif |
|||
|
|||
// Varying for domain shader |
|||
// Position and normal are always present (for tessellation) and in world space |
|||
struct VaryingsDS |
|||
{ |
|||
float3 positionWS; |
|||
#ifdef VARYING_DS_WANT_NORMAL |
|||
float3 normalWS; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TANGENT |
|||
float4 tangentWS; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD0 |
|||
float2 texCoord0; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD1 |
|||
float2 texCoord1; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD2 |
|||
float2 texCoord2; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD3 |
|||
float2 texCoord3; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_COLOR |
|||
float4 color; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsDS |
|||
{ |
|||
float3 interpolators0 : INTERNALTESSPOS; // positionWS |
|||
|
|||
#ifdef VARYING_DS_WANT_NORMAL |
|||
float3 interpolators1 : NORMAL; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TANGENT |
|||
float4 interpolators2 : TANGENT; |
|||
#endif |
|||
|
|||
// Allocate only necessary space if shader compiler in the future are able to automatically pack |
|||
#ifdef VARYING_DS_WANT_TEXCOORD1 |
|||
float4 interpolators3 : TEXCOORD0; |
|||
#elif defined(VARYING_DS_WANT_TEXCOORD0) |
|||
float2 interpolators3 : TEXCOORD0; |
|||
#endif |
|||
|
|||
#ifdef VARYING_DS_WANT_TEXCOORD3 |
|||
float4 interpolators4 : TEXCOORD1; |
|||
#elif defined(VARYING_DS_WANT_TEXCOORD2) |
|||
float2 interpolators4 : TEXCOORD1; |
|||
#endif |
|||
|
|||
#ifdef VARYING_DS_WANT_COLOR |
|||
float4 interpolators5 : TEXCOORD2; |
|||
#endif |
|||
}; |
|||
|
|||
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryingsDS PackVaryingsDS(VaryingsDS input) |
|||
{ |
|||
PackedVaryingsDS output; |
|||
|
|||
output.interpolators0 = input.positionWS; |
|||
#ifdef VARYING_DS_WANT_NORMAL |
|||
output.interpolators1 = input.normalWS; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TANGENT |
|||
output.interpolators2 = input.tangentWS; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD0 |
|||
output.interpolators3.xy = input.texCoord0; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD1 |
|||
output.interpolators3.zw = input.texCoord1; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD2 |
|||
output.interpolators4.xy = input.texCoord2; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD3 |
|||
output.interpolators4.zw = input.texCoord3; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_COLOR |
|||
output.interpolators5 = input.color; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
VaryingsDS UnpackVaryingsDS(PackedVaryingsDS input) |
|||
{ |
|||
VaryingsDS output; |
|||
|
|||
output.positionWS = input.interpolators0; |
|||
#ifdef VARYING_DS_WANT_NORMAL |
|||
output.normalWS = input.interpolators1; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TANGENT |
|||
output.tangentWS = input.interpolators2; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD0 |
|||
output.texCoord0 = input.interpolators3.xy; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD1 |
|||
output.texCoord1 = input.interpolators3.zw; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD2 |
|||
output.texCoord2 = input.interpolators4.xy; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD3 |
|||
output.texCoord3 = input.interpolators4.zw; |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_COLOR |
|||
output.color = input.interpolators5; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
VaryingsDS InterpolateWithBaryCoords(VaryingsDS input0, VaryingsDS input1, VaryingsDS input2, float3 baryCoords) |
|||
{ |
|||
VaryingsDS ouput; |
|||
|
|||
TESSELLATION_INTERPOLATE_BARY(positionWS, baryCoords); |
|||
#ifdef VARYING_DS_WANT_NORMAL |
|||
TESSELLATION_INTERPOLATE_BARY(normalWS, baryCoords); |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TANGENT |
|||
// This will interpolate the sign but should be ok in practice as we may expect a triangle to have same sign (? TO CHECK) |
|||
TESSELLATION_INTERPOLATE_BARY(tangentWS, baryCoords); |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD0 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord0, baryCoords); |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD1 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord1, baryCoords); |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD2 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord2, baryCoords); |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_TEXCOORD3 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord3, baryCoords); |
|||
#endif |
|||
#ifdef VARYING_DS_WANT_COLOR |
|||
TESSELLATION_INTERPOLATE_BARY(color, baryCoords); |
|||
#endif |
|||
|
|||
return ouput; |
|||
} |
|||
|
|||
#endif // TESSELLATION_ON |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
#define VaryingsType VaryingsDS |
|||
#define PackedVaryingsType PackedVaryingsDS |
|||
#define PackVaryingsType PackVaryingsDS |
|||
#else |
|||
#define VaryingsType Varyings |
|||
#define PackedVaryingsType PackedVaryings |
|||
#define PackVaryingsType PackVaryings |
|||
#endif |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Attribute/Varying |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float2 uv0 : TEXCOORD0; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS; |
|||
float2 texCoord0; |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
}; |
|||
|
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionCS = input.positionCS; |
|||
output.interpolators[0] = float4(input.texCoord0.xy, 0.0, 0.0); |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInputs UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInputs output; |
|||
ZERO_INITIALIZE(FragInputs, output); |
|||
|
|||
output.unPositionSS = input.positionCS; |
|||
output.texCoord0.xy = input.interpolators[0].xy; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Vertex shader |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
PackedVaryings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionCS = TransformWorldToHClip(positionWS); |
|||
|
|||
output.texCoord0 = input.uv0; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6d56e29698894b440905cc5d63814ef9 |
|||
timeCreated: 1479292899 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9582236b174d65b4391e0f9890fd2194 |
|||
folderAsset: yes |
|||
timeCreated: 1483692743 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue