Unity中URP下获取主灯信息

文章目录

  • 前言
  • 一、计算BulinnPhone的函数有两个重载
    • 1、 目前最新使用的是该方法(这是我们之后主要分析的函数)
    • 2、 被淘汰的老方法,需要传入一堆数据
  • 二、GetMainLight
    • 1、Light结构体
    • 2、GetMainLight具有4个方法重载
    • 3、1号重载干了什么(该函数就是获取我们主光信息的函数)
  • 三、测试代码


前言

在上一篇文章中,我们大概了解了SampleLit下的片元着色器主要干了什么。

  • Unity中URP下的SimpleLit片元着色器

我们在这篇文章中,来看一下计算BlinnPhone光照时,怎么获取主光的信息。


一、计算BulinnPhone的函数有两个重载

1、 目前最新使用的是该方法(这是我们之后主要分析的函数)

在这里插入图片描述


/// Phong lighting...half4 UniversalFragmentBlinnPhong(InputData inputData, SurfaceData surfaceData)
{#if defined(DEBUG_DISPLAY)half4 debugColor;if (CanDebugOverrideOutputColor(inputData, surfaceData, debugColor)){return debugColor;}#endifuint meshRenderingLayers = GetMeshRenderingLayer();half4 shadowMask = CalculateShadowMask(inputData);AmbientOcclusionFactor aoFactor = CreateAmbientOcclusionFactor(inputData, surfaceData);Light mainLight = GetMainLight(inputData, shadowMask, aoFactor);MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, aoFactor);inputData.bakedGI *= surfaceData.albedo;LightingData lightingData = CreateLightingData(inputData, surfaceData);
#ifdef _LIGHT_LAYERSif (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
#endif{lightingData.mainLightColor += CalculateBlinnPhong(mainLight, inputData, surfaceData);}#if defined(_ADDITIONAL_LIGHTS)uint pixelLightCount = GetAdditionalLightsCount();#if USE_FORWARD_PLUSfor (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++){FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECKLight light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
#ifdef _LIGHT_LAYERSif (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
#endif{lightingData.additionalLightsColor += CalculateBlinnPhong(light, inputData, surfaceData);}}#endifLIGHT_LOOP_BEGIN(pixelLightCount)Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
#ifdef _LIGHT_LAYERSif (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
#endif{lightingData.additionalLightsColor += CalculateBlinnPhong(light, inputData, surfaceData);}LIGHT_LOOP_END#endif#if defined(_ADDITIONAL_LIGHTS_VERTEX)lightingData.vertexLightingColor += inputData.vertexLighting * surfaceData.albedo;#endifreturn CalculateFinalColor(lightingData, surfaceData.alpha);
}

2、 被淘汰的老方法,需要传入一堆数据

在这里插入图片描述


二、GetMainLight

  • 在 UniversalFragmentBlinnPhong 函数中,一开始就获取了主光的信息,这也是我们这篇文章中,主要分析的,怎么获取主光信息
    在这里插入图片描述

1、Light结构体

在这里插入图片描述

其中最主要的就是:

  1. direction:主光线方向
  2. color:主光线颜色

2、GetMainLight具有4个方法重载

  • 这里我们为了方便分析,分别叫他们 1号、2号、3号、4号重载

  • 带参数的方法重载额外实现了 阴影衰减

  • 不带参数的方法重载 主要实现了主光信息的获取
    在这里插入图片描述

  • BulinnPhone光照计算,调用的是4号重载

  • 我们按调用顺序依次展开分析

  • 4号重载 调用了3号重载
    在这里插入图片描述

  • 3号重载 调用了 1号重载
    在这里插入图片描述

  • 2号 重载也调用了 1号重载(但是,我们这里没有使用到,不做分析)
    在这里插入图片描述

  • 1号重载(该函数就是获取我们主光信息的函数)
    在这里插入图片描述

3、1号重载干了什么(该函数就是获取我们主光信息的函数)

  • _MainLightPosition 获取主光线方向

light.direction = half3(_MainLightPosition.xyz);

我们输出看看效果:
请添加图片描述

  • _MainLightColor 获取主光颜色

light.color = _MainLightColor.rgb;

我们输出看看效果:
请添加图片描述

  • unity_LightData.z 获取光照距离衰减值
  • 因为,主光线是平行灯。所以,没有距离远近的说法,这里值只有 1 和 0

// unity_LightData.z is 1 when not culled by the culling mask, otherwise 0.
//距离衰减,接收光照时为 1。剔除接收光照为 0
light.distanceAttenuation = unity_LightData.z;

  • 阴影衰减预先赋值为 1,后面再做处理

light.shadowAttenuation = 1.0;


三、测试代码

// Shader targeted for low end devices. Single Pass Forward Rendering.
Shader "MyShader/URP/P4_7_3"
{// Keep properties of StandardSpecular shader for upgrade reasons.Properties{[MainTexture] _BaseMap("Base Map (RGB) Smoothness / Alpha (A)", 2D) = "white" {}[MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1)_Cutoff("Alpha Clipping", Range(0.0, 1.0)) = 0.5_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5_SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 0.5)_SpecGlossMap("Specular Map", 2D) = "white" {}_SmoothnessSource("Smoothness Source", Float) = 0.0_SpecularHighlights("Specular Highlights", Float) = 1.0[HideInInspector] _BumpScale("Scale", Float) = 1.0[NoScaleOffset] _BumpMap("Normal Map", 2D) = "bump" {}[HDR] _EmissionColor("Emission Color", Color) = (0,0,0)[NoScaleOffset]_EmissionMap("Emission Map", 2D) = "white" {}// Blending state_Surface("__surface", Float) = 0.0_Blend("__blend", Float) = 0.0_Cull("__cull", Float) = 2.0[ToggleUI] _AlphaClip("__clip", Float) = 0.0[HideInInspector] _SrcBlend("__src", Float) = 1.0[HideInInspector] _DstBlend("__dst", Float) = 0.0[HideInInspector] _SrcBlendAlpha("__srcA", Float) = 1.0[HideInInspector] _DstBlendAlpha("__dstA", Float) = 0.0[HideInInspector] _ZWrite("__zw", Float) = 1.0[HideInInspector] _BlendModePreserveSpecular("_BlendModePreserveSpecular", Float) = 1.0[HideInInspector] _AlphaToMask("__alphaToMask", Float) = 0.0[ToggleUI] _ReceiveShadows("Receive Shadows", Float) = 1.0// Editmode props_QueueOffset("Queue offset", Float) = 0.0// ObsoleteProperties[HideInInspector] _MainTex("BaseMap", 2D) = "white" {}[HideInInspector] _Color("Base Color", Color) = (1, 1, 1, 1)[HideInInspector] _Shininess("Smoothness", Float) = 0.0[HideInInspector] _GlossinessSource("GlossinessSource", Float) = 0.0[HideInInspector] _SpecSource("SpecularHighlights", Float) = 0.0[HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}[HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}[HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}}SubShader{Tags{"RenderType" = "Opaque""RenderPipeline" = "UniversalPipeline""UniversalMaterialType" = "SimpleLit""IgnoreProjector" = "True"}LOD 300//ForwardLitPass{Name "ForwardLit"Tags{"LightMode" = "UniversalForward"}// -------------------------------------// Render State Commands// Use same blending / depth states as Standard shaderBlend[_SrcBlend][_DstBlend], [_SrcBlendAlpha][_DstBlendAlpha]ZWrite[_ZWrite]Cull[_Cull]AlphaToMask[_AlphaToMask]HLSLPROGRAM#pragma target 2.0// -------------------------------------// Shader Stages#pragma vertex LitPassVertexSimple#pragma fragment LitPassFragmentSimple// -------------------------------------// Material Keywords#pragma shader_feature_local _NORMALMAP#pragma shader_feature_local_fragment _EMISSION#pragma shader_feature_local _RECEIVE_SHADOWS_OFF#pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT#pragma shader_feature_local_fragment _ALPHATEST_ON#pragma shader_feature_local_fragment _ _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON#pragma shader_feature_local_fragment _ _SPECGLOSSMAP _SPECULAR_COLOR#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA// -------------------------------------// Universal Pipeline keywords#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS#pragma multi_compile _ EVALUATE_SH_MIXED EVALUATE_SH_VERTEX#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING#pragma multi_compile _ SHADOWS_SHADOWMASK#pragma multi_compile _ _LIGHT_LAYERS#pragma multi_compile _ _FORWARD_PLUS#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS#pragma multi_compile_fragment _ _SHADOWS_SOFT#pragma multi_compile_fragment _ _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3#pragma multi_compile_fragment _ _LIGHT_COOKIES#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"// -------------------------------------// Unity defined keywords#pragma multi_compile _ DIRLIGHTMAP_COMBINED#pragma multi_compile _ LIGHTMAP_ON#pragma multi_compile _ DYNAMICLIGHTMAP_ON#pragma multi_compile_fog#pragma multi_compile_fragment _ DEBUG_DISPLAY#pragma multi_compile_fragment _ LOD_FADE_CROSSFADE//--------------------------------------// GPU Instancing#pragma multi_compile_instancing#pragma instancing_options renderinglayer#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"//--------------------------------------// Defines#define BUMP_SCALE_NOT_SUPPORTED 1// -------------------------------------// Includes#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"CBUFFER_START(UnityPerMaterial)float4 _BaseMap_ST;half4 _BaseColor;half4 _SpecColor;half4 _EmissionColor;half _Cutoff;half _Surface;CBUFFER_END#ifdef UNITY_DOTS_INSTANCING_ENABLEDUNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)UNITY_DOTS_INSTANCED_PROP(float4, _BaseColor)UNITY_DOTS_INSTANCED_PROP(float4, _SpecColor)UNITY_DOTS_INSTANCED_PROP(float4, _EmissionColor)UNITY_DOTS_INSTANCED_PROP(float , _Cutoff)UNITY_DOTS_INSTANCED_PROP(float , _Surface)UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)static float4 unity_DOTS_Sampled_BaseColor;static float4 unity_DOTS_Sampled_SpecColor;static float4 unity_DOTS_Sampled_EmissionColor;static float  unity_DOTS_Sampled_Cutoff;static float  unity_DOTS_Sampled_Surface;void SetupDOTSSimpleLitMaterialPropertyCaches(){unity_DOTS_Sampled_BaseColor     = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _BaseColor);unity_DOTS_Sampled_SpecColor     = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _SpecColor);unity_DOTS_Sampled_EmissionColor = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _EmissionColor);unity_DOTS_Sampled_Cutoff        = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float  , _Cutoff);unity_DOTS_Sampled_Surface       = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float  , _Surface);}#undef UNITY_SETUP_DOTS_MATERIAL_PROPERTY_CACHES#define UNITY_SETUP_DOTS_MATERIAL_PROPERTY_CACHES() SetupDOTSSimpleLitMaterialPropertyCaches()#define _BaseColor          unity_DOTS_Sampled_BaseColor#define _SpecColor          unity_DOTS_Sampled_SpecColor#define _EmissionColor      unity_DOTS_Sampled_EmissionColor#define _Cutoff             unity_DOTS_Sampled_Cutoff#define _Surface            unity_DOTS_Sampled_Surface#endifTEXTURE2D(_SpecGlossMap);SAMPLER(sampler_SpecGlossMap);half4 SampleSpecularSmoothness(float2 uv, half alpha, half4 specColor,TEXTURE2D_PARAM(specMap, sampler_specMap)){half4 specularSmoothness = half4(0, 0, 0, 1);#ifdef _SPECGLOSSMAPspecularSmoothness = SAMPLE_TEXTURE2D(specMap, sampler_specMap, uv) * specColor;#elif defined(_SPECULAR_COLOR)specularSmoothness = specColor;#endif#ifdef _GLOSSINESS_FROM_BASE_ALPHAspecularSmoothness.a = alpha;#endifreturn specularSmoothness;}inline void InitializeSimpleLitSurfaceData(float2 uv, out SurfaceData outSurfaceData){outSurfaceData = (SurfaceData)0;half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));outSurfaceData.alpha = albedoAlpha.a * _BaseColor.a;outSurfaceData.alpha = AlphaDiscard(outSurfaceData.alpha, _Cutoff);outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;outSurfaceData.albedo = AlphaModulate(outSurfaceData.albedo, outSurfaceData.alpha);half4 specularSmoothness = SampleSpecularSmoothness(uv, outSurfaceData.alpha, _SpecColor,TEXTURE2D_ARGS(_SpecGlossMap, sampler_SpecGlossMap));outSurfaceData.metallic = 0.0; // unusedoutSurfaceData.specular = specularSmoothness.rgb;outSurfaceData.smoothness = specularSmoothness.a;outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap));outSurfaceData.occlusion = 1.0;outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb,TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap));}#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"#if defined(LOD_FADE_CROSSFADE)#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"#endifstruct Attributes{float4 positionOS : POSITION;float3 normalOS : NORMAL;float4 tangentOS : TANGENT;float2 texcoord : TEXCOORD0;float2 staticLightmapUV : TEXCOORD1;float2 dynamicLightmapUV : TEXCOORD2;UNITY_VERTEX_INPUT_INSTANCE_ID};struct Varyings{float2 uv : TEXCOORD0;float3 positionWS : TEXCOORD1; // xyz: posWS#ifdef _NORMALMAPhalf4 normalWS                 : TEXCOORD2;    // xyz: normal, w: viewDir.xhalf4 tangentWS                : TEXCOORD3;    // xyz: tangent, w: viewDir.yhalf4 bitangentWS              : TEXCOORD4;    // xyz: bitangent, w: viewDir.z#elsehalf3 normalWS : TEXCOORD2;#endif#ifdef _ADDITIONAL_LIGHTS_VERTEXhalf4 fogFactorAndVertexLight  : TEXCOORD5; // x: fogFactor, yzw: vertex light#elsehalf fogFactor : TEXCOORD5;#endif#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)float4 shadowCoord             : TEXCOORD6;#endifDECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 7);#ifdef DYNAMICLIGHTMAP_ONfloat2  dynamicLightmapUV : TEXCOORD8; // Dynamic lightmap UVs#endiffloat4 positionCS : SV_POSITION;UNITY_VERTEX_INPUT_INSTANCE_IDUNITY_VERTEX_OUTPUT_STEREO};void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData){inputData = (InputData)0;inputData.positionWS = input.positionWS;#ifdef _NORMALMAPhalf3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w);inputData.tangentToWorld = half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz);inputData.normalWS = TransformTangentToWorld(normalTS, inputData.tangentToWorld);#elsehalf3 viewDirWS = GetWorldSpaceNormalizeViewDir(inputData.positionWS);inputData.normalWS = input.normalWS;#endifinputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);viewDirWS = SafeNormalize(viewDirWS);inputData.viewDirectionWS = viewDirWS;#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)inputData.shadowCoord = input.shadowCoord;#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);#elseinputData.shadowCoord = float4(0, 0, 0, 0);#endif#ifdef _ADDITIONAL_LIGHTS_VERTEXinputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), input.fogFactorAndVertexLight.x);inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;#elseinputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), input.fogFactor);inputData.vertexLighting = half3(0, 0, 0);#endif#if defined(DYNAMICLIGHTMAP_ON)inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV, input.vertexSH, inputData.normalWS);#elseinputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.vertexSH, inputData.normalWS);#endifinputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);#if defined(DEBUG_DISPLAY)#if defined(DYNAMICLIGHTMAP_ON)inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy;#endif#if defined(LIGHTMAP_ON)inputData.staticLightmapUV = input.staticLightmapUV;#elseinputData.vertexSH = input.vertexSH;#endif#endif}/////                      Light Abstraction                                    /////Light GetMainLight1(){Light light;//通过内置参数获取主光线方向light.direction = half3(_MainLightPosition.xyz);#if USE_FORWARD_PLUS#if defined(LIGHTMAP_ON) && defined(LIGHTMAP_SHADOW_MIXING)light.distanceAttenuation = _MainLightColor.a;#elselight.distanceAttenuation = 1.0;#endif#else// unity_LightData.z is 1 when not culled by the culling mask, otherwise 0.//距离衰减,接收光照时为 1。反之,为0light.distanceAttenuation = unity_LightData.z;#endiflight.shadowAttenuation = 1.0;//通过内置参数获取主光线颜色light.color = _MainLightColor.rgb;light.layerMask = _MainLightLayerMask;return light;}Light GetMainLight1(float4 shadowCoord, float3 positionWS, half4 shadowMask){Light light = GetMainLight1();light.shadowAttenuation = MainLightShadow(shadowCoord, positionWS, shadowMask,_MainLightOcclusionProbes);#if defined(_LIGHT_COOKIES)real3 cookieColor = SampleMainLightCookie(positionWS);light.color *= cookieColor;#endifreturn light;}Light GetMainLight1(InputData inputData, half4 shadowMask, AmbientOcclusionFactor aoFactor){Light light = GetMainLight1(inputData.shadowCoord, inputData.positionWS, shadowMask);#if defined(_SCREEN_SPACE_OCCLUSION) && !defined(_SURFACE_TYPE_TRANSPARENT)if (IsLightingFeatureEnabled(DEBUGLIGHTINGFEATUREFLAGS_AMBIENT_OCCLUSION)){light.color *= aoFactor.directAmbientOcclusion;}#endifreturn light;}/// Phong lighting...half4 UniversalFragmentBlinnPhong1(InputData inputData, SurfaceData surfaceData){#if defined(DEBUG_DISPLAY)half4 debugColor;if (CanDebugOverrideOutputColor(inputData, surfaceData, debugColor)){return debugColor;}#endifuint meshRenderingLayers = GetMeshRenderingLayer();half4 shadowMask = CalculateShadowMask(inputData);AmbientOcclusionFactor aoFactor = CreateAmbientOcclusionFactor(inputData, surfaceData);Light mainLight = GetMainLight1(inputData, shadowMask, aoFactor);MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, aoFactor);inputData.bakedGI *= surfaceData.albedo;LightingData lightingData = CreateLightingData(inputData, surfaceData);#ifdef _LIGHT_LAYERSif (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))#endif{lightingData.mainLightColor += CalculateBlinnPhong(mainLight, inputData, surfaceData);}#if defined(_ADDITIONAL_LIGHTS)uint pixelLightCount = GetAdditionalLightsCount();#if USE_FORWARD_PLUSfor (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++){FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECKLight light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);#ifdef _LIGHT_LAYERSif (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))#endif{lightingData.additionalLightsColor += CalculateBlinnPhong(light, inputData, surfaceData);}}#endifLIGHT_LOOP_BEGIN(pixelLightCount)Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);#ifdef _LIGHT_LAYERSif (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))#endif{lightingData.additionalLightsColor += CalculateBlinnPhong(light, inputData, surfaceData);}LIGHT_LOOP_END#endif#if defined(_ADDITIONAL_LIGHTS_VERTEX)lightingData.vertexLightingColor += inputData.vertexLighting * surfaceData.albedo;#endifreturn CalculateFinalColor(lightingData, surfaceData.alpha);}/////                  Vertex and Fragment functions                            /////// Used in Standard (Simple Lighting) shaderVaryings LitPassVertexSimple(Attributes input){Varyings output = (Varyings)0;UNITY_SETUP_INSTANCE_ID(input);UNITY_TRANSFER_INSTANCE_ID(input, output);UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);#if defined(_FOG_FRAGMENT)half fogFactor = 0;#elsehalf fogFactor = ComputeFogFactor(vertexInput.positionCS.z);#endifoutput.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);output.positionWS.xyz = vertexInput.positionWS;output.positionCS = vertexInput.positionCS;#ifdef _NORMALMAPhalf3 viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS);output.normalWS = half4(normalInput.normalWS, viewDirWS.x);output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);#elseoutput.normalWS = NormalizeNormalPerVertex(normalInput.normalWS);#endifOUTPUT_LIGHTMAP_UV(input.staticLightmapUV, unity_LightmapST, output.staticLightmapUV);#ifdef DYNAMICLIGHTMAP_ONoutput.dynamicLightmapUV = input.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;#endifOUTPUT_SH(output.normalWS.xyz, output.vertexSH);#ifdef _ADDITIONAL_LIGHTS_VERTEXhalf3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);#elseoutput.fogFactor = fogFactor;#endif#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)output.shadowCoord = GetShadowCoord(vertexInput);#endifreturn output;}// Used for StandardSimpleLighting shadervoid LitPassFragmentSimple(Varyings input, out half4 outColor : SV_Target0#ifdef _WRITE_RENDERING_LAYERS, out float4 outRenderingLayers : SV_Target1#endif){UNITY_SETUP_INSTANCE_ID(input);UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);SurfaceData surfaceData;InitializeSimpleLitSurfaceData(input.uv, surfaceData);#ifdef LOD_FADE_CROSSFADELODFadeCrossFade(input.positionCS);#endifInputData inputData;InitializeInputData(input, surfaceData.normalTS, inputData);SETUP_DEBUG_TEXTURE_DATA(inputData, input.uv, _BaseMap);#ifdef _DBUFFERApplyDecalToSurfaceData(input.positionCS, surfaceData, inputData);#endifhalf4 color = UniversalFragmentBlinnPhong1(inputData, surfaceData);outColor = color;color.rgb = MixFog(color.rgb, inputData.fogCoord);color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface));outColor = color;#ifdef _WRITE_RENDERING_LAYERSuint renderingLayers = GetMeshRenderingLayer();outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);#endif}ENDHLSL}//ShadowCasterPass{Name "ShadowCaster"Tags{"LightMode" = "ShadowCaster"}// -------------------------------------// Render State CommandsZWrite OnZTest LEqualColorMask 0Cull[_Cull]HLSLPROGRAM#pragma target 2.0// -------------------------------------// Shader Stages#pragma vertex ShadowPassVertex#pragma fragment ShadowPassFragment// -------------------------------------// Material Keywords#pragma shader_feature_local_fragment _ALPHATEST_ON#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA// -------------------------------------// Unity defined keywords#pragma multi_compile_fragment _ LOD_FADE_CROSSFADE//--------------------------------------// GPU Instancing#pragma multi_compile_instancing#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"// This is used during shadow map generation to differentiate between directional and punctual light shadows, as they use different formulas to apply Normal Bias#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW// -------------------------------------// Includes#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"ENDHLSL}//GBufferPass{Name "GBuffer"Tags{"LightMode" = "UniversalGBuffer"}// -------------------------------------// Render State CommandsZWrite[_ZWrite]ZTest LEqualCull[_Cull]HLSLPROGRAM#pragma target 4.5// Deferred Rendering Path does not support the OpenGL-based graphics API:// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.#pragma exclude_renderers gles3 glcore// -------------------------------------// Shader Stages#pragma vertex LitPassVertexSimple#pragma fragment LitPassFragmentSimple// -------------------------------------// Material Keywords#pragma shader_feature_local_fragment _ALPHATEST_ON//#pragma shader_feature _ALPHAPREMULTIPLY_ON#pragma shader_feature_local_fragment _ _SPECGLOSSMAP _SPECULAR_COLOR#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA#pragma shader_feature_local _NORMALMAP#pragma shader_feature_local_fragment _EMISSION#pragma shader_feature_local _RECEIVE_SHADOWS_OFF// -------------------------------------// Universal Pipeline keywords#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN//#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS//#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS#pragma multi_compile_fragment _ _SHADOWS_SOFT#pragma multi_compile_fragment _ _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"// -------------------------------------// Unity defined keywords#pragma multi_compile _ DIRLIGHTMAP_COMBINED#pragma multi_compile _ LIGHTMAP_ON#pragma multi_compile _ DYNAMICLIGHTMAP_ON#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING#pragma multi_compile _ SHADOWS_SHADOWMASK#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED#pragma multi_compile_fragment _ LOD_FADE_CROSSFADE//--------------------------------------// GPU Instancing#pragma multi_compile_instancing#pragma instancing_options renderinglayer#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"//--------------------------------------// Defines#define BUMP_SCALE_NOT_SUPPORTED 1// -------------------------------------// Includes#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitGBufferPass.hlsl"ENDHLSL}//DepthOnlyPass{Name "DepthOnly"Tags{"LightMode" = "DepthOnly"}// -------------------------------------// Render State CommandsZWrite OnColorMask RCull[_Cull]HLSLPROGRAM#pragma target 2.0// -------------------------------------// Shader Stages#pragma vertex DepthOnlyVertex#pragma fragment DepthOnlyFragment// -------------------------------------// Material Keywords#pragma shader_feature_local_fragment _ALPHATEST_ON#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA// -------------------------------------// Unity defined keywords#pragma multi_compile_fragment _ LOD_FADE_CROSSFADE//--------------------------------------// GPU Instancing#pragma multi_compile_instancing#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"// -------------------------------------// Includes#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"ENDHLSL}// This pass is used when drawing to a _CameraNormalsTexture texturePass{Name "DepthNormals"Tags{"LightMode" = "DepthNormals"}// -------------------------------------// Render State CommandsZWrite OnCull[_Cull]HLSLPROGRAM#pragma target 2.0// -------------------------------------// Shader Stages#pragma vertex DepthNormalsVertex#pragma fragment DepthNormalsFragment// -------------------------------------// Material Keywords#pragma shader_feature_local _NORMALMAP#pragma shader_feature_local_fragment _ALPHATEST_ON#pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA// -------------------------------------// Unity defined keywords#pragma multi_compile_fragment _ LOD_FADE_CROSSFADE// Universal Pipeline keywords#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"//--------------------------------------// GPU Instancing#pragma multi_compile_instancing#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"// -------------------------------------// Includes#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitDepthNormalsPass.hlsl"ENDHLSL}// This pass it not used during regular rendering, only for lightmap baking.Pass{Name "Meta"Tags{"LightMode" = "Meta"}// -------------------------------------// Render State CommandsCull OffHLSLPROGRAM#pragma target 2.0// -------------------------------------// Shader Stages#pragma vertex UniversalVertexMeta#pragma fragment UniversalFragmentMetaSimple// -------------------------------------// Material Keywords#pragma shader_feature_local_fragment _EMISSION#pragma shader_feature_local_fragment _SPECGLOSSMAP#pragma shader_feature EDITOR_VISUALIZATION// -------------------------------------// Includes#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitMetaPass.hlsl"ENDHLSL}//Universal2DPass{Name "Universal2D"Tags{"LightMode" = "Universal2D""RenderType" = "Transparent""Queue" = "Transparent"}HLSLPROGRAM#pragma target 2.0// -------------------------------------// Shader Stages#pragma vertex vert#pragma fragment frag// -------------------------------------// Material Keywords#pragma shader_feature_local_fragment _ALPHATEST_ON#pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON// -------------------------------------// Includes#include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Universal2D.hlsl"ENDHLSL}}Fallback "Hidden/Universal Render Pipeline/FallbackError"CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.SimpleLitShader"
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/642042.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

主动轮廓——计算机视觉中的图像分割方法

​ 一、说明 简单来说&#xff0c;计算机视觉就是为计算机提供类似人类的视觉。作为人类&#xff0c;我们很容易识别任何物体。我们可以很容易地识别山丘、树木、土地、动物等&#xff0c;但计算机没有眼睛&#xff0c;也没有大脑&#xff0c;因此它很难识别任何图像。计算机只…

Linux下软件安装的命令【RPM,YUM】及常用服务安装【JDK,Tomcat,MySQL】

Linux下软件安装的命令 源码安装 以源代码安装软件&#xff0c;每次都需要配置操作系统、配置编译参数、实际编译&#xff0c;最后还要依据个人喜好的方式来安装软件。这个过程很麻烦很累人。 RPM软件包管理 RPM安装软件的默认路径: 注意&#xff1a; /etc 配置文件放置目录…

docker network网络

网络分类 bridge网络 bridge是docker默认网络模式&#xff0c;docker安装后会选择一个私有网段作为bridge的子网&#xff0c;在我们创建容器时默认会将容器网络加入到这个子网中。 原理&#xff1a;Docker Daemon&#xff08;后台进程&#xff09; 利用 veth pair 技术&#…

3dmax渲不出模型是什么原因---模大狮模型网

3DMax无法渲染模型可能有多种原因。以下是一些常见的问题和解决方法&#xff1a; 材质设置错误&#xff1a;检查模型的材质设置是否正确&#xff0c;包括纹理贴图的路径、UV映射是否正确等。确保材质的属性设置正确&#xff0c;如颜色、反射率、透明度等。 灯光设置问题&#…

【JS逆向学习】某壁纸下载(ast混淆)

逆向目标 目标网址&#xff1a;https://bz.zzzmh.cn/index逆向接口一&#xff1a;https://api.zzzmh.cn/bz/v3/getData逆向接口二&#xff1a;https://cdn2.zzzmh.cn/wallpaper/origin/0d7d8d691e644989b72ddda5f695aca2.jpg?response-content-dispositionattachment&aut…

AnimatedDrawings:让绘图动起来

老样子&#xff0c;先上图片和官网。这个项目是让绘制的动画图片动起来&#xff0c;还能绑定人体的运动进行行为定制。 快速开始 1. 下载代码并进入文件夹&#xff0c;启动一键安装 git clone https://github.com/facebookresearch/AnimatedDrawings.gitcd AnimatedDrawingspip…

react18介绍

改进已有属性&#xff0c;如自动批量处理【setState】、改进Suspense、组件返回undefined不再报错等 支持Concurrent模式&#xff0c;带来新的API&#xff0c;如useTransition、useDeferredValue等 如何升级React 18 npm install reactlatest react-domlatestnpm install ty…

VS2022 在非Qt项目中引用QString、QList等方法

目录 一、新建项目 二、拷贝 三、工程属性设置 四、测试 一、新建项目 在VS中创建了一个c控制台项目&#xff0c;会默认打印“Hello world”&#xff1b; 二、拷贝 需要拷贝的包括QtCore相关的lib, dll, 以及头文件&#xff1b; 1、lib文件 在下述qt安装路径下拷贝Qt5…

[设计模式Java实现附plantuml源码~创建型] 对象的克隆~原型模式

前言&#xff1a; 为什么之前写过Golang 版的设计模式&#xff0c;还在重新写Java 版&#xff1f; 答&#xff1a;因为对于我而言&#xff0c;当然也希望对正在学习的大伙有帮助。Java作为一门纯面向对象的语言&#xff0c;更适合用于学习设计模式。 为什么类图要附上uml 因为很…

07章【常用类库API】

字符串操作 String类 String可以表示一个字符串。String类实际是使用字符数组存储的。 String类的两种赋值方式&#xff1a; 一种称为直接赋值&#xff1a; String name “小白” 通过关键字new调用String的构造方法赋值 String name new String(“小白”)String类的两…

【Github】作为程序员不得不知道的几款Github加速神器

背景 众所周知&#xff0c;近几年国内用户在访问Github时&#xff0c;经常间歇性无法访问Github。 接下来推荐几款 作为程序员不得不知道的Github加速神器。 推荐1&#xff1a;FastGithub FastGithub是一款Github加速神器&#xff0c;解决github打不开、用户头像无法加载、r…

【数据结构和算法】--- 二叉树(3)--二叉树链式结构的实现(1)

目录 一、二叉树的创建(伪)二、二叉树的遍历2.1 前序遍历2.2 中序遍历2.3 后序遍历 三、二叉树节点个数及高度3.1 二叉树节点个数3.2 二叉树叶子节点个数3.3二叉树第k层节点个数3.4 二叉树查找值为x的节点 四、二叉树的创建(真) 一、二叉树的创建(伪) 在学习二叉树的基本操作前…

Unity Text超框 文字滚动循环显示

Unity Text超框 文字滚动循环显示 //container Text using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI;public class AutoScrollText : MonoBehaviour {private Text[] _texts new Text[…

MATLAB字符串编辑常用代码

1.字符串赋值 % 字符串赋值 sabcdefg 2.字符串属性和操作 (1)获取字符串长度 sabcdefg;% 字符串赋值 length(a) % 获取字符串长度 (2)连接字符串 % 连接两个字符串,每个字符串最右边的空格被裁切 s1a s2b s3strcat(s1,s2) 3.字符串比较 % strcmp 比较两个字符串是…

9. UE5 RPG创建UI(下)

在上一篇文章里&#xff0c;制作了显示血量和蓝量的ui&#xff0c;并且还将ui和获取数据使用的控制器层创建出来并初始化成功。现在只有主用户控件上面被添加了控制器层&#xff0c;还未给每个用户控件赋予控制器层。接下来要实现对属性的广播功能&#xff0c;在属性值变化的时…

gitlab.rb主要配置

根据是否docker安装,进入挂载目录或安装目录 修改此文件,我一般是在可视化窗口中修改,有时候也在命令行手敲 将下面的配置复制到该文件中 external_url http://192.168.100.50 # nginx[listen_port] = 8000 (docker安装的这一行不需要,因为端口映射导致此处修改会导致访问…

2024茶饮品牌如何出圈,媒介盒子分析

随着新式茶饮的消费场景更加多元化&#xff0c;品类不断拓宽&#xff0c;消费者对新式茶饮的热情也是只增不减。居民可支配收入水平不断上升&#xff0c;居民消费升级为新式茶饮的发展也提供了良好基础&#xff0c;今天媒介盒子就来和大家聊聊&#xff1a;2024茶饮品牌如何出圈…

win10系统 pdf 文件无法正常预览

网上也看了不少办法&#xff0c;修改注册表什么的&#xff0c;太麻烦了&#xff0c;尝试了一下下载Adobe Acrobat Reader&#xff0c;安装后就可以成功预览显示啦&#xff01;对&#xff0c;就是这么简单&#xff01;Adobe Acrobat Reader下载链接&#xff1a;link

随机森林中每个树模型分裂时的特征选取方式

随机森林中每个树模型分裂时的特征选取方式 随机森林中每个树模型的每次分裂都是基于随机选取的特征子集进行分裂的。 具体来说&#xff0c;对于每个决策树&#xff0c;在每个节点的分裂过程中&#xff0c;随机森林算法会从原始特征集合中随机选择一个特征子集&#xff0c;然…

vulhub之Zabbix篇

CVE-2016-10134--SQL注入 一、漏洞介绍 zabbix是一款服务器监控软件&#xff0c;其由server、agent、web等模块组成&#xff0c;其中web模块由PHP编写&#xff0c;用来显示数据库中的结果。 漏洞环境 在vulhub靶场进行复现&#xff0c;启动zabbix 3.0.3。 二、复现步骤 1…