public void ReSendObject(SObject obj) { SCamera cCam = obj as SCamera; SSphere cSphere = obj as SSphere; SLight cLight = obj as SLight; ICuttableToTriangles cICuttableToTriangles = obj as ICuttableToTriangles; if (cCam != null) { cCam.SendToShader(basicProgramID, "uCamera"); } else if (cSphere != null) { int id = spheres.FindIndex(x => x == cSphere); cSphere.SendToShader(basicProgramID, "spheres[" + id + "]"); } else if (cLight != null) { int id = lights.FindIndex(x => x == cLight); cLight.SendToShader(basicProgramID, "spheres[" + id + "]"); } else if (cICuttableToTriangles != null) { List <STriangle> trigs = cICuttableToTriangles.GetTriangles(); for (int i = 0; i < trigs.Count; i++) { int id = triangles.FindIndex(x => x == trigs[i]); trigs[i].SendToShader(basicProgramID, "triangles[" + id + "]"); } } }
public void InitShaders() { int basicVertexShader; int basicFragmentShader; basicProgramID = GL.CreateProgram(); LoadShader("../../raytracing.vert", ShaderType.VertexShader, basicProgramID, out basicVertexShader); LoadShader("../../raytracing.frag", ShaderType.FragmentShader, basicProgramID, out basicFragmentShader); GL.BindAttribLocation(basicProgramID, 1, "scale"); GL.LinkProgram(basicProgramID); int status = 0; GL.GetProgram(basicProgramID, GetProgramParameterName.LinkStatus, out status); Console.WriteLine(GL.GetProgramInfoLog(basicProgramID)); int attrLoc = GL.GetAttribLocation(basicProgramID, "scale"); if (attrLoc != -1) { GL.VertexAttrib1(attrLoc, 1f); } //INIT Vector3 camright, camup, camforward; SObject.GetLocalVectors(cam.rotation, out camright, out camup, out camforward); Matrix4 viewMat = Matrix4.LookAt(cam.position, camforward, camup); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref viewMat); int vbo_position; GL.GenBuffers(1, out vbo_position); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position); GL.BufferData <Vector3>(BufferTarget.ArrayBuffer, (IntPtr)(vertdata.Length * Vector3.SizeInBytes), vertdata, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); GL.UseProgram(basicProgramID); cam.SendToShader(basicProgramID, "uCamera"); SendListToShader(materials.Select(x => (ISendableToShader)x).ToList(), basicProgramID, "materials"); SendListToShader(spheres.Select(x => (ISendableToShader)x).ToList(), basicProgramID, "spheres"); SendListToShader(triangles.Select(x => (ISendableToShader)x).ToList(), basicProgramID, "triangles"); SendListToShader(lights.Select(x => (ISendableToShader)x).ToList(), basicProgramID, "lights"); int uniformLoc = GL.GetUniformLocation(basicProgramID, "maxDepth"); if (uniformLoc != -1) { GL.Uniform1(uniformLoc, maxDepth); } GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.EnableClientState(ArrayCap.VertexArray); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position); GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, 0); }