diff --git a/Runtime/PSXMesh.cs b/Runtime/PSXMesh.cs index 0faf94b..59e6c37 100644 --- a/Runtime/PSXMesh.cs +++ b/Runtime/PSXMesh.cs @@ -128,7 +128,7 @@ namespace SplashEdit.RuntimeCode Vector3 wv = transform.TransformPoint(vertices[index]); // Transform the normals to world space. Vector3 wn = transform.TransformDirection(smoothNormals[index]).normalized; - // Compute lighting for each vertex (this can be a custom function). + // Compute lighting for each vertex. Color c = PSXLightingBaker.ComputeLighting(wv, wn); // Convert vertex to PSX format, including fixed-point conversion and shading. return ConvertToPSXVertex(v, GTEScaling, normals[index], uv[index], psxTexture?.Width, psxTexture?.Height, c); @@ -148,7 +148,7 @@ namespace SplashEdit.RuntimeCode } // Add the constructed triangle to the mesh. - psxMesh.Triangles.Add(new Tri { v0 = convertData(vid0), v1 = convertData(vid0), v2 = convertData(vid0), Texture = psxTexture }); + psxMesh.Triangles.Add(new Tri { v0 = convertData(vid0), v1 = convertData(vid1), v2 = convertData(vid2), Texture = psxTexture }); } } @@ -187,9 +187,9 @@ namespace SplashEdit.RuntimeCode v = (byte)Mathf.Clamp((1.0f - uv.y) * (height - 1), 0, 255), // Apply lighting to the colors. - r = Utils.Clamp0255(color.r), - g = Utils.Clamp0255(color.g), - b = Utils.Clamp0255(color.b), + r = Utils.ColorUnityToPSX(color.r), + g = Utils.ColorUnityToPSX(color.g), + b = Utils.ColorUnityToPSX(color.b), }; return psxVertex; diff --git a/Runtime/Utils.cs b/Runtime/Utils.cs index 48839c3..c78c88e 100644 --- a/Runtime/Utils.cs +++ b/Runtime/Utils.cs @@ -332,7 +332,7 @@ namespace SplashEdit.RuntimeCode } - public static byte Clamp0255(float v) => (byte)(Mathf.Clamp(v, 0, 255)); + public static byte ColorUnityToPSX(float v) => (byte)(Mathf.Clamp(v*255, 0, 255)); } }