浏览代码

Refacto for better code integration

/main
Antoine Lelievre 6 年前
当前提交
7edc74d1
共有 7 个文件被更改,包括 21 次插入15 次删除
  1. 1
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/Shadow.hlsl
  2. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs
  3. 6
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl
  4. 6
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl
  5. 13
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  6. 3
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl
  7. 5
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl

1
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/Shadow.hlsl


StructuredBuffer<ShadowData> shadowDatas;
StructuredBuffer<int4> payloads;
SHADOWCONTEXT_DECLARE_TEXTURES( SHADOWCONTEXT_MAX_TEX2DARRAY, SHADOWCONTEXT_MAX_TEXCUBEARRAY, SHADOWCONTEXT_MAX_COMPSAMPLER, SHADOWCONTEXT_MAX_SAMPLER )
float contactShadow;
};
SHADOW_DEFINE_SAMPLING_FUNCS( SHADOWCONTEXT_MAX_TEX2DARRAY, SHADOWCONTEXT_MAX_TEXCUBEARRAY, SHADOWCONTEXT_MAX_COMPSAMPLER, SHADOWCONTEXT_MAX_SAMPLER )

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs


public Vector3 color;
public int shadowIndex; // -1 if unused
public int disableContactShadow; // 1 if disabled
public int contactShadowIndex; // -1 if unused
public Vector3 forward;
public int cookieIndex; // -1 if unused

6
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl


float invSqrAttenuationRadius;
float3 color;
int shadowIndex;
int disableContactShadow;
int contactShadowIndex;
float3 forward;
int cookieIndex;
float3 right;

{
return value.shadowIndex;
}
int GetDisableContactShadow(LightData value)
int GetContactShadowIndex(LightData value)
return value.disableContactShadow;
return value.contactShadowIndex;
}
float3 GetForward(LightData value)
{

6
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl


UNITY_BRANCH if (lightData.shadowIndex >= 0)
{
// TODO: make projector lights cast shadows.
contactShadow = LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.positionSS).x;
shadow = min(max(lightData.disableContactShadow, contactShadow), shadow);
contactShadow = GetSContactShadow(lightLoopContext, lightData.contactShadowIndex);
shadow = min(shadow, contactShadow);
#ifdef SHADOWS_SHADOWMASK
// Note: Legacy Unity have two shadow mask mode. ShadowMask (ShadowMask contain static objects shadow and ShadowMap contain only dynamic objects shadow, final result is the minimun of both value)

13
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs


lightData.lightType = gpuLightType;
lightData.disableContactShadow = 1;
lightData.contactShadowIndex = -1;
lightData.positionWS = light.light.transform.position;
// Setting 0 for invSqrAttenuationRadius mean we have no range attenuation, but still have inverse square attenuation.

int lightCount = Math.Min(cullResults.visibleLights.Count, k_MaxLightsOnScreen);
var sortKeys = new uint[lightCount];
int sortCount = 0;
float biggestLight = 0;
int dominantLightDataIndex = 0;
for (int lightIndex = 0, numLights = cullResults.visibleLights.Count; (lightIndex < numLights) && (sortCount < lightCount); ++lightIndex)
{

// 2. Go through all lights, convert them to GPU format.
// Simultaneously create data for culling (LightVolumeData and SFiniteLightBound)
//TODO: move this upwards
float biggestLight = 0;
int dominantLightDataIndex = 0;
for (int sortIndex = 0; sortIndex < sortCount; ++sortIndex)
{

//Activate contact shadows on dominant light
if (m_DominantLightIndex != -1)
{
m_DominantLightData.disableContactShadow = 0;
m_DominantLightData.contactShadowIndex = 0;
m_lightList.lights[dominantLightDataIndex] = m_DominantLightData;
}

{
if ((m_CurrentSunLight == null || m_CurrentSunLight.GetComponent<AdditionalShadowData>() == null || m_CurrentSunLightShadowIndex < 0) && m_DominantLightIndex == -1)
{
cmd.SetGlobalTexture(HDShaderIDs._DeferredShadowTexture, RuntimeUtilities.blackTexture);
cmd.SetGlobalTexture(HDShaderIDs._DeferredShadowTexture, RuntimeUtilities.whiteTexture);
return;
}

3
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl


context.sampleReflection = 0;
context.shadowContext = InitShadowContext();
context.shadowContext.contactShadow = LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.positionSS).x;
context.shadowContext.contactShadow = 1;
// This struct is define in the material. the Lightloop must not access it
// PostEvaluateBSDF call at the end will convert Lighting to diffuse and specular lighting
AggregateLighting aggregateLighting;

5
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


return _EnvLightDatas[j];
}
float GetSContactShadow(LightLoopContext lightLoopContact, int contactShadowIndex)
{
return 1;//max(lightLoopContact.shadowContext.contactShadow, abs(contactShadowIndex));
}
正在加载...
取消
保存