protected override Control CreateControl() { var changed = Changed.Adapt <int, AnySignalEditor> (this); var changedf = Changed.Adapt <float, AnySignalEditor> (this); return(FoldableContainer.WithLabel(Name, true, HAlign.Left, Container.LabelAndControl("Type: ", new Picker((int)NoiseKind, React.By((int i) => NoiseKind = (WorleyNoiseKind)i).And(changed), Enum.GetNames(typeof(WorleyNoiseKind))), true), Container.LabelAndControl("Seed: ", new NumericEdit(Seed, true, 1, React.By((float i) => Seed = (int)i).And(changedf)), true), Container.LabelAndControl("CP Type: ", new Picker((int)ControlPoints, React.By((int i) => ControlPoints = (ControlPointKind)i).And(changed), Enum.GetNames(typeof(ControlPointKind))), true), Container.LabelAndControl("CP Count: ", new NumericEdit(ControlPointCount, true, 1, React.By((float i) => ControlPointCount = (int)i).And(changedf).Filter(i => i > 2)), true), Container.LabelAndControl("Distance: ", new Picker((int)DistanceKind, React.By((int i) => DistanceKind = (DistanceKind)i).And(changed), Enum.GetNames(typeof(DistanceKind))), true), Container.LabelAndControl("Jitter: ", new NumericEdit(Jitter, false, 0.1f, React.By((float x) => Jitter = x).And(changedf)), true), Container.LabelAndControl("Periodic: ", new Picker(Periodic ? 1 : 0, React.By((int i) => Periodic = i != 0).And(changed), "No", "Yes"), true))); }
private void SetupRendering() { var renderMaterial = Materials.Renderer(_diffuseMap, _normalMap, _heightMap) .MapInput((double _) => _camera); var renderPanel = Panels.Renderer(_sceneGraph) .And(React.By((Vec2i vp) => ControlPanel <TexturedVertex> .UpdateAll(_sceneGraph, this, vp))) .MapInput((double _) => new Vec2i(ClientSize.Width, ClientSize.Height)); var renderMaterialPanel = MaterialPanels.Renderer(_sceneGraph) .MapInput((double _) => new Vec2i(ClientSize.Width, ClientSize.Height)); Render.Clear <double> (new Vec4(0f, 0f, 0f, 1f), ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit) .And(React.By <double> (UpdateCamera)) .And(renderMaterial) .And(renderPanel) .And(renderMaterialPanel) .Viewport(this) .SwapBuffers(this) .WhenRendered(this).Evoke(); Materials.UpdatePerspectiveMatrix() .MapInput((Vec2 size) => (_camera.Frustum = new ViewingFrustum(FrustumKind.Perspective, size.X, size.Y, -1f, -10000f)) .CameraToScreen) .WhenResized(this).Evoke(); }
public static Reaction <Camera> Renderer(SceneGraph sceneGraph) { _shader = PassThrough; return(React.By <Camera> (Render) .Program(_shader)); }
private void SetupRendering() { var shadowRender = Shadows.Renderer(_sceneGraph, 2500, ShadowMapType.Depth, true) .MapInput((double _) => _camera); var skyboxRender = Skybox.Renderer(_sceneGraph, _skyColor); var terrainRender = Terrain.Renderer(_sceneGraph, _skyColor, Shadows.Instance.csmUniforms); var entityRender = Entities.Renderer(_sceneGraph, Shadows.Instance.csmUniforms); var panelRender = Panels.Renderer(_sceneGraph) .And(React.By((Vec2i vp) => ControlPanel <TexturedVertex> .UpdateAll(_sceneGraph, this, vp))) .MapInput((double _) => new Vec2i(ClientSize.Width, ClientSize.Height)); var moveFighter = React.By <float> (UpdateFighterAndCamera) .Aggregate((float s, double t) => s + (float)t * 25f, 0f); React.By <double> (UpdateFPS) .And(shadowRender .And(skyboxRender .And(terrainRender) .And(entityRender) .MapInput((double _) => _camera) .And(panelRender) .Viewport(this))) .And(moveFighter) .SwapBuffers(this) .WhenRendered(this).Evoke(); Entities.UpdatePerspectiveMatrix() .And(Skybox.UpdatePerspectiveMatrix()) .And(Terrain.UpdatePerspectiveMatrix()) .MapInput((Vec2 size) => (_camera.Frustum = new ViewingFrustum(FrustumKind.Perspective, size.X, size.Y, -1f, -400f)) .CameraToScreen) .WhenResized(this).Evoke(); }
private Tuple <Control, Reaction <Control> > BandSlider(int band) { return(new Tuple <Control, Reaction <Control> > ( new Slider(VisualDirection.Vertical, 16f, 100f, 0f, 1f, BandWeights[band], React.By((float x) => BandWeights[band] = x) .And(Changed.Adapt <float, AnySignalEditor> (this))), null)); }
public static Reaction <T> Clear <T> (Vec4 clearColor, ClearBufferMask mask) { return(React.By <T> (input => { GL.ClearColor(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W); GL.Clear(mask); })); }
public ColorMapEdit(float domainMin, float domainMax, float knobWidth, float minVisualLength, ColorMap <Vec3> colorMap, Reaction <ColorMap <Vec3> > changed) : base(VisualDirection.Horizontal, HAlign.Left, VAlign.Top, false, false, Enumerable.Empty <Control> ()) { _bar = new ColorMapBar(domainMin, domainMax, knobWidth, minVisualLength, colorMap, changed, React.By <int?> (ItemSelected)); _picker = new ColorPicker(VisualDirection.Vertical, knobWidth, minVisualLength - (3f * knobWidth), Color.Black, true, React.By <Color> (ColorChanged)); Controls.AddRange(EnumerableExt.Enumerate <Control> (_bar, _picker) .Select(c => new Tuple <Control, Reaction <Control> > (c, null))); }
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 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 void SetupCameraMovement() { React.By <Vec2> (RotateCamera) .MapInput((MouseMoveEventArgs e) => new Vec2(-e.XDelta.Radians(), -e.YDelta.Radians()) * 0.2f) .Filter(_ => Mouse[MouseButton.Left]) .WhenMouseMovesOn(this) .Evoke(); React.By <float> (ZoomCamera) .MapInput(delta => delta * -0.5f) .WhenMouseWheelDeltaChangesOn(this) .Evoke(); }
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)); }
private Control Editor(Vec2i outputSize, string fileName, MaterialPanel <TexturedVertex> panel) { var worley = SignalEditor.Worley("Worley", WorleyNoiseKind.F1, ControlPointKind.Random, 10, 0, DistanceKind.Euclidean, 0f, true); var transform = worley.Transform("Transform", -30f, 0.5f); var dv = new Vec2(1f) / new Vec2(outputSize.X, outputSize.Y); var perlin = SignalEditor.Perlin("Perlin", new Vec2(10f)); var spectral = perlin.SpectralControl("Spectral", 0, 2, null, 1f, 0.5f, 0.2f); var warp = transform.Warp("Warp", spectral, 0.1f, dv, _heightMap); var signal = warp.Colorize("Signal", ColorMap <Vec3> .GrayScale(), _diffuseMap); var normal = warp.NormalMap("Normal", 1f, dv, _normalMap); return(SignalEditor.EditorUI(fileName, outputSize, React.By((Texture tex) => panel.Texture = tex), _updater, normal, signal)); }
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)); }
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 <T> Delay <T> (this Reaction <T> reaction, DelayedReactionUpdater updater, double delay) { return(React.By <T> (x => { DelayedReactionUpdater.PendingAction pa; if (updater._pending.TryGetValue(reaction, out pa)) { pa.Elapsed = 0; } else { updater._pending.Add(reaction, new DelayedReactionUpdater.PendingAction() { Delay = delay, Action = () => reaction(x) }); } })); }
protected override Control CreateControl() { var changed = Changed.Adapt <int, AnySignalEditor> (this); var changedf = Changed.Adapt <float, AnySignalEditor> (this); return(FoldableContainer.WithLabel(Name, true, HAlign.Left, Container.LabelAndControl("Seed: ", new NumericEdit(Seed, true, 1f, React.By((float s) => Seed = (int)s) .And(changedf)), true), Container.LabelAndControl("Scale X: ", new NumericEdit(Scale.X, false, 1f, React.By((float s) => Scale = new Vec2(s, Scale.Y)) .And(changedf)), true), Container.LabelAndControl("Scale Y: ", new NumericEdit(Scale.Y, false, 1f, React.By((float s) => Scale = new Vec2(Scale.X, s)) .And(changedf)), true), Container.LabelAndControl("Periodic: ", new Picker(Periodic ? 1 : 0, React.By((int i) => Periodic = i != 0).And(changed), "No", "Yes"), true))); }
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 ColorPicker(VisualDirection direction, float knobWidth, float minVisualLength, Color color, bool preview, Reaction <Color> changed) : base(preview ? direction : direction.Opposite(), HAlign.Left, VAlign.Top, true, false, Enumerable.Empty <Control> ()) { Changed = changed; _hue = ColorSlider.Hue(direction, knobWidth, minVisualLength, color, React.By <float> (ChangeHue)); _saturation = ColorSlider.Saturation(direction, knobWidth, minVisualLength, color, React.By <float> (ChangeSaturation)); _brightness = ColorSlider.Brightness(direction, knobWidth, minVisualLength, color, React.By <float> (ChangeBrightness)); var controls = EnumerableExt.Enumerate <Control> (_hue, _saturation, _brightness); var contents = preview ? EnumerableExt.Enumerate( new Container(direction, HAlign.Center, VAlign.Center, false, false, new Container(direction.Opposite(), HAlign.Left, VAlign.Top, false, false, controls), Label.ColorPreview(() => _value, new SizeF(3.5f * knobWidth, 3.5f * knobWidth)))) : controls; Controls.AddRange(contents.Select(c => new Tuple <Control, Reaction <Control> > (c, null))); }
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)); }
protected override Control CreateControl() { var changed = Changed.Adapt <float, AnySignalEditor> (this); return(FoldableContainer.WithLabel(Name, true, HAlign.Left, InputSignalControl("Source", Source), InputSignalControl("Warp", Warp), Container.LabelAndControl("Scale: ", new NumericEdit(Scale, false, 0.1f, React.By((float s) => Scale = s).And(changed)), true))); }
protected override Control CreateControl() { var changed = Changed.Adapt <float, AnySignalEditor> (this); var fbEdit = Container.LabelAndControl("First Band: ", new NumericEdit(FirstBand, true, 1f, React.By <float> (ChangeFirstBand).And(changed)), true); var lbEdit = Container.LabelAndControl("Last Band: ", new NumericEdit(LastBand, true, 1f, React.By <float> (ChangeLastBand).And(changed)), true); var sliders = Enumerable.Range(FirstBand, LastBand - FirstBand + 1) .Select(BandSlider).ToArray(); _bandContainer = Container.Horizontal(true, false, sliders); return(FoldableContainer.WithLabel(Name, true, HAlign.Left, InputSignalControl("Source", Source), fbEdit, lbEdit, _bandContainer)); }
public static Reaction <Mat4> UpdatePerspectiveMatrix() { return(React.By <Mat4> (matrix => _skybox.perspectiveMatrix &= matrix) .Program(_skyboxShader)); }
public static Reaction <Mat4> UpdatePerspectiveMatrix() { return(React.By <Mat4> (matrix => _terrain.transforms.perspectiveMatrix &= matrix) .Program(_terrainShader)); }