public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { UpdateCustomFloatBuffer(); prog.Use(); prog.BindTexture2D("tex", capi.BlockTextureAtlas.Positions[0].atlasTextureId, 0); prog.Uniform("rgbaFogIn", capi.Render.FogColor); prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor); prog.Uniform("fogMinIn", capi.Render.FogMin); prog.Uniform("fogDensityIn", capi.Render.FogDensity); prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf); if (quantityGearboxes > 0) { floatsPeg.Count = quantityGearboxes * 20; floatsCage.Count = quantityGearboxes * 20; updateMesh.CustomFloats = floatsPeg; capi.Render.UpdateMesh(gearboxPeg, updateMesh); updateMesh.CustomFloats = floatsCage; capi.Render.UpdateMesh(gearboxCage, updateMesh); capi.Render.RenderMeshInstanced(gearboxPeg, quantityGearboxes); capi.Render.RenderMeshInstanced(gearboxCage, quantityGearboxes); } prog.Stop(); /*capi.Render.RenderMeshInstanced(gearboxCage, quantityGearboxes); * capi.Render.RenderMeshInstanced(axle, quantityAxles); * capi.Render.RenderMeshInstanced(windmillRotor, quantityRotors);*/ }
public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { if (workItemMeshRef == null) { return; } if (stage == EnumRenderStage.AfterFinalComposition) { if (api.World.Player?.InventoryManager?.ActiveHotbarSlot?.Itemstack?.Collectible is ItemHammer) { RenderRecipeOutLine(); } return; } IRenderAPI rpi = api.Render; IClientWorldAccessor worldAccess = api.World; Vec3d camPos = worldAccess.Player.Entity.CameraPos; int temp = (int)ingot.Collectible.GetTemperature(api.World, ingot); Vec4f lightrgbs = worldAccess.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z); int extraGlow = GameMath.Clamp((temp - 550) / 2, 0, 255); float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f(temp); glowRgb.R = glowColor[0]; glowRgb.G = glowColor[1]; glowRgb.B = glowColor[2]; glowRgb.A = extraGlow / 255f; rpi.GlDisableCullFace(); IShaderProgram prog = coreMod.anvilShaderProg; prog.Use(); rpi.BindTexture2d(texId); prog.Uniform("rgbaAmbientIn", rpi.AmbientColor); prog.Uniform("rgbaFogIn", rpi.FogColor); prog.Uniform("fogMinIn", rpi.FogMin); prog.Uniform("dontWarpVertices", (int)0); prog.Uniform("addRenderFlags", (int)0); prog.Uniform("fogDensityIn", rpi.FogDensity); prog.Uniform("rgbaTint", ColorUtil.WhiteArgbVec); prog.Uniform("rgbaLightIn", lightrgbs); prog.Uniform("rgbaGlowIn", glowRgb); prog.Uniform("extraGlow", extraGlow); prog.UniformMatrix("modelMatrix", ModelMat .Identity() .Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z) .Values ); prog.UniformMatrix("viewMatrix", rpi.CameraMatrixOriginf); prog.UniformMatrix("projectionMatrix", rpi.CurrentProjectionMatrix); rpi.RenderMesh(workItemMeshRef); prog.Stop(); }
public override void Render(GuiElementMap map, float dt) { map.TranslateWorldPosToViewPos(entity.Pos.XYZ, ref viewPos); float x = (float)(map.Bounds.renderX + viewPos.X); float y = (float)(map.Bounds.renderY + viewPos.Y); //api.Render.GlToggleBlend(true, EnumBlendMode.PremultipliedAlpha); ICoreClientAPI api = map.Api; IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui); prog.Uniform("rgbaIn", ColorUtil.WhiteArgbVec); prog.Uniform("extraGlow", 0); prog.Uniform("applyColor", 0); prog.Uniform("noTexture", 0f); prog.BindTexture2D("tex2d", Texture.TextureId, 0); api.Render.GlPushMatrix(); api.Render.GlTranslate(x, y, 60); api.Render.GlScale(Texture.Width, Texture.Height, 0); api.Render.GlScale(0.5f, 0.5f, 0); //api.Render.GlTranslate(1f, 1f, 0); api.Render.GlRotate(-entity.Pos.Yaw * GameMath.RAD2DEG + 90, 0, 0, 1); prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", api.Render.CurrentModelviewMatrix); api.Render.RenderMesh(quadModel); api.Render.GlPopMatrix(); }
public void Draw(IRenderState renderState, ITexture2D depth, float mipmapLevel = 0) { _geometries[_entity.Type].SetAttribute(_environmentMapProgram.GetResourceLocation(ShaderResourceType.Attribute, "transform"), new[] { _entity.Transform }, true); GL.ClearColor(Color.FromArgb(0, 0, 0, 0)); _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _environmentMapProgram.Activate(); _environmentMapProgram.ActivateTexture("cubeMap", 0, _cubeFbo.Texture); _environmentMapProgram.ActivateTexture("depth", 1, depth); _environmentMapProgram.Uniform("camera", _camera); Matrix4x4.Invert(_camera.Matrix, out var invert); _environmentMapProgram.Uniform("camPos", invert.Translation / invert.M44); _environmentMapProgram.Uniform("mipmapLevel", mipmapLevel); _geometries[_entity.Type].Draw(); _environmentMapProgram.DeactivateTexture(0, _cubeFbo.Texture); _environmentMapProgram.DeactivateTexture(1, depth); _environmentMapProgram.Deactivate(); _outputSurface.Deactivate(); GL.ClearColor(Color.FromArgb(0, 0, 0, 1)); }
private void SumValues(ITexture2D sourceTexture, IShaderProgram program, IRenderSurface fbo) { int SATSampler = GL.GetUniformLocation(fullScreenQuad.ProgramID, "sourceSampler"); fbo.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); program.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Uniform1(SATSampler, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID); program.Uniform("blockLengthX", blockSizeX); program.Uniform("blockLengthY", blockSizeX); program.Uniform("amountBlockX", amountBlocksX); program.Uniform("amountBlockY", amountBlocksX); //satFilter.GetFilterTexture().Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); //satFilter.GetFilterTexture().Deactivate(); program.Deactivate(); fbo.Deactivate(); }
public override void Render(GuiElementMap map, float dt) { map.TranslateWorldPosToViewPos(waypoint.Position, ref viewPos); float x = (float)(map.Bounds.renderX + viewPos.X); float y = (float)(map.Bounds.renderY + viewPos.Y); ICoreClientAPI api = map.Api; IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui); prog.Uniform("rgbaIn", color); prog.Uniform("extraGlow", 0); prog.Uniform("applyColor", 0); prog.Uniform("noTexture", 0f); prog.BindTexture2D("tex2d", Texture.TextureId, 0); api.Render.GlPushMatrix(); api.Render.GlTranslate(x, y, 60); api.Render.GlScale(Texture.Width, Texture.Height, 0); api.Render.GlScale(0.5f, 0.5f, 0); prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", api.Render.CurrentModelviewMatrix); api.Render.RenderMesh(quadModel); api.Render.GlPopMatrix(); }
//Filter FBO2 and Write result in FBO1[0] private void ProcessFilterPass(ITexture2D sourceTexture, IRenderSurface fbo) { int halfKernelX = kernelSizeX / 2; int halfKernelY = kernelSizeY / 2; fbo.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); shaderSATFilter.Activate(); int SATSampler = GL.GetUniformLocation(shaderSATFilter.ProgramID, "sourceSampler"); GL.Uniform1(SATSampler, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID); //sourceTexture.Activate(); shaderSATFilter.Uniform("width", sourceTexture.Width); shaderSATFilter.Uniform("height", sourceTexture.Height); shaderSATFilter.Uniform("halfKernelX", halfKernelX); shaderSATFilter.Uniform("halfKernelY", halfKernelY); GL.DrawArrays(PrimitiveType.Quads, 0, 4); //sourceTexture.Deactivate(); shaderSATFilter.Deactivate(); fbo.Deactivate(); }
uint CreateIrradianceMap(int frameBuffer, Matrix4x4 projection, Matrix4x4[] viewMatrices, uint cubeMap) { DefaultMesh cubeMesh = Meshes.CreateCubeWithNormals(); VAO renderIrradMapCube = VAOLoader.FromMesh(cubeMesh, irradianceMapShader); //Create Irradiance Texture int fbIrrWidth = 32; int fbIrrHeight = 32; int irradMap = CreateCubeMap(32, 32); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); //GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.TextureCubeMap, irradMap, 0); //Render //Irradiance Map irradianceMapShader.Activate(); SetSampler(irradianceMapShader.ProgramID, 0, "environmentMap", cubeMap, TextureTarget.TextureCubeMap); irradianceMapShader.Uniform("projection", projection, true); GL.Viewport(0, 0, fbIrrWidth, fbIrrHeight); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); for (int i = 0; i < 6; i++) { irradianceMapShader.Uniform("view", viewMatrices[i], true); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.TextureCubeMapPositiveX + i, irradMap, 0); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderIrradMapCube.Draw(); } GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); return((uint)irradMap); }
public void Draw() { shader.Uniform("camera", Camera); shader.Uniform(nameof(instanceSqrt), instanceSqrt); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.DrawArraysInstanced(PrimitiveType.Patches, 0, 4, instanceSqrt * instanceSqrt); }
public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { if (prog.Disposed) { prog = capi.Shader.GetProgramByName("instanced"); } capi.Render.GlDisableCullFace(); if (stage == EnumRenderStage.Opaque) { capi.Render.GlToggleBlend(false); // Seems to break SSAO without prog.Use(); prog.BindTexture2D("tex", capi.ItemTextureAtlas.Positions[0].atlasTextureId, 0); prog.Uniform("rgbaFogIn", capi.Render.FogColor); prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor); prog.Uniform("fogMinIn", capi.Render.FogMin); prog.Uniform("fogDensityIn", capi.Render.FogDensity); prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf); foreach (var val in renderers) { val.Value.OnRenderFrame(deltaTime, prog); } prog.Stop(); } capi.Render.GlEnableCullFace(); }
void RenderUIElement(UIElement element) { renderstate.Set(new DepthTest(true)); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); uiShader.Activate(); int hasTexture = 0; if (element.texture != null) { element.texture.Activate(); hasTexture = 1; } uiShader.Uniform("hasTexture", hasTexture); uiShader.Uniform("scale", element.transform.scale); uiShader.Uniform("position", element.transform.position); uiShader.Uniform("elementColor", element.color); GL.DrawArrays(PrimitiveType.Quads, 0, 4); if (element.texture != null) { element.texture.Deactivate(); } uiShader.Deactivate(); GL.Disable(EnableCap.Blend); }
public void OnRenderFrame(float dt, EnumRenderStage stage) { if (updateMesh == null) { return; } tickPhysics(dt); int count = 0; updateMesh.CustomFloats.Count = 0; foreach (var val in clothSystems) { if (!val.Value.Active) { continue; } count += val.Value.UpdateMesh(updateMesh, dt); updateMesh.CustomFloats.Count = count * (4 + 16); } if (count > 0) { //float dt = 1.5f * deltaTime; if (prog.Disposed) { prog = capi.Shader.GetProgramByName("instanced"); } capi.Render.GlToggleBlend(false); // Seems to break SSAO without prog.Use(); prog.BindTexture2D("tex", capi.ItemTextureAtlas.Positions[0].atlasTextureId, 0); prog.Uniform("rgbaFogIn", capi.Render.FogColor); prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor); prog.Uniform("fogMinIn", capi.Render.FogMin); prog.Uniform("fogDensityIn", capi.Render.FogDensity); prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf); updateMesh.CustomFloats.Count = count * (4 + 16); capi.Render.UpdateMesh(ropeMeshRef, updateMesh); capi.Render.RenderMeshInstanced(ropeMeshRef, count); prog.Stop(); } foreach (var val in clothSystems) { if (!val.Value.Active) { continue; } val.Value.CustomRender(dt); } }
public void Draw(ITransformation camera) { GL.PolygonMode(MaterialFace.FrontAndBack, Wireframe ? PolygonMode.Line : PolygonMode.Fill); shader.Uniform("camera", camera); shader.Uniform(nameof(instanceSqrt), instanceSqrt); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.DrawArraysInstanced(PrimitiveType.Patches, 0, 4, instanceSqrt * instanceSqrt); }
public void UpdateResolution(int width, int height) { ((FBO)_depthSurface)?.Dispose(); _depthSurface = new FBOwithDepth(Texture2dGL.Create(width * 4, height * 4, 1, true)); ((FBO)_outputSurface)?.Dispose(); _outputSurface = new FBOwithDepth(Texture2dGL.Create(width, height, 1)); _depthShader.Uniform("iResolution", new Vector2(width, height)); _shadowShader.Uniform("iResolution", new Vector2(width, height)); }
public override void Render(GuiElementMap map, float dt) { //if (Texture.Disposed) throw new Exception("Fatal. Trying to render a disposed texture"); if (quadModel == null || quadModel.Disposed) { throw new Exception("Fatal. Trying to render a disposed meshref"); } map.TranslateWorldPosToViewPos(waypoint.Position, ref viewPos); float x = (float)(map.Bounds.renderX + viewPos.X); float y = (float)(map.Bounds.renderY + viewPos.Y); if (waypoint.Pinned) { map.Api.Render.PushScissor(null); x = (float)GameMath.Clamp(x, map.Bounds.renderX + 2, map.Bounds.renderX + map.Bounds.InnerWidth - 2); y = (float)GameMath.Clamp(y, map.Bounds.renderY + 2, map.Bounds.renderY + map.Bounds.InnerHeight - 2); } ICoreClientAPI api = map.Api; IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui); prog.Uniform("rgbaIn", color); prog.Uniform("extraGlow", 0); prog.Uniform("applyColor", 0); prog.Uniform("noTexture", 0f); LoadedTexture tex; float hover = (mouseOver ? 6 : 0) - 1.5f * Math.Max(1, 1 / map.ZoomLevel); if (wpLayer.texturesByIcon.TryGetValue(waypoint.Icon, out tex)) { prog.BindTexture2D("tex2d", wpLayer.texturesByIcon[waypoint.Icon].TextureId, 0); mvMat .Set(api.Render.CurrentModelviewMatrix) .Translate(x, y, 60) .Scale(tex.Width + hover, tex.Height + hover, 0) .Scale(0.5f, 0.5f, 0) ; prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", mvMat.Values); api.Render.RenderMesh(quadModel); } if (waypoint.Pinned) { map.Api.Render.PopScissor(); } }
public override void Render(GuiElementMap map, float dt) { map.TranslateWorldPosToViewPos(waypoint.Position, ref viewPos); if (waypoint.Pinned) { map.Api.Render.PushScissor(null); map.ClampButPreserveAngle(ref viewPos, 2); } else { if (viewPos.X < -10 || viewPos.Y < -10 || viewPos.X > map.Bounds.OuterWidth + 10 || viewPos.Y > map.Bounds.OuterHeight + 10) { return; } } float x = (float)(map.Bounds.renderX + viewPos.X); float y = (float)(map.Bounds.renderY + viewPos.Y); ICoreClientAPI api = map.Api; IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui); prog.Uniform("rgbaIn", color); prog.Uniform("extraGlow", 0); prog.Uniform("applyColor", 0); prog.Uniform("noTexture", 0f); LoadedTexture tex; float hover = (mouseOver ? 6 : 0) - 1.5f * Math.Max(1, 1 / map.ZoomLevel); if (wpLayer.texturesByIcon.TryGetValue(waypoint.Icon, out tex)) { prog.BindTexture2D("tex2d", wpLayer.texturesByIcon[waypoint.Icon].TextureId, 0); mvMat .Set(api.Render.CurrentModelviewMatrix) .Translate(x, y, 60) .Scale(tex.Width + hover, tex.Height + hover, 0) .Scale(0.5f, 0.5f, 0) ; prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", mvMat.Values); api.Render.RenderMesh(wpLayer.quadModel); } if (waypoint.Pinned) { map.Api.Render.PopScissor(); } }
public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { if (prog.Disposed) { prog = capi.Shader.GetProgramByName("instanced"); } capi.Render.GlDisableCullFace(); if (stage == EnumRenderStage.Opaque) { capi.Render.GlToggleBlend(false); // Seems to break SSAO without prog.Use(); prog.BindTexture2D("tex", capi.BlockTextureAtlas.Positions[0].atlasTextureId, 0); prog.Uniform("rgbaFogIn", capi.Render.FogColor); prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor); prog.Uniform("fogMinIn", capi.Render.FogMin); prog.Uniform("fogDensityIn", capi.Render.FogDensity); prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf); for (int i = 0; i < MechBlockRenderer.Count; i++) { MechBlockRenderer[i].OnRenderFrame(deltaTime, prog); } prog.Stop(); } else { // TODO: Needs a custom shadow map shader /*IRenderAPI rapi = capi.Render; * rapi.CurrentActiveShader.BindTexture2D("tex2d", capi.BlockTextureAtlas.Positions[0].atlasTextureId, 0); * * float[] mvpMat = Mat4f.Mul(Mat4f.Create(), capi.Render.CurrentProjectionMatrix, capi.Render.CurrentModelviewMatrix); * * capi.Render.CurrentActiveShader.UniformMatrix("mvpMatrix", mvpMat); * //capi.Render.CurrentActiveShader.Uniform("origin", new Vec3f()); * * for (int i = 0; i < MechBlockRenderer.Count; i++) * { * MechBlockRenderer[i].OnRenderFrame(deltaTime, prog); * }*/ } capi.Render.GlEnableCullFace(); }
internal void Draw(ITransformation camera, Vector3 cameraPos) { void SetWorld(ITransformation transform) => shader.Uniform("world", transform); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); shader.Activate(); shader.Uniform(nameof(cameraPos), cameraPos); shader.Uniform(nameof(camera), camera); model.Draw((float)time.Elapsed.TotalSeconds, SetWorld); shader.Deactivate(); if (time.ElapsedMilliseconds > 5000) { time.Restart(); } }
public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { if (Level <= 0 || capi.World.Player.CameraMode != EnumCameraMode.FirstPerson) { return; } if (Level > 0.2 && capi.World.Rand.Next(60) == 0) { rndTarget = (float)capi.World.Rand.NextDouble() / 5f - 1 / 10f; } curRndVal += (rndTarget - curRndVal) * deltaTime; IShaderProgram curShader = capi.Render.CurrentActiveShader; curShader.Stop(); eyeShaderProg.Use(); capi.Render.GlToggleBlend(true); eyeShaderProg.Uniform("level", Level + curRndVal); capi.Render.RenderMesh(quadRef); eyeShaderProg.Stop(); curShader.Use(); }
private void RenderRecipeOutLine() { if (recipeOutlineMeshRef == null || api.HideGuis) { return; } IRenderAPI rpi = api.Render; IClientWorldAccessor worldAccess = api.World; EntityPos plrPos = worldAccess.Player.Entity.Pos; Vec3d camPos = worldAccess.Player.Entity.CameraPos; ModelMat.Set(rpi.CameraMatrixOriginf).Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z); outLineColorMul.A = 1 - GameMath.Clamp((float)Math.Sqrt(plrPos.SquareDistanceTo(pos.X, pos.Y, pos.Z)) / 5 - 1f, 0, 1); rpi.LineWidth = 2; rpi.GLEnableDepthTest(); rpi.GlToggleBlend(true); IShaderProgram prog = rpi.GetEngineShader(EnumShaderProgram.Wireframe); prog.Use(); prog.UniformMatrix("projectionMatrix", rpi.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", ModelMat.Values); prog.Uniform("colorIn", outLineColorMul); rpi.RenderMesh(recipeOutlineMeshRef); prog.Stop(); }
public void PointLightPass(Matrix4x4 cameraMatrix, Vector3 cameraPosition, Vector3 cameraDirection) { pointLightFBO.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderState.Set(new DepthTest(false)); renderState.Set(new FaceCullingModeState(FaceCullingMode.FRONT_SIDE)); renderState.Set(BlendStates.Additive); pointLightShader.Activate(); int position = GL.GetUniformLocation(pointLightShader.ProgramID, "positionSampler"); int albedo = GL.GetUniformLocation(pointLightShader.ProgramID, "albedoSampler"); int normal = GL.GetUniformLocation(pointLightShader.ProgramID, "normalSampler"); GL.Uniform1(position, 1); GL.Uniform1(albedo, 2); GL.Uniform1(normal, 3); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[0].ID); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[1].ID); GL.ActiveTexture(TextureUnit.Texture3); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[2].ID); pointLightShader.Uniform("camera", cameraMatrix); pointLightShader.Uniform("cameraPosition", cameraPosition); pointLightShader.Uniform("camDir", cameraDirection); GL.ActiveTexture(TextureUnit.Texture0); pointLightFBO.Textures[0].Activate(); DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[1]; drawBuffers[0] = DrawBuffersEnum.ColorAttachment0; GL.DrawBuffers(1, drawBuffers); pointLightSphere.Draw(pointLightAmount); GL.ActiveTexture(TextureUnit.Texture0); pointLightFBO.Textures[0].Deactivate(); pointLightShader.Deactivate(); renderState.Set(BlendStates.Opaque); renderState.Set(new FaceCullingModeState(FaceCullingMode.NONE)); renderState.Set(new DepthTest(false)); pointLightFBO.Deactivate(); }
public override void Render(GuiElementMap map, float dt) { if ((entity as EntityPlayer)?.Player?.WorldData?.CurrentGameMode == EnumGameMode.Spectator == true) { return; } map.TranslateWorldPosToViewPos(entity.Pos.XYZ, ref viewPos); float x = (float)(map.Bounds.renderX + viewPos.X); float y = (float)(map.Bounds.renderY + viewPos.Y); ICoreClientAPI api = map.Api; if (Texture.Disposed) { throw new Exception("Fatal. Trying to render a disposed texture"); } if (quadModel.Disposed) { throw new Exception("Fatal. Trying to render a disposed texture"); } capi.Render.GlToggleBlend(true); IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui); prog.Uniform("rgbaIn", ColorUtil.WhiteArgbVec); prog.Uniform("extraGlow", 0); prog.Uniform("applyColor", 0); prog.Uniform("noTexture", 0f); prog.BindTexture2D("tex2d", Texture.TextureId, 0); mvMat .Set(api.Render.CurrentModelviewMatrix) .Translate(x, y, 60) .Scale(Texture.Width, Texture.Height, 0) .Scale(0.5f, 0.5f, 0) .RotateZ(-entity.Pos.Yaw + 90 * GameMath.DEG2RAD) ; prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", mvMat.Values); api.Render.RenderMesh(quadModel); }
uint CreatePrefilteredMap(int frameBuffer, Matrix4x4 projection, Matrix4x4[] viewMatrices, uint cubeMap) { DefaultMesh cubeMesh = Meshes.CreateCubeWithNormals(); VAO renderPrefilterCube = VAOLoader.FromMesh(cubeMesh, prefilterMapShader); int texResX = 128; int texResY = 128; int prefiltMap = CreateCubeMap(texResX, texResY); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap); prefilterMapShader.Activate(); SetSampler(prefilterMapShader.ProgramID, 0, "environmentMap", cubeMap, TextureTarget.TextureCubeMap); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); prefilterMapShader.Uniform("projection", projection, true); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); int maxMipLvl = 5; for (int i = 0; i < maxMipLvl; i++) { float mipWidth = texResX * (float)Math.Pow(0.5, i); float mipHeight = texResY * (float)Math.Pow(0.5, i); GL.Viewport(0, 0, (int)mipWidth, (int)mipHeight); float roughness = (float)i / (float)(maxMipLvl - 1.0); prefilterMapShader.Uniform("roughness", roughness); for (int j = 0; j < 6; j++) { prefilterMapShader.Uniform("view", viewMatrices[j], true); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.TextureCubeMapPositiveX + j, prefiltMap, i); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderPrefilterCube.Draw(); } } GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); return((uint)prefiltMap); }
public void Draw(IRenderState renderState, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, Dictionary <Enums.EntityType, ITexture2D> textures, Dictionary <Enums.EntityType, ITexture2D> normalMaps, List <Enums.EntityType> disableBackFaceCulling) { _outputSurface.Activate(); renderState.Set(new DepthTest(true)); GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 }); GL.DrawBuffers(4, new[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3 }); _deferredProgram.Activate(); _deferredProgram.Uniform("camera", camera); Matrix4x4.Invert(camera.Matrix, out var invert); _deferredProgram.Uniform("camPos", invert.Translation / invert.M44); foreach (var type in _geometries.Keys) { if (instanceCounts[type] == 0) { continue; } if (normalMaps.ContainsKey(type)) { _deferredProgram.ActivateTexture("normalMap", 1, normalMaps[type]); } else { _deferredProgram.ActivateTexture("normalMap", 1, _defaultMap); _deferredProgram.Uniform("normalMapping", 0f); _deferredProgram.Uniform("paralaxMapping", 0f); } if (textures.ContainsKey(type)) { _deferredProgram.ActivateTexture("tex", 0, textures[type]); _deferredProgram.Uniform("textured", 1f); } else { _deferredProgram.Uniform("materialColor", System.Drawing.Color.LightGray); _deferredProgram.Uniform("textured", 0f); } renderState.Set(disableBackFaceCulling.Contains(type) ? new BackFaceCulling(false) : new BackFaceCulling(true)); _geometries[type].Draw(instanceCounts[type]); if (textures.ContainsKey(type)) { _deferredProgram.DeactivateTexture(0, textures[type]); } } renderState.Set(new DepthTest(false)); renderState.Set(new BackFaceCulling(true)); _outputSurface.Deactivate(); }
public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { IShaderProgram curShader = capi.Render.CurrentActiveShader; Vec4f color = new Vec4f(1, 1, 1, 1); // Render rectangle curShader.Uniform("rgbaIn", color); curShader.Uniform("extraGlow", 0); curShader.Uniform("applyColor", 0); curShader.Uniform("tex2d", 0); curShader.Uniform("noTexture", 1f); capi.Render.GlPushMatrix(); capi.Render.GlTranslate(10, 10, 50); capi.Render.GlScale(100, 20, 0); capi.Render.GlTranslate(0.5f, 0.5f, 0); capi.Render.GlScale(0.5f, 0.5f, 0); curShader.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix); curShader.UniformMatrix("modelViewMatrix", capi.Render.CurrentModelviewMatrix); capi.Render.RenderMesh(whiteRectangleRef); capi.Render.GlPopMatrix(); // Render progress bar float width = (capi.World.ElapsedMilliseconds / 10f) % 100; capi.Render.GlPushMatrix(); capi.Render.GlTranslate(10, 10, 50); capi.Render.GlScale(width, 20, 0); capi.Render.GlTranslate(0.5f, 0.5f, 0); capi.Render.GlScale(0.5f, 0.5f, 0); curShader.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix); curShader.UniformMatrix("modelViewMatrix", capi.Render.CurrentModelviewMatrix); capi.Render.RenderMesh(progressQuadRef); capi.Render.GlPopMatrix(); }
public void UpdateResolution(int width, int height) { ((FBO)_outputSurface)?.Dispose(); _outputSurface = new FBO(Texture2dGL.Create(width, height, _fboTexComponentCount, _fboTexFloat)); _postProcessShader.Activate(); _postProcessShader.Uniform("iResolution", new Vector2(width, height)); _postProcessShader.Deactivate(); }
public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { prog.Use(); prog.BindTexture2D("tex", capi.BlockTextureAtlas.Positions[0].atlasTextureId, 0); prog.Uniform("rgbaFogIn", capi.Render.FogColor); prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor); prog.Uniform("fogMinIn", capi.Render.FogMin); prog.Uniform("fogDensityIn", capi.Render.FogDensity); prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix); prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf); for (int i = 0; i < MechBlockRenderer.Count; i++) { MechBlockRenderer[i].OnRenderFrame(deltaTime, prog); } prog.Stop(); }
public void CreateMaps(float time) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); mapFBO.Activate(); waterMapShader.Activate(); waterMapShader.Uniform("time", time); waterMapShader.Uniform("numberOfWaves", numberOfWaves); int buffer = waterMapShader.GetResourceLocation(ShaderResourceType.RWBuffer, "WavesBuffer"); waveBuffer.ActivateBind(buffer); //Activate Textures of FBO int textAmount = mapFBO.Textures.Count; //Number of Texture Channels of FBO for (int i = 0; i < textAmount; i++) { GL.ActiveTexture(TextureUnit.Texture0 + i); mapFBO.Textures[i].Activate(); } DrawBuffersEnum[] buffers = new DrawBuffersEnum[textAmount]; for (int i = 0; i < textAmount; i++) { buffers[i] = DrawBuffersEnum.ColorAttachment0 + i; } GL.DrawBuffers(textAmount, buffers); GL.DrawArrays(PrimitiveType.Quads, 0, 4); waveBuffer.Deactivate(); for (int i = textAmount - 1; i >= 0; i--) { GL.ActiveTexture(TextureUnit.Texture0 + i); mapFBO.Textures[i].Deactivate(); } waterMapShader.Deactivate(); mapFBO.Deactivate(); }
public void Draw(ITransformation camera, ITexture2D materialColor, ITexture2D normals, ITexture2D position, ITexture2D shadowSurface, ITexture2D intensity, List <LightSource> lightSources) { if (lightSources.Count > _lightArraySizeInShader) { throw new ArgumentException("A maximum of " + _lightArraySizeInShader + " light sources is possible. See shader 'deferredLighting.glsl' for details."); } _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit); _shader.Activate(); Matrix4x4.Invert(camera.Matrix, out var invert); _shader.Uniform("camPos", invert.Translation / invert.M44); _shader.Uniform("hemColorTop", new Vector3(0.9f, 0.9f, 1.0f)); _shader.Uniform("hemColorBottom", new Vector3(41.0f / 255.0f, 49.0f / 255.0f, 51.0f / 255.0f)); _shader.ActivateTexture("materialColor", 0, materialColor); _shader.ActivateTexture("normals", 1, normals); _shader.ActivateTexture("position", 2, position); _shader.ActivateTexture("shadowSurface", 3, shadowSurface); _shader.ActivateTexture("intensity", 4, intensity); var bufferObject = LightSourcesToBufferObject(lightSources); var loc = _shader.GetResourceLocation(ShaderResourceType.RWBuffer, "Lights"); bufferObject.ActivateBind(loc); GL.DrawArrays(PrimitiveType.Quads, 0, 4); _shader.DeactivateTexture(4, intensity); _shader.DeactivateTexture(3, shadowSurface); _shader.DeactivateTexture(2, position); _shader.DeactivateTexture(1, normals); _shader.DeactivateTexture(0, materialColor); _shader.Deactivate(); _outputSurface.Deactivate(); }
public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { if (prog?.Disposed ?? true) { return; } capi.Render.GlToggleBlend(true); IShaderProgram curShader = capi.Render.CurrentActiveShader; curShader?.Stop(); prog.Use(); prog.Uniform("iTime", capi.World.ElapsedMilliseconds / 500f); prog.Uniform("iResolution", new Vec2f(capi.Render.FrameWidth, capi.Render.FrameHeight)); prog.Uniform("iProgressBar", capi.ModLoader.GetModSystem <InWorldCraftingSystem>().progress); capi.Render.RenderMesh(quadRef); prog.Stop(); curShader?.Use(); }