提交 ce25ddb3 编写于 作者: timchen1002's avatar timchen1002

update

上级 11e04252
......@@ -129,7 +129,7 @@ public partial class CameraRenderer
{
enableDynamicBatching = useDynamicBatching,
enableInstancing = useGPUInstancing,
perObjectData = PerObjectData.Lightmaps | PerObjectData.ShadowMask | PerObjectData.LightProbe | PerObjectData.OcclusionProbe | PerObjectData.LightProbeProxyVolume,
perObjectData = PerObjectData.Lightmaps | PerObjectData.ShadowMask | PerObjectData.LightProbe | PerObjectData.OcclusionProbe | PerObjectData.LightProbeProxyVolume | PerObjectData.ReflectionProbes,
};
// 渲染CustomLit表示的pass块
drawingSettings.SetShaderPassName(1, litShaderTagId);
......
......@@ -11,6 +11,10 @@ struct BRDF
float3 specular;
// 粗糙度
float roughness;
// 感知粗糙度
float perceptualRoughness;
// 菲涅尔反射
float fresnel;
};
// 电介质的反射率平均约0.04
......@@ -37,8 +41,9 @@ BRDF GetBRDF(inout Surface surface, bool applyAlphaToDiffuse = false)
brdf.specular = lerp(MIN_REFLECTIVITY, surface.color, surface.metallic);
// 光滑度转为实际粗糙度
float perceptualSmoothness = PerceptualSmoothnessToPerceptualRoughness(surface.smoothness);
brdf.roughness = PerceptualRoughnessToRoughness(perceptualSmoothness);
brdf.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surface.smoothness);
brdf.roughness = PerceptualRoughnessToRoughness(brdf.perceptualRoughness);
brdf.fresnel = saturate(surface.smoothness + 1.0 - oneMinusReflectivity);
return brdf;
}
......@@ -63,7 +68,8 @@ float3 DirectBRDF (Surface surface, BRDF brdf, Light light)
// 获取基于BRDF的间接照明
float3 IndirectBRDF(Surface surface, BRDF brdf, float3 diffuse, float3 specular)
{
float3 reflection = specular * brdf.specular;
float fresnelStrength = surface.fresnelStrength * Pow4(1.0 - saturate(dot(surface.normal, surface.viewDirection)));
float3 reflection = specular * lerp(brdf.specular, brdf.fresnel, fresnelStrength);
reflection /= brdf.roughness * brdf.roughness + 1.0;
return diffuse * brdf.diffuse + reflection;
}
......
......@@ -3,6 +3,7 @@
#define CUSTOM_GI_INCLUDED
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ImageBasedLighting.hlsl"
TEXTURE2D(unity_Lightmap);
SAMPLER(samplerunity_Lightmap);
......@@ -13,6 +14,9 @@ SAMPLER(samplerunity_ProbeVolumeSH);
TEXTURE2D(unity_ShadowMask);
SAMPLER(samplerunity_ShadowMask);
TEXTURECUBE(unity_SpecCube0);
SAMPLER(samplerunity_SpecCube0);
// 当需要渲染光照贴图对象时
#if defined(LIGHTMAP_ON)
#define GI_ATTRIBUTE_DATA float2 lightMapUV : TEXCOORD1;
......@@ -31,6 +35,8 @@ struct GI
{
// 漫反射颜色
float3 diffuse;
// 镜面反射颜色
float3 specular;
ShadowMask shadowMask;
};
......@@ -111,10 +117,22 @@ float4 SampleBakedShadows(float2 lightMapUV, Surface surfaceWS)
#endif
}
GI GetGI(float2 lightMapUV, Surface surfaceWS)
// 采样环境立方体纹理
float3 SampleEnvironment(Surface surfaceWS, BRDF brdf)
{
float3 uvw = reflect(-surfaceWS.viewDirection, surfaceWS.normal);
float mip = PerceptualRoughnessToMipmapLevel(brdf.perceptualRoughness);
float4 environment = SAMPLE_TEXTURECUBE_LOD(
unity_SpecCube0, samplerunity_SpecCube0, uvw, mip
);
return DecodeHDREnvironment(environment, unity_SpecCube0_HDR);
}
GI GetGI(float2 lightMapUV, Surface surfaceWS, BRDF brdf)
{
GI gi;
gi.diffuse = SampleLightMap(lightMapUV) + SampleLightProbe(surfaceWS);
gi.specular = SampleEnvironment(surfaceWS, brdf);
gi.shadowMask.always = false;
gi.shadowMask.distance = false;
gi.shadowMask.shadows = 1.0;
......
......@@ -22,7 +22,7 @@ float3 GetLighting(Surface surfaceWS, BRDF brdf, GI gi)
shadowData.shadowMask = gi.shadowMask;
// 可见光的光照结果进行累加得到最终光照结果
float3 color = IndirectBRDF(surfaceWS, brdf, gi.diffuse, 1.0);
float3 color = IndirectBRDF(surfaceWS, brdf, gi.diffuse, gi.specular);
for (int i = 0; i < GetDirectionalLightCount(); i++)
{
Light light = GetDirectionalLight(i, surfaceWS, shadowData);
......
......@@ -16,6 +16,8 @@ struct Surface
float smoothness;
// 抖动属性
float dither;
// 菲涅尔反射强度
float fresnelStrength;
};
#endif
\ No newline at end of file
......@@ -11,6 +11,8 @@ CBUFFER_START(UnityPerDraw)
float4 unity_ProbesOcclusion;
float4 unity_SpecCube0_HDR;
float4 unity_LightmapST;
float4 unity_DynamicLightmapST;
......
......@@ -11,14 +11,16 @@ Shader "Custom RP/Lit"
[Toggle(_RECEIVE_SHADOWS)] _ReceiveShadows ("Receive Shadows", Float) = 1
// 阴影模式
[KeywordEnum(On, Clip, Dither, Off)] _Shadows ("Shadows", Float) = 0
// 透明通道预乘
[Toggle(_PREMULTIPLY_ALPHA)] _PremulAlpha("Premultiply Alpha", Float) = 0
// 金属度和光滑度
_Metallic("Metallic", Range(0, 1)) = 0
_Smoothness("Smoothness", Range(0, 1)) = 0.5
// 菲涅尔反射强度
_Fresnel ("Fresnel", Range(0, 1)) = 1
// 自发光
[NoScaleOffset] _EmissionMap("Emission", 2D) = "white" {}
[HDR] _EmissionColor("Emission", Color) = (0.0, 0.0, 0.0, 0.0)
// 透明通道预乘
[Toggle(_PREMULTIPLY_ALPHA)] _PremulAlpha("Premultiply Alpha", Float) = 0
// 设置混合模式
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend", Float) = 1
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend", Float) = 0
......
......@@ -12,6 +12,7 @@ UNITY_INSTANCING_BUFFER_START(UnityPerMaterial)
UNITY_DEFINE_INSTANCED_PROP(float, _Cutoff)
UNITY_DEFINE_INSTANCED_PROP(float, _Metallic)
UNITY_DEFINE_INSTANCED_PROP(float, _Smoothness)
UNITY_DEFINE_INSTANCED_PROP(float, _Fresnel)
UNITY_INSTANCING_BUFFER_END(UnityPerMaterial)
float2 TransformBaseUV(float2 baseUV)
......@@ -53,5 +54,9 @@ float GetSmoothness(float2 baseUV)
return UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Smoothness);
}
float GetFresnel(float2 baseUV)
{
return UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _Fresnel);
}
#endif
\ No newline at end of file
......@@ -70,6 +70,7 @@ float4 LitPassFragment(Varyings input) : SV_TARGET
surface.alpha = base.a;
surface.metallic = GetMetallic(input.baseUV);
surface.smoothness = GetSmoothness(input.baseUV);
surface.fresnelStrength = GetFresnel(input.baseUV);
// 计算抖动值
surface.dither = InterleavedGradientNoise(input.positionCS.xy, 0);
// 通过表面属性和BRDF计算最终光照结果
......@@ -79,7 +80,7 @@ float4 LitPassFragment(Varyings input) : SV_TARGET
BRDF brdf = GetBRDF(surface);
#endif
// 获取全局照明数据
GI gi = GetGI(GI_FRAGMENT_DATA(input), surface);
GI gi = GetGI(GI_FRAGMENT_DATA(input), surface, brdf);
float3 color = GetLighting(surface, brdf, gi);
color += GetEmission(input.baseUV);
return float4(color, surface.alpha);
......
......@@ -18,9 +18,9 @@ LightingSettings:
m_UsingShadowmask: 1
m_BakeBackend: 1
m_LightmapMaxSize: 1024
m_BakeResolution: 40
m_BakeResolution: 20
m_Padding: 2
m_TextureCompression: 1
m_TextureCompression: 0
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
......@@ -41,16 +41,16 @@ LightingSettings:
m_PVRCulling: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVREnvironmentSampleCount: 256
m_PVRSampleCount: 500
m_PVREnvironmentSampleCount: 500
m_PVREnvironmentReferencePointCount: 2048
m_LightProbeSampleCountMultiplier: 4
m_LightProbeSampleCountMultiplier: 2
m_PVRBounces: 2
m_PVRMinBounces: 1
m_PVREnvironmentMIS: 1
m_PVREnvironmentMIS: 0
m_PVRFilteringMode: 2
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
......
......@@ -97,10 +97,8 @@ LightmapSettings:
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 112000000, guid: 4772e383a675c4016a19a76456116c09,
type: 2}
m_LightingSettings: {fileID: 4890085278179872738, guid: e43cc08759a4c7444a7410feac07b614,
type: 2}
m_LightingDataAsset: {fileID: 112000000, guid: 4772e383a675c4016a19a76456116c09, type: 2}
m_LightingSettings: {fileID: 4890085278179872738, guid: 1556591ee3227314c9a52a04dddc0ddf, type: 2}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
......@@ -3347,7 +3345,7 @@ Light:
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 1.02e-43, y: 1.1950786e+34, z: 4.5904e-41, w: 0}
m_BoundingSphereOverride: {x: 8.06e-43, y: 1.39e-43, z: 0, w: -0.0000032726402}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
......@@ -4278,6 +4276,70 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 859762734}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &869728042
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 869728044}
- component: {fileID: 869728043}
m_Layer: 0
m_Name: Reflection Probe
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!215 &869728043
ReflectionProbe:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 869728042}
m_Enabled: 1
serializedVersion: 2
m_Type: 0
m_Mode: 0
m_RefreshMode: 0
m_TimeSlicingMode: 0
m_Resolution: 128
m_UpdateFrequency: 0
m_BoxSize: {x: 10, y: 10, z: 10}
m_BoxOffset: {x: 0, y: 0, z: 0}
m_NearClip: 0.3
m_FarClip: 1000
m_ShadowDistance: 100
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_IntensityMultiplier: 1
m_BlendDistance: 1
m_HDR: 1
m_BoxProjection: 0
m_RenderDynamicObjects: 0
m_UseOcclusionCulling: 1
m_Importance: 1
m_CustomBakedTexture: {fileID: 0}
--- !u!4 &869728044
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 869728042}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.10134385, y: 1.3073847, z: -2.0773427}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &901141089
GameObject:
m_ObjectHideFlags: 0
......@@ -6203,7 +6265,7 @@ Light:
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 1.016e-42, y: 0, z: 0, w: 6.0005074}
m_BoundingSphereOverride: {x: 1.02e-43, y: 1.1950786e+34, z: 4.5904e-41, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
......
fileFormatVersion: 2
guid: ab3d583a0e5f4fd4abd2b2166bc2de9c
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 1
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 3
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 12
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
......@@ -3,7 +3,7 @@ guid: eb5027765e9124d74aea8517bc5b5ff7
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
......@@ -23,6 +23,7 @@ TextureImporter:
isReadable: 0
streamingMipmaps: 1
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
......@@ -54,9 +55,13 @@ TextureImporter:
textureType: 6
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
......
......@@ -3,7 +3,7 @@ guid: 31afb30c757ea4b828c2f7de72c2dc7e
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
......@@ -23,6 +23,7 @@ TextureImporter:
isReadable: 0
streamingMipmaps: 1
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
......@@ -48,15 +49,19 @@ TextureImporter:
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaUsage: 0
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureType: 11
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
......
......@@ -3,7 +3,7 @@ guid: 5c403d4740467403b8e46a1e11e971ad
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
......@@ -23,6 +23,7 @@ TextureImporter:
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 1
......@@ -54,9 +55,13 @@ TextureImporter:
textureType: 0
textureShape: 2
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
......
fileFormatVersion: 2
guid: 41557bce2a12d8d4a8a839f71fadbec0
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 1
seamlessCubemap: 1
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 2
aniso: 0
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 2
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 100
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册