public void Draw(Matrix4 mvpMatrix) { Shader shader = OpenTKSharedResources.shaders["SolidColor3D"]; if (!shader.ProgramCreatedSuccessfully) { return; } // Set up. shader.UseProgram(); shader.EnableVertexAttributes(); positionBuffer.Bind(); // Set shader values. Matrix4 matrix = mvpMatrix; shader.SetMatrix4x4("mvpMatrix", ref matrix); // Draw. int rectangularPrismVertCount = 24; GL.DrawArrays(PrimitiveType.TriangleFan, 0, rectangularPrismVertCount); shader.DisableVertexAttributes(); }
private void SetScaleUniform() { Shader shader = OpenTKSharedResources.shaders["SolidColor3D"]; shader.UseProgram(); shader.SetVector3("scale", scaleX, scaleY, scaleZ); }
private void SetCenterUniform(float centerX, float centerY, float centerZ) { Shader shader = OpenTKSharedResources.shaders["SolidColor3D"]; shader.UseProgram(); shader.SetVector3("center", centerX, centerY, centerZ); }
private void SetColorUniform() { Shader shader = OpenTKSharedResources.shaders["SolidColor3D"]; shader.UseProgram(); shader.SetVector4("color", color); }
private static void DrawPolygonUv(NUD.Polygon p, int windowWidth, int windowHeight) { Shader shader = OpenTKSharedResources.shaders["UV"]; shader.UseProgram(); shader.EnableVertexAttributes(); uvPositionVbo.Bind(); // Draw over everything GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); GL.Clear(ClearBufferMask.DepthBufferBit); // Scale to 0 to 1 UV space and flip vertically. Matrix4 matrix = Matrix4.CreateOrthographicOffCenter(0, 1, 1, 0, -1, 1); shader.SetMatrix4x4("mvpMatrix", ref matrix); SetVertexAttributes(shader); // Draw the uvs. GL.LineWidth(1.5f); GL.Enable(EnableCap.LineSmooth); uvElementsIbo.Bind(); GL.DrawElements(PrimitiveType.Triangles, p.displayFaceSize, DrawElementsType.UnsignedInt, p.Offset); shader.DisableVertexAttributes(); }
public static void DrawRectangularPrism(Matrix4 mvpMatrix, float scaleX = 1, float scaleY = 1, float scaleZ = 1, float centerX = 0, float centerY = 0, float centerZ = 0) { Shader shader = OpenTKSharedResources.shaders["SolidColor3D"]; if (!shader.ProgramCreatedSuccessfully) { return; } // Set up. shader.UseProgram(); shader.EnableVertexAttributes(); rectangularPrismPositionBuffer.Bind(); // Set shader values. SetVertexAttributes(shader); SetShaderUniforms(mvpMatrix, scaleX, scaleY, scaleZ, centerX, centerY, centerZ, shader); // Draw. int rectangularPrismVertCount = 24; GL.DrawArrays(PrimitiveType.TriangleFan, 0, rectangularPrismVertCount); shader.DisableVertexAttributes(); }
public static void DrawQuadGradient(Vector3 topColor, Vector3 bottomColor, VertexArrayObject screenVao) { // draw RGB and alpha channels of texture to screen quad Shader shader = OpenTKSharedResources.shaders["Gradient"]; shader.UseProgram(); EnableAlphaBlendingWhiteBackground(); shader.SetVector3("topColor", topColor); shader.SetVector3("bottomColor", bottomColor); DrawScreenTriangle(shader, screenVao); }
public static void DrawScreenQuadPostProcessing(int texture0, int texture1, VertexArrayObject screenVao) { // Draws RGB and alpha channels of texture to screen quad. Shader shader = OpenTKSharedResources.shaders["ScreenQuad"]; shader.UseProgram(); shader.SetTexture("image0", texture0, TextureTarget.Texture2D, 0); shader.SetTexture("image1", texture1, TextureTarget.Texture2D, 1); shader.SetBoolToInt("renderBloom", Runtime.renderBloom); shader.SetFloat("bloomIntensity", Runtime.bloomIntensity); ShaderTools.SystemColorVector3Uniform(shader, Runtime.backgroundGradientBottom, "backgroundBottomColor"); ShaderTools.SystemColorVector3Uniform(shader, Runtime.backgroundGradientTop, "backgroundTopColor"); // Draw full screen "quad" (big triangle) DrawScreenTriangle(shader, screenVao); }
public static void DrawNudMaterialSphere(Shader shader, NUD.Material material, Mesh3D screenTriangle, Dictionary <NUD.DummyTextures, Texture> dummyTextures) { if (!shader.ProgramCreatedSuccessfully) { return; } shader.UseProgram(); // Use the same uniforms as the NUD shader. GenericMaterial genericMaterial = new GenericMaterial(); NudUniforms.SetMaterialPropertyUniforms(genericMaterial, material); genericMaterial.SetShaderUniforms(shader); NUD.SetStageLightingUniforms(shader, 0); ModelContainer.SetRenderSettingsUniforms(shader); nudSphereCamera.UpdateMatrices(); ModelContainer.SetLightingUniforms(shader, nudSphereCamera); ModelContainer.SetCameraMatrixUniforms(nudSphereCamera, shader); // Use default textures rather than textures from the NUT. NudUniforms.SetTextureUniformsNudMatSphere(shader, material, dummyTextures); // These values aren't needed in the shader currently. shader.SetVector3("cameraPosition", 0, 0, 0); shader.SetFloat("zBufferOffset", 0); shader.SetFloat("bloomThreshold", Runtime.bloomThreshold); bool isTransparent = (material.srcFactor > 0) || (material.dstFactor > 0) || (material.alphaFunction > 0) || (material.alphaTest > 0); shader.SetBoolToInt("isTransparent", isTransparent); // Set texture uniforms for the mesh attributes. shader.SetTexture("normalTex", sphereNrmTex.Id, TextureTarget.Texture2D, 15); shader.SetTexture("uvTex", sphereUvTex.Id, TextureTarget.Texture2D, 16); shader.SetTexture("tanTex", sphereTanTex.Id, TextureTarget.Texture2D, 17); shader.SetTexture("bitanTex", sphereBitanTex.Id, TextureTarget.Texture2D, 18); // Draw full screen "quad" (big triangle) ScreenDrawing.DrawScreenTriangle(shader, screenTriangle); }
public static void DrawTexturedQuad(int texture, int width, int height, VertexArrayObject screenVao, bool renderR = true, bool renderG = true, bool renderB = true, bool renderA = false, bool keepAspectRatio = false, float intensity = 1, int currentMipLevel = 0) { // Draws RGB and alpha channels of texture to screen quad. Shader shader = OpenTKSharedResources.shaders["Texture"]; shader.UseProgram(); EnableAlphaBlendingWhiteBackground(); // Single texture uniform. shader.SetTexture("image", texture, TextureTarget.Texture2D, 0); // Channel toggle uniforms. shader.SetBoolToInt("renderR", renderR); shader.SetBoolToInt("renderG", renderG); shader.SetBoolToInt("renderB", renderB); shader.SetBoolToInt("renderAlpha", renderA); shader.SetFloat("intensity", intensity); bool alphaOverride = renderA && !renderR && !renderG && !renderB; shader.SetBoolToInt("alphaOverride", alphaOverride); // Perform aspect ratio calculations in shader. // This only displays correctly if the viewport is square. shader.SetBoolToInt("preserveAspectRatio", keepAspectRatio); shader.SetFloat("width", width); shader.SetFloat("height", height); // Display certain mip levels. shader.SetInt("currentMipLevel", currentMipLevel); // Draw full screen "quad" (big triangle) DrawScreenTriangle(shader, screenVao); }
private void SetVertexAttributes(Shader shader) { shader.UseProgram(); GL.VertexAttribPointer(shader.GetVertexAttributeUniformLocation("position"), 3, VertexAttribPointerType.Float, false, sizeof(float) * 3, 0); }