浏览代码

First draft for aniso as materialId

/main
sebastienlagarde 7 年前
当前提交
ea1d4cf6
共有 8 个文件被更改,包括 53 次插入100 次删除
  1. 6
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  2. 10
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Deferred.compute
  3. 4
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
  5. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  6. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  7. 76
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  8. 26
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitReference.hlsl

6
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs. Please don't edit by hand.
//
#ifndef LIGHTDEFINITION_CS_HLSL

#define GPULIGHTTYPE_PROJECTOR_PYRAMID (4)
#define GPULIGHTTYPE_LINE (5)
#define GPULIGHTTYPE_RECTANGLE (6)
#define GPULIGHTTYPE_SPHERE (7)
#define GPULIGHTTYPE_DISK (8)
#define GPULIGHTTYPE_HEMISPHERE (9)
#define GPULIGHTTYPE_CYLINDER (10)
//
// UnityEngine.Experimental.Rendering.HDPipeline.EnvShapeType: static fields

10
ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Deferred.compute


#pragma kernel Deferred_Indirect_Fptl_Variant23 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant23 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=23
#pragma kernel Deferred_Indirect_Fptl_Variant24 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant24 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=24
#pragma kernel Deferred_Indirect_Fptl_Variant25 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant25 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=25
#pragma kernel Deferred_Indirect_Fptl_Variant26 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant26 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=26
#pragma kernel Deferred_Indirect_Fptl_Variant27 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant27 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=27
#pragma kernel Deferred_Indirect_Fptl_Variant28 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant28 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=28
#pragma kernel Deferred_Indirect_Fptl_Variant29 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant29 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=29
#pragma kernel Deferred_Indirect_Fptl_Variant30 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant30 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=30
/* Tag: SUPPORT_COMPUTE_CLUSTER_OPAQUE - Uncomment this if you want to do cluster opaque with compute shader (by default we support only fptl on opaque)
#pragma kernel Deferred_Indirect_Clustered_Variant0 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant0 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=0

#pragma kernel Deferred_Indirect_Clustered_Variant23 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant23 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=23
#pragma kernel Deferred_Indirect_Clustered_Variant24 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant24 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=24
#pragma kernel Deferred_Indirect_Clustered_Variant25 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant25 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=25
#pragma kernel Deferred_Indirect_Clustered_Variant26 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant26 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=26
#pragma kernel Deferred_Indirect_Clustered_Variant27 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant27 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=27
#pragma kernel Deferred_Indirect_Clustered_Variant28 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant28 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=28
#pragma kernel Deferred_Indirect_Clustered_Variant29 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant29 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=29
#pragma kernel Deferred_Indirect_Clustered_Variant30 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Clustered_Variant30 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=30
*/
#define LIGHTLOOP_TILE_PASS 1

4
ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


using UnityEngine.Rendering;
using UnityEngine.Rendering;
using System.Collections.Generic;
using System;

public static int s_TileSizeClustered = 32;
// feature variants
public static int s_NumFeatureVariants = 31;
public static int s_NumFeatureVariants = 26;
// Following define the maximum number of bits use in each feature category.
public static uint s_LightFeatureMaskFlags = 0xFF00;

4
ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs. Please don't edit by hand.
//
#ifndef TILEPASS_CS_HLSL

#define USE_LEFT_HAND_CAMERA_SPACE (1)
#define TILE_SIZE_FPTL (16)
#define TILE_SIZE_CLUSTERED (32)
#define NUM_FEATURE_VARIANTS (31)
#define NUM_FEATURE_VARIANTS (26)
#define LIGHT_FEATURE_MASK_FLAGS (65280)
#define MATERIAL_FEATURE_MASK_FLAGS (255)

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


{
LitSSS = 0,
LitStandard = 1,
LitClearCoat = 2,
LitUnused = 3,
// We don't store any materialId for aniso but instead deduce it from LitStandard + value of specular + anisotropy parameters
// Consequence is that when querying materialId alone, it will read 2 RT and not only one. This may be a performance hit when only materialId is desired (like in material classification pass)
// Alternative is to use a materialId slot, if any are available.
LitAniso = 4,
LitAniso = 2,
LitClearCoat = 3,
LitSpecular = 5,
LitSpecular = 4,
};
// If change, be sure it match what is done in Lit.hlsl: MaterialFeatureFlagsFromGBuffer

{
LitSSS = 1 << MaterialId.LitSSS,
LitStandard = 1 << MaterialId.LitStandard,
LitAniso = 1 << MaterialId.LitAniso,
LitUnused = 1 << MaterialId.LitUnused,
LitAniso = 1 << MaterialId.LitAniso,
};
[GenerateHLSL]

14
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs. Please don't edit by hand.
//
#ifndef LIT_CS_HLSL

//
#define MATERIALID_LIT_SSS (0)
#define MATERIALID_LIT_STANDARD (1)
#define MATERIALID_LIT_CLEAR_COAT (2)
#define MATERIALID_LIT_UNUSED (3)
#define MATERIALID_LIT_ANISO (4)
#define MATERIALID_LIT_SPECULAR (5)
#define MATERIALID_LIT_ANISO (2)
#define MATERIALID_LIT_CLEAR_COAT (3)
#define MATERIALID_LIT_SPECULAR (4)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+MaterialFeatureFlags: static fields

#define MATERIALFEATUREFLAGS_LIT_CLEAR_COAT (4)
#define MATERIALFEATUREFLAGS_LIT_UNUSED (8)
#define MATERIALFEATUREFLAGS_LIT_ANISO (16)
#define MATERIALFEATUREFLAGS_LIT_ANISO (4)
#define MATERIALFEATUREFLAGS_LIT_CLEAR_COAT (8)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+StandardDefinitions: static fields

76
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


/* 23 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_PUNCTUAL | LIGHTFEATUREFLAGS_ENV | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT,
/* 24 */ LIGHT_FEATURE_MASK_FLAGS | MATERIALFEATUREFLAGS_LIT_CLEAR_COAT,
// Future usage
/* 25 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_PUNCTUAL | MATERIALFEATUREFLAGS_LIT_UNUSED,
/* 26 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_AREA | MATERIALFEATUREFLAGS_LIT_UNUSED,
/* 27 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_ENV | MATERIALFEATUREFLAGS_LIT_UNUSED,
/* 28 */ LIGHTFEATUREFLAGS_SKY | LIGHTFEATUREFLAGS_DIRECTIONAL | LIGHTFEATUREFLAGS_PUNCTUAL | LIGHTFEATUREFLAGS_ENV | MATERIALFEATUREFLAGS_LIT_UNUSED,
/* 29 */ LIGHT_FEATURE_MASK_FLAGS | MATERIALFEATUREFLAGS_LIT_UNUSED,
/* 30 */ LIGHT_FEATURE_MASK_FLAGS | MATERIAL_FEATURE_MASK_FLAGS, // Catch all case with MATERIAL_FEATURE_MASK_FLAGS is needed in case we disable material classification
/* 25 */ LIGHT_FEATURE_MASK_FLAGS | MATERIAL_FEATURE_MASK_FLAGS, // Catch all case with MATERIAL_FEATURE_MASK_FLAGS is needed in case we disable material classification
};
uint FeatureFlagsToTileVariant(uint featureFlags)

}
else if (surfaceData.materialId == MATERIALID_LIT_ANISO)
{
outGBuffer1.a = PackMaterialId(MATERIALID_LIT_STANDARD); // Encode MATERIALID_LIT_SPECULAR as MATERIALID_LIT_STANDARD + GBUFFER_LIT_STANDARD_ANISOTROPIC_ID value in GBuffer2
// Encode tangent on 16bit with oct compression
float2 octTangentWS = PackNormalOctEncode(surfaceData.tangentWS);
outGBuffer2 = float4(octTangentWS * 0.5 + 0.5, surfaceData.anisotropy, PackFloatInt8bit(surfaceData.metallic, GBUFFER_LIT_STANDARD_ANISOTROPIC_ID, 4.0));

// The material features system for material classification must allow compile time optimization (i.e everything should be static)
// Note that as we store materialId for Aniso based on content of RT2 we need to add few extra condition.
// The code is also call from MaterialFeatureFlagsFromGBuffer, so must work fully dynamic if featureFlags is 0xFFFFFFFF
int supportsStandard = (featureFlags & (MATERIALFEATUREFLAGS_LIT_STANDARD | MATERIALFEATUREFLAGS_LIT_ANISO)) != 0;
int supportsSSS = (featureFlags & (MATERIALFEATUREFLAGS_LIT_SSS)) != 0;
int supportClearCoat = (featureFlags & (MATERIALFEATUREFLAGS_LIT_CLEAR_COAT)) != 0;
int supportsStandard = (featureFlags & MATERIALFEATUREFLAGS_LIT_STANDARD) != 0;
int supportsAniso = (featureFlags & MATERIALFEATUREFLAGS_LIT_ANISO) != 0;
int supportsSSS = (featureFlags & MATERIALFEATUREFLAGS_LIT_SSS) != 0;
int supportClearCoat = (featureFlags & MATERIALFEATUREFLAGS_LIT_CLEAR_COAT) != 0;
if (supportsStandard + supportsSSS + supportClearCoat > 1)
if (supportsStandard + supportsSSS + supportsAniso + supportClearCoat > 1)
{
// only fetch materialid if it is not statically known from feature flags
bsdfData.materialId = UnpackMaterialId(inGBuffer1.a);

// materialid is statically known. this allows the compiler to eliminate a lot of code.
if (supportsStandard)
bsdfData.materialId = MATERIALID_LIT_STANDARD;
if (supportsAniso)
bsdfData.materialId = MATERIALID_LIT_ANISO;
else if (supportsSSS)
bsdfData.materialId = MATERIALID_LIT_SSS;
else

float metallic;
int materialIdExtent;
UnpackFloatInt8bit(inGBuffer2.a, 4.0, metallic, materialIdExtent);
float anisotropy = inGBuffer2.b;
if (featureFlags & (MATERIAL_FEATURE_MASK_FLAGS) == MATERIALFEATUREFLAGS_LIT_STANDARD)
if (materialIdExtent == GBUFFER_LIT_STANDARD_SPECULAR_COLOR_ID)
if (materialIdExtent == GBUFFER_LIT_STANDARD_SPECULAR_COLOR_ID)
{
// Note: Specular is not a material id but just a way to parameterize the standard materialid, thus we reset materialId to MATERIALID_LIT_STANDARD
// For material classification it will be consider as Standard as well, thus no need to create special case
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = inGBuffer2.rgb;
}
else
{
FillMaterialIdStandardData(baseColor, metallic, bsdfData);
}
// Note: Specular is not a material id but just a way to parameterize the standard materialid, thus we reset materialId to MATERIALID_LIT_STANDARD
// For material classification it will be consider as Standard as well, thus no need to create special case
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = inGBuffer2.rgb;
else if (featureFlags & (MATERIAL_FEATURE_MASK_FLAGS) == MATERIALFEATUREFLAGS_LIT_ANISO)
else // GBUFFER_LIT_STANDARD_REGULAR_ID
bsdfData.materialId = MATERIALID_LIT_ANISO;
float3 tangentWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0));
FillMaterialIdAnisoData(bsdfData.roughness, bsdfData.normalWS, tangentWS, anisotropy, bsdfData);
}
else // either MATERIAL_FEATURE_MASK_FLAGS or MATERIALFEATUREFLAGS_LIT_STANDARD | MATERIALFEATUREFLAGS_LIT_ANISO
{
if (materialIdExtent == GBUFFER_LIT_STANDARD_SPECULAR_COLOR_ID)
{
// Note: Specular is not a material id but just a way to parameterize the standard materialid, thus we reset materialId to MATERIALID_LIT_STANDARD
// For material classification it will be consider as Standard as well, thus no need to create special case
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = inGBuffer2.rgb;
}
else if (materialIdExtent == GBUFFER_LIT_STANDARD_ANISOTROPIC_ID)
{
bsdfData.materialId = MATERIALID_LIT_ANISO;
FillMaterialIdStandardData(baseColor, metallic, bsdfData);
float3 tangentWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0));
FillMaterialIdAnisoData(bsdfData.roughness, bsdfData.normalWS, tangentWS, anisotropy, bsdfData);
}
else // GBUFFER_LIT_STANDARD_REGULAR_ID
{
FillMaterialIdStandardData(baseColor, metallic, bsdfData);
}
}
}
else if (bsdfData.materialId == MATERIALID_LIT_SSS)

int subsurfaceProfile = UnpackByte(inGBuffer2.w);
FillMaterialIdSSSData(baseColor, subsurfaceProfile, subsurfaceRadius, thickness, bsdfData);
}
else if (bsdfData.materialId == MATERIALID_LIT_ANISO)
{
float metallic;
int unused;
UnpackFloatInt8bit(inGBuffer2.a, 4.0, metallic, unused);
float anisotropy = inGBuffer2.b;
FillMaterialIdStandardData(baseColor, metallic, bsdfData);
float3 tangentWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0));
FillMaterialIdAnisoData(bsdfData.roughness, bsdfData.normalWS, tangentWS, anisotropy, bsdfData);
}
else //if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{

26
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitReference.hlsl


switch (lightData.lightType)
{
case GPULIGHTTYPE_SPHERE:
SampleSphere(u, localToWorld, lightData.size.x, lightPdf, P, Ns);
break;
case GPULIGHTTYPE_HEMISPHERE:
SampleHemisphere(u, localToWorld, lightData.size.x, lightPdf, P, Ns);
break;
case GPULIGHTTYPE_CYLINDER:
SampleCylinder(u, localToWorld, lightData.size.x, lightData.size.y, lightPdf, P, Ns);
break;
//case GPULIGHTTYPE_SPHERE:
// SampleSphere(u, localToWorld, lightData.size.x, lightPdf, P, Ns);
// break;
//case GPULIGHTTYPE_HEMISPHERE:
// SampleHemisphere(u, localToWorld, lightData.size.x, lightPdf, P, Ns);
// break;
//case GPULIGHTTYPE_CYLINDER:
// SampleCylinder(u, localToWorld, lightData.size.x, lightData.size.y, lightPdf, P, Ns);
// break;
case GPULIGHTTYPE_DISK:
SampleDisk(u, localToWorld, lightData.size.x, lightPdf, P, Ns);
break;
//case GPULIGHTTYPE_DISK:
// SampleDisk(u, localToWorld, lightData.size.x, lightPdf, P, Ns);
// break;
// case GPULIGHTTYPE_LINE: handled by a separate function.
}

}
return acc / sampleCount;
}
}
正在加载...
取消
保存