예제 #1
0
        public static Material CreateRegularPassMaterial(ResourceFactory factory)
        {
            Shader            vs          = factory.CreateShader(ShaderStages.Vertex, ShaderHelper.LoadShaderCode("shadow-vertex", ShaderStages.Vertex, factory));
            Shader            fs          = factory.CreateShader(ShaderStages.Fragment, ShaderHelper.LoadShaderCode("shadow-frag", ShaderStages.Fragment, factory));
            VertexInputLayout inputLayout = factory.CreateInputLayout(
                new VertexInputDescription(
                    32,
                    new VertexInputElement("in_position", VertexSemanticType.Position, VertexElementFormat.Float3),
                    new VertexInputElement("in_normal", VertexSemanticType.Normal, VertexElementFormat.Float3),
                    new VertexInputElement("in_texCoord", VertexSemanticType.TextureCoordinate, VertexElementFormat.Float2)));
            ShaderSet shaderSet = factory.CreateShaderSet(inputLayout, vs, fs);
            ShaderResourceBindingSlots constantSlots = factory.CreateShaderResourceBindingSlots(
                shaderSet,
                new ShaderResourceDescription("ProjectionMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("ViewMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("LightProjectionMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("LightViewMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("LightInfoBuffer", ShaderConstantType.Float4),
                new ShaderResourceDescription("WorldMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("InverseTransposeWorldMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("SurfaceTexture", ShaderResourceType.Texture),
                new ShaderResourceDescription("SurfaceTexture", ShaderResourceType.Sampler),
                new ShaderResourceDescription("ShadowMap", ShaderResourceType.Texture),
                new ShaderResourceDescription("ShadowMap", ShaderResourceType.Sampler));

            return(new Material(shaderSet, constantSlots));
        }
예제 #2
0
        private WaterArea(AssetLoadContext loadContext, string bumpTexName = null)
        {
            _shaderSet = loadContext.ShaderResources.Water.ShaderSet;
            _pipeline  = loadContext.ShaderResources.Water.Pipeline;

            _resourceSets = new Dictionary <TimeOfDay, ResourceSet>();

            Texture bumpTexture = null;

            if (bumpTexName != null)
            {
                bumpTexture = loadContext.AssetStore.Textures.GetByName(bumpTexName);
            }
            else
            {
                bumpTexture = loadContext.StandardGraphicsResources.SolidWhiteTexture;
            }

            foreach (var waterSet in loadContext.AssetStore.WaterSets)
            {
                // TODO: Cache these resource sets in some sort of scoped data context.
                var resourceSet = AddDisposable(loadContext.ShaderResources.Water.CreateMaterialResourceSet(waterSet.WaterTexture.Value, bumpTexture));

                _resourceSets.Add(waterSet.TimeOfDay, resourceSet);
            }

            _beforeRender = (cl, context) =>
            {
                cl.SetGraphicsResourceSet(4, _resourceSets[context.Scene3D.Lighting.TimeOfDay]);
                cl.SetVertexBuffer(0, _vertexBuffer);
            };
        }
        protected override void PlatformSetShaderSet(ShaderSet shaderSet)
        {
            OpenGLShaderSet glShaderSet = (OpenGLShaderSet)shaderSet;

            GL.UseProgram(glShaderSet.ProgramID);
            _vertexLayoutChanged = true;
        }
예제 #4
0
        public static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X           = 100, Y = 100,
                WindowWidth = 960, WindowHeight = 540,
                WindowTitle = "Veldrid TinyDemo",
            };
            RenderContextCreateInfo contextCI = new RenderContextCreateInfo();

            VeldridStartup.CreateWindowAndRenderContext(ref windowCI, ref contextCI, out var window, out RenderContext rc);

            VertexBuffer vb = rc.ResourceFactory.CreateVertexBuffer(Cube.Vertices, new VertexDescriptor(VertexPositionColor.SizeInBytes, 2), false);
            IndexBuffer  ib = rc.ResourceFactory.CreateIndexBuffer(Cube.Indices, false);

            string folder    = rc.BackendType == GraphicsBackend.Direct3D11 ? "HLSL" : "GLSL";
            string extension = rc.BackendType == GraphicsBackend.Direct3D11 ? "hlsl" : "glsl";

            VertexInputLayout inputLayout = rc.ResourceFactory.CreateInputLayout(new VertexInputDescription[]
            {
                new VertexInputDescription(
                    new VertexInputElement("Position", VertexSemanticType.Position, VertexElementFormat.Float3),
                    new VertexInputElement("Color", VertexSemanticType.Color, VertexElementFormat.Float4))
            });

            string vsPath = Path.Combine(AppContext.BaseDirectory, folder, $"vertex.{extension}");
            string fsPath = Path.Combine(AppContext.BaseDirectory, folder, $"fragment.{extension}");

            Shader vs = rc.ResourceFactory.CreateShader(ShaderStages.Vertex, File.ReadAllText(vsPath));
            Shader fs = rc.ResourceFactory.CreateShader(ShaderStages.Fragment, File.ReadAllText(fsPath));

            ShaderSet shaderSet = rc.ResourceFactory.CreateShaderSet(inputLayout, vs, fs);
            ShaderResourceBindingSlots bindingSlots = rc.ResourceFactory.CreateShaderResourceBindingSlots(
                shaderSet,
                new ShaderResourceDescription("ViewProjectionMatrix", ShaderConstantType.Matrix4x4));
            ConstantBuffer viewProjectionBuffer = rc.ResourceFactory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);

            while (window.Exists)
            {
                InputSnapshot snapshot = window.PumpEvents();
                rc.ClearBuffer();

                rc.SetViewport(0, 0, window.Width, window.Height);
                float timeFactor = Environment.TickCount / 1000f;
                viewProjectionBuffer.SetData(
                    Matrix4x4.CreateLookAt(
                        new Vector3(2 * (float)Math.Sin(timeFactor), (float)Math.Sin(timeFactor), 2 * (float)Math.Cos(timeFactor)),
                        Vector3.Zero,
                        Vector3.UnitY)
                    * Matrix4x4.CreatePerspectiveFieldOfView(1.05f, (float)window.Width / window.Height, .5f, 10f));
                rc.SetVertexBuffer(0, vb);
                rc.IndexBuffer = ib;
                rc.ShaderSet   = shaderSet;
                rc.ShaderResourceBindingSlots = bindingSlots;
                rc.SetConstantBuffer(0, viewProjectionBuffer);
                rc.DrawIndexedPrimitives(Cube.Indices.Length);

                rc.SwapBuffers();
            }
        }
예제 #5
0
 public Material(
     ShaderSet shaderSet,
     ShaderResourceBindingSlots resourceBindings)
 {
     ShaderSet        = shaderSet;
     ResourceBindings = resourceBindings;
 }
예제 #6
0
        private void InitializeContextObjects(AssetDatabase ad, RenderContext rc)
        {
            ResourceFactory factory = rc.ResourceFactory;

            _vb = factory.CreateVertexBuffer(1024, true);
            _ib = factory.CreateIndexBuffer(1024, true);

            Shader            vs          = factory.CreateShader(ShaderStages.Vertex, ShaderHelper.LoadShaderCode("wireframe-vertex", ShaderStages.Vertex, rc.ResourceFactory));
            Shader            fs          = factory.CreateShader(ShaderStages.Fragment, ShaderHelper.LoadShaderCode("wireframe-frag", ShaderStages.Fragment, rc.ResourceFactory));
            VertexInputLayout inputLayout = factory.CreateInputLayout(
                new VertexInputElement("in_position", VertexSemanticType.Position, VertexElementFormat.Float3),
                new VertexInputElement("in_color", VertexSemanticType.Color, VertexElementFormat.Byte4));
            ShaderSet shaderSet            = factory.CreateShaderSet(inputLayout, vs, fs);
            ShaderResourceBindingSlots cbs = factory.CreateShaderResourceBindingSlots(
                shaderSet,
                new ShaderResourceDescription("ProjectionMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("ViewMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("WorldMatrixBuffer", ShaderConstantType.Matrix4x4));

            _material = new Material(shaderSet, cbs);

            _worldBuffer = factory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);
            Matrix4x4 identity = Matrix4x4.Identity;

            _worldBuffer.SetData(ref identity, 64);

            _wireframeState = factory.CreateRasterizerState(FaceCullingMode.None, TriangleFillMode.Solid, true, true);
        }
예제 #7
0
        static void Main()
        {
            var renderer = new Renderer();
            var game     = new Game(renderer);

            var vertShaderString = File.ReadAllText("Assets/Shaders/basic.vert");
            var fragShaderString = File.ReadAllText("Assets/Shaders/basic.frag");

            RawModel model;

            using (var reader = new StreamReader("Assets/Models/dragon.obj"))
            {
                model = new RawModel(ObjParser.LoadModel(reader));
            }

            var textureData = new ImageSharpTexture("Assets/Textures/white.png");
            var shaderSet   = new ShaderSet(vertShaderString, fragShaderString);

            renderer.Initialize(true);

            var mesh   = renderer.CreateMesh(model, textureData, shaderSet);
            var entity = new RenderableEntity(new Transform(new Vector3(0, -5, -10), new Vector3(), 1), mesh);

            entity.InitializeMesh(renderer);

            game.AddEntity(entity);
            game.AddEntity(new CameraController());

            game.RunMainLoop();
            renderer.DisposeGraphicsDevices();
        }
예제 #8
0
 public void SetShaderSet(ShaderSet shaderSet)
 {
     if (_shaderSet != shaderSet)
     {
         PlatformSetShaderSet(shaderSet);
         _shaderSet = shaderSet;
     }
 }
예제 #9
0
        protected override void PlatformSetShaderSet(ShaderSet shaderSet)
        {
            OpenGLESShaderSet glShaderSet = (OpenGLESShaderSet)shaderSet;

            GL.UseProgram(glShaderSet.ProgramID);
            Utilities.CheckLastGLES3Error();
            _vertexLayoutChanged = true;
        }
        protected override void PlatformSetTexture(int slot, ShaderTextureBinding textureBinding)
        {
            OpenGLTextureBinding         glTextureBinding = (OpenGLTextureBinding)textureBinding;
            OpenGLTextureBindingSlotInfo info             = ShaderResourceBindingSlots.GetTextureBindingInfo(slot);

            _textureSamplerManager.SetTexture(info.RelativeIndex, glTextureBinding);
            ShaderSet.UpdateTextureUniform(info.UniformLocation, info.RelativeIndex);
        }
예제 #11
0
        public ComputePipeline(GraphicsState graphics, ShaderSet shader, params IGraphicsResource[] resources)
        {
            Resources = resources.ToImmutableArray();
            var rf = graphics.Device.ResourceFactory;

            Pipeline = rf.CreateComputePipeline(new ComputePipelineDescription(shader.Description.Shaders[0],
                                                                               resources.Select(x => x.ResourceLayout).ToArray(), 1, 1, 1));
        }
예제 #12
0
 public override ShaderConstantBindings CreateShaderConstantBindings(
     RenderContext rc,
     ShaderSet shaderSet,
     MaterialInputs <MaterialGlobalInputElement> globalInputs,
     MaterialInputs <MaterialPerObjectInputElement> perObjectInputs)
 {
     return(new D3DShaderConstantBindings(rc, _device, shaderSet, globalInputs, perObjectInputs));
 }
예제 #13
0
    // TODO: Also material constants?

    public RenderKey(
        SurfaceType surfaceType,
        ShaderSet shaderSet,
        Pipeline pipeline)
    // TODO: Also material constants?
    {
        // TODO
        _key = 0;
    }
예제 #14
0
 public void Dispose()
 {
     ShaderSet.Dispose();
     ConstantBindings.Dispose();
     foreach (var binding in DefaultTextureBindings)
     {
         binding.TextureBinding.Dispose();
     }
 }
예제 #15
0
파일: WaterArea.cs 프로젝트: wu162/OpenSAGE
        private WaterArea(AssetLoadContext loadContext)
        {
            _shaderSet = loadContext.ShaderResources.Water.ShaderSet;
            _pipeline  = loadContext.ShaderResources.Water.Pipeline;

            _beforeRender = (cl, context) =>
            {
                cl.SetVertexBuffer(0, _vertexBuffer);
            };
        }
예제 #16
0
        private WaterArea(
            ContentManager contentManager,
            PolygonTrigger trigger)
        {
            var triggerPoints = trigger.Points
                                .Select(x => new Vector2(x.X, x.Y))
                                .ToArray();

            Triangulator.Triangulate(
                triggerPoints,
                WindingOrder.CounterClockwise,
                out var trianglePoints,
                out var triangleIndices);

            var vertices = trianglePoints
                           .Select(x =>
                                   new WaterShaderResources.WaterVertex
            {
                Position = new Vector3(x.X, x.Y, trigger.Points[0].Z)
            })
                           .ToArray();

            _boundingBox = BoundingBox.CreateFromPoints(vertices.Select(x => x.Position));

            _vertexBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticBuffer(
                                              vertices,
                                              BufferUsage.VertexBuffer));

            _numIndices = (uint)triangleIndices.Length;

            _indexBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticBuffer(
                                             triangleIndices,
                                             BufferUsage.IndexBuffer));

            _shaderSet = contentManager.ShaderResources.Water.ShaderSet;
            _pipeline  = contentManager.ShaderResources.Water.Pipeline;

            _resourceSets = new Dictionary <TimeOfDay, ResourceSet>();

            foreach (var waterSet in contentManager.IniDataContext.WaterSets)
            {
                var waterTexture = contentManager.Load <Texture>(Path.Combine("Art", "Textures", waterSet.WaterTexture));

                // TODO: Cache these resource sets in some sort of scoped data context.
                var resourceSet = AddDisposable(contentManager.ShaderResources.Water.CreateMaterialResourceSet(waterTexture));

                _resourceSets.Add(waterSet.TimeOfDay, resourceSet);
            }

            _beforeRender = (cl, context) =>
            {
                cl.SetGraphicsResourceSet(4, _resourceSets[context.Scene3D.Lighting.TimeOfDay]);
                cl.SetVertexBuffer(0, _vertexBuffer);
            };
        }
예제 #17
0
 internal ModelMesh(
     GraphicsDevice graphicsDevice,
     ShaderResourceManager shaderResources,
     string name,
     ShaderSet shaderSet,
     Pipeline depthPipeline,
     ReadOnlySpan <byte> vertexData,
     ushort[] indices,
     List <ModelMeshPart> meshParts,
     bool isSkinned,
     in BoundingBox boundingBox,
예제 #18
0
        public unsafe void ChangeRenderContext(AssetDatabase ad, RenderContext rc)
        {
            var factory = rc.ResourceFactory;

            _vb = factory.CreateVertexBuffer(s_vertices.Length * VertexPosition.SizeInBytes, false);
            _vb.SetVertexData(s_vertices, new VertexDescriptor(VertexPosition.SizeInBytes, 1, IntPtr.Zero));

            _ib = factory.CreateIndexBuffer(s_indices.Length * sizeof(int), false);
            _ib.SetIndices(s_indices);

            Shader            vs          = factory.CreateShader(ShaderStages.Vertex, ShaderHelper.LoadShaderCode("skybox-vertex", ShaderStages.Vertex, rc.ResourceFactory));
            Shader            fs          = factory.CreateShader(ShaderStages.Fragment, ShaderHelper.LoadShaderCode("skybox-frag", ShaderStages.Fragment, rc.ResourceFactory));
            VertexInputLayout inputLayout = factory.CreateInputLayout(
                new VertexInputDescription(
                    12,
                    new VertexInputElement("position", VertexSemanticType.Position, VertexElementFormat.Float3)));
            ShaderSet shaderSet = factory.CreateShaderSet(inputLayout, vs, fs);
            ShaderResourceBindingSlots constantSlots = factory.CreateShaderResourceBindingSlots(
                shaderSet,
                new ShaderResourceDescription("ProjectionMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("ViewMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("Skybox", ShaderResourceType.Texture),
                new ShaderResourceDescription("Skybox", ShaderResourceType.Sampler));

            _material         = new Material(shaderSet, constantSlots);
            _viewMatrixBuffer = factory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);

            fixed(Rgba32 *frontPin = &_front.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * backPin   = &_back.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * leftPin   = &_left.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * rightPin  = &_right.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * topPin    = &_top.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            fixed(Rgba32 * bottomPin = &_bottom.ISImage.DangerousGetPinnableReferenceToPixelBuffer())
            {
                var cubemapTexture = factory.CreateCubemapTexture(
                    (IntPtr)frontPin,
                    (IntPtr)backPin,
                    (IntPtr)leftPin,
                    (IntPtr)rightPin,
                    (IntPtr)topPin,
                    (IntPtr)bottomPin,
                    _front.Width,
                    _front.Height,
                    _front.PixelSizeInBytes,
                    _front.Format);

                _cubemapBinding = factory.CreateShaderTextureBinding(cubemapTexture);
            }

            _rasterizerState = factory.CreateRasterizerState(FaceCullingMode.None, TriangleFillMode.Solid, false, false);

            _viewProvider = new DependantDataProvider <Matrix4x4>(SharedDataProviders.GetProvider <Matrix4x4>("ViewMatrix"), Utilities.ConvertToMatrix3x3);
        }
예제 #19
0
        public GraphicsPipeline(GraphicsState graphics, Blend blend, DepthTest depthTest, bool culling,
                                ShaderSet shaders, OutputDescription output, params IGraphicsResource[] resources)
        {
            Resources = resources.ToImmutableArray();
            var rf = graphics.Device.ResourceFactory;

            Pipeline = rf.CreateGraphicsPipeline(new GraphicsPipelineDescription(
                                                     blend switch
            {
                Blend.Alpha => BlendStateDescription.SingleAlphaBlend,
                Blend.Override => BlendStateDescription.SingleOverrideBlend,
                _ => throw new ArgumentException()
            },
예제 #20
0
 public Material(
     RenderContext rc,
     ShaderSet shaderSet,
     ShaderConstantBindings constantBindings,
     ShaderTextureBindingSlots textureBindingSlots,
     DefaultTextureBindingInfo[] defaultTextureBindings)
 {
     _rc                    = rc;
     ShaderSet              = shaderSet;
     ConstantBindings       = constantBindings;
     TextureBindingSlots    = textureBindingSlots;
     DefaultTextureBindings = defaultTextureBindings;
 }
예제 #21
0
        private void InitializeContextObjects(AssetDatabase ad, RenderContext rc)
        {
            ResourceFactory factory = rc.ResourceFactory;
            MeshData        sphere  = ad.LoadAsset <ObjFile>(new AssetID("Models/Sphere.obj")).GetFirstMesh();

            Vector3[] spherePositions = sphere.GetVertexPositions();
            _sphereGeometryVB = factory.CreateVertexBuffer(spherePositions.Length * 12, false);
            _sphereGeometryVB.SetVertexData(spherePositions, new VertexDescriptor(12, 1));
            _ib = sphere.CreateIndexBuffer(factory, out _indexCount);

            Random r     = new Random();
            int    width = InstanceRows;

            InstanceData[] instanceData = new InstanceData[width * width * width];
            for (int z = 0; z < width; z++)
            {
                for (int y = 0; y < width; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        instanceData[z * width * width + y * width + x] = new InstanceData(
                            new Vector3(x * 10, y * 10, z * 10),
                            new RgbaFloat((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble()));
                    }
                }
            }

            _instanceVB = factory.CreateVertexBuffer(instanceData.Length * InstanceData.SizeInBytes, false);
            _instanceVB.SetVertexData(instanceData, new VertexDescriptor(InstanceData.SizeInBytes, 2, 0, IntPtr.Zero));

            Shader            vs          = factory.CreateShader(ShaderStages.Vertex, ShaderHelper.LoadShaderCode("instanced-simple-vertex", ShaderStages.Vertex, rc.ResourceFactory));
            Shader            fs          = factory.CreateShader(ShaderStages.Fragment, ShaderHelper.LoadShaderCode("instanced-simple-frag", ShaderStages.Fragment, rc.ResourceFactory));
            VertexInputLayout inputLayout = factory.CreateInputLayout(
                new VertexInputDescription(VertexPosition.SizeInBytes, new VertexInputElement("in_position", VertexSemanticType.Position, VertexElementFormat.Float3)),
                new VertexInputDescription(
                    InstanceData.SizeInBytes,
                    new VertexInputElement("in_offset", VertexSemanticType.TextureCoordinate, VertexElementFormat.Float3, VertexElementInputClass.PerInstance, 1),
                    new VertexInputElement("in_color", VertexSemanticType.Color, VertexElementFormat.Float4, VertexElementInputClass.PerInstance, 1)));
            ShaderSet shaderSet = factory.CreateShaderSet(inputLayout, vs, fs);
            ShaderResourceBindingSlots constantBindings = factory.CreateShaderResourceBindingSlots(
                shaderSet,
                new ShaderResourceDescription("ProjectionMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("ViewMatrixBuffer", ShaderConstantType.Matrix4x4),
                new ShaderResourceDescription("WorldMatrixBuffer", ShaderConstantType.Matrix4x4));

            _material    = new Material(shaderSet, constantBindings);
            _worldBuffer = factory.CreateConstantBuffer(ShaderConstantType.Matrix4x4);
            Matrix4x4 identity = Matrix4x4.Identity;

            _worldBuffer.SetData(ref identity, 64);
        }
예제 #22
0
파일: Terrain.cs 프로젝트: ybwsfl/OpenSAGE
        internal Terrain(
            HeightMap heightMap,
            List <TerrainPatch> patches,
            ShaderSet shaderSet,
            Pipeline pipeline,
            ResourceSet cloudResourceSet)
        {
            HeightMap        = heightMap;
            Patches          = patches;
            CloudResourceSet = cloudResourceSet;

            _shaderSet = shaderSet;
            _pipeline  = pipeline;
        }
예제 #23
0
 internal void BuildRenderList(
     RenderList renderList,
     ShaderSet shaderSet,
     Pipeline pipeline)
 {
     renderList.Opaque.RenderItems.Add(new RenderItem(
                                           shaderSet,
                                           pipeline,
                                           BoundingBox,
                                           Matrix4x4.Identity,
                                           0,
                                           _numIndices,
                                           _indexBuffer,
                                           _beforeRender));
 }
예제 #24
0
        /// <summary>Creates a new playable instance of the given SPA animation using the given shader set.</summary>
        public SPAInstance(SPA animation, ShaderSet shaders)
        {
            Animation = animation;
            float fr = (float)animation.FrameRate;

            if (fr == 0f)
            {
                FrameDelay = float.MaxValue;
            }
            else
            {
                FrameDelay = 1f / fr;
            }

            Setup(shaders);
        }
        public OpenGLESTextureBindingSlots(ShaderSet shaderSet, ShaderResourceDescription[] textureInputs)
        {
            _textureBindings = new OpenGLESProgramTextureBinding[textureInputs.Length];
            for (int i = 0; i < textureInputs.Length; i++)
            {
                var element  = textureInputs[i];
                int location = GL.GetUniformLocation(((OpenGLESShaderSet)shaderSet).ProgramID, element.Name);
                Utilities.CheckLastGLES3Error();
                if (location == -1)
                {
                    throw new VeldridException($"No sampler was found with the name {element.Name}");
                }

                _textureBindings[i] = new OpenGLESProgramTextureBinding(location);
            }
        }
예제 #26
0
        public static Material CreateShadowPassMaterial(ResourceFactory factory)
        {
            Shader            vs          = factory.CreateShader(ShaderStages.Vertex, ShaderHelper.LoadShaderCode("shadowmap-vertex", ShaderStages.Vertex, factory));
            Shader            fs          = factory.CreateShader(ShaderStages.Fragment, ShaderHelper.LoadShaderCode("shadowmap-frag", ShaderStages.Fragment, factory));
            VertexInputLayout inputLayout = factory.CreateInputLayout(
                new VertexInputDescription(
                    12,
                    new VertexInputElement("in_position", VertexSemanticType.Position, VertexElementFormat.Float3)));
            ShaderSet shaderSet = factory.CreateShaderSet(inputLayout, vs, fs);
            ShaderResourceBindingSlots constantSlots = factory.CreateShaderResourceBindingSlots(
                shaderSet,
                new ShaderResourceDescription("ProjectionMatrixBuffer", ShaderConstantType.Matrix4x4), // Light Projection
                new ShaderResourceDescription("ViewMatrixBuffer", ShaderConstantType.Matrix4x4),       // Light View
                new ShaderResourceDescription("WorldMatrixBuffer", ShaderConstantType.Matrix4x4));

            return(new Material(shaderSet, constantSlots));
        }
예제 #27
0
    public Material(
        ShaderSet shaderSet,
        Pipeline pipeline,
        ResourceSet materialResourceSet)
    {
        Id = shaderSet.GetNextMaterialId();

        ShaderSet           = shaderSet;
        Pipeline            = pipeline;
        MaterialResourceSet = materialResourceSet;

        // Bit 24-31: ShaderSet
        RenderKey |= (ShaderSet.Id << 24);

        // Bit 16-23: Material
        RenderKey |= (Id) << 16;
    }
예제 #28
0
        public OpenGLTextureBindingSlots(ShaderSet shaderSet, MaterialTextureInputs textureInputs)
        {
            TextureInputs = textureInputs;

            _textureBindings = new OpenGLProgramTextureBinding[textureInputs.Elements.Length];
            for (int i = 0; i < textureInputs.Elements.Length; i++)
            {
                var element  = textureInputs.Elements[i];
                int location = GL.GetUniformLocation(((OpenGLShaderSet)shaderSet).ProgramID, element.Name);
                if (location == -1)
                {
                    throw new InvalidOperationException($"No sampler was found with the name {element.Name}");
                }

                _textureBindings[i] = new OpenGLProgramTextureBinding(location);
            }
        }
예제 #29
0
        public static Material CreateMaterial(
            this ResourceFactory factory,
            RenderContext rc,
            string vertexShaderName,
            string fragmentShaderName,
            VertexInputDescription[] vertexInputs,
            ShaderResourceDescription[] resources)

        {
            Shader                     vs               = factory.CreateShader(ShaderStages.Vertex, ShaderHelper.LoadShaderCode(vertexShaderName, ShaderStages.Vertex, rc.ResourceFactory));
            Shader                     fs               = factory.CreateShader(ShaderStages.Fragment, ShaderHelper.LoadShaderCode(fragmentShaderName, ShaderStages.Fragment, rc.ResourceFactory));
            VertexInputLayout          inputLayout      = factory.CreateInputLayout(vertexInputs);
            ShaderSet                  shaderSet        = factory.CreateShaderSet(inputLayout, vs, fs);
            ShaderResourceBindingSlots resourceBindings = factory.CreateShaderResourceBindingSlots(shaderSet, resources);

            return(new Material(shaderSet, resourceBindings));
        }
예제 #30
0
        private WaterArea(AssetLoadContext loadContext, string debugName)
        {
            _shaderSet = loadContext.ShaderResources.Water;
            _pipeline  = loadContext.ShaderResources.Water.Pipeline;

            _material = AddDisposable(
                new Material(
                    _shaderSet,
                    _pipeline,
                    null)); // TODO: MaterialResourceSet

            _debugName = debugName;

            _beforeRender = (CommandList cl, RenderContext context, in RenderItem renderItem) =>
            {
                cl.SetVertexBuffer(0, _vertexBuffer);
            };
        }