Skip to content

Commit f11a428

Browse files
committed
Headlight back to the original linear model
1 parent 429f587 commit f11a428

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Source/RunActivity/Content/SceneryShader.fx

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int MorphConfig[9]; // 0-5: position of POSITION, NORMAL, TANGENT, TEXCOORD
8585
float MorphWeights[MAX_MORPH_TARGETS]; // the actual morphing animation state
8686

8787
int NumLights; // The number of the lights used
88-
float LightTypes[MAX_LIGHTS]; // 0: directional, 1: point, 2: spot
88+
float LightTypes[MAX_LIGHTS]; // 0: directional, 1: point, 2: spot, 3: headlight
8989
float3 LightPositions[MAX_LIGHTS];
9090
float3 LightDirections[MAX_LIGHTS];
9191
float3 LightColors[MAX_LIGHTS];

Source/RunActivity/Viewer3D/Lights.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,12 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
272272
LightConeDirection = Vector3.Transform(Vector3.Lerp(ActiveLightCone.Direction1, ActiveLightCone.Direction2, ActiveLightCone.Fade.Y), ShapeXNATranslations[coneIndex]);
273273
LightConeDirection -= ShapeXNATranslations[coneIndex].Translation;
274274
LightConeDirection.Normalize();
275-
// The original shaders followed the phylisophy of wanting 50% brightness at half the range. (LightConeDistance is only the half.) Now we need the full range.
276-
LightConeDistance = 2 * MathHelper.Lerp(ActiveLightCone.Distance1, ActiveLightCone.Distance2, ActiveLightCone.Fade.Y);
275+
LightConeDistance = 4 * MathHelper.Lerp(ActiveLightCone.Distance1, ActiveLightCone.Distance2, ActiveLightCone.Fade.Y);
277276
LightConeOuterAngle = MathHelper.Lerp(ActiveLightCone.Angle1, ActiveLightCone.Angle2, ActiveLightCone.Fade.Y);
278277
var lightConeColor = Vector4.Lerp(ActiveLightCone.Color1, ActiveLightCone.Color2, ActiveLightCone.Fade.Y);
279-
LightConeColor = new Vector3(lightConeColor.X, lightConeColor.Y, lightConeColor.Z);
278+
LightConeColor = new Vector3(lightConeColor.X, lightConeColor.Y, lightConeColor.Z) * lightConeColor.W;
280279

281-
frame.AddLight(LightMode.Spot, LightConePosition, LightConeDirection, LightConeColor, RenderFrame.HeadLightIntensity * lightConeColor.W, LightConeDistance, 0, LightConeOuterAngle, ActiveLightCone.Fade.X, false);
280+
frame.AddLight(LightMode.Headlight, LightConePosition, LightConeDirection, LightConeColor, RenderFrame.HeadLightIntensity, LightConeDistance, 0, LightConeOuterAngle, ActiveLightCone.Fade.X, false);
282281
}
283282
else
284283
{

Source/RunActivity/Viewer3D/RenderFrame.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public enum LightMode
7373
{
7474
Directional = 0,
7575
Point = 1,
76-
Spot = 2
76+
Spot = 2,
77+
Headlight = 3
7778
}
7879

7980
public abstract class RenderPrimitive
@@ -392,7 +393,8 @@ public class RenderFrame
392393
static readonly Vector3 MoonGlow = new Vector3(245f / 255f, 243f / 255f, 206f / 255f);
393394
const float SunIntensity = 1;
394395
const float MoonIntensity = SunIntensity / 380000;
395-
public const float HeadLightIntensity = 250000; // See some sample values: https://docs.unity3d.com/Packages/com.unity.cloud.gltfast@5.2/manual/LightUnits.html
396+
//public const float HeadLightIntensity = 250000; // See some sample values: https://docs.unity3d.com/Packages/com.unity.cloud.gltfast@5.2/manual/LightUnits.html
397+
public const float HeadLightIntensity = 4; // Using the old linear attenuation model
396398

397399
const float LIGHT_INTENSITY_ADJUSTMENT_SPOT = 1f;
398400
const float LIGHT_INTENSITY_ADJUSTMENT_POINT = 0.08f; // By visual inspection of PlaysetLightTest at nighttime. Probably should be 1 / 4π = 0.08

0 commit comments

Comments
 (0)