protected Light(Light input) : base(input) { Color = input.Color; intensity = input.intensity; falloff = input.falloff; fov = input.fov; light_type = input.light_type; strct = input.strct; //Initialize new MeshVao meshVao = new GLMeshVao(); meshVao.type = TYPES.LIGHT; meshVao.vao = new Primitives.LineSegment(1, new Vector3(1.0f, 0.0f, 0.0f)).getVAO(); meshVao.metaData = new MeshMetaData(); meshVao.metaData.batchcount = 2; meshVao.material = RenderState.activeResMgr.GLmaterials["lightMat"]; instanceId = GLMeshBufferManager.addInstance(ref meshVao, this); //Add instance //Copy Matrices lightProjectionMatrix = input.lightProjectionMatrix; lightSpaceMatrices = new Matrix4[6]; for (int i = 0; i < 6; i++) { lightSpaceMatrices[i] = input.lightSpaceMatrices[i]; } update_struct(); RenderState.activeResMgr.GLlights.Add(this); }
public static void setInstanceSelectedStatus(GLMeshVao mesh, int instance_id, bool status) { unsafe { mesh.dataBuffer[instance_id * instance_struct_size_floats + instance_isSelected_Float_Offset] = status ? 1.0f : 0.0f; } }
public static bool getInstanceSelectedStatus(GLMeshVao mesh, int instance_id) { unsafe { return(mesh.dataBuffer[instance_id * instance_struct_size_floats + instance_isSelected_Float_Offset] > 0.0f); } }
public static void setInstanceLODLevel(GLMeshVao mesh, int instance_id, int level) { unsafe { mesh.dataBuffer[instance_id * instance_struct_size_floats + instance_LOD_Float_Offset] = (float)level; } }
public static int getInstanceLODLevel(GLMeshVao mesh, int instance_id, int level) { unsafe { return((int)mesh.dataBuffer[instance_id * instance_struct_size_floats + instance_LOD_Float_Offset]); } }
public static Vector4 getInstanceUniform(GLMeshVao mesh, int instance_id, string un_name) { Vector4 un; unsafe { int offset = instanceData_Float_Offset + instance_id * instance_struct_size_floats + instance_Uniforms_Float_Offset; int uniform_id = 0; switch (un_name) { case "gUserDataVec4": uniform_id = 0; break; } offset += uniform_id * 4; un.X = mesh.dataBuffer[offset]; un.Y = mesh.dataBuffer[offset + 1]; un.Z = mesh.dataBuffer[offset + 2]; un.W = mesh.dataBuffer[offset + 3]; } return(un); }
//Instance Data Format: //0-16 : instance WorldMatrix //16-17: isOccluded //17-18: isSelected //18-20: padding public static int addInstance(ref GLMeshVao mesh, Model m) { int instance_id = mesh.instance_count; //Expand mesh data buffer if required if (instance_id * instance_struct_size_bytes > mesh.dataBuffer.Length) { float[] newBuffer = new float[mesh.dataBuffer.Length + 256]; Array.Copy(mesh.dataBuffer, newBuffer, mesh.dataBuffer.Length); mesh.dataBuffer = newBuffer; } if (instance_id < GLMeshVao.MAX_INSTANCES) { //Uplod worldMat to the meshVao Matrix4 actualWorldMat = m.worldMat; Matrix4 actualWorldMatInv = (actualWorldMat).Inverted(); setInstanceWorldMat(mesh, instance_id, actualWorldMat); setInstanceWorldMatInv(mesh, instance_id, actualWorldMatInv); setInstanceNormalMat(mesh, instance_id, Matrix4.Transpose(actualWorldMatInv)); mesh.instanceRefs.Add(m); //Keep reference mesh.instance_count++; } return(instance_id); }
public Light() { type = TYPES.LIGHT; fov = 360; intensity = 1.0f; falloff = ATTENUATION_TYPE.CONSTANT; light_type = LIGHT_TYPE.POINT; //Initialize new MeshVao meshVao = new GLMeshVao(); meshVao.type = TYPES.LIGHT; meshVao.vao = new Primitives.LineSegment(1, new Vector3(1.0f, 0.0f, 0.0f)).getVAO(); meshVao.metaData = new MeshMetaData(); meshVao.metaData.batchcount = 2; meshVao.material = Common.RenderState.activeResMgr.GLmaterials["lightMat"]; instanceId = GLMeshBufferManager.addInstance(ref meshVao, this); // Add instance //Init projection Matrix lightProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathUtils.radians(90), 1.0f, 1.0f, 300f); //Init lightSpace Matrices lightSpaceMatrices = new Matrix4[6]; for (int i = 0; i < 6; i++) { lightSpaceMatrices[i] = Matrix4.Identity * lightProjectionMatrix; } //Catch changes to MVector from the UI color = new MVector4(1.0f); color.PropertyChanged += catchPropertyChanged; }
public static void setInstanceOccludedStatus(GLMeshVao mesh, int instance_id, bool status) { mesh.visible_instances += (status ? -1 : 1); unsafe { mesh.dataBuffer[instance_id * instance_struct_size_floats + instance_isOccluded_Float_Offset] = status ? 1.0f : 0.0f; } }
public static Matrix4 getInstanceNormalMat(GLMeshVao mesh, int instance_id) { unsafe { fixed(float *ar = mesh.dataBuffer) { return(MathUtils.Matrix4FromArray(ar, instance_id * instance_struct_size_floats + instance_normalMat_Float_Offset)); } } }
public static Vector3 getInstanceColor(GLMeshVao mesh, int instance_id) { float col; unsafe { col = mesh.dataBuffer[instance_id * instance_struct_size_floats + instance_color_Float_Offset]; } return(new Vector3(col, col, col)); }
public static Matrix4 getInstanceWorldMat(GLMeshVao mesh, int instance_id) { unsafe { fixed(float *ar = mesh.dataBuffer) { int offset = instanceData_Float_Offset + instance_id * instance_struct_size_floats + instance_worldMat_Float_Offset; return(MathUtils.Matrix4FromArray(ar, offset)); } } }
public static void setInstanceNormalMat(GLMeshVao mesh, int instance_id, Matrix4 mat) { unsafe { fixed(float *ar = mesh.dataBuffer) { int offset = instanceData_Float_Offset + instance_id * instance_struct_size_floats + instance_normalMat_Float_Offset; MathUtils.insertMatToArray16(ar, offset, mat); } } }
protected Joint(Joint input) : base(input) { this.jointIndex = input.jointIndex; this.BindMat = input.BindMat; this.invBMat = input.invBMat; this.color = input.color; meshVao = new GLMeshVao(); instanceId = GLMeshBufferManager.addInstance(ref meshVao, this); GLMeshBufferManager.setInstanceWorldMat(meshVao, instanceId, Matrix4.Identity); meshVao.type = TYPES.JOINT; meshVao.metaData = new MeshMetaData(); //TODO: Find a place to keep references from the joint GLMeshVAOs meshVao.vao = new Primitives.LineSegment(children.Count, new Vector3(1.0f, 0.0f, 0.0f)).getVAO(); meshVao.material = Common.RenderState.activeResMgr.GLmaterials["jointMat"]; }
//Save GLMeshVAO to gobject public bool saveGLMeshVAO(ulong hash, string matname, GLMeshVao meshVao) { if (GLMeshVaos.ContainsKey(hash)) { if (GLMeshVaos[hash].ContainsKey(matname)) { Console.WriteLine("MeshVao already in the dictionary, nothing to do..."); return(false); } } else { GLMeshVaos[hash] = new Dictionary <string, GLMeshVao>(); } GLMeshVaos[hash][matname] = meshVao; return(true); }
public static void setInstanceUniform4(GLMeshVao mesh, int instance_id, string un_name, Vector4 un) { unsafe { int offset = instanceData_Float_Offset + instance_id * instance_struct_size_floats + instance_Uniforms_Float_Offset; int uniform_id = 0; switch (un_name) { case "gUserDataVec4": uniform_id = 0; break; } offset += uniform_id * 4; mesh.dataBuffer[offset] = un.X; mesh.dataBuffer[offset + 1] = un.Y; mesh.dataBuffer[offset + 2] = un.Z; mesh.dataBuffer[offset + 3] = un.W; } }
//Overload with transform overrides public static int addInstance(GLMeshVao mesh, Model m, Matrix4 worldMat, Matrix4 worldMatInv, Matrix4 normMat) { int instance_id = mesh.instance_count; //Expand mesh data buffer if required if (instance_id * instance_struct_size_bytes > mesh.dataBuffer.Length) { float[] newBuffer = new float[mesh.dataBuffer.Length + 256]; Array.Copy(mesh.dataBuffer, newBuffer, mesh.dataBuffer.Length); mesh.dataBuffer = newBuffer; } if (instance_id < GLMeshVao.MAX_INSTANCES) { setInstanceWorldMat(mesh, instance_id, worldMat); setInstanceWorldMatInv(mesh, instance_id, worldMatInv); setInstanceNormalMat(mesh, instance_id, normMat); mesh.instanceRefs.Add(m); //Keep reference mesh.instance_count++; } return(instance_id); }
public static void clearInstances(GLMeshVao mesh) { mesh.instanceRefs.Clear(); mesh.instance_count = 0; }
public static void removeInstance(GLMeshVao mesh, Model m) { int id = mesh.instanceRefs.IndexOf(m); //TODO: Make all the memory shit to push the instances backwards }