Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ public void ClearWorldChunks()
public bool IsWorldLit(Renderer renderer) => _worldLitRenderers.Contains(renderer);
// Lightmap light per cell (ToCell) of the light mapped world polygons, sampled at their centers by WorldMeshBuilder.
private readonly Dictionary<long, Color> _lightmapCells = new();
private MaterialPropertyBlock _vobLightBlock;

/// <summary>
/// The lightmap light of the world's light mapped polygons per cell (rgb summed, w = polygon count).
Expand Down Expand Up @@ -378,15 +377,18 @@ public void ApplyWorldLight(GameObject vobGo)
if (!light.HasValue)
return;

_vobLightBlock ??= new MaterialPropertyBlock();
var tint = new Vector4(light.Value.r, light.Value.g, light.Value.b, 1f);
foreach (var renderer in renderers)
{
if (renderer is MeshRenderer meshRenderer && IsWorldChunk(meshRenderer))
continue;
renderer.GetPropertyBlock(_vobLightBlock);
_vobLightBlock.SetVector(_vobLightTintShaderId, tint);
renderer.SetPropertyBlock(_vobLightBlock);
// Into the renderer's own materials (each has its own - UpdateRenderer writes its light indices there
// too), not a MaterialPropertyBlock: the SRP batcher skips renderers with one, ~1900 VOBs in Khorinis
// were drawn one by one.
renderer.GetSharedMaterials(_rendererMaterials);
foreach (var material in _rendererMaterials)
if (material != null)
material.SetVector(_vobLightTintShaderId, tint);
_worldLitRenderers.Add(renderer);
}
}
Expand Down
5 changes: 3 additions & 2 deletions Assets/Gothic-Core/Shaders/Lit-World.shader
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Shader "Lit/World"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

float _FocusBrightness;

struct appdata
{
float4 vertex : POSITION;
Expand Down Expand Up @@ -68,13 +66,16 @@ Shader "Lit/World"
SAMPLER(sampler_WorldLightmaps);
float _WorldLightmapBrightness;

// Every material property in here, the same in every pass - else the SRP batcher skips the world and
// draws it chunk by chunk.
CBUFFER_START(UnityPerMaterial)
float4 _MainTex_TexelSize;
int _StationaryLightCount;
float4x4 _StationaryLightIndices;
float4x4 _StationaryLightIndices2;
float _WindStrength;
float4 _VobLightTint;
float _FocusBrightness;
CBUFFER_END

#include "GothicIncludes.hlsl"
Expand Down