public void InjectDeferredBuffer(Texture normalBuffer, Texture depthBuffer) { var normalUniform = new TextureUniform("normalBuffer", normalBuffer, TextureUnit.Texture0); var depthUniform = new TextureUniform("depthBuffer", depthBuffer, TextureUnit.Texture1); PointLights.AddSettings(normalUniform, depthUniform); }
internal void Light() { allLights = LightObject.GetLights(); DirectionalLights.Clear(); PointLights.Clear(); SpotLights.Clear(); for (int i = 0; i < allLights.Count; i++) { if (allLights[i].type == LightType.Spot) { //if (l.cookie == null) // l.cookie = DefaultSpotCookie; SpotLights.Add(allLights[i]); } else if (allLights[i].type == LightType.Point) { PointLights.Add(allLights[i]); } else if (allLights[i].type == LightType.Directional) { DirectionalLights.Add(allLights[i]); } if (UseAlloyLight) { allLights[i].light.GetOrAddComponent <AlloyAreaLight>().UpdateBinding(); } } }
internal void Light() { allLights = GameObject.FindObjectsOfType <Light>(); DirectionalLights.Clear(); PointLights.Clear(); SpotLights.Clear(); for (int i = 0; i < allLights.Length; i++) { if (allLights[i].type == LightType.Spot) { /* * if (l.cookie == null) * l.cookie = DefaultSpotCookie; */ SpotLights.Add(allLights[i]); } else if (allLights[i].type == LightType.Point) { PointLights.Add(allLights[i]); } else if (allLights[i].type == LightType.Directional) { DirectionalLights.Add(allLights[i]); } if (UseAlloyLight) { allLights[i].GetOrAddComponent <AlloyAreaLight>().UpdateBinding(); } } }
public void Clear() { SurfaceLights.Clear(); PointLights.Clear(); _intersectables.Clear(); _boundables.Clear(); Objects.Clear(); }
public void Reset() { // TODO: this should be replaced with a solution that supports multiple playback sources Playback = Playback.Current; LocalTime = Playback.TimeInBars; LocalFxTime = Playback.FxTimeInBars; PointLights.Clear(); PbrContextSettings.SetDefaultToContext(this); }
//-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- /// <inheritdoc/> public void Reset() { ReferenceNode = null; _referencePosition = null; DirectionalLights.Clear(); AmbientLights.Clear(); PointLights.Clear(); Spotlights.Clear(); ProjectorLights.Clear(); ImageBasedLights.Clear(); OtherLights.Clear(); }
internal void Light() { allLights = LightObject.GetLights(); DirectionalLights.Clear(); PointLights.Clear(); SpotLights.Clear(); for (int i = 0; i < allLights.Count; i++) { if (allLights[i].type == LightType.Spot) { //if (l.cookie == null) // l.cookie = DefaultSpotCookie; SpotLights.Add(allLights[i]); } else if (allLights[i].type == LightType.Point) { PointLights.Add(allLights[i]); } else if (allLights[i].type == LightType.Directional) { if (Graphics.Instance.Settings.UsePCSS) { if (null == pcss) { pcss = allLights[i].light.GetOrAddComponent <PCSSLight>(); } if (null != pcss) { pcss.enabled = true; } } else { if (null == pcss) { pcss = allLights[i].light.GetComponent <PCSSLight>(); } if (null != pcss) { pcss.enabled = false; } } DirectionalLights.Add(allLights[i]); } if (UseAlloyLight) { allLights[i].light.GetOrAddComponent <AlloyAreaLight>().UpdateBinding(); } } }
public void RemovePointLight(LightPoint lp) { if (!PointLights.Contains(lp)) { return; } foreach (GameObject obj in lp.AffectedObjects) { obj.LightsAffecting.Remove(lp); } PointLights.Remove(lp); PhysicsManager.Instance.RemoveCollider(lp.MyCollider); PhysicsManager.Instance.RemovePhysicalObject(lp); }
private void InitializeLightingScene() { //All lighting objects are requires to be in a layer named Lighting var lighting = m_level.getLayerByName("Lighting").Items; for (int i = 0; i < lighting.Count; ++i) { Vector3 lightPosition = new Vector3(); lightPosition.X = lighting[i].Position.X; lightPosition.Y = lighting[i].Position.Y; lightPosition.Z = 0; PointLights.Add(new PointLight() { Colour = Color.Red, LightIntensity = 4, LightRadius = 50, LightPosition = lightPosition }); } }
/// <summary> /// Draw the scene /// </summary> /// <param name="camera">The camera where you want to draw from</param> /// <param name="window">The window you want to draw to</param> public void Draw(Camera camera, GameWindow window) { Matrix4 mat = camera.CalculateMatrix(); _voxelData.Update(); _modelData.Update(); for (int i = 0; i < _models.Count; i++) { Matrix4 inverseModelMatrix = _models[i].Transform.CalculateInverseMatrix(); Matrix4 modelMatrix = _models[i].Transform.CalculateMatrix(); Matrix4 normalMatrix = _models[i].Transform.CalculateNormalMatrix(); // Check if the matrices are the same to avoid sending data the gpu already has if (_modelTransformations[i * 3 + 0] != inverseModelMatrix) { _modelTransformations[i * 3 + 0] = inverseModelMatrix; } if (_modelTransformations[i * 3 + 1] != modelMatrix) { _modelTransformations[i * 3 + 1] = modelMatrix; } if (_modelTransformations[i * 3 + 2] != normalMatrix) { _modelTransformations[i * 3 + 2] = normalMatrix; } } _modelTransformations.Update(); Shader.Bind(); GL.BindVertexArray(_canvasFB.Vao); // Send the buffers containing the models _voxelData.Bind(TextureUnit.Texture0); GL.Uniform1(Shader.GetUniformLocation("u_voxelBuffer"), 1, new[] { 0 }); _modelData.Bind(TextureUnit.Texture1); GL.Uniform1(Shader.GetUniformLocation("u_modelData"), 1, new[] { 1 }); _modelTransformations.Bind(TextureUnit.Texture2); GL.Uniform1(Shader.GetUniformLocation("u_modelTransformations"), 1, new[] { 2 }); // Send the materials Materials.Bind("u_materials"); // Send the windowsize GL.Uniform2(Shader.GetUniformLocation("u_windowSize"), 1, new float[] { window.Width, window.Height / 2 }); // Send the camera GL.Uniform1(Shader.GetUniformLocation("u_camera.zoom"), 1, new[] { (window.Height / 1.5f) / (float)Math.Tan(camera.Fov * (Math.PI / 360.0f)) }); GL.UniformMatrix4(Shader.GetUniformLocation("u_camera.matrix"), false, ref mat); // Send the lights GL.Uniform1(Shader.GetUniformLocation("u_dirLightCount"), DirectionalLights.Count()); for (int i = 0; i < DirectionalLights.Count(); i++) { GL.Uniform3(Shader.GetUniformLocation($"u_dirLights[{i}].direction"), DirectionalLights[i].direction); GL.Uniform1(Shader.GetUniformLocation($"u_dirLights[{i}].intensity"), DirectionalLights[i].intensity); GL.Uniform3(Shader.GetUniformLocation($"u_dirLights[{i}].colour"), DirectionalLights[i].colour); } GL.Uniform1(Shader.GetUniformLocation("u_pointLightCount"), PointLights.Count()); for (int i = 0; i < PointLights.Count(); i++) { GL.Uniform3(Shader.GetUniformLocation($"u_pointLights[{i}].position"), PointLights[i].position); //_pointLights[i].position GL.Uniform1(Shader.GetUniformLocation($"u_pointLights[{i}].intensity"), PointLights[i].intensity); GL.Uniform3(Shader.GetUniformLocation($"u_pointLights[{i}].colour"), PointLights[i].colour); } GL.BindFramebuffer(FramebufferTarget.Framebuffer, _framebuffer); //GL.Viewport(window.Width / 2, window.Height / 2, window.Width / 2, window.Height / 2); GL.DrawArrays(PrimitiveType.TriangleFan, 0, 4); GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); Shader.Unbind(); ScaleShader.Bind(); GL.BindVertexArray(_canvas.Vao); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, _textureColorBuffer); GL.Uniform1(ScaleShader.GetUniformLocation("u_framebuffer"), 1, new[] { 0 }); GL.Uniform2(ScaleShader.GetUniformLocation("u_resolution"), 1, new float[] { window.Width, window.Height }); //GL.Viewport(0,0, window.Width,window.Height); GL.DrawArrays(PrimitiveType.TriangleFan, 0, 4); ScaleShader.Unbind(); }
private void AddNode(LightNode lightNode) { Debug.Assert(lightNode.ActualIsEnabled, "Scene query contains disabled nodes."); // Ignore light if the reference position is not in the clip geometry. if (lightNode.Clip != null && _referencePosition.HasValue) { bool haveContact = HaveContact(lightNode.Clip, _referencePosition.Value); if (lightNode.InvertClip == haveContact) { return; } } // ----- Sort by estimated light contribution. // All lights except IBL will be sorted by contribution. // Note: If we have no reference node, it still makes sense to sort the objects // by their contribution. We choose to get the light contribution at the position // of each light. Vector3F position = _referencePosition ?? lightNode.PoseWorld.Position; //lightNode.SortTag = lightNode.GetLightContribution(position, 0.7f); // Or simpler: Sort light nodes by distance. --> Use for image-based lights. // (We use distance², because it is faster.) //float distance = (position - lightNode.PoseWorld.Position).LengthSquared; //lightNode.SortTag = -distance; // minus because we use descending sort. if (lightNode.Light is AmbientLight) { AmbientLights.Add(lightNode); lightNode.SortTag = lightNode.GetLightContribution(position, 0.7f); } else if (lightNode.Light is DirectionalLight) { DirectionalLights.Add(lightNode); lightNode.SortTag = lightNode.GetLightContribution(position, 0.7f); } else if (lightNode.Light is PointLight) { PointLights.Add(lightNode); lightNode.SortTag = lightNode.GetLightContribution(position, 0.7f); } else if (lightNode.Light is Spotlight) { Spotlights.Add(lightNode); lightNode.SortTag = lightNode.GetLightContribution(position, 0.7f); } else if (lightNode.Light is ProjectorLight) { ProjectorLights.Add(lightNode); lightNode.SortTag = lightNode.GetLightContribution(position, 0.7f); } else if (lightNode.Light is ImageBasedLight) { ImageBasedLights.Add(lightNode); float distance = (position - lightNode.PoseWorld.Position).LengthSquared; lightNode.SortTag = -distance; // minus because we use descending sort. } else { OtherLights.Add(lightNode); lightNode.SortTag = lightNode.GetLightContribution(position, 0.7f); } }
public void Set(SceneNode referenceNode, IList <SceneNode> nodes, RenderContext context) { Reset(); ReferenceNode = referenceNode; // We use the origin of the reference node as the reference position for determining // the light contribution. Alternatively we could use the closest point in/on model AABB, // but this requires valid AABBs, is more expensive, etc. if (referenceNode != null) { _referencePosition = referenceNode.PoseWorld.Position; } int numberOfNodes = nodes.Count; #if DEBUG for (int i = 0; i < numberOfNodes; i++) { Debug.Assert(nodes[i].ActualIsEnabled, "Scene query contains disabled nodes."); } #endif if (context.LodCameraNode == null) { // ----- No LOD for (int i = 0; i < numberOfNodes; i++) { var lightNode = nodes[i] as LightNode; if (lightNode != null) { AddNode(lightNode); } } } else { // ----- LOD // Get values for LOD computations. var cameraNode = context.LodCameraNode; _cameraPosition = cameraNode.PoseLocal.Position; _lodBiasOverYScale = 1 / Math.Abs(cameraNode.Camera.Projection.ToMatrix44F().M11) * cameraNode.LodBias * context.LodBias; // Add nodes and evaluate LOD groups. for (int i = 0; i < numberOfNodes; i++) { AddNodeWithLod(nodes[i], context); } } // Sort lights. if (referenceNode != null) { AmbientLights.Sort(DescendingLightNodeComparer.Instance); DirectionalLights.Sort(DescendingLightNodeComparer.Instance); PointLights.Sort(DescendingLightNodeComparer.Instance); Spotlights.Sort(DescendingLightNodeComparer.Instance); ProjectorLights.Sort(DescendingLightNodeComparer.Instance); ImageBasedLights.Sort(DescendingLightNodeComparer.Instance); OtherLights.Sort(DescendingLightNodeComparer.Instance); } }
public void Add(PointLight pointLight) { PointLights.Add(pointLight); }