protected override void CreateResources() { albedoMap = Texture.White; specularMap = Texture.White; normalMap = Texture.Blue; ssrBuffer = Buffer.CreateUniformBuffer <SSRDepthInfo>(); planeInfo = Buffer.CreateUniformBuffer <PlaneInfoPack>(); SSRDepthInfo sSRDepthInfo = new SSRDepthInfo { depth = new vec4(0.0f, 0.3f, 1.0f, 1.0f) }; ssrBuffer.SetData(ref sSRDepthInfo); planeInfoPack.numPlanes = 1; planeInfoPack.planeInfo.item1.centerPoint = new vec4(0.0f, 0.0f, 0.0f, 0.0f); planeInfoPack.planeInfo.item1.size = new vec4(100.0f); planeInfoPack.planeInfo.item2.centerPoint = new vec4(4.5f, 0.3f, 1.0f, 0.0f); planeInfoPack.planeInfo.item2.size = new vec4(7.0f, 1.5f, 0.0f, 0.0f); planeInfoPack.planeInfo.item3.centerPoint = new vec4(4.5f, 0.3f, -2.0f, 0.0f); planeInfoPack.planeInfo.item3.size = new vec4(7.0f, 1.5f, 0.0f, 0.0f); mat4 basicMat = new mat4(); basicMat[0] = new vec4(1.0f, 0.0f, 0.0f, 0.0f); //tan basicMat[1] = new vec4(0.0f, 1.0f, 0.0f, 0.0f); //bitan basicMat[2] = new vec4(0.0f, 0.0f, 1.0f, 0.0f); //normal basicMat[3] = new vec4(0.0f, 0.0f, 0.0f, 1.0f); planeInfoPack.planeInfo.item1.rotMat = glm.rotate(basicMat, glm.radians(-90.0f), glm.vec3(1.0f, 0.0f, 0.0f)); planeInfoPack.planeInfo.item2.rotMat = glm.rotate(basicMat, glm.radians(-110.0f), glm.vec3(1.0f, 0.0f, 0.0f)); planeInfoPack.planeInfo.item3.rotMat = glm.rotate(basicMat, glm.radians(-70.0f), glm.vec3(1.0f, 0.0f, 0.0f)); planeInfo.SetData(ref planeInfoPack); }
public void AddBoundingBox(ref BoundingBox box, ref mat4 transform, Color color, bool depthTest, bool solid) { vec3 min = box.min; vec3 max = box.max; vec3 v0 = vec3.Transform(min, transform); vec3 v1 = vec3.Transform(new vec3(max.X, min.Y, min.Z), transform); vec3 v2 = vec3.Transform(new vec3(max.X, max.Y, min.Z), transform); vec3 v3 = vec3.Transform(new vec3(min.X, max.Y, min.Z), transform); vec3 v4 = vec3.Transform(new vec3(min.X, min.Y, max.Z), transform); vec3 v5 = vec3.Transform(new vec3(max.X, min.Y, max.Z), transform); vec3 v6 = vec3.Transform(new vec3(min.X, max.Y, max.Z), transform); vec3 v7 = vec3.Transform(max, transform); int uintColor = color.ToRgba(); if (!solid) { AddLine(v0, v1, uintColor, depthTest); AddLine(v1, v2, uintColor, depthTest); AddLine(v2, v3, uintColor, depthTest); AddLine(v3, v0, uintColor, depthTest); AddLine(v4, v5, uintColor, depthTest); AddLine(v5, v7, uintColor, depthTest); AddLine(v7, v6, uintColor, depthTest); AddLine(v6, v4, uintColor, depthTest); AddLine(v0, v4, uintColor, depthTest); AddLine(v1, v5, uintColor, depthTest); AddLine(v2, v7, uintColor, depthTest); AddLine(v3, v6, uintColor, depthTest); } else { AddPolygon(v0, v1, v2, v3, uintColor, depthTest); AddPolygon(v4, v5, v7, v6, uintColor, depthTest); AddPolygon(v0, v4, v6, v3, uintColor, depthTest); AddPolygon(v1, v5, v7, v2, uintColor, depthTest); AddPolygon(v3, v2, v7, v6, uintColor, depthTest); AddPolygon(v0, v1, v5, v4, uintColor, depthTest); } }
protected override void OnUpdate() { RenderView view = View; UpdateLight(view); tile_count_x = ((uint)view.Width - 1) / TILE_WIDTH + 1; tile_count_y = ((uint)view.Height - 1) / TILE_HEIGHT + 1; Camera camera = view.Camera; clusterUniforms.view = camera.View; mat4 clip = new mat4(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f); //clusterUniforms.projection_clip = clip*camera.Projection; clusterUniforms.projection_clip = camera.VkProjection; clusterUniforms.inv_view_proj = glm.inverse(camera.VkProjection * camera.View); clusterUniforms.tile_size[0] = (float)(TILE_WIDTH); clusterUniforms.tile_size[1] = (float)(TILE_HEIGHT); clusterUniforms.grid_dim[0] = tile_count_x; clusterUniforms.grid_dim[1] = tile_count_y; clusterUniforms.cam_pos = camera.Node.WorldPosition; clusterUniforms.cam_near = camera.NearClip; clusterUniforms.cam_forward = camera.Node.WorldDirection; clusterUniforms.cam_far = camera.FarClip; clusterUniforms.resolution[0] = (float)(view.Width); clusterUniforms.resolution[1] = (float)(view.Height); clusterUniforms.num_lights = num_lights; uboCluster.SetData(ref clusterUniforms); uboCluster.Flush(); }
/// <summary> /// Creates a new instance of BoundingFrustum. /// </summary> /// <param name="matrix">Combined matrix that usually takes view × projection matrix.</param> public Frustum(mat4 matrix) { this.matrix = matrix; GetPlanesFromMatrix(in this.matrix, out near, out far, out left, out right, out top, out bottom); }
public void SetLightMatrices(int index, ref mat4 mat) { lightMatrices[index] = mat; }