diff --git a/shaders/BSDF手搓.shader b/shaders/BSDF手搓.shader index b4f0c80..477f797 100644 --- a/shaders/BSDF手搓.shader +++ b/shaders/BSDF手搓.shader @@ -119,31 +119,46 @@ Shader "BSDF/StandardURP" data.positionWS = input.positionWS; data.shadowCoord = TransformWorldToShadowCoord(input.positionWS);// 阴影坐标 data.fogCoord = ComputeFogFactor(input.positionWS);//雾坐标 - data.normalWS = input.normalWS; - data.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS); + data.normalWS = input.normalWS;//世界空间法线 + data.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);//视线方向 // 采样光照贴图 - //float2 lightmapUV = _Lightmap * unity_LightmapST.xy + unity_LightmapST.zw; - //data.bakedGI = SampleLightmap(lightmapUV, inputData.normalWS); //SampleSH(data.normalWS); // 球谐函数采样环境光//float3(0.5, 0.5, 0.5) - data.bakedGI = SampleSH(data.normalWS); // 球谐函数采样环境光//float3(0.5, 0.5, 0.5) + float2 lightmapUV = input.uv0 * unity_LightmapST.xy + unity_LightmapST.zw; + 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) return data; } BRDFData SurfaceDataToBSDFData(SurfaceData surface, InputData inputData){ BRDFData bsdf; 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.reflectance = surface.specular * surface.metallic + bsdf.diffuse * (1.0 - surface.metallic);//反射率 - bsdf.normalWS = inputData.normalWS; - bsdf.viewDirectionWS = inputData.viewDirectionWS; - bsdf.emission = surface.emission; - bsdf.alpha = surface.alpha; - bsdf.occlusion = surface.occlusion; - bsdf.clearCoatMask = surface.clearCoatMask; - bsdf.clearCoatSmoothness = surface.clearCoatSmoothness; + bsdf.reflectivity = ReflectivitySpecular(bsdf.specular);//反射率 + bsdf.perceptualRoughness = 1.0 - surface.smoothness;//感知粗糙度 + bsdf.roughness = bsdf.perceptualRoughness * bsdf.perceptualRoughness;//粗糙度 + bsdf.roughness2 = bsdf.roughness * bsdf.roughness;//粗糙度平方 + bsdf.grazingTerm =saturate(surface.smoothness+bsdf.reflectivity);//光滑度+反射率 + bsdf.normalizationTerm = bsdf.roughness*4.0+2.0;//归一化项 + bsdf.roughness2MinusOne = bsdf.roughness2 - 1.0;//粗糙度平方-1 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 output; VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); @@ -157,27 +172,11 @@ Shader "BSDF/StandardURP" float4 MainFragmentShader(Varyings input):SV_TARGET{ InputData inputData = InitializeInputData(input); SurfaceData surface = GetSurfaceData(input); - float4 color = UniversalFragmentPBR(inputData, surface); - /* uint pixelLightCount = GetAdditionalLightsCount(); - for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex) - { - Light light = GetAdditionalLight(lightIndex, inputData.positionWS); - color.rgb += LightingPhysicallyBased(surface, inputData, light); - } */ + BRDFData bsdf = SurfaceDataToBSDFData(surface, inputData); + //float4 color = UniversalFragmentPBR(inputData, bsdf); + float3 color = BRDFToColor(bsdf, inputData, inputData.positionWS); color.rgb += surface.emission * _EmissionStrength;//自发光 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); } ENDHLSL diff --git a/材质/背景材质.mat b/材质/背景材质.mat index 6486bac..33ac43d 100644 --- a/材质/背景材质.mat +++ b/材质/背景材质.mat @@ -98,6 +98,7 @@ Material: - _DetailNormalMapScale: 1 - _DstBlend: 0 - _DstBlendAlpha: 0 + - _EmissionStrength: 0 - _EnvironmentReflections: 1 - _GlossMapScale: 0 - _Glossiness: 0 diff --git a/材质/草地材质.mat b/材质/草地材质.mat index 36c11ea..78229fe 100644 --- a/材质/草地材质.mat +++ b/材质/草地材质.mat @@ -59,6 +59,10 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _NormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _OcclusionMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -98,6 +102,7 @@ Material: - _DetailNormalMapScale: 1 - _DstBlend: 0 - _DstBlendAlpha: 0 + - _EmissionStrength: 0 - _EnvironmentReflections: 1 - _GlossMapScale: 0 - _Glossiness: 0 @@ -107,7 +112,7 @@ Material: - _Parallax: 0.005 - _QueueOffset: 0 - _ReceiveShadows: 1 - - _Smoothness: 0.5 + - _Smoothness: 0 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 @@ -120,6 +125,7 @@ Material: - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, 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: [] --- !u!114 &6454390938563187997 MonoBehaviour: diff --git a/贴图/狐狸贴图.meta b/贴图/狐狸贴图.meta new file mode 100644 index 0000000..4884fb5 --- /dev/null +++ b/贴图/狐狸贴图.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 87147127ceb77494192aa42e42b7d4e6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/贴图/狐狸贴图/狐狸头贴图.png b/贴图/狐狸贴图/狐狸头贴图.png new file mode 100644 index 0000000..00ae9f3 Binary files /dev/null and b/贴图/狐狸贴图/狐狸头贴图.png differ diff --git a/贴图/狐狸贴图/狐狸头贴图.png.meta b/贴图/狐狸贴图/狐狸头贴图.png.meta new file mode 100644 index 0000000..4a4e5dd --- /dev/null +++ b/贴图/狐狸贴图/狐狸头贴图.png.meta @@ -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: diff --git a/贴图/狐狸贴图/狐狸尾巴贴图.png b/贴图/狐狸贴图/狐狸尾巴贴图.png new file mode 100644 index 0000000..28a5b27 Binary files /dev/null and b/贴图/狐狸贴图/狐狸尾巴贴图.png differ diff --git a/贴图/狐狸贴图/狐狸尾巴贴图.png.meta b/贴图/狐狸贴图/狐狸尾巴贴图.png.meta new file mode 100644 index 0000000..b19695f --- /dev/null +++ b/贴图/狐狸贴图/狐狸尾巴贴图.png.meta @@ -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: diff --git a/贴图/狐狸贴图/狐狸身体贴图.png b/贴图/狐狸贴图/狐狸身体贴图.png new file mode 100644 index 0000000..157fad7 Binary files /dev/null and b/贴图/狐狸贴图/狐狸身体贴图.png differ diff --git a/贴图/狐狸贴图/狐狸身体贴图.png.meta b/贴图/狐狸贴图/狐狸身体贴图.png.meta new file mode 100644 index 0000000..5620284 --- /dev/null +++ b/贴图/狐狸贴图/狐狸身体贴图.png.meta @@ -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: