public Entities(GLProgram program, SceneGraph scene) : base(program) { var numPointLights = 0; var plights = new LightingShaders.PointLight[4]; using (program.Scope()) { foreach (var pointLight in scene.Root.Traverse().OfType <PointLight> ()) { plights[numPointLights++] = new LightingShaders.PointLight { position = pointLight.Position, intensity = pointLight.Intensity, linearAttenuation = pointLight.LinearAttenuation, quadraticAttenuation = pointLight.QuadraticAttenuation }; } pointLights &= plights; var samp = new Sampler2D[4]; for (int i = 0; i < samp.Length; i++) { samp[i] = new Sampler2D(i + 1).LinearFiltering().ClampToEdges(Axes.All); } samplers &= samp; diffuseMap &= new SamplerCube(5).LinearFiltering().ClampToEdges(Axes.All); lighting = new LightingUniforms(program, scene); transforms = new TransformUniforms(program); shadows = new CascadedShadowUniforms(program, new Sampler2DArray(0).LinearFiltering().ClampToEdges(Axes.All)); } }
public static Reaction <Camera> Renderer(SceneGraph sceneGraph) { _shader = PassThrough; return(React.By <Camera> (Render) .Program(_shader)); }
public unsafe void SetFloatArray(float[] array, int count, int uniform, GLProgram shaderProgram) { fixed(float *a = &array[0]) { SetFloatArray((IntPtr)a, count, uniform, shaderProgram); } }
/// <summary> /// Compile the compute program /// </summary> /// <param name="codelisting">The code</param> /// <param name="constvalues">List of constant values to use. Set of {name,value} pairs</param> /// <param name="saveable">True if want to save to binary</param> /// <param name="completeoutfile">If non null, output the post processed code listing to this file</param> public void CompileLink(string codelisting, object[] constvalues = null, bool saveable = false, string completeoutfile = null) { Program = new GLProgram(); string ret = Program.Compile(ShaderType.ComputeShader, codelisting, constvalues, completeoutfile); System.Diagnostics.Debug.Assert(ret == null, "Compute Shader", ret); ret = Program.Link(wantbinary: saveable); System.Diagnostics.Debug.Assert(ret == null, "Link", ret); GLStatics.Check(); }
private Shadows(GLProgram program, bool cascaded) : base(program) { _cascaded = cascaded; if (_cascaded) csmUniforms = new CascadedShadowUniforms (program); else { shadowUniforms = new ShadowUniforms (program); } }
public Materials(GLProgram program) : base(program) { using (program.Scope()) { transforms = new TransformUniforms(program); diffuseMap &= new Sampler2D(0).LinearFiltering(); normalMap &= new Sampler2D(1).LinearFiltering(); heightMap &= new Sampler2D(2).LinearFiltering(); } }
private Shadows(GLProgram program, bool cascaded) : base(program) { _cascaded = cascaded; if (_cascaded) { csmUniforms = new CascadedShadowUniforms(program); } else { shadowUniforms = new ShadowUniforms(program); } }
/// <summary> /// Compile and link the pipeline component. /// If you specify varyings, you must set up a buffer, and a start action of Gl.BindBuffer(GL.TRANSFORM_FEEDBACK_BUFFER,bufid) AND BeingTransformFeedback. /// </summary> /// <param name="shadertype">Shader type,Fragment, Vertex etc </param> /// <param name="codelisting">The code</param> /// <param name="constvalues">List of constant values to use. Set of {name,value} pairs</param> /// <param name="varyings">List of varyings to report</param> /// <param name="varymode">How to write the varying to the buffer</param> /// <param name="saveable">True if want to save to binary</param> /// <param name="auxname">For reporting purposes on error, name to give to shader </param> /// <param name="completeoutfile">If non null, output the post processed code listing to this file</param> protected void CompileLink(ShaderType shadertype, string codelisting, object[] constvalues = null, string[] varyings = null, TransformFeedbackMode varymode = TransformFeedbackMode.InterleavedAttribs, bool saveable = false, string auxname = "", string completeoutfile = null) { Program = new GLProgram(); string ret = Program.Compile(shadertype, codelisting, constvalues, completeoutfile); System.Diagnostics.Debug.Assert(ret == null, auxname, ret); ret = Program.Link(separable: true, varyings, varymode, saveable); System.Diagnostics.Debug.Assert(ret == null, auxname, ret); }
public static Reaction <Camera> Renderer(SceneGraph scene, int mapSize, ShadowMapType type, bool cascaded) { var depthFramebuffer = new Framebuffer(FramebufferTarget.Framebuffer); _shadowShader = cascaded ? new GLProgram( VertexShaderCascaded(), GeometryShaderCascaded(), DepthFragmentShader()) : new GLProgram( VertexShader(), type == ShadowMapType.Depth ? DepthFragmentShader() : VarianceFragmentShader()); _instance = new Shadows(_shadowShader, cascaded); Texture depthTexture; var render = React.By <Camera> (_instance.Render); if (type == ShadowMapType.Depth || cascaded) { depthTexture = cascaded ? new Texture(TextureTarget.Texture2DArray, PixelInternalFormat.DepthComponent16, mapSize, mapSize, CascadedShadowUniforms.MapCount, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero) : new Texture(TextureTarget.Texture2D, PixelInternalFormat.DepthComponent16, mapSize, mapSize, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero); depthFramebuffer.AddTexture(FramebufferAttachment.DepthAttachment, depthTexture); } else { depthTexture = new Texture(TextureTarget.Texture2D, PixelInternalFormat.Rg32f, mapSize, mapSize, PixelFormat.Rg, PixelType.Float, IntPtr.Zero); depthFramebuffer.AddTexture(FramebufferAttachment.ColorAttachment0, depthTexture); depthFramebuffer.AddRenderbuffer(FramebufferAttachment.DepthAttachment, RenderbufferStorage.DepthComponent16, mapSize, mapSize); var gaussTexture = new Texture(TextureTarget.Texture2D, PixelInternalFormat.Rg32f, mapSize / 2, mapSize / 2, PixelFormat.Rg, PixelType.Float, IntPtr.Zero); render = render.And(GaussianFilter.Both().MapInput((Camera cam) => Tuple.Create(depthTexture, gaussTexture))); } scene.GlobalLighting.ShadowMap = depthTexture; return(render .DrawBuffer(type == ShadowMapType.Depth ? DrawBufferMode.None : DrawBufferMode.Front) .DepthTest() .Culling() .Viewport(new Vec2i(mapSize, mapSize)) .Program(_shadowShader) .Texture(depthTexture) .Framebuffer(depthFramebuffer)); }
private TextureFilter(GLProgram program) { _program = program; _uniforms = new TextureUniforms (_program, new Sampler2D (0).LinearFiltering () .ClampToEdges (Axes.X | Axes.Y)); _framebuffer = new Framebuffer (FramebufferTarget.Framebuffer); var rectangle = Quadrilateral<TexturedVertex>.Rectangle (2f, 2f); rectangle.ApplyTextureFront (1f, new Vec2 (0f), new Vec2 (1f)); _vertexBuffer = new VBO<TexturedVertex> (rectangle.Vertices, BufferTarget.ArrayBuffer); _indexBuffer = new VBO<int> (rectangle.Indices, BufferTarget.ElementArrayBuffer); }
public static Reaction <Vec2i> Renderer(SceneGraph scene) { _panelShader = new GLProgram( VertexShaders.TransformedTexture <TexturedVertex, PanelFragment, TransformUniforms> (), FragmentShaders.TexturedOutput <PanelFragment, TextureUniforms> ()); _panels = new Panels(); _scene = scene; return(React.By <Vec2i> (_panels.Render) .Blending() .Culling() .Program(_panelShader)); }
private TextureFilter(GLProgram program) { _program = program; _uniforms = new TextureUniforms(_program, new Sampler2D(0).LinearFiltering() .ClampToEdges(Axes.X | Axes.Y)); _framebuffer = new Framebuffer(FramebufferTarget.Framebuffer); var rectangle = Quadrilateral <TexturedVertex> .Rectangle(2f, 2f); rectangle.ApplyTextureFront(1f, new Vec2(0f), new Vec2(1f)); _vertexBuffer = new VBO <TexturedVertex> (rectangle.Vertices, BufferTarget.ArrayBuffer); _indexBuffer = new VBO <int> (rectangle.Indices, BufferTarget.ElementArrayBuffer); }
private Terrain(GLProgram program, SceneGraph scene, Vec3 skyCol) : base(program) { transforms = new TransformUniforms(program); lighting = new LightingUniforms(program, scene); shadows = new CascadedShadowUniforms(program, new Sampler2DArray(0).LinearFiltering().ClampToEdges(Axes.All)); using (program.Scope()) { skyColor &= skyCol; sandSampler &= new Sampler2D(1); rockSampler &= new Sampler2D(2); grassSampler &= new Sampler2D(3); } }
public LightingUniforms(GLProgram program, SceneGraph scene) : base(program) { using (program.Scope()) { var gl = scene.GlobalLighting; if (gl != null) { globalLighting &= new LightingShaders.GlobalLight() { ambientLightIntensity = gl.AmbientLightIntensity, maxintensity = gl.MaxIntensity, inverseGamma = 1f / gl.GammaCorrection }; } } }
public static Reaction <Camera> Renderer(SceneGraph sceneGraph, CascadedShadowUniforms shadowSource) { _entityShader = new GLProgram( VertexShader(), FragmentShader()); _entities = new Entities(_entityShader, sceneGraph); return(React.By <Camera> (cam => _entities.Render(cam, shadowSource)) .BindSamplers(new Dictionary <Sampler, Texture> () { { !_entities.shadows.csmShadowMap, sceneGraph.GlobalLighting.ShadowMap }, { !_entities.diffuseMap, sceneGraph.GlobalLighting.DiffuseMap } }) .DepthTest() .Culling() .Program(_entityShader)); }
/// <summary> /// Compile and link the pipeline component. /// If you specify varyings, you must set up a buffer, and a start action of Gl.BindBuffer(GL.TRANSFORM_FEEDBACK_BUFFER,bufid) AND BeingTransformFeedback. /// </summary> /// <param name="vertex">The code for this shader type, or null</param> /// <param name="tcs">The code for this shader type, or null</param> /// <param name="tes">The code for this shader type, or null</param> /// <param name="geo">The code for this shader type, or null</param> /// <param name="frag">The code for this shader type, or null</param> /// <param name="vertexconstvars">List of constant values to use. Set of {name,value} pairs</param> /// <param name="tcsconstvars">List of constant values to use. Set of {name,value} pairs</param> /// <param name="tesconstvars">List of constant values to use. Set of {name,value} pairs</param> /// <param name="geoconstvars">List of constant values to use. Set of {name,value} pairs</param> /// <param name="fragconstvars">List of constant values to use. Set of {name,value} pairs</param> /// <param name="varyings">List of varyings to report</param> /// <param name="varymode">How to write the varying to the buffer</param> /// <param name="saveable">True if want to save to binary</param> public void CompileLink(string vertex = null, string tcs = null, string tes = null, string geo = null, string frag = null, object[] vertexconstvars = null, object[] tcsconstvars = null, object[] tesconstvars = null, object[] geoconstvars = null, object[] fragconstvars = null, string[] varyings = null, TransformFeedbackMode varymode = TransformFeedbackMode.InterleavedAttribs, bool saveable = false ) { Program = new GLProgram(); string ret; if (vertex != null) { ret = Program.Compile(ShaderType.VertexShader, vertex, vertexconstvars); System.Diagnostics.Debug.Assert(ret == null, "Vertex Shader", ret); } if (tcs != null) { ret = Program.Compile(ShaderType.TessControlShader, tcs, tcsconstvars); System.Diagnostics.Debug.Assert(ret == null, "Tesselation Control Shader", ret); } if (tes != null) { ret = Program.Compile(ShaderType.TessEvaluationShader, tes, tesconstvars); System.Diagnostics.Debug.Assert(ret == null, "Tesselation Evaluation Shader", ret); } if (geo != null) { ret = Program.Compile(ShaderType.GeometryShader, geo, geoconstvars); System.Diagnostics.Debug.Assert(ret == null, "Geometry shader", ret); } if (frag != null) { ret = Program.Compile(ShaderType.FragmentShader, frag, fragconstvars); System.Diagnostics.Debug.Assert(ret == null, "Fragment Shader", ret); } ret = Program.Link(false, varyings, varymode, saveable); System.Diagnostics.Debug.Assert(ret == null, "Link", ret); GLStatics.Check(); }
public static Filter Renderer(GLProgram program) { var filter = new TextureFilter (program); return React.By<Tuple<Texture, Texture>> (t => filter._program.DrawElements (PrimitiveType.Triangles, filter._vertexBuffer, filter._indexBuffer)) .BindSamplers (t => new Dictionary<Sampler, Texture> () { { (!filter._uniforms.textureMap), t.Item1 } }) .Viewport (t => t.Item2.Size) .Culling () .Program (program) .Texture (t => t.Item1) .FramebufferTexture (t => Tuple.Create (filter._framebuffer, FramebufferAttachment.ColorAttachment0, t.Item2)); }
public static Filter Renderer(GLProgram program) { var filter = new TextureFilter(program); return(React.By <Tuple <Texture, Texture> > (t => filter._program.DrawElements(PrimitiveType.Triangles, filter._vertexBuffer, filter._indexBuffer)) .BindSamplers(t => new Dictionary <Sampler, Texture> () { { (!filter._uniforms.textureMap), t.Item1 } }) .Viewport(t => t.Item2.Size) .Culling() .Program(program) .Texture(t => t.Item1) .FramebufferTexture(t => Tuple.Create(filter._framebuffer, FramebufferAttachment.ColorAttachment0, t.Item2))); }
public static Reaction <Camera> Renderer(Texture diffuseMap, Texture normalMap, Texture heightMap) { _materialShader = new GLProgram( VertexShader(), FragmentShader()); _materials = new Materials(_materialShader); return(React.By <Camera> (_materials.Render) .BindSamplers(new Dictionary <Sampler, Texture> () { { !_materials.diffuseMap, diffuseMap }, { !_materials.normalMap, normalMap }, { !_materials.heightMap, heightMap } }) .DepthTest() .Culling() .Program(_materialShader)); }
void Init() { Console.WriteLine(GL.GetString(StringName.Renderer)); Console.WriteLine(GL.GetString(StringName.Version)); AssetLoader.Init(); RenderCore.Create(); GameLoop = new GameLoop(this); EditorLoop = new GameLoop(this); DisplayRT = new RenderTexture(); FullscreenQuadProgram = ShaderUtils.CreateFromResource("RasterDraw.Shaders.SimpleVert.glsl", "RasterDraw.Shaders.SimpleFrag.glsl"); PhysicsEngine = new PhysicsManager(); EditorManager = new EditorManager(ClientSize); EditorManager.GameGameLoop = GameLoop; GameObject editorManager = new GameObject("Editor Manager"); editorManager.AddScript(EditorManager); EditorManager.Enabled = false; EditorLoop.Add(editorManager); }
public static Reaction <Camera> Renderer(SceneGraph sceneGraph, Vec3 skyCol, CascadedShadowUniforms shadowSource) { _terrainShader = new GLProgram(VertexShader(), FragmentShader()); _terrain = new Terrain(_terrainShader, sceneGraph, skyCol); var sandTexture = LoadTexture("Sand"); var rockTexture = LoadTexture("Rock"); var grassTexture = LoadTexture("Grass"); return(React.By((Camera cam) => _terrain.Render(cam, shadowSource)) .BindSamplers(new Dictionary <Sampler, Texture> () { { !_terrain.shadows.csmShadowMap, sceneGraph.GlobalLighting.ShadowMap }, { !_terrain.sandSampler, sandTexture }, { !_terrain.rockSampler, rockTexture }, { !_terrain.grassSampler, grassTexture } }) .DepthTest() .Culling() .Program(_terrainShader)); }
public static Reaction<Camera> Renderer(SceneGraph sceneGraph, Vec3 skyColor) { _skyboxShader = new GLProgram (VertexShader (), FragmentShader ()); _skybox = new Skybox (_skyboxShader); _skyColor = skyColor; var cube = Extrusion.Cube<PositionalVertex> (_cubeSize, _cubeSize, _cubeSize).Center (); _vertices = new VBO<PositionalVertex> (cube.Vertices, BufferTarget.ArrayBuffer); _indices = new VBO<int> (cube.Indices, BufferTarget.ElementArrayBuffer); var environmentMap = Texture.CubeMapFromFiles ( _paths.Map (s => string.Format (@"Textures/{0}.bmp", s)), 0) .LinearFiltering ().ClampToEdges (Axes.All); sceneGraph.GlobalLighting.DiffuseMap = environmentMap; return React.By<Camera> (_skybox.Render) .BindSamplers (new Dictionary<Sampler, Texture> () { { !_skybox.cubeMap, environmentMap } }) .Culling (CullFaceMode.Front) .Program (_skyboxShader); }
public static Reaction <Camera> Renderer(SceneGraph sceneGraph, Vec3 skyColor) { _skyboxShader = new GLProgram(VertexShader(), FragmentShader()); _skybox = new Skybox(_skyboxShader); _skyColor = skyColor; var cube = Extrusion.Cube <PositionalVertex> (_cubeSize, _cubeSize, _cubeSize).Center(); _vertices = new VBO <PositionalVertex> (cube.Vertices, BufferTarget.ArrayBuffer); _indices = new VBO <int> (cube.Indices, BufferTarget.ElementArrayBuffer); var environmentMap = Texture.CubeMapFromFiles( _paths.Map(s => string.Format(@"Textures/{0}.bmp", s)), 0) .LinearFiltering().ClampToEdges(Axes.All); sceneGraph.GlobalLighting.DiffuseMap = environmentMap; return(React.By <Camera> (_skybox.Render) .BindSamplers(new Dictionary <Sampler, Texture> () { { !_skybox.cubeMap, environmentMap } }) .Culling(CullFaceMode.Front) .Program(_skyboxShader)); }
private Skybox(GLProgram program) : base(program) { using (program.Scope()) cubeMap &= new SamplerCube(0).LinearFiltering().ClampToEdges(Axes.All); }
public ShadowUniforms(GLProgram program) : base(program) { }
/// <summary> Load the binary into the shader </summary> public void Load(byte[] bin, BinaryFormat binformat) { Program = new GLProgram(bin, binformat); }
public TextureUniforms(GLProgram program, Sampler2D sampler) : base(program) { using (program.Scope()) textureMap &= sampler; }
public CascadedShadowUniforms(GLProgram program) : base(program) { }
public Materials(GLProgram program) : base(program) { using (program.Scope ()) { transforms = new TransformUniforms (program); diffuseMap &= new Sampler2D (0).LinearFiltering ().ClampToEdges (Axes.All); normalMap &= new Sampler2D (1).LinearFiltering ().ClampToEdges (Axes.All); } }
private MaterialPanels(GLProgram program) : base(program) { Texture = new TextureUniforms(_panelShader, new Sampler2D(0).NearestColor()); Transform = new TransformUniforms(_panelShader); }
public static Reaction <T> Program <T> (this Reaction <T> render, GLProgram program) { return(render.Program(i => program)); }
public ShadowUniforms(GLProgram program, Sampler2D sampler) : base(program) { using (program.Scope ()) shadowMap &= sampler; }
public LightingUniforms(GLProgram program, SceneGraph scene) : base(program) { using (program.Scope ()) { var gl = scene.GlobalLighting; if (gl != null) { globalLighting &= new LightingShaders.GlobalLight () { ambientLightIntensity = gl.AmbientLightIntensity, maxintensity = gl.MaxIntensity, inverseGamma = 1f / gl.GammaCorrection }; } } }
private Skybox(GLProgram program) : base(program) { using (program.Scope ()) cubeMap &= new SamplerCube (0).LinearFiltering ().ClampToEdges (Axes.All); }
public static Reaction<Camera> Renderer(Texture diffuseMap, Texture normalMap) { _materialShader = new GLProgram ( VertexShader (), FragmentShader ()); _materials = new Materials (_materialShader); return React.By<Camera> (_materials.Render) .BindSamplers (new Dictionary<Sampler, Texture> () { { !_materials.diffuseMap, diffuseMap }, { !_materials.normalMap, normalMap } }) .DepthTest () .Culling () .Program (_materialShader); }
public CascadedShadowUniforms(GLProgram program, Sampler2DArray sampler) : base(program) { using (program.Scope ()) csmShadowMap &= sampler; }
public ShadowUniforms(GLProgram program, Sampler2D sampler) : base(program) { using (program.Scope()) shadowMap &= sampler; }
public static Reaction<Camera> Renderer(SceneGraph scene, int mapSize, ShadowMapType type, bool cascaded) { var depthFramebuffer = new Framebuffer (FramebufferTarget.Framebuffer); _shadowShader = cascaded ? new GLProgram ( VertexShaderCascaded (), GeometryShaderCascaded (), DepthFragmentShader ()) : new GLProgram ( VertexShader (), type == ShadowMapType.Depth ? DepthFragmentShader () : VarianceFragmentShader ()); _instance = new Shadows (_shadowShader, cascaded); Texture depthTexture; var render =React.By<Camera> (_instance.Render); if (type == ShadowMapType.Depth || cascaded) { depthTexture = cascaded ? new Texture (TextureTarget.Texture2DArray, PixelInternalFormat.DepthComponent16, mapSize, mapSize, CascadedShadowUniforms.MapCount, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero) : new Texture (TextureTarget.Texture2D, PixelInternalFormat.DepthComponent16, mapSize, mapSize, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero); depthFramebuffer.AddTexture (FramebufferAttachment.DepthAttachment, depthTexture); } else { depthTexture = new Texture (TextureTarget.Texture2D, PixelInternalFormat.Rg32f, mapSize, mapSize, PixelFormat.Rg, PixelType.Float, IntPtr.Zero); depthFramebuffer.AddTexture (FramebufferAttachment.ColorAttachment0, depthTexture); depthFramebuffer.AddRenderbuffer (FramebufferAttachment.DepthAttachment, RenderbufferStorage.DepthComponent16, mapSize, mapSize); var gaussTexture = new Texture (TextureTarget.Texture2D, PixelInternalFormat.Rg32f, mapSize / 2, mapSize / 2, PixelFormat.Rg, PixelType.Float, IntPtr.Zero); render = render.And (GaussianFilter.Both ().MapInput ((Camera cam) => Tuple.Create (depthTexture, gaussTexture))); } scene.GlobalLighting.ShadowMap = depthTexture; return render .DrawBuffer (type == ShadowMapType.Depth ? DrawBufferMode.None : DrawBufferMode.Front) .DepthTest () .Culling () .Viewport (new Vec2i (mapSize, mapSize)) .Program (_shadowShader) .Texture (depthTexture) .Framebuffer (depthFramebuffer); }
public CascadedShadowUniforms(GLProgram program, Sampler2DArray sampler) : base(program) { using (program.Scope()) csmShadowMap &= sampler; }
public TransformUniforms(GLProgram program) : base(program) { }