void OnSceneGUI() { PolygonLight fow = (PolygonLight)target; Handles.color = Color.white; Handles.DrawWireArc(fow.transform.position, Vector3.forward, Vector3.right, 360, fow.lightRadius); Vector3 viewAngleA = fow.DirFromAngle(-fow.lightAngle / 2, false); Vector3 viewAngleB = fow.DirFromAngle(fow.lightAngle / 2, false); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.lightRadius); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.lightRadius); }
private static void ConvexHullTesting() { var writer = new TextWriterTraceListener(Console.Out); Debug.Listeners.Add(writer); Message.Verbosity = VerbosityLevels.OnlyCritical; DirectoryInfo dir; if (Directory.Exists("../../../../TVGLTest/Convex Hull Tests")) { //x64 dir = new DirectoryInfo("../../../../TVGLTest/Convex Hull Tests"); } else { //x86 dir = new DirectoryInfo("../../../TVGLTest/Convex Hull Tests"); } var random = new Random(); var fileNames = dir.GetFiles("*").ToArray(); for (var i = 0; i < fileNames.Count(); i++) { //var filename = FileNames[i]; var filename = fileNames[i].FullName; if (!File.Exists(filename) || !filename.EndsWith(".PolyLight")) { continue; } Console.WriteLine("Attempting: " + filename); var polyLight = PolygonLight.Deserialize(filename); var cxvHull = MinimumEnclosure.ConvexHull2D(polyLight.Path); var polygon = new Polygon(cxvHull.Select(p => new Point(p))); if (!polygon.IsConvex()) { Presenter.ShowAndHang(polyLight.Path, "Convex Hull Error", Plot2DType.Points); Presenter.ShowAndHang(cxvHull); } } Console.WriteLine("Completed."); Console.ReadKey(); }
public void IrradianceUseComputeShader(ComputeShader indirectLightPassCS, UnityLmGBuffer gBuffer, RenderTexture shadowmap, PolygonLight polygonLight, RenderTexture rt, Vector2 farPlane, int lightmapIndex, ShadowMapParams shadowFactor) { //rt.Clear(); int mainKernel = indirectLightPassCS.FindKernel("CSMain"); indirectLightPassCS.SetTexture(mainKernel, "_NormalTex", gBuffer.NormalTex[lightmapIndex]); indirectLightPassCS.SetTexture(mainKernel, "_PositionTex", gBuffer.PositionTex[lightmapIndex]); Matrix4x4 matrix = gBuffer.RenderCameraVPInverse[lightmapIndex]; //转换成行优先? float[] matrixFloats = { matrix[0, 0], matrix[1, 0], matrix[2, 0], matrix[3, 0], matrix[0, 1], matrix[1, 1], matrix[2, 1], matrix[3, 1], matrix[0, 2], matrix[1, 2], matrix[2, 2], matrix[3, 2], matrix[0, 3], matrix[1, 3], matrix[2, 3], matrix[3, 3] }; float[] matrixFloats1 = { matrix[0, 0], matrix[0, 1], matrix[0, 2], matrix[0, 3], matrix[1, 0], matrix[1, 1], matrix[1, 2], matrix[1, 3], matrix[2, 0], matrix[2, 1], matrix[2, 2], matrix[2, 3], matrix[3, 0], matrix[3, 1], matrix[3, 2], matrix[3, 3] }; indirectLightPassCS.SetFloats("_GBufferCameraVPInverse", matrixFloats); indirectLightPassCS.SetVector("_GBufferCameraPos", gBuffer.RenderCameraPos[lightmapIndex]); //塞入polygonlight 多边形的信息 ComputeBuffer polygonLightBuffer = new ComputeBuffer(_polygonLight.Count, sizeof(float) * 3); //polygonLightBuffer.SetData(polygonLight.PolygonHull.ToArray()); polygonLightBuffer.SetData(_polygonLight.ToArray()); indirectLightPassCS.SetBuffer(mainKernel, "_PolygonHull", polygonLightBuffer); indirectLightPassCS.SetVector("_PolygonCenter", polygonLight.Center); indirectLightPassCS.SetVector("_PolygonNormal", polygonLight.Normal); indirectLightPassCS.SetVector("_PolygonTotalFlux", polygonLight.SumPower); indirectLightPassCS.SetInt("_PolygonVertexCount", _polygonLight.Count); indirectLightPassCS.SetFloat("_ShadowBias", shadowFactor.ShadowBias); indirectLightPassCS.SetVector("_FarPlane", farPlane); indirectLightPassCS.SetInt("_LightMapSize", LightMapSize); indirectLightPassCS.SetInt("_ShadowMapSize", ShadowMapSize); indirectLightPassCS.SetInt("_IsmCount", MaxVPLPerIsm); indirectLightPassCS.SetInt("_IsmIndexOffset", 0); indirectLightPassCS.SetFloat("_ShadowSoftness", shadowFactor.ShadowSoftness); indirectLightPassCS.SetFloat("_BiasFade", shadowFactor.BiasFade); //塞入最后返回的RenderTexture indirectLightPassCS.SetTexture(mainKernel, "_LightMap", rt); indirectLightPassCS.SetTexture(mainKernel, "_Ism", ISM); // ComputeBuffer outputPosBuffer = new ComputeBuffer(100*1000, sizeof(float)); // IndirectLightPassCS.SetBuffer(mainKernel, "_OutputGBufferPos", outputPosBuffer); indirectLightPassCS.Dispatch(mainKernel, LightMapSize / 32, LightMapSize / 32, 1); //dispose polygonLightBuffer.Dispose(); }
public void IrradianceUseComputeShader(ComputeShader indirectLightPassCS, UnityLmGBuffer gBuffer, RenderTexture shadowmap, PolygonLight polygonLight, RenderTexture rt, Vector2 farPlane, int lightmapIndex, int lightmapSize, int shadowmapSize, ShadowMapParams shadowFactor) { //rt.Clear(); int mainKernel = indirectLightPassCS.FindKernel("CSMain"); _gBuffer.SetComputeShaderData(indirectLightPassCS, mainKernel, lightmapIndex); //塞入polygonlight 多边形的信息 ComputeBuffer polygonLightBuffer = new ComputeBuffer(_polygonLight.Count, sizeof(float) * 3); //polygonLightBuffer.SetData(polygonLight.PolygonHull.ToArray()); polygonLightBuffer.SetData(_polygonLight.ToArray()); indirectLightPassCS.SetBuffer(mainKernel, "_PolygonHull", polygonLightBuffer); indirectLightPassCS.SetVector("_PolygonCenter", polygonLight.Center); indirectLightPassCS.SetVector("_PolygonNormal", polygonLight.Normal); indirectLightPassCS.SetVector("_PolygonTotalFlux", polygonLight.SumPower); indirectLightPassCS.SetInt("_PolygonVertexCount", _polygonLight.Count); indirectLightPassCS.SetFloat("_ShadowBias", shadowFactor.ShadowBias); indirectLightPassCS.SetVector("_FarPlane", farPlane); indirectLightPassCS.SetInt("_LightMapSize", lightmapSize); indirectLightPassCS.SetInt("_ShadowMapSize", shadowmapSize); indirectLightPassCS.SetInt("_IsmIndexOffset", 0); indirectLightPassCS.SetFloat("_ShadowSoftness", shadowFactor.ShadowSoftness); indirectLightPassCS.SetFloat("_BiasFade", shadowFactor.BiasFade); //塞入最后返回的RenderTexture indirectLightPassCS.SetTexture(mainKernel, "_LightMap", rt); indirectLightPassCS.SetTexture(mainKernel, "_Ism", shadowmap); // ComputeBuffer outputPosBuffer = new ComputeBuffer(100*1000, sizeof(float)); // IndirectLightPassCS.SetBuffer(mainKernel, "_OutputGBufferPos", outputPosBuffer); indirectLightPassCS.Dispatch(mainKernel, lightmapSize / 32, lightmapSize / 32, 1); //dispose polygonLightBuffer.Dispose(); }