浏览代码

HDrenderPipeline: Generate hlsl debug functions

Instead of wrtiting functions by hand user can now call generated debug
function and override thing he/she want.
/Branch_batcher
sebastienlagarde 7 年前
当前提交
68b2246c
共有 19 个文件被更改,包括 513 次插入286 次删除
  1. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  2. 98
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  3. 36
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
  4. 11
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Builtin/BuiltinData.cs
  5. 63
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Builtin/BuiltinData.cs.hlsl
  6. 30
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Builtin/BuiltinData.hlsl
  7. 17
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  8. 130
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  9. 106
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  10. 3
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.cs
  11. 28
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.cs.hlsl
  12. 26
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.hlsl
  13. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl
  14. 18
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowBase.cs.hlsl
  15. 14
      Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl
  16. 68
      Assets/ScriptableRenderPipeline/fptl/LightDefinitions.cs.hlsl
  17. 9
      Assets/ShaderGenerator/Editor/CSharpToHLSL.cs
  18. 126
      Assets/ShaderGenerator/Editor/ShaderTypeGeneration.cs
  19. 12
      Assets/ShaderGenerator/ShaderGeneratorAttributes.cs

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


// Get attribute to get the start number of the value for the enum
var attr = attributes[0] as GenerateHLSL;
if (!attr.needParamDefines)
if (!attr.needParamDebug)
{
return;
}

98
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl


//
float3 GetPositionWS(LightData value)
{
return value.positionWS;
return value.positionWS;
return value.invSqrAttenuationRadius;
return value.invSqrAttenuationRadius;
return value.color;
return value.color;
return value.angleScale;
return value.angleScale;
return value.forward;
return value.forward;
return value.angleOffset;
return value.angleOffset;
return value.up;
return value.up;
return value.diffuseScale;
return value.diffuseScale;
return value.right;
return value.right;
return value.specularScale;
return value.specularScale;
return value.shadowDimmer;
return value.shadowDimmer;
return value.shadowIndex;
return value.shadowIndex;
return value.IESIndex;
return value.IESIndex;
return value.cookieIndex;
return value.cookieIndex;
return value.lightType;
return value.lightType;
return value.size;
return value.size;
return value.twoSided;
return value.twoSided;
}
//

{
return value.forward;
return value.forward;
return value.diffuseScale;
return value.diffuseScale;
return value.up;
return value.up;
return value.invScaleY;
return value.invScaleY;
return value.right;
return value.right;
return value.invScaleX;
return value.invScaleX;
return value.positionWS;
return value.positionWS;
return value.tileCookie;
return value.tileCookie;
return value.color;
return value.color;
return value.specularScale;
return value.specularScale;
return value.cosAngle;
return value.cosAngle;
return value.sinAngle;
return value.sinAngle;
return value.shadowIndex;
return value.shadowIndex;
return value.cookieIndex;
return value.cookieIndex;
}
//

{
return value.worldToShadow;
return value.worldToShadow;
return value.bias;
return value.bias;
return value.quality;
return value.quality;
return value.unused;
return value.unused;
return value.unused2;
return value.unused2;
return value.invResolution;
return value.invResolution;
}
//

{
return value.positionWS;
return value.positionWS;
return value.envShapeType;
return value.envShapeType;
return value.forward;
return value.forward;
return value.envIndex;
return value.envIndex;
return value.up;
return value.up;
return value.blendDistance;
return value.blendDistance;
return value.right;
return value.right;
return value.unused0;
return value.unused0;
return value.innerDistance;
return value.innerDistance;
return value.unused1;
return value.unused1;
return value.offsetLS;
return value.offsetLS;
return value.unused2;
return value.unused2;
}

36
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl


//
float3 GetBoxAxisX(SFiniteLightBound value)
{
return value.boxAxisX;
return value.boxAxisX;
return value.boxAxisY;
return value.boxAxisY;
return value.boxAxisZ;
return value.boxAxisZ;
return value.center;
return value.center;
return value.scaleXY;
return value.scaleXY;
return value.radius;
return value.radius;
}
//

{
return value.lightPos;
return value.lightPos;
return value.lightVolume;
return value.lightVolume;
return value.lightAxisX;
return value.lightAxisX;
return value.lightCategory;
return value.lightCategory;
return value.lightAxisY;
return value.lightAxisY;
return value.radiusSq;
return value.radiusSq;
return value.lightAxisZ;
return value.lightAxisZ;
return value.cotan;
return value.cotan;
return value.boxInnerDist;
return value.boxInnerDist;
return value.featureFlags;
return value.featureFlags;
return value.boxInvRange;
return value.boxInvRange;
return value.unused2;
return value.unused2;
}

11
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Builtin/BuiltinData.cs


// We would prefer to split lighting and material information but for performance reasons,
// those lighting information are fill
// at the same time than material information.
[SurfaceDataAttributes("Bake Diffuse Lighting")]
[SurfaceDataAttributes("Bake Diffuse Lighting", false, true)]
[SurfaceDataAttributes("Emissive Color")]
[SurfaceDataAttributes("Emissive Color", false, true)]
public Vector3 emissiveColor;
[SurfaceDataAttributes("Emissive Intensity")]
public float emissiveIntensity;

};
//-----------------------------------------------------------------------------
// LighTransportData
// LightTransportData
public struct LighTransportData
public struct LightTransportData
[SurfaceDataAttributes("", false, true)]
public Vector3 emissiveColor;
public Vector3 emissiveColor; // HDR value
};
public class RenderLoop : Object

63
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Builtin/BuiltinData.cs.hlsl


#define DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET (107)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Builtin.LighTransportData: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Builtin.LightTransportData: static fields
#define DEBUGVIEW_BUILTIN_LIGHTRANSPORTDATA_DIFFUSE_COLOR (120)
#define DEBUGVIEW_BUILTIN_LIGHTRANSPORTDATA_EMISSIVE_COLOR (121)
#define DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_DIFFUSE_COLOR (120)
#define DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_EMISSIVE_COLOR (121)
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Builtin.BuiltinData
// PackingRules = Exact

float depthOffset;
};
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Builtin.LighTransportData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Builtin.LightTransportData
struct LighTransportData
struct LightTransportData
//
// Debug functions
//
void GetGeneratedBuiltinDataDebug(uint paramId, BuiltinData builtindata, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_BUILTIN_BUILTINDATA_OPACITY:
result = builtindata.opacity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_BAKE_DIFFUSE_LIGHTING:
result = builtindata.bakeDiffuseLighting;
needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_COLOR:
result = builtindata.emissiveColor;
needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_INTENSITY:
result = builtindata.emissiveIntensity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_VELOCITY:
result = float3(builtindata.velocity, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION:
result = float3(builtindata.distortion, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR:
result = builtindata.distortionBlur.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET:
result = builtindata.depthOffset.xxx;
break;
}
}
//
// Debug functions
//
void GetGeneratedLightTransportDataDebug(uint paramId, LightTransportData lighttransportdata, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_DIFFUSE_COLOR:
result = lighttransportdata.diffuseColor;
needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_EMISSIVE_COLOR:
result = lighttransportdata.emissiveColor;
break;
}
}
#endif

30
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Builtin/BuiltinData.hlsl


// Note: These parameters can be store in GBuffer if the writer wants
//-----------------------------------------------------------------------------
//TODO: return this original relative path include after fixing a bug in Unity side
//#include "BuiltinData.cs.hlsl"
#include "../../Material/Builtin/BuiltinData.cs.hlsl"
#include "BuiltinData.cs.hlsl"
//-----------------------------------------------------------------------------
// common Encode/Decode functions

void GetBuiltinDataDebug(uint paramId, BuiltinData builtinData, inout float3 result, inout bool needLinearToSRGB)
{
GetGeneratedBuiltinDataDebug(paramId, builtinData, result, needLinearToSRGB);
case DEBUGVIEW_BUILTIN_BUILTINDATA_OPACITY:
result = builtinData.opacity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_BAKE_DIFFUSE_LIGHTING:
// TODO: require a remap
// TODO: we should not gamma correct, but easier to debug for now without correct high range value

// emissiveColor is premultiply by emissive intensity
result = (builtinData.emissiveColor / builtinData.emissiveIntensity); needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_INTENSITY:
result = builtinData.emissiveIntensity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_VELOCITY:
result = float3(builtinData.velocity, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION:
result = float3(builtinData.distortion, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR:
result = builtinData.distortionBlur.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET:
result = builtinData.depthOffset.xxx * 10.0; // * 10 assuming 1 unity unity is 1m
break;

void GetLighTransportDataDebug(uint paramId, LighTransportData lightTransportData, inout float3 result, inout bool needLinearToSRGB)
void GetLightTransportDataDebug(uint paramId, LightTransportData lightTransportData, inout float3 result, inout bool needLinearToSRGB)
GetGeneratedLightTransportDataDebug(paramId, lightTransportData, result, needLinearToSRGB);
case DEBUGVIEW_BUILTIN_LIGHTRANSPORTDATA_DIFFUSE_COLOR:
result = lightTransportData.diffuseColor; needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_LIGHTRANSPORTDATA_EMISSIVE_COLOR:
case DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_EMISSIVE_COLOR:
// TODO: Need a tonemap ?
result = lightTransportData.emissiveColor;
break;

17
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


[GenerateHLSL(PackingRules.Exact, false, true, 1000)]
public struct SurfaceData
{
[SurfaceDataAttributes("Base Color")]
[SurfaceDataAttributes("Base Color", false, true)]
[SurfaceDataAttributes("Normal")]
[SurfaceDataAttributes("Normal", true)]
public Vector3 normalWS;
[SurfaceDataAttributes("Smoothness")]
public float perceptualSmoothness;

// MaterialId dependent attribute
// standard
[SurfaceDataAttributes("Tangent")]
[SurfaceDataAttributes("Tangent", true)]
public Vector3 tangentWS;
[SurfaceDataAttributes("Anisotropy")]
public float anisotropy; // anisotropic ratio(0->no isotropic; 1->full anisotropy in tangent direction)

public int subsurfaceProfile;
// Clearcoat
[SurfaceDataAttributes("Coat Normal")]
[SurfaceDataAttributes("Coat Normal", true)]
[SurfaceDataAttributes("Specular Color")]
[SurfaceDataAttributes("Specular Color", false, true)]
public Vector3 specularColor;
};

[GenerateHLSL(PackingRules.Exact, false, true, 1030)]
public struct BSDFData
{
[SurfaceDataAttributes("", false, true)]
public Vector3 diffuseColor;
public Vector3 fresnel0;

[SurfaceDataAttributes("", true)]
public float materialId;
public int materialId;
[SurfaceDataAttributes("", true)]
[SurfaceDataAttributes("", true)]
public Vector3 bitangentWS;
public float roughnessT;
public float roughnessB;

public Vector3 transmittance;
// Clearcoat
[SurfaceDataAttributes("", true)]
public Vector3 coatNormalWS;
public float coatRoughness;

130
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


float3 normalWS;
float perceptualRoughness;
float roughness;
float materialId;
int materialId;
float3 tangentWS;
float3 bitangentWS;
float roughnessT;

float3 coatNormalWS;
float coatRoughness;
};
//
// Debug functions
//
void GetGeneratedSurfaceDataDebug(uint paramId, SurfaceData surfacedata, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_LIT_SURFACEDATA_BASE_COLOR:
result = surfacedata.baseColor;
needLinearToSRGB = true;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_OCCLUSION:
result = surfacedata.specularOcclusion.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_NORMAL_WS:
result = surfacedata.normalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUAL_SMOOTHNESS:
result = surfacedata.perceptualSmoothness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_MATERIAL_ID:
result = GetIndexColor(surfacedata.materialId);
break;
case DEBUGVIEW_LIT_SURFACEDATA_AMBIENT_OCCLUSION:
result = surfacedata.ambientOcclusion.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_TANGENT_WS:
result = surfacedata.tangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_ANISOTROPY:
result = surfacedata.anisotropy.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_METALLIC:
result = surfacedata.metallic.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR:
result = surfacedata.specular.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACE_RADIUS:
result = surfacedata.subsurfaceRadius.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_THICKNESS:
result = surfacedata.thickness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACE_PROFILE:
result = GetIndexColor(surfacedata.subsurfaceProfile);
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS:
result = surfacedata.coatNormalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_PERCEPTUAL_SMOOTHNESS:
result = surfacedata.coatPerceptualSmoothness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_COLOR:
result = surfacedata.specularColor;
needLinearToSRGB = true;
break;
}
}
//
// Debug functions
//
void GetGeneratedBSDFDataDebug(uint paramId, BSDFData bsdfdata, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_LIT_BSDFDATA_DIFFUSE_COLOR:
result = bsdfdata.diffuseColor;
needLinearToSRGB = true;
break;
case DEBUGVIEW_LIT_BSDFDATA_FRESNEL0:
result = bsdfdata.fresnel0;
break;
case DEBUGVIEW_LIT_BSDFDATA_SPECULAR_OCCLUSION:
result = bsdfdata.specularOcclusion.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_NORMAL_WS:
result = bsdfdata.normalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_PERCEPTUAL_ROUGHNESS:
result = bsdfdata.perceptualRoughness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS:
result = bsdfdata.roughness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_MATERIAL_ID:
result = GetIndexColor(bsdfdata.materialId);
break;
case DEBUGVIEW_LIT_BSDFDATA_TANGENT_WS:
result = bsdfdata.tangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_BITANGENT_WS:
result = bsdfdata.bitangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_T:
result = bsdfdata.roughnessT.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_B:
result = bsdfdata.roughnessB.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_ANISOTROPY:
result = bsdfdata.anisotropy.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACE_RADIUS:
result = bsdfdata.subsurfaceRadius.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_THICKNESS:
result = bsdfdata.thickness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACE_PROFILE:
result = GetIndexColor(bsdfdata.subsurfaceProfile);
break;
case DEBUGVIEW_LIT_BSDFDATA_ENABLE_TRANSMISSION:
result = (bsdfdata.enableTransmission) ? float3(1.0, 1.0, 1.0) : float3(0.0, 0.0, 0.0);
break;
case DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE:
result = bsdfdata.transmittance;
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS:
result = bsdfdata.coatNormalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS:
result = bsdfdata.coatRoughness.xxx;
break;
}
}
#endif

106
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


void GetSurfaceDataDebug(uint paramId, SurfaceData surfaceData, inout float3 result, inout bool needLinearToSRGB)
{
GetGeneratedSurfaceDataDebug(paramId, surfaceData, result, needLinearToSRGB);
case DEBUGVIEW_LIT_SURFACEDATA_BASE_COLOR:
result = surfaceData.baseColor; needLinearToSRGB = true;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_OCCLUSION:
result = surfaceData.specularOcclusion.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_NORMAL_WS:
result = surfaceData.normalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUAL_SMOOTHNESS:
result = surfaceData.perceptualSmoothness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_MATERIAL_ID:
result = GetIndexColor(surfaceData.materialId);
break;
case DEBUGVIEW_LIT_SURFACEDATA_AMBIENT_OCCLUSION:
result = surfaceData.ambientOcclusion.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_TANGENT_WS:
result = surfaceData.tangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_ANISOTROPY:
result = surfaceData.anisotropy.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_METALLIC:
result = surfaceData.metallic.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACE_RADIUS:
result = surfaceData.subsurfaceRadius.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_THICKNESS:
result = surfaceData.thickness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACE_PROFILE:
result = GetIndexColor(surfaceData.subsurfaceProfile);
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS:
result = surfaceData.coatNormalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_PERCEPTUAL_SMOOTHNESS:
result = surfaceData.coatPerceptualSmoothness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_COLOR:
result = surfaceData.specularColor; needLinearToSRGB = true;
break;
switch (paramId)
{
case DEBUGVIEW_LIT_BSDFDATA_DIFFUSE_COLOR:
result = bsdfData.diffuseColor; needLinearToSRGB = true;
break;
case DEBUGVIEW_LIT_BSDFDATA_FRESNEL0:
result = bsdfData.fresnel0;
break;
case DEBUGVIEW_LIT_BSDFDATA_SPECULAR_OCCLUSION:
result = bsdfData.specularOcclusion.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_NORMAL_WS:
result = bsdfData.normalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_PERCEPTUAL_ROUGHNESS:
result = bsdfData.perceptualRoughness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS:
result = bsdfData.roughness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_MATERIAL_ID:
result = GetIndexColor(bsdfData.materialId);
break;
case DEBUGVIEW_LIT_BSDFDATA_TANGENT_WS:
result = bsdfData.tangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_BITANGENT_WS:
result = bsdfData.bitangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_T:
result = bsdfData.roughnessT.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_B:
result = bsdfData.roughnessB.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_ANISOTROPY:
result = bsdfData.anisotropy.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACE_RADIUS:
result = bsdfData.subsurfaceRadius.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_THICKNESS:
result = bsdfData.thickness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACE_PROFILE:
result = GetIndexColor(bsdfData.subsurfaceProfile);
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS:
result = bsdfData.coatNormalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS:
result = bsdfData.coatRoughness.xxx;
break;
}
GetGeneratedBSDFDataDebug(paramId, bsdfData, result, needLinearToSRGB);
}
//-----------------------------------------------------------------------------

// light transport functions
//-----------------------------------------------------------------------------
LighTransportData GetLightTransportData(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData)
LightTransportData GetLightTransportData(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData)
LighTransportData lightTransportData;
LightTransportData lightTransportData;
// diffuseColor for lightmapping should basically be diffuse color.
// But rough metals (black diffuse) still scatter quite a lot of light around, so

3
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.cs


[GenerateHLSL(PackingRules.Exact, false, true, 1100)]
public struct SurfaceData
{
[SurfaceDataAttributes("Color")]
[SurfaceDataAttributes("Color", false, true)]
public Vector3 color;
};

[GenerateHLSL(PackingRules.Exact, false, true, 1130)]
public struct BSDFData
{
[SurfaceDataAttributes("", false, true)]
public Vector3 color;
};
}

28
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.cs.hlsl


float3 color;
};
//
// Debug functions
//
void GetGeneratedSurfaceDataDebug(uint paramId, SurfaceData surfacedata, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_UNLIT_SURFACEDATA_COLOR:
result = surfacedata.color;
needLinearToSRGB = true;
break;
}
}
//
// Debug functions
//
void GetGeneratedBSDFDataDebug(uint paramId, BSDFData bsdfdata, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_UNLIT_BSDFDATA_COLOR:
result = bsdfdata.color;
needLinearToSRGB = true;
break;
}
}
#endif

26
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.hlsl


}
//-----------------------------------------------------------------------------
// No light evaluation, this is unlit
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
switch (paramId)
{
case DEBUGVIEW_UNLIT_SURFACEDATA_COLOR:
result = surfaceData.color; needLinearToSRGB = true;
break;
}
GetGeneratedSurfaceDataDebug(paramId, surfaceData, result, needLinearToSRGB);
switch (paramId)
{
case DEBUGVIEW_UNLIT_SURFACEDATA_COLOR:
result = bsdfData.color; needLinearToSRGB = true;
break;
}
GetGeneratedBSDFDataDebug(paramId, bsdfData, result, needLinearToSRGB);
LighTransportData GetLightTransportData(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData)
//-----------------------------------------------------------------------------
// No light evaluation, this is unlit
//-----------------------------------------------------------------------------
LightTransportData GetLightTransportData(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData)
LighTransportData lightTransportData;
LightTransportData lightTransportData;
lightTransportData.diffuseColor = float3(0.0, 0.0, 0.0);
lightTransportData.emissiveColor = builtinData.emissiveColor;

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl


GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
LighTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData);
LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData);
// This shader is call two time. Once for getting emissiveColor, the other time to get diffuseColor
// We use unity_MetaFragmentControl to make the distinction.

18
Assets/ScriptableRenderPipeline/HDRenderPipeline/Shadow/ShadowBase.cs.hlsl


//
float4x4 GetWorldToShadow(ShadowData value)
{
return value.worldToShadow;
return value.worldToShadow;
return value.scaleOffset;
return value.scaleOffset;
return value.texelSizeRcp;
return value.texelSizeRcp;
return value.id;
return value.id;
return value.shadowType;
return value.shadowType;
return value.payloadOffset;
return value.payloadOffset;
return value.lightType;
return value.lightType;
return value.bias;
return value.bias;
return value.quality;
return value.quality;
}

14
Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl


// Example: unL for unormalized light vector
// use capital letter for regular vector, vector are always pointing outward the current pixel position (ready for lighting equation)
// capital letter mean the vector is normalize, unless we put un in front of it.
// capital letter mean the vector is normalize, unless we put 'un' in front of it.
// V: View vector (no eye vector)
// L: Light vector
// N: Normal vector

#define FLT_MIN 1.175494351e-38 // Minimum representable positive floating-point number
#define FLT_MAX 3.402823466e+38 // Maximum representable floating-point number
#define MERGE_NAME(X, Y) X##Y
float DegToRad(float deg)
{
return deg * PI / 180.0;

return (x < 0.0) ? -t0 : t0;
}
// Same smoothstep except it assume 0, 1 interval for x
// Same as smoothstep except it assume 0, 1 interval for x
float smoothstep01(float x)
{
return x * x * (3.0 - (2.0 * x));

// Texture format sampling
// ----------------------------------------------------------------------------
float2 DirectionToLatLongCoordinate(float3 dir_in)
float2 DirectionToLatLongCoordinate(float3 unDir)
float3 dir = normalize(dir_in);
float3 dir = normalize(unDir);
// coordinate frame is (-Z, X) meaning negative Z is primary axis and X is secondary axis.
return float2(1.0 - 0.5 * INV_PI * atan2(dir.x, -dir.z), asin(dir.y) * INV_PI + 0.5);
}

posInput.depthVS = positionCS.w;
posInput.depthRaw = positionCS.z / positionCS.w;
}
// ----------------------------------------------------------------------------
// Misc utilities
// ----------------------------------------------------------------------------
// Generates a triangle in homogeneous clip space, s.t.
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).

68
Assets/ScriptableRenderPipeline/fptl/LightDefinitions.cs.hlsl


//
float GetPenumbra(SFiniteLightData value)
{
return value.penumbra;
return value.penumbra;
return value.flags;
return value.flags;
return value.lightType;
return value.lightType;
return value.lightModel;
return value.lightModel;
return value.lightPos;
return value.lightPos;
return value.lightIntensity;
return value.lightIntensity;
return value.lightAxisX;
return value.lightAxisX;
return value.recipRange;
return value.recipRange;
return value.lightAxisY;
return value.lightAxisY;
return value.radiusSq;
return value.radiusSq;
return value.lightAxisZ;
return value.lightAxisZ;
return value.cotan;
return value.cotan;
return value.color;
return value.color;
return value.sliceIndex;
return value.sliceIndex;
return value.boxInnerDist;
return value.boxInnerDist;
return value.decodeExp;
return value.decodeExp;
return value.boxInvRange;
return value.boxInvRange;
return value.shadowLightIndex;
return value.shadowLightIndex;
return value.localCubeCapturePoint;
return value.localCubeCapturePoint;
return value.probeBlendDistance;
return value.probeBlendDistance;
}
//

{
return value.boxAxisX;
return value.boxAxisX;
return value.boxAxisY;
return value.boxAxisY;
return value.boxAxisZ;
return value.boxAxisZ;
return value.center;
return value.center;
return value.scaleXY;
return value.scaleXY;
return value.radius;
return value.radius;
}
//

{
return value.color;
return value.color;
return value.intensity;
return value.intensity;
return value.lightAxisX;
return value.lightAxisX;
return value.shadowLightIndex;
return value.shadowLightIndex;
return value.lightAxisY;
return value.lightAxisY;
return value.pad0;
return value.pad0;
return value.lightAxisZ;
return value.lightAxisZ;
return value.pad1;
return value.pad1;
}

9
Assets/ShaderGenerator/Editor/CSharpToHLSL.cs


}
}
foreach (var gen in it.Value)
{
if (gen.hasStatics && gen.hasFields && gen.needParamDebug)
{
writer.Write(gen.EmitFunctions() + "\n");
}
}
}
}
}

126
Assets/ShaderGenerator/Editor/ShaderTypeGeneration.cs


public Accessor accessor;
};
class DebugFieldInfo
{
public DebugFieldInfo(string defineName, string fieldName, Type fieldType, bool isDirection, bool isSRGB)
{
this.defineName = defineName;
this.fieldName = fieldName;
this.fieldType = fieldType;
this.isDirection = isDirection;
this.isSRGB = isSRGB;
}
public string defineName;
public string fieldName;
public Type fieldType;
public bool isDirection;
public bool isSRGB;
}
void Error(string error)
{
if (errors == null)

return shaderText;
}
public string EmitFunctions()
{
string shaderText = string.Empty;
// In case users ask for debug functions
if (!attr.needParamDebug)
return shaderText;
// Specific to HDRenderPipeline
string lowerStructName = type.Name.ToLower();
shaderText += "//\n";
shaderText += "// Debug functions\n";
shaderText += "//\n";
shaderText += "void GetGenerated" + type.Name + "Debug(uint paramId, " + type.Name + " " + lowerStructName + ", inout float3 result, inout bool needLinearToSRGB)\n";
shaderText += "{\n";
shaderText += " switch (paramId)\n";
shaderText += " {\n";
foreach (var debugField in m_DebugFields)
{
shaderText += " case " + debugField.defineName + ":\n";
if (debugField.fieldType == typeof(float))
{
if (debugField.isDirection)
{
shaderText += " result = " + lowerStructName + "." + debugField.fieldName + ".xxx * 0.5 + 0.5;\n";
}
else
{
shaderText += " result = " + lowerStructName + "." + debugField.fieldName + ".xxx;\n";
}
}
else if (debugField.fieldType == typeof(Vector2))
{
shaderText += " result = float3(" + lowerStructName + "." + debugField.fieldName + ", 0.0);\n";
}
else if (debugField.fieldType == typeof(Vector3))
{
if (debugField.isDirection)
{
shaderText += " result = " + lowerStructName + "." + debugField.fieldName + " * 0.5 + 0.5;\n";
}
else
{
shaderText += " result = " + lowerStructName + "." + debugField.fieldName + ";\n";
}
}
else if (debugField.fieldType == typeof(Vector4))
{
shaderText += " result = " + lowerStructName + "." + debugField.fieldName + ".xyz;\n";
}
else if (debugField.fieldType == typeof(bool))
{
shaderText += " result = (" + lowerStructName + "." + debugField.fieldName + ") ? float3(1.0, 1.0, 1.0) : float3(0.0, 0.0, 0.0);\n";
}
else if (debugField.fieldType == typeof(uint) || debugField.fieldType == typeof(int))
{
shaderText += " result = GetIndexColor(" + lowerStructName + "." + debugField.fieldName + ");\n";
}
else // This case left is suppose to be a complex structure. Either we don't support it or it is an enum. Consider it is an enum with GetIndexColor, user can override it if he want.
{
shaderText += " result = GetIndexColor(" + lowerStructName + "." + debugField.fieldName + ");\n";
}
if (debugField.isSRGB)
{
shaderText += " needLinearToSRGB = true;\n";
}
shaderText += " break;\n";
}
shaderText += " }\n";
shaderText += "}\n";
return shaderText;
}
// This function is a helper to follow unity convertion
// when converting fooBar ro FOO_BAR
// This function is a helper to follow unity convention
// when converting fooBar to FOO_BAR
string InsertUnderscore(string name)
{
for (int i = 1; i < name.Length; i++)

FieldInfo[] fields = type.GetFields();
m_ShaderFields = new List<ShaderFieldInfo>();
m_DebugFields = new List<DebugFieldInfo>();
if (type.IsEnum)
{

continue;
}
if (attr.needParamDefines)
if (attr.needParamDebug)
m_Statics[("DEBUGVIEW_" + subNamespace + "_" + type.Name + "_" + name).ToUpper()] = Convert.ToString(attr.paramDefinesStart + debugCounter++);
string defineName = ("DEBUGVIEW_" + subNamespace + "_" + type.Name + "_" + name).ToUpper();
m_Statics[defineName] = Convert.ToString(attr.paramDefinesStart + debugCounter++);
bool isDirection = false;
bool sRGBDisplay = false;
// Check if the display name have been override by the users
if (Attribute.IsDefined(field, typeof(SurfaceDataAttributes)))
{
var propertyAttr = (SurfaceDataAttributes[])field.GetCustomAttributes(typeof(SurfaceDataAttributes), false);
isDirection = propertyAttr[0].isDirection;
sRGBDisplay = propertyAttr[0].sRGBDisplay;
}
m_DebugFields.Add(new DebugFieldInfo(defineName, field.Name, field.FieldType, isDirection, sRGBDisplay));
}
if (field.FieldType.IsPrimitive)

{
get { return attr.needAccessors; }
}
public bool needParamDebug
{
get { return attr.needParamDebug; }
}
public Type type;
public GenerateHLSL attr;

Dictionary<string, string> m_Statics;
List<ShaderFieldInfo> m_ShaderFields;
List<ShaderFieldInfo> m_PackedFields;
List<DebugFieldInfo> m_DebugFields;
}
}

12
Assets/ShaderGenerator/ShaderGeneratorAttributes.cs


{
public PackingRules packingRules;
public bool needAccessors; // Whether or not to generate the accessors
public bool needParamDefines; // Wheter or not to generate define for each parameters of the struc
public bool needParamDebug; // // Whether or not to generate define for each field of the struct + debug function (use in HDRenderPipeline)
public GenerateHLSL(PackingRules rules = PackingRules.Exact, bool needAccessors = true, bool needParamDefines = false, int paramDefinesStart = 1)
public GenerateHLSL(PackingRules rules = PackingRules.Exact, bool needAccessors = true, bool needParamDebug = false, int paramDefinesStart = 1)
this.needParamDefines = needParamDefines;
this.needParamDebug = needParamDebug;
this.paramDefinesStart = paramDefinesStart;
}
}

{
public string displayName;
public bool isDirection;
public bool sRGBDisplay;
public SurfaceDataAttributes(string displayName = "")
public SurfaceDataAttributes(string displayName = "", bool isDirection = false, bool sRGBDisplay = false)
this.isDirection = isDirection;
this.sRGBDisplay = sRGBDisplay;
}
}
}
正在加载...
取消
保存