浏览代码
First integration for a *suitable* approach of MaterialGraph & ScriptableRenderloop (MasterNode description is draft, that's why MaterialIDAttribute is tagget as "WIP")
/scriptablerenderloop-materialgraph
First integration for a *suitable* approach of MaterialGraph & ScriptableRenderloop (MasterNode description is draft, that's why MaterialIDAttribute is tagget as "WIP")
/scriptablerenderloop-materialgraph
Paul Demeulenaere
8 年前
当前提交
f286e852
共有 8 个文件被更改,包括 459 次插入 和 40 次删除
-
224Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
25Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.cs
-
114Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.template
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.template.meta
-
19Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.template
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.template.meta
-
93Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitShare.template
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitShare.template.meta
|
|||
Shader "Unity/Lit/${ShaderName}" |
|||
{ |
|||
Properties |
|||
{ |
|||
${ShaderPropertiesHeader} |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "common.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPass.cs.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
// Set of users variables |
|||
${LightingFunction} |
|||
${ShaderFunctions} |
|||
${ShaderPropertyUsages} |
|||
|
|||
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 "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl" |
|||
|
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.template" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitShare.template" |
|||
|
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassGBuffer.hlsl" |
|||
ENDHLSL |
|||
} |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Debug pass |
|||
// ------------------------------------------------------------------ |
|||
//TODO |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Extracts information for lightmapping, GI (emission, albedo, ...) |
|||
// This pass it not used during regular rendering. |
|||
// ------------------------------------------------------------------ |
|||
//TODO |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// Depth only |
|||
// ------------------------------------------------------------------ |
|||
//TODO |
|||
|
|||
// ------------------------------------------------------------------ |
|||
// forward pass |
|||
// ------------------------------------------------------------------ |
|||
/* //Preview doesn't work for now |
|||
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 |
|||
// TEMP until pragma work in include |
|||
// #include "../../Lighting/Forward.hlsl" |
|||
#pragma multi_compile LIGHTLOOP_SINGLE_PASS |
|||
#pragma multi_compile SHADOWFILTERING_FIXED_SIZE_PCF |
|||
|
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl" |
|||
|
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.template" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitShare.template" |
|||
|
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
}*/ |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 810d1d06c0329e0488541cc00c884938 |
|||
timeCreated: 1477907157 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
struct FragInput |
|||
{ |
|||
float4 positionHS; |
|||
float3 positionWS; |
|||
float2 meshUV0; |
|||
float2 meshUV1; |
|||
float2 meshUV2; |
|||
float3 tangentToWorld[3]; |
|||
bool isFrontFace; |
|||
}; |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInput IN, out SurfaceData o, out BuiltinData builtinData) |
|||
{ |
|||
o = (SurfaceData)0; |
|||
builtinData = (BuiltinData)0; |
|||
float3 vertexNormalWS = IN.tangentToWorld[2].xyz; |
|||
o.normalWS = vertexNormalWS; |
|||
${PixelShaderBody} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d6c7ab7e8a2de574d88d5358af9647df |
|||
timeCreated: 1477915331 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
//------------------------------------------------------------------------------------- |
|||
// Attribute/Varying |
|||
//------------------------------------------------------------------------------------- |
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float3 normalOS : NORMAL; |
|||
float2 uv0 : TEXCOORD0; |
|||
float2 uv1 : TEXCOORD1; |
|||
float2 uv2 : TEXCOORD2; |
|||
float4 tangentOS : TANGENT; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionHS; |
|||
float3 positionWS; |
|||
float2 meshUV0; |
|||
float2 meshUV1; |
|||
float2 meshUV2; |
|||
float3 tangentToWorld[3]; |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionHS : SV_Position; |
|||
float4 interpolators[5] : 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].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.meshUV0.x; |
|||
output.interpolators[1].w = input.meshUV0.y; |
|||
output.interpolators[2].w = input.meshUV1.x; |
|||
output.interpolators[3].w = input.meshUV1.y; |
|||
|
|||
output.interpolators[4] = float4(input.meshUV1.xy, 0.0, 0.0); |
|||
|
|||
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.meshUV0.xy = float2(input.interpolators[0].w, input.interpolators[1].w); |
|||
output.meshUV1.xy = float2(input.interpolators[2].w, input.interpolators[3].w); |
|||
output.meshUV2 = input.interpolators[4].xy; |
|||
|
|||
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); |
|||
output.positionHS = TransformWorldToHClip(output.positionWS); |
|||
|
|||
float3 normalWS = TransformObjectToWorldNormal(input.normalOS); |
|||
output.meshUV0 = input.uv0; |
|||
output.meshUV1 = input.uv1; |
|||
output.meshUV2 = input.uv2; |
|||
|
|||
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: 81531b5e1c67b7f41b9307691ecd9d23 |
|||
timeCreated: 1477915331 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue