Anis Benyoub
6 年前
当前提交
08f93184
共有 21 个文件被更改,包括 971 次插入 和 0 次删除
-
2com.unity.render-pipelines.high-definition/HDRP/Material/Material.hlsl
-
8com.unity.render-pipelines.high-definition/HDRP/Material/Cloth.meta
-
44com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.cs
-
70com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.cs.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.cs.hlsl.meta
-
11com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.cs.meta
-
429com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.hlsl.meta
-
220com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.shader
-
9com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/Cloth.shader.meta
-
49com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ClothData.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ClothData.hlsl.meta
-
19com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ClothProperties.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ClothProperties.hlsl.meta
-
8com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ShaderPass.meta
-
12com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ShaderPass/ClothDepthPass.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ShaderPass/ClothDepthPass.hlsl.meta
-
36com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ShaderPass/ClothSharePass.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Material/Cloth/ShaderPass/ClothSharePass.hlsl.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 831a16854a7b1024dae2c848b1ccddd9 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// structure definition
|
|||
//-----------------------------------------------------------------------------
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class ShaderName : RenderPipelineMaterial |
|||
{ |
|||
//-----------------------------------------------------------------------------
|
|||
// SurfaceData
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
// Main structure that store the user data (i.e user input of master node in material graph)
|
|||
// The number '10000' must be a unique value across all material. It give an id to each of the parameters
|
|||
// so debug material mode can retrieve it and display it. With 10000, it mean that debug values
|
|||
// are sign from 10000 with incremental order.
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 10000)] |
|||
public struct SurfaceData |
|||
{ |
|||
// Standard
|
|||
[SurfaceDataAttributes("Base Color", false, true)] |
|||
public Vector3 baseColor; |
|||
|
|||
[SurfaceDataAttributes("Normal", true)] |
|||
public Vector3 normalWS; |
|||
}; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// BSDFData
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 10100)] |
|||
public struct BSDFData |
|||
{ |
|||
[SurfaceDataAttributes("", false, true)] |
|||
public Vector3 diffuseColor; |
|||
|
|||
[SurfaceDataAttributes("Normal", true)] |
|||
public Vector3 normalWS; |
|||
}; |
|||
} |
|||
} |
|
|||
// |
|||
// This file was automatically generated. Please don't edit by hand. |
|||
// |
|||
|
|||
#ifndef SHADERNAME_CS_HLSL |
|||
#define SHADERNAME_CS_HLSL |
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.ShaderName+SurfaceData: static fields |
|||
// |
|||
#define DEBUGVIEW_SHADERNAME_SURFACEDATA_BASE_COLOR (10000) |
|||
#define DEBUGVIEW_SHADERNAME_SURFACEDATA_NORMAL (10001) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.ShaderName+BSDFData: static fields |
|||
// |
|||
#define DEBUGVIEW_SHADERNAME_BSDFDATA_DIFFUSE_COLOR (10100) |
|||
#define DEBUGVIEW_SHADERNAME_BSDFDATA_NORMAL (10101) |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.ShaderName+SurfaceData |
|||
// PackingRules = Exact |
|||
struct SurfaceData |
|||
{ |
|||
float3 baseColor; |
|||
float3 normalWS; |
|||
}; |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.ShaderName+BSDFData |
|||
// PackingRules = Exact |
|||
struct BSDFData |
|||
{ |
|||
float3 diffuseColor; |
|||
float3 normalWS; |
|||
}; |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedSurfaceDataDebug(uint paramId, SurfaceData surfacedata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_SHADERNAME_SURFACEDATA_BASE_COLOR: |
|||
result = surfacedata.baseColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_SHADERNAME_SURFACEDATA_NORMAL: |
|||
result = surfacedata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedBSDFDataDebug(uint paramId, BSDFData bsdfdata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_SHADERNAME_BSDFDATA_DIFFUSE_COLOR: |
|||
result = bsdfdata.diffuseColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_SHADERNAME_BSDFDATA_NORMAL: |
|||
result = bsdfdata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: c8253363006e4a9428a799250ac5b2b0 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 93e2716a30b38c44c9ed06602a0fc923 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
//----------------------------------------------------------------------------- |
|||
// SurfaceData and BSDFData |
|||
//----------------------------------------------------------------------------- |
|||
// SurfaceData is defined in Cloth.cs which generates Cloth.cs.hlsl |
|||
#include "Cloth.cs.hlsl" |
|||
|
|||
// This function is use to help with debugging and must be implemented by any lit material |
|||
// Implementer must take into account what are the current override component and |
|||
// adjust SurfaceData properties accordingdly |
|||
void ApplyDebugToSurfaceData(float3x3 worldToTangent, inout SurfaceData surfaceData) |
|||
{ |
|||
#ifdef DEBUG_DISPLAY |
|||
// NOTE: THe _Debug* uniforms come from /HDRP/Debug/DebugDisplay.hlsl |
|||
|
|||
// Override value if requested by user |
|||
// this can be use also in case of debug lighting mode like diffuse only |
|||
bool overrideAlbedo = _DebugLightingAlbedo.x != 0.0; |
|||
bool overrideSmoothness = _DebugLightingSmoothness.x != 0.0; |
|||
bool overrideNormal = _DebugLightingNormal.x != 0.0; |
|||
|
|||
if (overrideAlbedo) |
|||
{ |
|||
float3 overrideAlbedoValue = _DebugLightingAlbedo.yzw; |
|||
surfaceData.baseColor = overrideAlbedoValue; |
|||
} |
|||
|
|||
if (overrideSmoothness) |
|||
{ |
|||
//float overrideSmoothnessValue = _DebugLightingSmoothness.y; |
|||
//surfaceData.perceptualSmoothness = overrideSmoothnessValue; |
|||
} |
|||
|
|||
if (overrideNormal) |
|||
{ |
|||
surfaceData.normalWS = worldToTangent[2]; |
|||
} |
|||
#endif |
|||
} |
|||
|
|||
// This function is similar to ApplyDebugToSurfaceData but for BSDFData |
|||
// Note: This will be available and used in ShaderPassForward.hlsl since in Cloth.shader, |
|||
// just before including the core code of the pass (ShaderPassForward.hlsl) we include |
|||
// Material.hlsl (or Lighting.hlsl which includes it) which in turn includes us, |
|||
// Cloth.shader, via the #if defined(UNITY_MATERIAL_*) glue mechanism. |
|||
void ApplyDebugToBSDFData(inout BSDFData bsdfData) |
|||
{ |
|||
#ifdef DEBUG_DISPLAY |
|||
// Override value if requested by user |
|||
// this can be use also in case of debug lighting mode like specular only |
|||
|
|||
//bool overrideSpecularColor = _DebugLightingSpecularColor.x != 0.0; |
|||
|
|||
//if (overrideSpecularColor) |
|||
//{ |
|||
// float3 overrideSpecularColor = _DebugLightingSpecularColor.yzw; |
|||
// bsdfData.fresnel0 = overrideSpecularColor; |
|||
//} |
|||
#endif |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// conversion function for forward |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
BSDFData ConvertSurfaceDataToBSDFData(uint2 positionSS, SurfaceData surfaceData) |
|||
{ |
|||
BSDFData bsdfData; |
|||
ZERO_INITIALIZE(BSDFData, bsdfData); |
|||
|
|||
bsdfData.diffuseColor = surfaceData.baseColor; |
|||
bsdfData.normalWS = surfaceData.normalWS; |
|||
|
|||
ApplyDebugToBSDFData(bsdfData); |
|||
return bsdfData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Debug method (use to display values) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// This function call the generated debug function and allow to override the debug output if needed |
|||
void GetSurfaceDataDebug(uint paramId, SurfaceData surfaceData, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
GetGeneratedSurfaceDataDebug(paramId, surfaceData, result, needLinearToSRGB); |
|||
} |
|||
|
|||
// This function call the generated debug function and allow to override the debug output if needed |
|||
void GetBSDFDataDebug(uint paramId, BSDFData bsdfData, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
GetGeneratedBSDFDataDebug(paramId, bsdfData, result, needLinearToSRGB); |
|||
} |
|||
|
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// PreLightData |
|||
// |
|||
// Make sure we respect naming conventions to reuse ShaderPassForward as is, |
|||
// ie struct (even if opaque to the ShaderPassForward) name is PreLightData, |
|||
// GetPreLightData prototype. |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Precomputed lighting data to send to the various lighting functions |
|||
struct PreLightData |
|||
{ |
|||
float NdotV; // Could be negative due to normal mapping, use ClampNdotV() |
|||
}; |
|||
|
|||
// This function is call to precompute heavy calculation before lightloop |
|||
PreLightData GetPreLightData(float3 V, PositionInputs posInput, inout BSDFData bsdfData) |
|||
{ |
|||
PreLightData preLightData; |
|||
ZERO_INITIALIZE(PreLightData, preLightData); |
|||
|
|||
float3 N = bsdfData.normalWS; |
|||
preLightData.NdotV = dot(N, V); |
|||
|
|||
//float NdotV = ClampNdotV(preLightData.NdotV); |
|||
|
|||
return preLightData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// bake lighting function |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// |
|||
// GetBakedDiffuseLighting will be called from ShaderPassForward.hlsl. |
|||
// |
|||
// GetBakedDiffuseLighting function compute the bake lighting + emissive color to be store in emissive buffer (Deferred case) |
|||
// In forward it must be add to the final contribution. |
|||
// This function require the 3 structure surfaceData, builtinData, bsdfData because it may require both the engine side data, and data that will not be store inside the gbuffer. |
|||
float3 GetBakedDiffuseLighting(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData, PreLightData preLightData) |
|||
{ |
|||
#ifdef DEBUG_DISPLAY |
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER) |
|||
{ |
|||
// The lighting in SH or lightmap is assume to contain bounced light only (i.e no direct lighting), and is divide by PI (i.e Lambert is apply), so multiply by PI here to get back the illuminance |
|||
return builtinData.bakeDiffuseLighting * PI; |
|||
} |
|||
#endif |
|||
|
|||
// Premultiply bake diffuse lighting information with DisneyDiffuse pre-integration |
|||
//return builtinData.bakeDiffuseLighting * preLightData.diffuseFGD * surfaceData.ambientOcclusion * bsdfData.diffuseColor + builtinData.emissiveColor; |
|||
return builtinData.bakeDiffuseLighting * bsdfData.diffuseColor; |
|||
} |
|||
|
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// light transport functions |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
LightTransportData GetLightTransportData(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData) |
|||
{ |
|||
LightTransportData lightTransportData; |
|||
|
|||
// diffuseColor for lightmapping |
|||
lightTransportData.diffuseColor = bsdfData.diffuseColor; |
|||
lightTransportData.emissiveColor = builtinData.emissiveColor; |
|||
|
|||
return lightTransportData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// LightLoop related function (Only include if required) |
|||
// HAS_LIGHTLOOP is define in Lighting.hlsl |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
#ifdef HAS_LIGHTLOOP |
|||
|
|||
#ifndef _SURFACE_TYPE_TRANSPARENT |
|||
// For /Lighting/LightEvaluation.hlsl: |
|||
#define USE_DEFERRED_DIRECTIONAL_SHADOWS // Deferred shadows are always enabled for opaque objects |
|||
#endif |
|||
|
|||
#include "HDRP/Material/MaterialEvaluation.hlsl" |
|||
#include "HDRP/Lighting/LightEvaluation.hlsl" |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// BSDF share between directional light, punctual light and area light (reference) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// This function apply BSDF. Assumes that NdotL is positive. |
|||
void BSDF( float3 V, float3 L, float NdotL, float3 positionWS, PreLightData preLightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
float diffuseTerm = Lambert(); |
|||
|
|||
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF(). |
|||
diffuseLighting = diffuseTerm; |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Directional |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DirectLighting EvaluateBSDF_Directional(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, |
|||
DirectionalLightData lightData, BSDFData bsdfData, |
|||
BakeLightingData bakeLightingData) |
|||
{ |
|||
DirectLighting lighting; |
|||
ZERO_INITIALIZE(DirectLighting, lighting); |
|||
|
|||
float3 N = bsdfData.normalWS; |
|||
float3 L = -lightData.forward; // Lights point backward in Unity |
|||
float NdotL = dot(N, L); |
|||
|
|||
// color and attenuation are outputted by EvaluateLight: |
|||
float3 color; |
|||
float attenuation; |
|||
EvaluateLight_Directional(lightLoopContext, posInput, lightData, bakeLightingData, N, L, color, attenuation); |
|||
|
|||
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light) |
|||
|
|||
// Note: We use NdotL here to early out, but in case of clear coat this is not correct. But we are ok with this |
|||
UNITY_BRANCH if (intensity > 0.0) |
|||
{ |
|||
BSDF(V, L, NdotL, posInput.positionWS, preLightData, bsdfData, lighting.diffuse, lighting.specular); |
|||
|
|||
lighting.diffuse *= intensity * lightData.diffuseScale; |
|||
lighting.specular *= intensity * lightData.specularScale; |
|||
} |
|||
|
|||
// Save ALU by applying light and cookie colors only once. |
|||
lighting.diffuse *= color; |
|||
lighting.specular *= color; |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER) |
|||
{ |
|||
// Only lighting, not BSDF |
|||
lighting.diffuse = color * intensity * lightData.diffuseScale; |
|||
} |
|||
#endif |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Punctual (supports spot, point and projector lights) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DirectLighting EvaluateBSDF_Punctual(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData) |
|||
{ |
|||
DirectLighting lighting; |
|||
ZERO_INITIALIZE(DirectLighting, lighting); |
|||
|
|||
float3 lightToSample = posInput.positionWS - lightData.positionWS; |
|||
int lightType = lightData.lightType; |
|||
|
|||
float3 L; |
|||
float4 distances; // {d, d^2, 1/d, d_proj} |
|||
distances.w = dot(lightToSample, lightData.forward); |
|||
|
|||
if (lightType == GPULIGHTTYPE_PROJECTOR_BOX) |
|||
{ |
|||
L = -lightData.forward; |
|||
distances.xyz = 1; // No distance or angle attenuation |
|||
} |
|||
else |
|||
{ |
|||
float3 unL = -lightToSample; |
|||
float distSq = dot(unL, unL); |
|||
float distRcp = rsqrt(distSq); |
|||
float dist = distSq * distRcp; |
|||
|
|||
L = unL * distRcp; |
|||
distances.xyz = float3(dist, distSq, distRcp); |
|||
} |
|||
|
|||
float3 N = bsdfData.normalWS; |
|||
float NdotV = ClampNdotV(preLightData.NdotV); |
|||
float NdotL = dot(N, L); |
|||
float LdotV = dot(L, V); |
|||
|
|||
float3 color; |
|||
float attenuation; |
|||
EvaluateLight_Punctual(lightLoopContext, posInput, lightData, bakeLightingData, N, L, |
|||
lightToSample, distances, color, attenuation); |
|||
|
|||
|
|||
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light) |
|||
|
|||
// Note: We use NdotL here to early out, but in case of clear coat this is not correct. But we are ok with this |
|||
UNITY_BRANCH if (intensity > 0.0) |
|||
{ |
|||
// Shader implementer is free to use minRoughness paramter or not(But better if it is done) |
|||
// Simulate a sphere light with this hack |
|||
// Note that it is not correct with our pre-computation of PartLambdaV (mean if we disable the optimization we will not have the |
|||
// same result) but we don't care as it is a hack anyway |
|||
|
|||
//bsdfData.coatRoughness = max(bsdfData.coatRoughness, lightData.minRoughness); |
|||
//bsdfData.roughnessT = max(bsdfData.roughnessT, lightData.minRoughness); |
|||
//bsdfData.roughnessB = max(bsdfData.roughnessB, lightData.minRoughness); |
|||
|
|||
BSDF(V, L, NdotL, posInput.positionWS, preLightData, bsdfData, lighting.diffuse, lighting.specular); |
|||
|
|||
lighting.diffuse *= intensity * lightData.diffuseScale; |
|||
lighting.specular *= intensity * lightData.specularScale; |
|||
} |
|||
|
|||
// Save ALU by applying light and cookie colors only once. |
|||
lighting.diffuse *= color; |
|||
lighting.specular *= color; |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER) |
|||
{ |
|||
// Only lighting, not BSDF |
|||
lighting.diffuse = color * intensity * lightData.diffuseScale; |
|||
} |
|||
#endif |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Line |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DirectLighting EvaluateBSDF_Line( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData) |
|||
{ |
|||
DirectLighting lighting; |
|||
ZERO_INITIALIZE(DirectLighting, lighting); |
|||
|
|||
// TODO |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Rect |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DirectLighting EvaluateBSDF_Rect( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData) |
|||
{ |
|||
DirectLighting lighting; |
|||
ZERO_INITIALIZE(DirectLighting, lighting); |
|||
|
|||
// TODO |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
DirectLighting EvaluateBSDF_Area(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, |
|||
BSDFData bsdfData, BakeLightingData bakeLightingData) |
|||
{ |
|||
if (lightData.lightType == GPULIGHTTYPE_LINE) |
|||
{ |
|||
return EvaluateBSDF_Line(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, bakeLightingData); |
|||
} |
|||
else |
|||
{ |
|||
return EvaluateBSDF_Rect(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, bakeLightingData); |
|||
} |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_SSLighting for screen space lighting |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
IndirectLighting EvaluateBSDF_SSLighting(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, BSDFData bsdfData, |
|||
EnvLightData envLightData, |
|||
int GPUImageBasedLightingType, |
|||
inout float hierarchyWeight) |
|||
{ |
|||
IndirectLighting lighting; |
|||
ZERO_INITIALIZE(IndirectLighting, lighting); |
|||
|
|||
// TODO |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Env |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
// _preIntegratedFGD and _CubemapLD are unique for each BRDF |
|||
IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData, |
|||
int influenceShapeType, int GPUImageBasedLightingType, |
|||
inout float hierarchyWeight) |
|||
{ |
|||
IndirectLighting lighting; |
|||
ZERO_INITIALIZE(IndirectLighting, lighting); |
|||
|
|||
// TODO |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// PostEvaluateBSDF |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
void PostEvaluateBSDF( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, BSDFData bsdfData, BakeLightingData bakeLightingData, AggregateLighting lighting, |
|||
out float3 diffuseLighting, out float3 specularLighting) |
|||
{ |
|||
AmbientOcclusionFactor aoFactor; |
|||
GetScreenSpaceAmbientOcclusion(posInput.positionSS, preLightData.NdotV, 1.0, 1.0, 1.0, aoFactor); |
|||
ApplyAmbientOcclusionFactor(aoFactor, bakeLightingData, lighting); |
|||
|
|||
// Apply the albedo to the direct diffuse lighting and that's about it. |
|||
// diffuse lighting has already had the albedo applied in GetBakedDiffuseLighting(). |
|||
diffuseLighting = bsdfData.diffuseColor * lighting.direct.diffuse + bakeLightingData.bakeDiffuseLighting; |
|||
specularLighting = lighting.direct.specular + lighting.indirect.specularReflected; |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
PostEvaluateBSDFDebugDisplay(aoFactor, bakeLightingData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting); |
|||
#endif |
|||
} |
|||
|
|||
#endif // #ifdef HAS_LIGHTLOOP |
|
|||
fileFormatVersion: 2 |
|||
guid: 9d559bc1da0ed3b49a6c549d3b90b375 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "HDRenderPipeline/Cloth" |
|||
{ |
|||
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 |
|||
// Be careful, do not change the name here to _Color. It will conflict with the "fake" parameters (see end of properties) required for GI. |
|||
_BaseColor("BaseColor", Color) = (1,1,1,1) |
|||
_BaseColorMap("BaseColorMap", 2D) = "white" {} |
|||
|
|||
// Transparency |
|||
[ToggleUI] _PreRefractionPass("PreRefractionPass", Float) = 0.0 |
|||
|
|||
[ToggleUI] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 |
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
_TransparentSortPriority("_TransparentSortPriority", Float) = 0 |
|||
|
|||
// Stencil state |
|||
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting (fixed at compile time) |
|||
[HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 7 // StencilMask.Lighting (fixed at compile time) |
|||
[HideInInspector] _StencilRefMV("_StencilRefMV", Int) = 128 // StencilLightingUsage.RegularLighting (fixed at compile time) |
|||
[HideInInspector] _StencilWriteMaskMV("_StencilWriteMaskMV", Int) = 128 // StencilMask.ObjectsVelocity (fixed at compile time) |
|||
|
|||
// 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 |
|||
[HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal |
|||
|
|||
[ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0 |
|||
[ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0 |
|||
|
|||
// HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes. |
|||
_MainTex("Albedo", 2D) = "white" {} |
|||
_Color("Color", Color) = (1,1,1,1) |
|||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 xboxone vulkan metal |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Variant |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
|
|||
// Keyword for transparent |
|||
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT |
|||
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY |
|||
#pragma shader_feature _BLENDMODE_PRESERVE_SPECULAR_LIGHTING // easily handled in material.hlsl, so adding this already. |
|||
#pragma shader_feature _ENABLE_FOG_ON_TRANSPARENT |
|||
|
|||
//enable GPU instancing support |
|||
#pragma multi_compile_instancing |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Define |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#define UNITY_MATERIAL_CLOTH // Need to be define before including Material.hlsl |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "CoreRP/ShaderLibrary/Common.hlsl" |
|||
#include "../../ShaderPass/FragInputs.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "../../Material/Cloth/ClothProperties.hlsl" |
|||
|
|||
// All our shaders use same name for entry point |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
// This tags allow to use the shader replacement features |
|||
Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDClothShader" } |
|||
|
|||
// Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not be the meta pass. |
|||
|
|||
Pass |
|||
{ |
|||
Name "Depth prepass" |
|||
Tags{ "LightMode" = "DepthForwardOnly" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZWrite On |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_DEPTH_ONLY |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/ClothDepthPass.hlsl" |
|||
#include "ClothData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDepthOnly.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. |
|||
|
|||
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/ClothSharePass.hlsl" |
|||
#include "ClothData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassLightTransport.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Name "ShadowCaster" |
|||
Tags{ "LightMode" = "ShadowCaster" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZClip [_ZClip] |
|||
ZWrite On |
|||
ZTest LEqual |
|||
|
|||
ColorMask 0 |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_SHADOWS |
|||
#define USE_LEGACY_UNITY_MATRIX_VARIABLES |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Material/Material.hlsl" |
|||
|
|||
#include "ShaderPass/ClothDepthPass.hlsl" |
|||
#include "ClothData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// Cloth shader always render in forward |
|||
Pass |
|||
{ |
|||
Name "Forward" // Name is not used |
|||
Tags { "LightMode" = "ForwardOnly" } |
|||
|
|||
Stencil |
|||
{ |
|||
WriteMask [_StencilWriteMask] |
|||
Ref [_StencilRef] |
|||
Comp Always |
|||
Pass Replace |
|||
} |
|||
|
|||
Blend [_SrcBlend] [_DstBlend] |
|||
// In case of forward we want to have depth equal for opaque alpha tested mesh |
|||
ZTest [_ZTestDepthEqualForOpaque] |
|||
ZWrite [_ZWrite] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma multi_compile _ DEBUG_DISPLAY |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile _ DYNAMICLIGHTMAP_ON |
|||
#pragma multi_compile _ SHADOWS_SHADOWMASK |
|||
|
|||
// #include "../../Lighting/Forward.hlsl" : nothing left in there. |
|||
//#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS |
|||
#define LIGHTLOOP_TILE_PASS |
|||
#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD |
|||
#include "../../ShaderVariables.hlsl" |
|||
#ifdef DEBUG_DISPLAY |
|||
#include "../../Debug/DebugDisplay.hlsl" |
|||
#endif |
|||
#include "../../Lighting/Lighting.hlsl" |
|||
//...this will include #include "../../Material/Material.hlsl" but also LightLoop which the forward pass directly uses. |
|||
|
|||
#include "ShaderPass/ClothSharePass.hlsl" |
|||
#include "ClothData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
} |
|||
|
|||
//CustomEditor "Experimental.Rendering.HDPipeline.ClothGUI" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6a6a4e0a7fa7acb4db5434242d16a50f |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
#include "../MaterialUtilities.hlsl" |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
surfaceData.normalWS = input.worldToTangent[2].xyz; |
|||
|
|||
float2 baseColorMapUv = TRANSFORM_TEX(input.texCoord0, _BaseColorMap); |
|||
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, baseColorMapUv).rgb * _BaseColor.rgb; |
|||
float alpha = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, baseColorMapUv).a * _BaseColor.a; |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
DoAlphaTest(alpha, _AlphaCutoff); |
|||
#endif |
|||
|
|||
#if defined(DEBUG_DISPLAY) |
|||
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) |
|||
{ |
|||
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, baseColorMapUv, _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, surfaceData.baseColor); |
|||
} |
|||
#endif |
|||
|
|||
// Builtin Data |
|||
builtinData.opacity = alpha; |
|||
|
|||
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionWS, surfaceData.normalWS, input.texCoord1, input.texCoord2); |
|||
|
|||
builtinData.emissiveColor = float3(0.0, 0.0, 0.0); |
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
|
|||
#ifdef SHADOWS_SHADOWMASK |
|||
float4 shadowMask = SampleShadowMask(input.positionWS, input.texCoord1); |
|||
builtinData.shadowMask0 = shadowMask.x; |
|||
builtinData.shadowMask1 = shadowMask.y; |
|||
builtinData.shadowMask2 = shadowMask.z; |
|||
builtinData.shadowMask3 = shadowMask.w; |
|||
#else |
|||
builtinData.shadowMask0 = 0.0; |
|||
builtinData.shadowMask1 = 0.0; |
|||
builtinData.shadowMask2 = 0.0; |
|||
builtinData.shadowMask3 = 0.0; |
|||
#endif |
|||
|
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
builtinData.depthOffset = 0.0; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f77d977338f663640bdae0ddeb5d3426 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// =========================================================================== |
|||
// WARNING: |
|||
// On PS4, texture/sampler declarations need to be outside of CBuffers |
|||
// Otherwise those parameters are not bound correctly at runtime. |
|||
// =========================================================================== |
|||
|
|||
TEXTURE2D(_BaseColorMap); |
|||
SAMPLER(sampler_BaseColorMap); |
|||
|
|||
CBUFFER_START(UnityPerMaterial) |
|||
|
|||
float4 _BaseColor; |
|||
float4 _BaseColorMap_ST; |
|||
float4 _BaseColorMap_TexelSize; |
|||
float4 _BaseColorMap_MipInfo; |
|||
|
|||
float _AlphaCutoff; |
|||
|
|||
CBUFFER_END |
|
|||
fileFormatVersion: 2 |
|||
guid: 1cac3ffd4f003744fb5730a5c48ba9b5 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f79d82fdc4e5c2041973e2f65f9666fd |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
|
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
#endif //..._ALPHATEST_ON |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "HDRP/ShaderPass/VaryingMesh.hlsl" |
|
|||
fileFormatVersion: 2 |
|||
guid: 9946a17aceea4734d82fcd2044af9b69 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
// This first set of define allow to say which attributes will be use by the mesh in the vertex and domain shader (for tesselation) |
|||
|
|||
// Attributes |
|||
#define ATTRIBUTES_NEED_NORMAL |
|||
#define ATTRIBUTES_NEED_TANGENT // Always present as we require it also in case of anisotropic lighting |
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
#define ATTRIBUTES_NEED_TEXCOORD1 |
|||
#define ATTRIBUTES_NEED_COLOR |
|||
|
|||
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) || defined(DYNAMICLIGHTMAP_ON) || defined(DEBUG_DISPLAY) || (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) |
|||
#define ATTRIBUTES_NEED_TEXCOORD2 |
|||
#endif |
|||
#if defined(_REQUIRE_UV3) || defined(DEBUG_DISPLAY) |
|||
#define ATTRIBUTES_NEED_TEXCOORD3 |
|||
#endif |
|||
|
|||
// Varying - Use for pixel shader |
|||
// This second set of define allow to say which varyings will be output in the vertex (no more tesselation) |
|||
#define VARYINGS_NEED_POSITION_WS |
|||
#define VARYINGS_NEED_TANGENT_TO_WORLD |
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
#define VARYINGS_NEED_TEXCOORD1 |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD2 |
|||
#define VARYINGS_NEED_TEXCOORD2 |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD3 |
|||
#define VARYINGS_NEED_TEXCOORD3 |
|||
#endif |
|||
#define VARYINGS_NEED_COLOR |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "HDRP/ShaderPass/VaryingMesh.hlsl" |
|
|||
fileFormatVersion: 2 |
|||
guid: fdaa5fc96d0e0b8438df418fc7a19ae0 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue