This commit is contained in:
Mrhongxing committed 2026-09-10 15:47:21 +08:00
1 parent 34ee00a443
commit 153708c3b9
10 files changed
+429 -34

No files matched your search

+32 -33
View File
@@ -119,31 +119,46 @@ Shader "BSDF/StandardURP"
data.positionWS = input.positionWS; data.positionWS = input.positionWS;
data.shadowCoord = TransformWorldToShadowCoord(input.positionWS);// 阴影坐标 data.shadowCoord = TransformWorldToShadowCoord(input.positionWS);// 阴影坐标
data.fogCoord = ComputeFogFactor(input.positionWS);//雾坐标 data.fogCoord = ComputeFogFactor(input.positionWS);//雾坐标
data.normalWS = input.normalWS; data.normalWS = input.normalWS;//世界空间法线
data.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS); data.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);//视线方向
// 采样光照贴图 // 采样光照贴图
//float2 lightmapUV = _Lightmap * unity_LightmapST.xy + unity_LightmapST.zw; float2 lightmapUV = input.uv0 * unity_LightmapST.xy + unity_LightmapST.zw;
//data.bakedGI = SampleLightmap(lightmapUV, inputData.normalWS); //SampleSH(data.normalWS); // 球谐函数采样环境光//float3(0.5, 0.5, 0.5) data.bakedGI = SAMPLE_TEXTURE2D(_LightMap, sampler_LightMap, lightmapUV).rgb; //SampleSH(data.normalWS); // 球谐函数采样环境光//float3(0.5, 0.5, 0.5)
data.bakedGI = SampleSH(data.normalWS); // 球谐函数采样环境光//float3(0.5, 0.5, 0.5) //data.bakedGI = SampleSH(data.normalWS); // 球谐函数采样环境光//float3(0.5, 0.5, 0.5)
return data; return data;
} }
BRDFData SurfaceDataToBSDFData(SurfaceData surface, InputData inputData){ BRDFData SurfaceDataToBSDFData(SurfaceData surface, InputData inputData){
BRDFData bsdf; BRDFData bsdf;
bsdf.albedo = surface.albedo;//漫反射颜色 bsdf.albedo = surface.albedo;//漫反射颜色
bsdf.specular = lerp(float3(0.04, 0.04, 0.04), _Specular.rgb, surface.metallic);//镜面反射颜色 bsdf.specular = lerp(float3(0.04, 0.04, 0.04), surface.albedo, surface.metallic);//镜面反射颜色
bsdf.diffuse = surface.albedo * (1.0 - surface.metallic);//漫反射颜色 bsdf.diffuse = surface.albedo * (1.0 - surface.metallic);//漫反射颜色
bsdf.reflectance = surface.specular * surface.metallic + bsdf.diffuse * (1.0 - surface.metallic);//反射率 bsdf.reflectivity = ReflectivitySpecular(bsdf.specular);//反射率
bsdf.normalWS = inputData.normalWS; bsdf.perceptualRoughness = 1.0 - surface.smoothness;//感知粗糙度
bsdf.viewDirectionWS = inputData.viewDirectionWS; bsdf.roughness = bsdf.perceptualRoughness * bsdf.perceptualRoughness;//粗糙度
bsdf.emission = surface.emission; bsdf.roughness2 = bsdf.roughness * bsdf.roughness;//粗糙度平方
bsdf.alpha = surface.alpha; bsdf.grazingTerm =saturate(surface.smoothness+bsdf.reflectivity);//光滑度+反射率
bsdf.occlusion = surface.occlusion; bsdf.normalizationTerm = bsdf.roughness*4.0+2.0;//归一化项
bsdf.clearCoatMask = surface.clearCoatMask; bsdf.roughness2MinusOne = bsdf.roughness2 - 1.0;//粗糙度平方-1
bsdf.clearCoatSmoothness = surface.clearCoatSmoothness;
return bsdf; return bsdf;
} }
float3 BRDFToColor(BRDFData bsdf, InputData inputData,float3 positionWS){
float3 color = float3(0, 0, 0);
//主光源
Light mainLight = GetMainLight();
color += LightingPhysicallyBased(bsdf,mainLight, inputData.normalWS, inputData.viewDirectionWS);
//附加光源
for (int i = 0; i < GetAdditionalLightsCount(); ++i)
{
Light additionalLight = GetAdditionalLight(i, positionWS);
color += LightingPhysicallyBased(bsdf, additionalLight, inputData.normalWS, inputData.viewDirectionWS);
}
//环境光
color += inputData.bakedGI.rgb * bsdf.diffuse;//烘焙全局光照
return color;
}
Varyings MainVertexShader(Attributes input){ Varyings MainVertexShader(Attributes input){
Varyings output; Varyings output;
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
@@ -157,27 +172,11 @@ Shader "BSDF/StandardURP"
float4 MainFragmentShader(Varyings input):SV_TARGET{ float4 MainFragmentShader(Varyings input):SV_TARGET{
InputData inputData = InitializeInputData(input); InputData inputData = InitializeInputData(input);
SurfaceData surface = GetSurfaceData(input); SurfaceData surface = GetSurfaceData(input);
float4 color = UniversalFragmentPBR(inputData, surface); BRDFData bsdf = SurfaceDataToBSDFData(surface, inputData);
/* uint pixelLightCount = GetAdditionalLightsCount(); //float4 color = UniversalFragmentPBR(inputData, bsdf);
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex) float3 color = BRDFToColor(bsdf, inputData, inputData.positionWS);
{
Light light = GetAdditionalLight(lightIndex, inputData.positionWS);
color.rgb += LightingPhysicallyBased(surface, inputData, light);
} */
color.rgb += surface.emission * _EmissionStrength;//自发光 color.rgb += surface.emission * _EmissionStrength;//自发光
color.rgb = MixFog(color.rgb, inputData.fogCoord);//混合雾效 color.rgb = MixFog(color.rgb, inputData.fogCoord);//混合雾效
/* Light mainLight = GetMainLight();
float3 normal = normalize(input.normalWS);
float3 lightDir = normalize(mainLight.direction);
float NdotL = saturate(dot(normal, lightDir));
float lambert = 0.5 + 0.5 * NdotL;
lambert *=pow(0.5 + 0.5 * NdotL, 2);
float3 headUpDir = normalize(_HeadUp);
float3 headForwardDir = normalize(_HeadForward);
float3 headRightDir = normalize(_HeadRight);
float4 basemap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv0);
float3 baseColor = _BaseColor.rgb;
float3 finalColor = baseColor * basemap.rgb * lambert; */
return float4(color.rgb, 1); return float4(color.rgb, 1);
} }
ENDHLSL ENDHLSL
+1
View File
@@ -98,6 +98,7 @@ Material:
- _DetailNormalMapScale: 1 - _DetailNormalMapScale: 1
- _DstBlend: 0 - _DstBlend: 0
- _DstBlendAlpha: 0 - _DstBlendAlpha: 0
- _EmissionStrength: 0
- _EnvironmentReflections: 1 - _EnvironmentReflections: 1
- _GlossMapScale: 0 - _GlossMapScale: 0
- _Glossiness: 0 - _Glossiness: 0
+7 -1
View File
@@ -59,6 +59,10 @@ Material:
m_Texture: {fileID: 0} m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1} m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap: - _OcclusionMap:
m_Texture: {fileID: 0} m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1} m_Scale: {x: 1, y: 1}
@@ -98,6 +102,7 @@ Material:
- _DetailNormalMapScale: 1 - _DetailNormalMapScale: 1
- _DstBlend: 0 - _DstBlend: 0
- _DstBlendAlpha: 0 - _DstBlendAlpha: 0
- _EmissionStrength: 0
- _EnvironmentReflections: 1 - _EnvironmentReflections: 1
- _GlossMapScale: 0 - _GlossMapScale: 0
- _Glossiness: 0 - _Glossiness: 0
@@ -107,7 +112,7 @@ Material:
- _Parallax: 0.005 - _Parallax: 0.005
- _QueueOffset: 0 - _QueueOffset: 0
- _ReceiveShadows: 1 - _ReceiveShadows: 1
- _Smoothness: 0.5 - _Smoothness: 0
- _SmoothnessTextureChannel: 0 - _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1 - _SpecularHighlights: 1
- _SrcBlend: 1 - _SrcBlend: 1
@@ -120,6 +125,7 @@ Material:
- _Color: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
- _Specular: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: [] m_BuildTextureStacks: []
--- !u!114 &6454390938563187997 --- !u!114 &6454390938563187997
MonoBehaviour: MonoBehaviour:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 87147127ceb77494192aa42e42b7d4e6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: 57db7d8947ba7a94abfffaf8a0993fce
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
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
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
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: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

After

Width:  |  Height:  |  Size: 544 KiB

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: 3c01cc018994ca347bba7de70ea936d4
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
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
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
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: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: aa363b3e21d5f1c4ba750b7b33414d5a
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
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
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
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: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant: