public static Material Create(ShaderPipeline shader, Color mainColor, Texture2D mainTexture) { Material material = new Material(GraphicsContext.graphicsDevice, GraphicsContext.uniform0, shader.ShaderPair, mainColor, mainTexture); return(material); }
public static Material Create(ShaderPipeline shader) { Material material = new Material(GraphicsContext.graphicsDevice, GraphicsContext.uniform0, shader.ShaderPair, Color.white, Texture2D.White); return(material); }
public void LoadContent() { if (Resource.TryGetString(this.GetType().Assembly, "Thundershock.Resources.Effects.PostProcessor.glsl", out var text)) { _ppEffect = ShaderPipeline.CompileShader(_gpu, text); } _brightnessThreshold = _ppEffect.Programs["BloomThreshold"]; _gaussian = _ppEffect.Programs["BloomGaussian"]; _bloom = _ppEffect.Programs["Bloom"]; _shadowmask = _ppEffect.Programs["CRT"]; /* _brightnessThreshold.Parameters["Threshold"].SetValue(_bloomThreshold); * // _gaussian.Parameters["Kernel"].SetValue(_gaussianKernel); * * // _bloom.Parameters["BaseIntensity"].SetValue(_baseIntensity); * // _bloom.Parameters["BloomIntensity"].SetValue(_bloomIntensity); * * // _bloom.Parameters["BloomSaturation"].SetValue(_bloomSaturation); * // _bloom.Parameters["BaseSaturation"].SetValue(_baseSaturation); */ _brightnessThreshold.Parameters["transform"].SetValue(_matrix); _gaussian.Parameters["transform"].SetValue(_matrix); _bloom.Parameters["transform"].SetValue(_matrix); _shadowmask.Parameters["transform"].SetValue(_matrix); }
public void OnCreate(ECSWorld world) { var fragShader = Asset.Load <ShaderAsset>("mesh_instanced_default.frag"); var vertShader = Asset.Load <ShaderAsset>("mesh_instanced_default.vert"); var shader = new ShaderPipeline(fragShader, vertShader, ShaderType.Instanced); defaultShader = shader.ShaderPair; defaultMaterial = new Material(GraphicsContext.graphicsDevice, GraphicsContext.uniform0, defaultShader); defaultMaterial.wireframe = true; instanceMatrix = new DeviceBuffer(GraphicsContext.graphicsDevice, (ulong)Unsafe.SizeOf <ObjectToWorld>(), BufferUsageFlags.VertexBuffer, BufferMemoryUsageHint.Dynamic); var matrix = mat4.Identity; var normalMatrix = new mat3(matrix); ObjectToWorld matrices = new ObjectToWorld() { model = matrix, normal = normalMatrix }; instanceMatrix.SetData(matrices, 0); MeshData initialData = new MeshData(); initialData.subMeshes = new SubMeshData[1]; initialData.subMeshes[0] = new SubMeshData(vertices, indices); defaultMesh = new Mesh(GraphicsContext.graphicsDevice, initialData, true); }
protected AbstractDisplayList(uint vertexSize, ShaderPipeline pipeline = null, VertexAttributeDescription[] vertexAttributes = null) { this.pipeline = pipeline ?? new ShaderPipeline( DefaultShader.FromType(typeof(T), ShaderType.Vertex), DefaultShader.FromType(typeof(T), ShaderType.Fragment)); this.vertexAttributes = vertexAttributes ?? DefaultVertexDefinition.FromType(typeof(T)); this.vertexSize = vertexSize; }
public override void ApplyEffect(ShaderPipeline pipeline) { pipeline.FragmentShader.SetUniform(ReservedUniforms.ConvolutionReach, Intensity); pipeline.FragmentShader.SetUniform(ReservedUniforms.Convolution, (new Matrix3 ( 1, 2, 1, 2, 4, 2, 1, 2, 1 ) * (1f / 16)).SingleIndexedValues); }
public void OnCreate(ECSWorld world) { query.IncludeReadonly <ObjectToWorld>(); query.IncludeShared <DebugMeshConvexHullRenderer>(); query.ExcludeShared <CulledRenderTag>(); var fragShader = Asset.Load <ShaderAsset>("mesh_instanced_default.frag"); var vertShader = Asset.Load <ShaderAsset>("mesh_instanced_default.vert"); var shader = new ShaderPipeline(fragShader, vertShader, ShaderType.Instanced); defaultShader = shader.ShaderPair; defaultMaterial = new Material(GraphicsContext.graphicsDevice, GraphicsContext.uniform0, defaultShader); defaultMaterial.wireframe = true; instanceMatricesBuffers = new List <DeviceBuffer>(1); GrowInstanceMatrices(); }
private void Setup() { pipeline = new ShaderPipeline(DefaultShader.FromType(typeof(VertexPositionColor), ShaderType.Vertex), DefaultShader.FromType(typeof(VertexPositionColor), ShaderType.Fragment)); vab = new VertexArrayBuffer <VertexPositionColor>(VertexPositionColor.Size, OpenGL.BufferUsage.StaticDraw); vao = new VertexArrayObject <VertexPositionColor>(vab, pipeline, DefaultVertexDefinition.FromType(typeof(VertexPositionColor))); renderTexture = new RenderTexture(400, 400); vab.Bind(); vao.Bind(); pipeline.Bind(); vab.CopyData(vertices); worldMatrix = new Matrix4fUniform(DefaultShader.MVP_UNIFORM_NAME); pipeline.Unbind(); vao.Unbind(); vab.Unbind(); spriteRenderer = new SpriteRenderer(); defaultFramebuffer = Framebuffer.GetDefault(); spriteDisplayList = new DynamicDisplayList <VertexPositionColorTexture>(VertexPositionColorTexture.Size); resourceSet = new TextureResourceSet(window); }
protected void Setup() { var vs = DefaultShader.FromType(typeof(VertexPositionColorTexture), PlainCore.Graphics.Core.ShaderType.Vertex); var fs = DefaultShader.FromType(typeof(VertexPositionColorTexture), PlainCore.Graphics.Core.ShaderType.Fragment); pipeline = new ShaderPipeline(vs, fs); buffer = new VertexArrayBuffer <VertexPositionColorTexture>(32, OpenGL.BufferUsage.StaticDraw); indexBuffer = new IndexBuffer <VertexPositionColorTexture>(OpenGL.BufferUsage.StaticDraw); vao = new VertexArrayObject <VertexPositionColorTexture>(buffer, pipeline, DefaultVertexDefinition.FromType(typeof(VertexPositionColorTexture))); texture = new DeviceTexture(DefaultShader.DEFFAULT_TEXTURE_UNIFORM_NAME, 100, 100, true); defaultFramebuffer = Framebuffer.GetDefault(); var imageData = Image.Load("Example.png").SavePixelData(); texture.Bind(); texture.CopyData(imageData); buffer.Bind(); buffer.CopyData(_ArrayPosition); buffer.Unbind(); indexBuffer.Bind(); indexBuffer.CopyData(indexArray); indexBuffer.Unbind(); worldMatrix = new Matrix4fUniform(DefaultShader.MVP_UNIFORM_NAME); }
public StaticDisplayList(T[] vertices, int[] indices, uint vertexSize, OpenGL.PrimitiveType primitiveType = OpenGL.PrimitiveType.Triangles, ShaderPipeline pipeline = null, VertexAttributeDescription[] attributes = null) : base(vertexSize, pipeline, attributes) { if (vertices == null) { throw new ArgumentNullException(nameof(vertices)); } if (indices == null) { throw new ArgumentNullException(nameof(indices)); } vertexArrayBuffer = new VertexArrayBuffer <T>(vertexSize, OpenGL.BufferUsage.StaticDraw, primitiveType); indexBuffer = new IndexBuffer <T>(OpenGL.BufferUsage.StaticDraw); vertexArrayObject = new VertexArrayObject <T>(vertexArrayBuffer, this.pipeline, vertexAttributes); vertexArrayBuffer.Bind(); indexBuffer.Bind(); vertexArrayBuffer.CopyData(vertices); indexBuffer.CopyData(indices); indexBuffer.Unbind(); vertexArrayBuffer.Unbind(); elementCount = indices.Length; }
public StreamDisplayList(uint vertexSize, OpenGL.PrimitiveType primitiveType = OpenGL.PrimitiveType.Triangles, uint vertexBufferSize = 1024, uint indexBufferSize = 1024, ShaderPipeline pipeline = null, Core.VertexAttributeDescription[] vertexAttributes = null) : base(vertexSize, pipeline, vertexAttributes) { vertexArrayBuffer = new VertexArrayBuffer <T>(vertexSize, OpenGL.BufferUsage.StreamDraw, primitiveType); indexBuffer = new IndexBuffer <T>(OpenGL.BufferUsage.StreamDraw); vertexArrayObject = new VertexArrayObject <T>(vertexArrayBuffer, this.pipeline, this.vertexAttributes); vertexArrayBuffer.Bind(); indexBuffer.Bind(); vertexArrayBuffer.CopyRawData(IntPtr.Zero, vertexSize * vertexBufferSize); indexBuffer.CopyRawData(IntPtr.Zero, sizeof(int) * indexBufferSize); indexBuffer.Unbind(); vertexArrayBuffer.Unbind(); }
public void Set(ShaderPipeline pipeline) { deviceTexture.Bind(); deviceTexture.Set(pipeline); deviceTexture.Unbind(); }
public DynamicDisplayList(uint vertexSize, OpenGL.PrimitiveType primitiveType = OpenGL.PrimitiveType.Triangles, ShaderPipeline pipeline = null, VertexAttributeDescription[] vertexAttributes = null) : base(vertexSize, pipeline, vertexAttributes) { vertexArrayBuffer = new VertexArrayBuffer <T>(vertexSize, OpenGL.BufferUsage.DynamicDraw, primitiveType); indexBuffer = new IndexBuffer <T>(OpenGL.BufferUsage.DynamicDraw); vertexArrayObject = new VertexArrayObject <T>(vertexArrayBuffer, this.pipeline, this.vertexAttributes); }
public abstract void ApplyEffect(ShaderPipeline pipeline);
public abstract void SetDefaults(ShaderPipeline pipeline);
public override void SetDefaults(ShaderPipeline pipeline) { pipeline.FragmentShader.SetUniform(ReservedUniforms.ConvolutionReach, 0); pipeline.FragmentShader.SetUniform(ReservedUniforms.Convolution, new float[] { 0, 0, 0, 0, 1, 0, 0, 0, 0 }); }
public BatchDisplayList(uint vertexSize, uint vertexBufferSize = DEFAULT_BUFFER_SIZE, OpenGL.PrimitiveType primitive = OpenGL.PrimitiveType.Triangles, ShaderPipeline pipeline = null, Core.VertexAttributeDescription[] vertexAttributes = null) : base(vertexSize, pipeline, vertexAttributes) { vertexArrayBuffer = new VertexArrayBuffer <T>(vertexSize, OpenGL.BufferUsage.StreamDraw, primitive); indexBuffer = new IndexBuffer <T>(OpenGL.BufferUsage.DynamicDraw); vertexArrayObject = new VertexArrayObject <T>(vertexArrayBuffer, this.pipeline, this.vertexAttributes); vertexArrayBuffer.Bind(); vertexArrayBuffer.CopyRawData(IntPtr.Zero, vertexSize * vertexBufferSize); vertexArrayBuffer.Unbind(); currentVertexBufferSize = vertexBufferSize; }
//TODO: Texture flipping needs to happen somewhere in y axis static void InitializeWorld() { var world = CoreEngine.World; var cm = world.ComponentManager; Random random = new Random(1); var fragShader = Asset.Load <ShaderAsset>("mesh_instanced.frag"); var vertShader = Asset.Load <ShaderAsset>("mesh_instanced.vert"); var shader = new ShaderPipeline(fragShader, vertShader, ShaderType.Instanced); var playerModel = Asset.Load <MeshAsset>("PUSHILIN_rocket_ship"); var playerTexture = Asset.Load <TextureAsset>("PUSHILIN_rocket_ship_color"); var asteroidModel0 = Asset.Load <MeshAsset>("asteroid0"); var asteroidTexture = Asset.Load <TextureAsset>("Asteroids_BaseColor"); playerModel.StartLoad(LoadPriority.High); playerTexture.StartLoad(LoadPriority.Medium); asteroidModel0.StartLoad(LoadPriority.Medium); asteroidTexture.StartLoad(LoadPriority.Medium); var playerTex = Texture2D.Create(playerTexture); var playerMat = Material.Create(shader, Color.white, playerTex); MeshRenderer playerRenderer = new MeshRenderer(Mesh.Create(playerModel), playerMat); Prefab player = new Prefab(); player.AddComponent(new Position() { value = vec3.UnitY }); player.AddComponent(new Rotation() { value = quat.Identity }); player.AddComponent(new Scale() { value = vec3.Ones }); player.AddComponent(new ObjectToWorld() { model = mat4.Identity }); player.AddComponent(new BoundingBox()); player.AddSharedComponent(playerRenderer); player.AddSharedComponent(RenderTag.Opaque); player.AddComponent(new Player() { movementSpeed = 5, turningSpeed = 5 }); player.AddComponent(new RigidBody() { mass = 10, detectionMode = CollisionDetectionMode.Continuous }); player.AddSharedComponent(new MeshCollider(playerRenderer.mesh.meshData, true)); player.AddSharedComponent(new DebugMeshConvexHullRenderer(playerRenderer.mesh.meshData)); player.AddComponent(new Velocity() { }); player.AddComponent(new AngularVelocity() { }); player.AddComponent(new PhysicsBodyLockAxis() { lockZ = true, lockRotX = true, lockRotY = true }); //var satelliteMesh = Mesh.Create(satelliteModel); //var satelliteTex = Texture2D.Create(satelliteTexture); //var satelliteMaterial = Material.Create(shader, Color.white, satelliteTex); //MeshRenderer renderer = new MeshRenderer(satelliteMesh, satelliteMaterial); //Prefab satellite = new Prefab(); //satellite.AddComponent(new Position() { value = vec3.Zero }); //satellite.AddComponent(new Rotation() { value = quat.Identity }); //satellite.AddComponent(new Scale() { value = vec3.Ones * 0.2f }); //satellite.AddComponent(new ObjectToWorld() { model = mat4.Identity }); //satellite.AddComponent(new BoundingBox()); //satellite.AddSharedComponent(renderer); //satellite.AddSharedComponent(RenderTag.Opaque); //satelliteModel.LoadNow(); //satellite.AddComponent(new RigidBody() { mass = 10, detectionMode = CollisionDetectionMode.Continuous }); //satellite.AddSharedComponent(new MeshCollider(satelliteMesh.meshData, true)); //satellite.AddSharedComponent(new DebugMeshConvexHullRenderer(satelliteMesh.meshData)); //satellite.AddComponent(new Velocity() { value = vec3.UnitY * 10 }); //satellite.AddComponent(new AngularVelocity() { value = vec3.UnitX * 1 }); var asteroidTex = Texture2D.Create(asteroidTexture); var asteroidMat = Material.Create(shader, Color.white, asteroidTex); var asteroidMesh0 = Mesh.Create(asteroidModel0); MeshRenderer asteroidRenderer0 = new MeshRenderer(asteroidMesh0, asteroidMat); Prefab asteroid0 = new Prefab(); asteroid0.AddComponent(new Position() { value = vec3.Zero }); asteroid0.AddComponent(new Rotation() { value = quat.Identity }); asteroid0.AddComponent(new Scale() { value = vec3.Ones * 0.2f }); asteroid0.AddComponent(new ObjectToWorld() { model = mat4.Identity }); asteroid0.AddComponent(new BoundingBox()); asteroid0.AddSharedComponent(asteroidRenderer0); asteroid0.AddSharedComponent(RenderTag.Opaque); asteroid0.AddComponent(new RigidBody() { mass = 10, detectionMode = CollisionDetectionMode.Continuous }); asteroid0.AddSharedComponent(new MeshCollider(asteroidMesh0.meshData, true)); //asteroid0.AddComponent(new BoxCollider() { width = asteroidMesh0.bounds.Size.x, height = asteroidMesh0.bounds.Size.y, length = asteroidMesh0.bounds.Size.z }); //asteroid0.AddSharedComponent(new DebugMeshConvexHullRenderer(asteroidMesh0.meshData)); asteroid0.AddComponent(new Velocity() { value = vec3.UnitY * 10 }); asteroid0.AddComponent(new AngularVelocity() { value = vec3.UnitX * 1 }); asteroid0.AddComponent(new PhysicsBodyLockAxis() { lockZ = true }); asteroid0.AddComponent(new Asteroid()); var cubeTex = Texture2D.Create(playerTexture); var cubeMaterial = Material.Create(shader, Color.white, cubeTex); var cubeMeshRend = new MeshRenderer() { mesh = RenderUtilities.UnitCube, materials = new[] { cubeMaterial } }; Prefab cube = new Prefab(); cube.AddComponent(new Position() { value = vec3.Zero }); cube.AddComponent(new Rotation() { value = quat.Identity }); cube.AddComponent(new Scale() { value = vec3.Ones }); cube.AddComponent(new ObjectToWorld() { model = mat4.Identity }); cube.AddComponent(new BoundingBox()); cube.AddSharedComponent(cubeMeshRend); cube.AddSharedComponent(RenderTag.Opaque); cube.AddComponent(new RigidBody() { mass = 1 }); cube.AddComponent(new BoxCollider() { height = 1f, length = 1f, width = 1f }); cube.AddComponent(new Velocity()); cube.AddComponent(new AngularVelocity() { value = vec3.UnitX * 10 }); //Prefab floor = new Prefab(); //floor.AddComponent(new Position() { value = -vec3.UnitY * 2 }); //floor.AddComponent(new Rotation() { value = quat.Identity }); //floor.AddComponent(new Scale() { value = new vec3(1000, 0.2f, 1000) }); //floor.AddComponent(new ObjectToWorld() { model = mat4.Identity }); //floor.AddComponent(new BoundingBox()); //floor.AddSharedComponent(cubeMeshRend); //floor.AddSharedComponent(RenderTag.Opaque); //floor.AddComponent(new StaticRigidBody()); //floor.AddComponent(new BoxCollider() { height = 1f, length = 1f, width = 1f }); //const int numCubes = 10; //const int tallCubes = 10; //for (int i = 0; i < tallCubes; i++) //{ // for (int j = 0; j < numCubes; j++) // { // var entity = world.Instantiate(cube); // cm.SetComponent(entity, new Position() // { // value = new vec3( // random.Next(-(int)Math.Sqrt(numCubes) * 10 - 5, (int)Math.Sqrt(numCubes) * 10 + 5), // i * 3 + 10, // random.Next(-(int)Math.Sqrt(numCubes) * 10 - 5, (int)Math.Sqrt(numCubes) * 10 + 5)) // }); // } //} const int numThings = 10000; for (int i = 0; i < numThings; i++) { var entity = world.Instantiate(asteroid0); const int multi = 10; cm.SetComponent(entity, new Position() { value = new vec3( random.Next(-(int)Math.Sqrt(numThings) * multi, (int)Math.Sqrt(numThings) * multi), random.Next(-(int)Math.Sqrt(numThings) * multi, (int)Math.Sqrt(numThings) * multi), 0 ) }); var maxVel = 10f; cm.SetComponent(entity, new Velocity() { value = new vec3( (float)random.NextDouble() * maxVel * 2 - maxVel, (float)random.NextDouble() * maxVel * 2 - maxVel, 0 ) }); cm.SetComponent(entity, new AngularVelocity() { value = new vec3( (float)random.NextDouble() * 10 - 5, (float)random.NextDouble() * 10 - 5, (float)random.NextDouble() * 10 - 5 ) }); cm.SetComponent(entity, new Scale() { value = new vec3((float)random.NextDouble() + 0.5f) }); } var playerEntity = world.Instantiate(player); var cameraEntity = world.Instantiate(Prefabs.Camera); var cameraPosition = new vec3(4, 4, 10); //var cameraRotation = MathHelper.LookAt(cameraPosition, vec3.Zero, vec3.UnitY); var cameraRotation = quat.Identity; cm.SetComponent(cameraEntity, new Position() { value = cameraPosition }); cm.SetComponent(cameraEntity, new Rotation() { value = cameraRotation }); //cm.AddComponent(cameraEntity, // new CameraFlightComponent() { flightSpeed = 5 }); cm.AddComponent(cameraEntity, new CameraFollow() { entityToFollow = playerEntity, zDistance = 40 }); //var floorEnt = world.Instantiate(floor); world.SystemManager.RegisterSystem(new AsteroidSpawner() { asteroidPrefabs = new[] { asteroid0 }, maxCount = 5000, playerEntity = playerEntity }); }