public RenderShaderComponent SetAttribute(string name, Action <int> setAction)
        {
            shader.Activate();
            var position = shader.GetResourceLocation(ShaderResourceType.Attribute, name);

            // Do only if found
            if (position != -1)
            {
                setAction?.Invoke(position);
            }
            shader.Deactivate();
            return(this);
        }
示例#2
0
 private void RenderVoxels(Vector3 cameraPosition, float[] cam)
 {
     _voxelShader.Activate();
     GL.ActiveTexture(TextureUnit.Texture0);
     _materialTextureArray.Activate();
     GL.Uniform1(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "texArray"), TextureUnit.Texture0 - TextureUnit.Texture0);
     GL.UniformMatrix4(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "camera"), 1, false, cam);
     GL.Uniform3(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "cameraPosition"), cameraPosition.ToOpenTK());
     GL.Uniform3(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "ambientLightColor"), new OpenTK.Vector3(0.1f, 0.1f, 0.1f));
     GL.Uniform3(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "lightDirection"), new OpenTK.Vector3(1f, 1.5f, -2f).Normalized());
     GL.Uniform3(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "lightColor"), new OpenTK.Vector3(1f, 1f, 1f));
     foreach (var valuePair in _chunkGeometrys)
     {
         _amountBuffers[valuePair.Key].ActivateBind(3);
         _idBuffers[valuePair.Key].ActivateBind(4);
         if (valuePair.Value.IDLength > 0)
         {
             valuePair.Value.Draw();
         }
         _idBuffers[valuePair.Key].Deactivate();
         _amountBuffers[valuePair.Key].Deactivate();
     }
     _materialTextureArray.Deactivate();
     _voxelShader.Deactivate();
 }
示例#3
0
 private void RenderSsao(ITexture depthTexture)
 {
     _ssaoShader.Activate();
     GL.Uniform2(_ssaoShader.GetResourceLocation(ShaderResourceType.Uniform, "iResolution"), new OpenTK.Vector2(_width, _height));
     GL.Uniform1(_ssaoShader.GetResourceLocation(ShaderResourceType.Uniform, "iGlobalTime"), _time);
     GL.ActiveTexture(TextureUnit.Texture0);
     depthTexture.Activate();
     GL.DrawArrays(PrimitiveType.Quads, 0, 4);
     _ssaoShader.Deactivate();
     depthTexture.Deactivate();
 }
示例#4
0
        private void RenderRaytrace(float[] cam, bool raytraceCollided)
        {
            UpdateRaytraceMesh();

            if (raytraceCollided)
            {
                GL.Color4(Color4.Transparent);
                _raytraceShader.Activate();
                GL.UniformMatrix4(_raytraceShader.GetResourceLocation(ShaderResourceType.Uniform, "camera"), 1, false, cam);
                _raytraceGeometry.Draw();
                _raytraceShader.Deactivate();
            }
        }
示例#5
0
        private void RenderGround(Vector3 cameraPosition, float[] cam)
        {
            _geometryShader.Activate();
            GL.ActiveTexture(TextureUnit.Texture0);
            _groundTexture.Activate();
            GL.Uniform1(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "tex"), TextureUnit.Texture0 - TextureUnit.Texture0);
            GL.UniformMatrix4(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "camera"), 1, false, cam);
            GL.Uniform3(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "cameraPosition"), cameraPosition.ToOpenTK());
            GL.Uniform3(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "ambientLightColor"), new OpenTK.Vector3(0.1f, 0.1f, 0.1f));
            GL.Uniform3(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "lightDirection"), new OpenTK.Vector3(1f, 1.5f, -2f).Normalized());
            GL.Uniform3(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "lightColor"), new OpenTK.Vector3(1f, 1f, 1f));

            _groundGeometry.Draw();

            _groundTexture.Deactivate();
            _geometryShader.Deactivate();
        }
示例#6
0
 private void RenderDepth(Vector3 cameraPosition, float[] cam)
 {
     GL.Color4(Color4.White);
     GL.ClearColor(Color.Red);
     GL.Clear(ClearBufferMask.ColorBufferBit);
     _depthShader.Activate();
     GL.UniformMatrix4(_depthShader.GetResourceLocation(ShaderResourceType.Uniform, "camera"), 1, false, cam);
     foreach (var geometry in _chunkDepthGeometrys.Values)
     {
         if (geometry.IDLength > 0)
         {
             geometry.Draw();
         }
     }
     _groundDepthGeometry.Draw();
     _depthShader.Deactivate();
     GL.ClearColor(Color.Transparent);
 }
示例#7
0
        private void RenderAddedTextures(ITexture texture1, ITexture texture2, float opaque)
        {
            _addShader.Activate();
            GL.ActiveTexture(TextureUnit.Texture0);
            texture1.Activate();
            GL.Uniform1(_addShader.GetResourceLocation(ShaderResourceType.Uniform, "image1"), TextureUnit.Texture0 - TextureUnit.Texture0);

            GL.ActiveTexture(TextureUnit.Texture1);
            texture2.Activate();
            GL.Uniform1(_addShader.GetResourceLocation(ShaderResourceType.Uniform, "image2"), TextureUnit.Texture1 - TextureUnit.Texture0);

            GL.Uniform1(_addShader.GetResourceLocation(ShaderResourceType.Uniform, "opaque"), opaque);

            GL.DrawArrays(PrimitiveType.Quads, 0, 4);

            texture1.Deactivate();
            texture2.Deactivate();
            _addShader.Deactivate();
        }