Optimize lightmap rendering using emissive texture approach
Changed from lightmapTexture with lighting enabled to emissiveTexture with lighting disabled for better performance. The new approach provides the same lighting illusion without expensive per-pixel lighting calculations. - Added LightmapGenerator.ENABLED toggle for performance testing - Updated buildColor.ts to use emissiveColor + emissiveTexture with disableLighting = true - Updated buildMissingMaterial() to match new rendering approach - Fixed buildTool.ts to access emissiveColor instead of diffuseColor for material color detection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
3f02fc7ea5
commit
c7887d7d8f
@ -194,10 +194,18 @@ export function buildMissingMaterial(name: string, scene: Scene, color: string):
|
|||||||
const colorObj = Color3.FromHexString(color);
|
const colorObj = Color3.FromHexString(color);
|
||||||
const newMaterial = new StandardMaterial(name, scene);
|
const newMaterial = new StandardMaterial(name, scene);
|
||||||
newMaterial.id = name;
|
newMaterial.id = name;
|
||||||
newMaterial.diffuseColor = colorObj;
|
|
||||||
newMaterial.disableLighting = false;
|
if (LightmapGenerator.ENABLED) {
|
||||||
newMaterial.lightmapTexture = LightmapGenerator.generateLightmapForColor(colorObj, scene);
|
// Lightmap as emissive texture (lighting illusion, no lighting calculations)
|
||||||
newMaterial.useLightmapAsShadowmap = false;
|
newMaterial.emissiveColor = colorObj;
|
||||||
|
newMaterial.emissiveTexture = LightmapGenerator.generateLightmapForColor(colorObj, scene);
|
||||||
|
newMaterial.disableLighting = true;
|
||||||
|
} else {
|
||||||
|
// Flat emissive-only rendering (no lighting illusion)
|
||||||
|
newMaterial.emissiveColor = colorObj;
|
||||||
|
newMaterial.disableLighting = true;
|
||||||
|
}
|
||||||
|
|
||||||
newMaterial.alpha = 1;
|
newMaterial.alpha = 1;
|
||||||
return newMaterial;
|
return newMaterial;
|
||||||
}
|
}
|
||||||
@ -17,11 +17,17 @@ export async function buildColor(color: Color3, scene: Scene, parent: TransformN
|
|||||||
const width = .1;
|
const width = .1;
|
||||||
const height = .1;
|
const height = .1;
|
||||||
const material = new StandardMaterial("material-" + color.toHexString(), scene);
|
const material = new StandardMaterial("material-" + color.toHexString(), scene);
|
||||||
material.diffuseColor = color;
|
|
||||||
material.disableLighting = false;
|
if (LightmapGenerator.ENABLED) {
|
||||||
material.lightmapTexture = LightmapGenerator.generateLightmapForColor(color, scene);
|
// Lightmap as emissive texture (lighting illusion, no lighting calculations)
|
||||||
material.useLightmapAsShadowmap = false;
|
material.emissiveColor = color;
|
||||||
material.specularPower = 64;
|
material.emissiveTexture = LightmapGenerator.generateLightmapForColor(color, scene);
|
||||||
|
material.disableLighting = true;
|
||||||
|
} else {
|
||||||
|
// Flat emissive-only rendering (no lighting illusion)
|
||||||
|
material.emissiveColor = color;
|
||||||
|
material.disableLighting = true;
|
||||||
|
}
|
||||||
|
|
||||||
const colorBoxMesh = MeshBuilder.CreatePlane("toolbox-color-" + color.toHexString(), {
|
const colorBoxMesh = MeshBuilder.CreatePlane("toolbox-color-" + color.toHexString(), {
|
||||||
width: width,
|
width: width,
|
||||||
|
|||||||
@ -9,8 +9,11 @@ export async function buildTool(tool: ToolType, colorParent: AbstractMesh, mater
|
|||||||
let color = "#000000";
|
let color = "#000000";
|
||||||
switch (material.getClassName()) {
|
switch (material.getClassName()) {
|
||||||
case "StandardMaterial":
|
case "StandardMaterial":
|
||||||
id = toolId(tool, (material as StandardMaterial).diffuseColor);
|
const stdMat = material as StandardMaterial;
|
||||||
color = (material as StandardMaterial).diffuseColor.toHexString();
|
// Use emissiveColor (set for both lightmap and non-lightmap modes)
|
||||||
|
const materialColor = stdMat.emissiveColor || stdMat.diffuseColor;
|
||||||
|
id = toolId(tool, materialColor);
|
||||||
|
color = materialColor.toHexString();
|
||||||
break;
|
break;
|
||||||
case "PBRMaterial":
|
case "PBRMaterial":
|
||||||
id = toolId(tool, (material as PBRMaterial).albedoColor);
|
id = toolId(tool, (material as PBRMaterial).albedoColor);
|
||||||
|
|||||||
@ -5,6 +5,9 @@ export class LightmapGenerator {
|
|||||||
private static lightmapCache: Map<string, DynamicTexture> = new Map();
|
private static lightmapCache: Map<string, DynamicTexture> = new Map();
|
||||||
private static readonly DEFAULT_RESOLUTION = 512;
|
private static readonly DEFAULT_RESOLUTION = 512;
|
||||||
|
|
||||||
|
// Toggle to enable/disable lightmap usage (for performance testing)
|
||||||
|
public static ENABLED = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates or retrieves cached lightmap for a given color
|
* Generates or retrieves cached lightmap for a given color
|
||||||
* @param color The base color for the lightmap
|
* @param color The base color for the lightmap
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user