//utils static public int giveLightIndex(int editorObjectIndex) { SimEditor.LocalLight ll = getSimObjectAsLight(editorObjectIndex); for (int i = 0; i < mLights.Count; i++) { if (mLights[i].mSimEditorObject == ll) { return(i); } } return(-1); }
static public void rasterLightsToNode(worldChunk wc) { if (!TerrainGlobals.getEditor().doShowLighting()) { return; } clearLightInfluence(wc.mQNPointer.getDesc().mMinXVert, wc.mQNPointer.getDesc().mMinZVert); wc.mQNPointer.mDirty = true; wc.mQNPointer.clearVisibleDatHandle(); for (int i = 0; i < wc.mLightsAffectingMe.Count; i++) { SimEditor.LocalLight ll = wc.mLightsAffectingMe[i].mSimEditorObject; rasterLightToGrid(ll, TerrainGlobals.getEditor().getLightValues(), wc.mQNPointer.getDesc().mMinXVert, wc.mQNPointer.getDesc().mMinZVert); } }
//CLM called during normal export static public void rasterTerrainLightsToExportGrid(Vector3 [] lht) { //walk each world grid, raster the lights that are terrain only to the grid worldChunk wc = null; for (int x = 0; x < mWorldChunks.GetLength(0); x++) { for (int y = 0; y < mWorldChunks.GetLength(1); y++) { for (int i = 0; i < mWorldChunks[x, y].mLightsAffectingMe.Count; i++) { SimEditor.LocalLight ll = mWorldChunks[x, y].mLightsAffectingMe[i].mSimEditorObject; if (ll.LightData.TerrainOnly == true) { rasterLightToGrid(ll, lht, mWorldChunks[x, y].mQNPointer.getDesc().mMinXVert, mWorldChunks[x, y].mQNPointer.getDesc().mMinZVert); } } } } }
static private void rasterLightToGrid(SimEditor.LocalLight light, Vector3[] lht, int minXVert, int minZVert) { //CLM this code is a duplicate of what's on the 360! //ANY CHANGES TO THE 360 CODE MUST BE DUPLICATED HERE! Vector3 lightColor = new Vector3(light.LightData.LightColor.R / 255.0f, light.LightData.LightColor.G / 255.0f, light.LightData.LightColor.B / 255.0f); ////terrain fill, don't let the ligths go above 2.0; //convert to linear and multiply by intensity //srgb*srgb *intensity lightColor = BMathLib.Vec3Mul(lightColor, lightColor) * light.LightData.Intensity; float farAttenStart = Math.Min(0.999f, light.LightData.FarAttnStart); float omniOOFalloffRange = 1.0f / (1.0f - farAttenStart); float omniMul = -((1.0f / light.LightData.Radius) * omniOOFalloffRange); float omniAdd = 1.0f + farAttenStart * omniOOFalloffRange; float spotMul = 0.0f; float spotAdd = 100.0f; Vector3 spotDir = new Vector3(0, 0, 0); if (light is SimEditor.SpotLight) { float fovFudge = 0; spotDir = Vector3.Normalize((light as SimEditor.SpotLight).mDirection); float spotInner = Math.Max(Geometry.DegreeToRadian(.0125f), Geometry.DegreeToRadian(light.LightData.InnerAngle) - Geometry.DegreeToRadian(fovFudge)); float spotOuter = Math.Max(Geometry.DegreeToRadian(.025f), Geometry.DegreeToRadian(light.LightData.OuterAngle) - Geometry.DegreeToRadian(fovFudge)); spotMul = (float)(1.0f / ((Math.Cos(spotInner * .5f) - Math.Cos(spotOuter * .5f)))); spotAdd = (float)(1.0f - Math.Cos(spotInner * .5f) * spotMul); } //for each vert in this chunk.. for (int x = 0; x < BTerrainQuadNode.cMaxWidth; x++) { for (int y = 0; y < BTerrainQuadNode.cMaxHeight; y++) { Vector3 wpos = TerrainGlobals.getTerrain().getPostDeformPos(x + minXVert, y + minZVert); Vector3 normal = TerrainGlobals.getTerrain().getPostDeformNormal(x + minXVert, y + minZVert); Vector3 lightVec = light.getPosition() - wpos; float dist = lightVec.Length(); float ooLightDist = BMathLib.Clamp((float)(1.0f / dist), 0, 1); Vector3 lightNorm = BMathLib.Normalize(lightVec); float spotAngle = -BMathLib.Dot(ref spotDir, ref lightNorm); float lDot = BMathLib.Clamp(BMathLib.Dot(ref lightNorm, ref normal), 0, 1); Vector3 atten; atten.X = lDot; atten.Y = BMathLib.Clamp(spotAngle * spotMul + spotAdd, 0, 1); atten.Z = BMathLib.Clamp(dist * omniMul + omniAdd, 0, 1); atten.X = atten.X * atten.X * (-2.0f * atten.X + 3.0f); atten.Y = atten.Y * atten.Y * (-2.0f * atten.Y + 3.0f); atten.Z = atten.Z * atten.Z * (-2.0f * atten.Z + 3.0f); atten.X *= atten.Z; atten.X *= BMathLib.Clamp(light.LightData.DecayDist * ooLightDist, 0, 1); atten.X *= atten.Y; int index = (minXVert + x) * TerrainGlobals.getTerrain().getNumXVerts() + (minZVert + y); lht[index].X = (atten.X * lightColor.Z + lht[index].X); lht[index].Y = (atten.X * lightColor.Y + lht[index].Y); lht[index].Z = (atten.X * lightColor.X + lht[index].Z); } } }