public override void updateRenderState(Material m, RenderState state) { if (myLightVisualizer == null) { myLightVisualizer = Renderer.visualizers["light"] as LightVisualizer; } state.setUniformBuffer(m.myMaterialUniformBuffer.id, 2); state.setUniformBuffer(myLightVisualizer.myLightUniforBuffer.id, 1); //setup diffuse map, it should exists Texture tex = m.myTextures[(int)Material.TextureId.Diffuse].value(); state.setTexture((int)tex.id(), 0, TextureTarget.Texture2D); state.setUniform(new UniformData(20, Uniform.UniformType.Int, 0)); //setup specular map if it exists if (m.myTextures[(int)Material.TextureId.Specular] != null) { tex = m.myTextures[(int)Material.TextureId.Specular].value(); state.setTexture((int)tex.id(), 1, TextureTarget.Texture2D); state.setUniform(new UniformData(21, Uniform.UniformType.Int, 1)); } //setup normal map if it exists if (m.myTextures[(int)Material.TextureId.Normal] != null) { tex = m.myTextures[(int)Material.TextureId.Normal].value(); state.setTexture((int)tex.id(), 2, TextureTarget.Texture2D); state.setUniform(new UniformData(22, Uniform.UniformType.Int, 2)); } }
public void addTexture2d(Vector2 start, Vector2 end, Texture t, int layer = 0, bool linearDepth = false) { CanvasRenderCommand cmd = nextCommand(PrimitiveType.Triangles, Projection.ORTHO, t.id(), Fill.SOLID, false); switch (t.target) { case TextureTarget.Texture2D: cmd.renderState.setTexture(t.id(), 0, t.target); cmd.renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0)); cmd.renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 0)); cmd.renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, linearDepth)); break; case TextureTarget.TextureCubeMap: cmd.renderState.setTexture(t.id(), 0, t.target); cmd.renderState.setUniform(new UniformData(21, Uniform.UniformType.Int, 0)); cmd.renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 1)); cmd.renderState.setUniform(new UniformData(24, Uniform.UniformType.Int, layer)); cmd.renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, linearDepth)); break; case TextureTarget.Texture2DArray: cmd.renderState.setTexture(t.id(), 0, t.target); cmd.renderState.setUniform(new UniformData(22, Uniform.UniformType.Int, 0)); cmd.renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 2)); cmd.renderState.setUniform(new UniformData(24, Uniform.UniformType.Int, layer)); cmd.renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, linearDepth)); break; } cmd.renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, linearDepth)); UInt32 baseVertex = (UInt32)myVertCount; Vector2 mid1 = new Vector2(end.X, start.Y); Vector2 mid2 = new Vector2(start.X, end.Y); addVertex(new Vector3(start), uvSolid, Color4.White); addVertex(new Vector3(mid1), uvSolid, Color4.White); addVertex(new Vector3(end), uvSolid, Color4.White); addVertex(new Vector3(mid2), uvSolid, Color4.White); addIndex(cmd, baseVertex); addIndex(cmd, baseVertex + 1); addIndex(cmd, baseVertex + 2); addIndex(cmd, baseVertex); addIndex(cmd, baseVertex + 2); addIndex(cmd, baseVertex + 3); }
public RenderTexture2dCommand(Vector2 min, Vector2 max, Texture t, float alpha = 1.0f, bool isDepthBuffer = false) : base() { myMin = min; myMax = max; myAlpha = alpha; myVerts = new V3T2B4[4]; myVerts[0].Position = new Vector3(min.X, min.Y, 0); myVerts[0].TexCoord = new Vector2(0, 0); myVerts[0].Color = new Color4(1.0f, 1.0f, 1.0f, alpha).toUInt(); myVerts[1].Position = new Vector3(max.X, min.Y, 0); myVerts[1].TexCoord = new Vector2(1, 0); myVerts[1].Color = new Color4(1.0f, 1.0f, 1.0f, alpha).toUInt(); myVerts[2].Position = new Vector3(max.X, max.Y, 0); myVerts[2].TexCoord = new Vector2(1, 1); myVerts[2].Color = new Color4(1.0f, 1.0f, 1.0f, alpha).toUInt(); myVerts[3].Position = new Vector3(min.X, max.Y, 0); myVerts[3].TexCoord = new Vector2(0, 1); myVerts[3].Color = new Color4(1.0f, 1.0f, 1.0f, alpha).toUInt(); renderState.setTexture(t.id(), 0, t.target); renderState.setIndexBuffer(theIBO.id); renderState.setVertexBuffer(theVBO.id, 0, 0, V3T2B4.stride); renderState.setUniform(new UniformData(0, Uniform.UniformType.Bool, false)); renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0)); renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 0)); renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, isDepthBuffer)); pipelineState = new PipelineState(); pipelineState.shaderState.shaderProgram = theShader; pipelineState.vaoState.vao = theVAO; pipelineState.depthTest.enabled = false; pipelineState.blending.enabled = alpha < 1.0f; pipelineState.generateId(); }
public RenderTexturedQuadCommand(Vector3[] verts, Texture t, float alpha = 1.0f) { UInt32 col = new Color4(1.0f, 1.0f, 1.0f, alpha).toUInt(); myVerts = new V3T2B4[4]; myVerts[0].Position = verts[0]; myVerts[0].TexCoord = new Vector2(0, 0); myVerts[0].Color = col; myVerts[1].Position = verts[1]; myVerts[1].TexCoord = new Vector2(0, 1); myVerts[1].Color = col; myVerts[2].Position = verts[2]; myVerts[2].TexCoord = new Vector2(1, 1); myVerts[2].Color = col; myVerts[3].Position = verts[3]; myVerts[3].TexCoord = new Vector2(1, 0); myVerts[3].Color = col; renderState.setTexture(t.id(), 0, t.target); pipelineState = new PipelineState(); if (t.hasAlpha == true || alpha < 1.0f) { pipelineState.blending.enabled = true; } pipelineState.shaderState.shaderProgram = theShader; pipelineState.vaoState.vao = theVAO; pipelineState.depthTest.enabled = false; pipelineState.culling.enabled = false; pipelineState.generateId(); renderState.setIndexBuffer(theIBO.id); renderState.setVertexBuffer(theVBO.id, 0, 0, V3T2B4.stride); renderState.setUniform(new UniformData(0, Uniform.UniformType.Bool, true)); renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0)); renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 0)); renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, false)); }
public RenderTextureCubeCommand(Vector3 min, Vector3 max, Texture t, float alpha = 1.0f) : base() { myVerts = new V3T2B4[24]; V3T2[] verts = new V3T2[24]; UInt32 col = new Color4(1.0f, 1.0f, 1.0f, alpha).toUInt(); //front face myVerts[0].Position = new Vector3(max.X, min.Y, min.Z); myVerts[0].TexCoord = new Vector2(0, 0); myVerts[0].Color = col; myVerts[1].Position = new Vector3(min.X, min.Y, min.Z); myVerts[1].TexCoord = new Vector2(1, 0); myVerts[1].Color = col; myVerts[2].Position = new Vector3(min.X, max.Y, min.Z); myVerts[2].TexCoord = new Vector2(1, 1); myVerts[2].Color = col; myVerts[3].Position = new Vector3(max.X, max.Y, min.Z); myVerts[3].TexCoord = new Vector2(0, 1); myVerts[3].Color = col; //left myVerts[4].Position = new Vector3(min.X, min.Y, min.Z); myVerts[4].TexCoord = new Vector2(0, 0); myVerts[4].Color = col; myVerts[5].Position = new Vector3(min.X, min.Y, max.Z); myVerts[5].TexCoord = new Vector2(1, 0); myVerts[5].Color = col; myVerts[6].Position = new Vector3(min.X, max.Y, max.Z); myVerts[6].TexCoord = new Vector2(1, 1); myVerts[6].Color = col; myVerts[7].Position = new Vector3(min.X, max.Y, min.Z); myVerts[7].TexCoord = new Vector2(0, 1); myVerts[7].Color = col; //right myVerts[8].Position = new Vector3(max.X, min.Y, max.Z); myVerts[8].TexCoord = new Vector2(0, 0); myVerts[8].Color = col; myVerts[9].Position = new Vector3(max.X, min.Y, min.Z); myVerts[9].TexCoord = new Vector2(1, 0); myVerts[9].Color = col; myVerts[10].Position = new Vector3(max.X, max.Y, min.Z); myVerts[10].TexCoord = new Vector2(1, 1); myVerts[10].Color = col; myVerts[11].Position = new Vector3(max.X, max.Y, max.Z); myVerts[11].TexCoord = new Vector2(0, 1); myVerts[11].Color = col; //top myVerts[12].Position = new Vector3(min.X, max.Y, max.Z); myVerts[12].TexCoord = new Vector2(0, 0); myVerts[12].Color = col; myVerts[13].Position = new Vector3(max.X, max.Y, max.Z); myVerts[13].TexCoord = new Vector2(1, 0); myVerts[13].Color = col; myVerts[14].Position = new Vector3(max.X, max.Y, min.Z); myVerts[14].TexCoord = new Vector2(1, 1); myVerts[14].Color = col; myVerts[15].Position = new Vector3(min.X, max.Y, min.Z); myVerts[15].TexCoord = new Vector2(0, 1); myVerts[15].Color = col; //bottom myVerts[16].Position = new Vector3(min.X, min.Y, min.Z); myVerts[16].TexCoord = new Vector2(0, 0); myVerts[16].Color = col; myVerts[17].Position = new Vector3(max.X, min.Y, min.Z); myVerts[17].TexCoord = new Vector2(1, 0); myVerts[17].Color = col; myVerts[18].Position = new Vector3(max.X, min.Y, max.Z); myVerts[18].TexCoord = new Vector2(1, 1); myVerts[18].Color = col; myVerts[19].Position = new Vector3(min.X, min.Y, max.Z); myVerts[19].TexCoord = new Vector2(0, 1); myVerts[19].Color = col; //back myVerts[20].Position = new Vector3(min.X, min.Y, max.Z); myVerts[20].TexCoord = new Vector2(0, 0); myVerts[20].Color = col; myVerts[21].Position = new Vector3(max.X, min.Y, max.Z); myVerts[21].TexCoord = new Vector2(1, 0); myVerts[21].Color = col; myVerts[22].Position = new Vector3(max.X, max.Y, max.Z); myVerts[22].TexCoord = new Vector2(1, 1); myVerts[22].Color = col; myVerts[23].Position = new Vector3(min.X, max.Y, max.Z); myVerts[23].TexCoord = new Vector2(0, 1); myVerts[23].Color = col; renderState.setTexture(t.id(), 0, t.target); renderState.setIndexBuffer(theIBO.id); renderState.setVertexBuffer(theVBO.id, 0, 0, V3T2B4.stride); renderState.setUniform(new UniformData(0, Uniform.UniformType.Bool, true)); renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0)); renderState.setUniform(new UniformData(23, Uniform.UniformType.Int, 0)); renderState.setUniform(new UniformData(25, Uniform.UniformType.Bool, false)); pipelineState = new PipelineState(); pipelineState.shaderState.shaderProgram = theShader; pipelineState.vaoState.vao = theVAO; pipelineState.depthTest.enabled = false; pipelineState.blending.enabled = t.hasAlpha || alpha < 1.0f; pipelineState.generateId(); }
public CopyFramebufferCommand(Texture t, int width, int height) { pipelineState.shaderState.shaderProgram = theShader; pipelineState.vaoState.vao = theVao; pipelineState.depthTest.enabled = false; pipelineState.depthWrite.enabled = false; renderState.setUniform(new UniformData(0, Uniform.UniformType.Float, (float)TimeSource.currentTime())); renderState.setUniform(new UniformData(1, Uniform.UniformType.Float, (float)width)); renderState.setUniform(new UniformData(2, Uniform.UniformType.Float, (float)height)); renderState.setTexture(t.id(), 0, t.target); renderState.setUniform(new UniformData(20, Uniform.UniformType.Int, 0)); }
public void addLine(Vector3 start, Vector3 end, Color4 color, Fill fill, bool clip) { if (fill == Fill.WIREFRAME) { fill = Fill.SOLID; } CanvasRenderCommand cmd = nextCommand(PrimitiveType.Lines, Projection.PERSPECTIVE, myTexture.id(), fill, clip); UInt32 baseVertex = (UInt32)myVertCount; addVertex(start, uvSolid, color); addVertex(end, uvSolid, color); addIndex(cmd, baseVertex); addIndex(cmd, baseVertex + 1); }
public override void updateRenderState(Material m, RenderState state) { if (m.myTextures[(int)Material.TextureId.Diffuse] != null) { Texture tex = m.myTextures[(int)Material.TextureId.Diffuse].value(); state.setTexture((int)tex.id(), 0, TextureTarget.Texture2D); state.setUniform(new UniformData(20, Uniform.UniformType.Bool, true)); state.setUniform(new UniformData(21, Uniform.UniformType.Int, 0)); } else { state.setUniform(new UniformData(20, Uniform.UniformType.Bool, false)); } state.setUniform(new UniformData(22, Uniform.UniformType.Color4, m.diffuse)); state.setUniform(new UniformData(23, Uniform.UniformType.Float, m.alpha)); }
public override void updateRenderState(Material m, RenderState rs) { Texture tint1 = (m.findAttribute("tint1") as TextureAttribute).value(); Texture tint2 = (m.findAttribute("tint2") as TextureAttribute).value(); Texture sun = (m.findAttribute("sun") as TextureAttribute).value(); Texture moon = (m.findAttribute("moon") as TextureAttribute).value(); Texture clouds1 = (m.findAttribute("clouds1") as TextureAttribute).value(); Texture clouds2 = (m.findAttribute("clouds2") as TextureAttribute).value(); rs.setTexture((int)tint1.id(), 0, TextureTarget.Texture2D); rs.setTexture((int)tint2.id(), 1, TextureTarget.Texture2D); rs.setTexture((int)sun.id(), 2, TextureTarget.Texture2D); rs.setTexture((int)moon.id(), 3, TextureTarget.Texture2D); rs.setTexture((int)clouds1.id(), 4, TextureTarget.Texture2D); rs.setTexture((int)clouds2.id(), 5, TextureTarget.Texture2D); rs.setUniform(new UniformData(20, Uniform.UniformType.Int, 0)); rs.setUniform(new UniformData(21, Uniform.UniformType.Int, 1)); rs.setUniform(new UniformData(22, Uniform.UniformType.Int, 2)); rs.setUniform(new UniformData(23, Uniform.UniformType.Int, 3)); rs.setUniform(new UniformData(24, Uniform.UniformType.Int, 4)); rs.setUniform(new UniformData(25, Uniform.UniformType.Int, 5)); }
public virtual void attachTarget(FramebufferAttachment attachTarget, Texture tex) { GL.BindFramebuffer(FramebufferTarget.Framebuffer, myId); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachTarget, TextureTarget.Texture2D, tex.id(), 0); GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); myBuffers[attachTarget] = tex; //if it's a color buffer set it up as a draw buffer if (attachTarget >= FramebufferAttachment.ColorAttachment0 && attachTarget <= FramebufferAttachment.ColorAttachment15) { myTargets.Add((DrawBuffersEnum)attachTarget); } }
public virtual Int32 id() { return(myTexture.id()); }
public override void updateRenderState(Material m, RenderState state) { if (myLightVisualizer == null) { myLightVisualizer = Renderer.visualizers["light"] as LightVisualizer; } //material properties PerPixelUniformData matData = new PerPixelUniformData { ambientReflectivity = m.ambient, diffuseReflectivity = m.diffuse, specularReflectivity = m.spec, emmission = m.emission, shininess = m.shininess, alpha = m.alpha, alphaTest = m.alphaTest }; //setup diffuse map, it should exists Texture tex = m.myTextures[(int)Material.TextureId.Diffuse].value(); state.setTexture((int)tex.id(), 0, TextureTarget.Texture2D); state.setUniform(new UniformData(20, Uniform.UniformType.Int, 0)); //setup specular map if it exists if (m.myTextures[(int)Material.TextureId.Specular] != null) { tex = m.myTextures[(int)Material.TextureId.Specular].value(); state.setTexture((int)tex.id(), 1, TextureTarget.Texture2D); state.setUniform(new UniformData(21, Uniform.UniformType.Int, 1)); matData.hasSpecularMap = 1; } else { matData.hasSpecularMap = 0; } //setup normal map if it exists if (m.myTextures[(int)Material.TextureId.Normal] != null) { tex = m.myTextures[(int)Material.TextureId.Normal].value(); state.setTexture((int)tex.id(), 2, TextureTarget.Texture2D); state.setUniform(new UniformData(22, Uniform.UniformType.Int, 2)); matData.hasNormalMap = 1; if (tex.hasAlpha == true) { matData.hasParallaxMap = 1; matData.parallaxScale = 0.04f; } } else { matData.hasNormalMap = 0; } byte[] data = matData.toBytes(); state.setUniformUpload(myMaterialUniform, data); state.setUniformBuffer(myMaterialUniform.id, 2); state.setUniformBuffer(myLightVisualizer.myLightUniforBuffer.id, 1); }
public void addImage(Texture t, TextureAccess access, int bindPoint) { renderState.setImageBuffer((int)t.id(), bindPoint, access, (SizedInternalFormat)t.pixelFormat); }
public void updateFace(int face, Texture t) { GL.CopyImageSubData(t.id(), ImageTarget.Texture2D, 0, 0, 0, 0, myId, ImageTarget.TextureCubeMap, 0, 0, 0, face, t.width, t.height, 1); }