Skip to content

Commit 4feba6e

Browse files
committed
urp forward+
1 parent 4718736 commit 4feba6e

5 files changed

Lines changed: 27 additions & 6 deletions

File tree

Editor/Generation/TemplateOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ protected static void AddURPLightingPragmas(PassBuilder pass)
278278
// pass.pragmas.Add("#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3");
279279
pass.pragmas.Add("#pragma multi_compile_fragment _ _LIGHT_COOKIES");
280280
pass.pragmas.Add("#pragma multi_compile _ _LIGHT_LAYERS");
281-
// pass.pragmas.Add("#pragma multi_compile _ _FORWARD_PLUS");
281+
pass.pragmas.Add("#pragma multi_compile _ _CLUSTER_LIGHT_LOOP");
282282
#if UNITY_6000_0_OR_NEWER
283283
pass.pragmas.Add("#include_with_pragmas \"Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl\"");
284284
#endif

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
### PBR Features
3232

3333
- Based on CoreRP, Google Filament, OpenPBR
34+
- Custom UnityCG include with various improvements
3435
- [Bakery](https://assetstore.unity.com/packages/tools/level-design/bakery-gpu-lightmapper-122218) Features (MonoSH, Lightmapped Specular, Bicubic Lightmap)
3536
- [LTCGI](https://github.com/PiMaker/ltcgi), [AreaLit](https://booth.pm/ja/items/3661829)
3637
- [Clustered BIRP](https://github.com/z3y/ClusteredBIRP)
@@ -68,7 +69,6 @@
6869

6970
Currently not implemented:
7071

71-
- Forward+
7272
- Dots
7373
- Decals
7474
- Rendering Layers

Runtime/UdonRPManager.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MonoBehaviour:
1212
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
1313
m_Name: UdonRPManager
1414
m_EditorClassIdentifier:
15-
serializedUdonProgramAsset: {fileID: 11400000, guid: 91a33fc490acc0947b4ea3c1ce42ff76,
15+
serializedUdonProgramAsset: {fileID: 11400000, guid: e2cda85bcd88c3747903cf4e40f5e3c2,
1616
type: 2}
1717
udonAssembly:
1818
assemblyError:

ShaderLibrary/FragmentForwardPBR.hlsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ float4 frag(Varyings input) : SV_Target
175175
}
176176
#endif
177177

178+
#ifdef UNIVERSALRP
179+
float2 normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
180+
#else
181+
// unused
182+
float2 normalizedScreenSpaceUV = 0;
183+
#endif
184+
178185
half3 indirectSpecular = 0;
179186
#ifndef UNITY_PASS_FORWARDADD
180187
#if !defined(_GLOSSYREFLECTIONS_OFF) && !defined(_CBIRP_REFLECTIONS)
@@ -206,6 +213,12 @@ float4 frag(Varyings input) : SV_Target
206213
#ifdef UNIVERSALRP
207214
uint pixelLightCount = GetAdditionalLightsCount();
208215
uint meshRenderingLayers = GetMeshRenderingLayer();
216+
217+
// Unity expects hard coded variables in macros as usual.
218+
InputData inputData = (InputData)0;
219+
inputData.positionWS = positionWS;
220+
inputData.normalizedScreenSpaceUV = normalizedScreenSpaceUV;
221+
209222
LIGHT_LOOP_BEGIN(pixelLightCount)
210223
URPLight additionalURPLight = GetAdditionalLight(lightIndex, positionWS, SampleShadowMask(fragment.lightmapUV.xy));
211224
#ifdef _LIGHT_LAYERS

ShaderLibrary/GlobalIllumination/ReflectionProbe.hlsl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#define ENABLE_ENVIRONMENT_PROBE
1111
#endif
1212

13+
#ifdef _GLOSSYREFLECTIONS_OFF
14+
#define _ENVIRONMENTREFLECTIONS_OFF
15+
#endif
16+
1317
TEXTURE2D(_DFG);
1418
SAMPLER(sampler_DFG);
1519

@@ -76,10 +80,10 @@ half GetHorizonOcclusion(float3 reflectVector, float3 vertexNormalWS)
7680

7781
half3 CalculateIrradianceFromReflectionProbes(half3 reflectVector, float3 positionWS, half perceptualRoughness, float2 normalizedScreenSpaceUV, float3 vertexNormalWS)
7882
{
79-
half3 irradiance = half3(0.0h, 0.0h, 0.0h);
83+
half3 irradiance = 0.0;
8084
half mip = PerceptualRoughnessToMipmapLevel(perceptualRoughness);
81-
#if USE_FORWARD_PLUS
82-
float totalWeight = 0.0f;
85+
#if USE_CLUSTER_LIGHT_LOOP && CLUSTER_HAS_REFLECTION_PROBES
86+
float totalWeight = 0.0;
8387
uint probeIndex;
8488
ClusterIterator it = ClusterInit(normalizedScreenSpaceUV, positionWS, 1);
8589
[loop] while (ClusterNext(it, probeIndex) && totalWeight < 0.99f)
@@ -192,7 +196,11 @@ half3 CalculateIrradianceFromReflectionProbes(half3 reflectVector, float3 positi
192196
// Use any remaining weight to blend to environment reflection cube map
193197
if (totalWeight < 0.99f)
194198
{
199+
#ifdef UNIVERSALRP
200+
half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(_GlossyEnvironmentCubeMap, sampler_GlossyEnvironmentCubeMap, reflectVector, mip));
201+
#else
195202
half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(_GlossyEnvironmentCubeMap, samplerunity_SpecCube0, reflectVector, mip));
203+
#endif
196204

197205
irradiance += (1.0f - totalWeight) * DecodeHDREnvironment(encodedIrradiance, _GlossyEnvironmentCubeMap_HDR) * GetHorizonOcclusion(reflectVector, vertexNormalWS);
198206
}

0 commit comments

Comments
 (0)