public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                var outputPath = $"{tempFile.FilePath}.out";

                var encodeFlags = arguments.GetBoolean("Strip") ? 1 : 0;

                ProcessHelper.Run(
                    CommonParameters.GetBinaryPath("yari-v", arguments, "ShaderPlayground.Shims.Yariv.exe"),
                    $"\"{tempFile.FilePath}\" 0 {encodeFlags} \"{outputPath}\"",
                    out var stdOutput,
                    out var _);

                var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath);

                FileHelper.DeleteIfExists(outputPath);

                var hasCompilationError = string.IsNullOrEmpty(stdOutput);

                return(new ShaderCompilerResult(
                           !hasCompilationError,
                           !hasCompilationError ? new ShaderCode(outputLanguage, binaryOutput) : null,
                           hasCompilationError ? (int?)1 : null));
            }
        }
Exemple #2
0
        void Initialize()
        {
            // 1) We create vertex shader first.
            {
                vertexShader = new ShaderCode(BindingStage.VertexShader);
                vertexShader.InputOperation.AddInput(PinComponent.Position, PinFormat.Floatx2);

                // We now extend position
                ExpandOperation expandPositionOp = new ExpandOperation(PinFormat.Floatx4, ExpandType.AddOnesAtW);
                expandPositionOp.BindInputs(vertexShader.InputOperation.PinAsOutput(PinComponent.Position));
                Pin position = expandPositionOp.Outputs[0];

                // We now output position.
                vertexShader.OutputOperation.AddComponentAndLink(PinComponent.Position, position);
            }

            vertexShader.Immutable = true;

            // 2) We create pixel shader.
            {
                pixelShader = new ShaderCode(BindingStage.PixelShader);
                pixelShader.InputOperation.AddInput(PinComponent.Position, PinFormat.Floatx2);

                ConstantOperation interfaceOp = pixelShader.CreateConstant("Composite", PinFormat.Interface, Pin.DynamicArray);

                // We use the compositing operation.
                CompositingOperation op = new CompositingOperation();
                op.BindInputs(pixelShader.InputOperation.PinAsOutput(PinComponent.Position),
                              interfaceOp.Outputs[0]);

                // Compositing is bound to output.
                pixelShader.OutputOperation.AddComponentAndLink(PinComponent.Colour, op.Outputs[0]);
            }

            pixelShader.Immutable = true;

            // 3) Initialize states.

            // Depth-stencil state.
            depthStencilState = new DepthStencilState();
            depthStencilState.DepthTestEnabled  = false;
            depthStencilState.DepthWriteEnabled = false;

            // Blend state (no blending default).
            blendState = new BlendState();


            // Rasterization state.
            rasterizationState                      = new RasterizationState();
            rasterizationState.FrontFacing          = Facing.CCW;
            rasterizationState.CullMode             = CullMode.None;
            rasterizationState.FillMode             = FillMode.Solid;
            rasterizationState.MultiSamplingEnabled = true;


            // We intern all states.
            depthStencilState  = StateManager.Intern(depthStencilState);
            blendState         = StateManager.Intern(blendState);
            rasterizationState = StateManager.Intern(rasterizationState);
        }
        public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                var outputPath = $"{tempFile.FilePath}.out";

                ProcessHelper.Run(
                    CommonParameters.GetBinaryPath("miniz", arguments, "ShaderPlayground.Shims.Miniz.exe"),
                    $"\"{tempFile.FilePath}\" {arguments.GetString("CompressionLevel")} \"{outputPath}\"",
                    out var _,
                    out var _);

                var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath);

                FileHelper.DeleteIfExists(outputPath);

                return(new ShaderCompilerResult(
                           true,
                           new ShaderCode(outputLanguage, binaryOutput),
                           null,
                           new ShaderCompilerOutput("Output", null, $"Compressed {shaderCode.Binary.Length} bytes into {binaryOutput.Length} bytes")));
            }
        }
        public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                var outputPath = $"{tempFile.FilePath}.out";

                ProcessHelper.Run(
                    CommonParameters.GetBinaryPath("zstd", arguments, "zstd.exe"),
                    $"-{arguments.GetString("CompressionLevel")} -v \"{tempFile.FilePath}\" -o \"{outputPath}\"",
                    out var _,
                    out var stdError);

                var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath);

                FileHelper.DeleteIfExists(outputPath);

                return(new ShaderCompilerResult(
                           true,
                           new ShaderCode(outputLanguage, binaryOutput),
                           null,
                           new ShaderCompilerOutput("Output", null, stdError)));
            }
        }
 private TrefoilKnotRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.stateList.Add(new LineWidthState(3));
     this.stateList.Add(new PointSizeState(3));
 }
        public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                var outputPath = $"{tempFile.FilePath}.out";

                ProcessHelper.Run(
                    CommonParameters.GetBinaryPath("spirv-tools-legacy", arguments, "spirv-markv.exe"),
                    $"e --comments --model={arguments.GetString("Model")} -o \"{outputPath}\" \"{tempFile.FilePath}\"",
                    out var stdOutput,
                    out var stdError);

                var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath);

                FileHelper.DeleteIfExists(outputPath);

                return(new ShaderCompilerResult(
                           true,
                           new ShaderCode(outputLanguage, binaryOutput),
                           null,
                           new ShaderCompilerOutput("Output", outputLanguage, stdError)));
            }
        }
Exemple #7
0
 protected override void DoInitialize()
 {
     {
         var computeProgram = new ShaderProgram();
         var shaderCode     = new ShaderCode(File.ReadAllText(@"shaders\SunshineCompute.comp"), ShaderType.ComputeShader);
         var shader         = shaderCode.CreateShader();
         computeProgram.Create(shader);
         shader.Delete();
         this.computeProgram = computeProgram;
     }
     {
         OpenGL.GenTextures(1, textureBufferPosition);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_BUFFER, textureBufferPosition[0]);
         OpenGL.GetDelegateFor <OpenGL.glTexBuffer>()(OpenGL.GL_TEXTURE_BUFFER,
                                                      OpenGL.GL_RGBA32F, this.positionBufferPtrId);
     }
     {
         OpenGL.GetDelegateFor <OpenGL.glGenBuffers>()(1, attractor_buffer);
         OpenGL.BindBuffer(BufferTarget.UniformBuffer, attractor_buffer[0]);
         OpenGL.GetDelegateFor <OpenGL.glBufferData>()(OpenGL.GL_UNIFORM_BUFFER,
                                                       64 * Marshal.SizeOf(typeof(vec4)), IntPtr.Zero, OpenGL.GL_DYNAMIC_COPY);
         OpenGL.GetDelegateFor <OpenGL.glBindBufferBase>()(OpenGL.GL_UNIFORM_BUFFER,
                                                           0, attractor_buffer[0]);
     }
 }
Exemple #8
0
 private void Form02OrderIndependentTransparency_Load(object sender, EventArgs e)
 {
     {
         var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
         camera.Position = new vec3(0, 0, 5);
         camera.Target   = new vec3(0, 0, 0);
         camera.UpVector = new vec3(0, 1, 0);
         var rotator = new SatelliteRotator(camera);
         this.camera  = camera;
         this.rotator = rotator;
     }
     {
         IBufferable bufferable  = new Teapot();
         var         shaderCodes = new ShaderCode[2];
         shaderCodes[0] = new ShaderCode(File.ReadAllText(@"03OrderDependentTransparency\Transparent.vert"), ShaderType.VertexShader);
         shaderCodes[1] = new ShaderCode(File.ReadAllText(@"03OrderDependentTransparency\Transparent.frag"), ShaderType.FragmentShader);
         var map = new PropertyNameMap();
         map.Add("in_Position", "position");
         map.Add("in_Color", "color");
         var renderer = new PickableRenderer(bufferable, shaderCodes, map, "position");
         renderer.Name = "Order-Dependent Transparent Renderer";
         renderer.Initialize();
         {
             GLSwitch blendSwitch = new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha);
             renderer.SwitchList.Add(blendSwitch);
         }
         this.renderer = renderer;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.renderer);
         frmPropertyGrid.Show();
         this.formPropertyGrid = frmPropertyGrid;
     }
 }
 protected override void DoInitialize()
 {
     {
         // particleSimulator-fountain.comp is also OK.
         var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\ParticleSimulatorRenderer\particleSimulator.comp"), ShaderType.ComputeShader);
         this.computeProgram = shaderCode.CreateProgram();
     }
     {
         BufferPtr bufferPtr = this.positionBufferPtr;
         Texture   texture   = bufferPtr.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
         texture.Initialize();
         this.positionTexture = texture;
     }
     {
         BufferPtr bufferPtr = this.velocityBufferPtr;
         Texture   texture   = bufferPtr.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
         texture.Initialize();
         this.velocityTexture = texture;
     }
     {
         IndependentBufferPtr bufferPtr = null;
         using (var buffer = new UniformBuffer <vec4>(BufferUsage.DynamicCopy, noDataCopyed: true))
         {
             buffer.Create(elementCount: 64);
             bufferPtr = buffer.GetBufferPtr();
         }
         bufferPtr.Bind();
         OpenGL.BindBufferBase((BindBufferBaseTarget)BufferTarget.UniformBuffer, 0, bufferPtr.BufferId);
         this.attractorBufferPtr = bufferPtr;
         bufferPtr.Unbind();
     }
 }
Exemple #10
0
 public OrderIndependentTransparencyRenderer(IBufferable model,
                                             string positionName, string normalName)
 {
     {
         var map = new PropertyNameMap();
         map.Add("position", positionName);
         map.Add("normal", normalName);
         var build_lists = new ShaderCode[2];
         build_lists[0]          = new ShaderCode(File.ReadAllText(@"shaders\build_lists.vert"), ShaderType.VertexShader);
         build_lists[1]          = new ShaderCode(File.ReadAllText(@"shaders\build_lists.frag"), ShaderType.FragmentShader);
         this.buildListsRenderer = new PickableRenderer(model, build_lists, map, positionName);
     }
     {
         var map = new PropertyNameMap();
         map.Add("position", positionName);
         var resolve_lists = new ShaderCode[2];
         resolve_lists[0]   = new ShaderCode(File.ReadAllText(@"shaders\resolve_lists.vert"), ShaderType.VertexShader);
         resolve_lists[1]   = new ShaderCode(File.ReadAllText(@"shaders\resolve_lists.frag"), ShaderType.FragmentShader);
         this.resolve_lists = new PickableRenderer(model, resolve_lists, map, positionName);
     }
     {
         this.depthTestSwitch = new DepthTestSwitch(false);
         this.cullFaceSwitch  = new CullFaceSwitch(false);
     }
 }
 public OrderIndependentTransparencyRenderer(IBufferable model, vec3 lengths,
                                             string positionName, string normalName)
 {
     {
         var map = new AttributeMap();
         map.Add("position", positionName);
         map.Add("normal", normalName);
         var build_lists = new ShaderCode[2];
         build_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\OIT\build_lists.vert"), ShaderType.VertexShader);
         build_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\OIT\build_lists.frag"), ShaderType.FragmentShader);
         var provider = new ShaderCodeArray(build_lists);
         this.buildListsRenderer = new PickableRenderer(model, provider, map, positionName);
     }
     {
         var map = new AttributeMap();
         map.Add("position", positionName);
         var resolve_lists = new ShaderCode[2];
         resolve_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\OIT\resolve_lists.vert"), ShaderType.VertexShader);
         resolve_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\OIT\resolve_lists.frag"), ShaderType.FragmentShader);
         var provider = new ShaderCodeArray(resolve_lists);
         this.resolve_lists = new PickableRenderer(model, provider, map, positionName);
     }
     {
         this.depthTestState = new DepthTestState(false);
         this.cullFaceState  = new CullFaceState(false);
     }
     this.ModelSize = lengths;
 }
 public OrderIndependentTransparencyRenderer(IBufferable model, vec3 lengths,
     string positionName, string normalName)
 {
     {
         var map = new AttributeMap();
         map.Add("position", positionName);
         map.Add("normal", normalName);
         var build_lists = new ShaderCode[2];
         build_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\OIT\build_lists.vert"), ShaderType.VertexShader);
         build_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\OIT\build_lists.frag"), ShaderType.FragmentShader);
         this.buildListsRenderer = new PickableRenderer(model, build_lists, map, positionName);
     }
     {
         var map = new AttributeMap();
         map.Add("position", positionName);
         var resolve_lists = new ShaderCode[2];
         resolve_lists[0] = new ShaderCode(File.ReadAllText(@"shaders\OIT\resolve_lists.vert"), ShaderType.VertexShader);
         resolve_lists[1] = new ShaderCode(File.ReadAllText(@"shaders\OIT\resolve_lists.frag"), ShaderType.FragmentShader);
         this.resolve_lists = new PickableRenderer(model, resolve_lists, map, positionName);
     }
     {
         this.depthTestState = new DepthTestState(false);
         this.cullFaceState = new CullFaceState(false);
     }
     this.ModelSize = lengths;
 }
        protected override void DoInitialize()
        {
            {
                // Initialize our compute program
                var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\SimpleComputeRenderer\compute.comp"), ShaderType.ComputeShader);
                this.computeProgram = shaderCode.CreateProgram();
            }
            {
                // Initialize our resetProgram
                var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\SimpleComputeRenderer\computeReset.comp"), ShaderType.ComputeShader);
                this.computeResetProgram = shaderCode.CreateProgram();
            }
            {
                // This is the texture that the compute program will write into
                var texture = new Texture(TextureTarget.Texture2D,
                    new TexStorage2DImageFiller(8, OpenGL.GL_RGBA32F, 256, 256),
                    new NullSampler());
                texture.Initialize();
                this.outputImage = texture;
            }
            {
                this.GroupX = 1;
                this.GroupY = 1;
                this.GroupZ = 1;
            }
            base.DoInitialize();

            this.SetUniform("output_image", this.outputImage);
        }
Exemple #14
0
        public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var stage       = arguments.GetString("ShaderStage");
            var entryPoint  = arguments.GetString("EntryPoint");
            var glslVersion = arguments.GetString("GlslVersion");

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                var outputPath = $"{tempFile.FilePath}.out";

                ProcessHelper.Run(
                    Path.Combine(AppContext.BaseDirectory, "Binaries", "XShaderCompiler", "xsc.exe"),
                    $"-T {stage} -E {entryPoint} -Vout {glslVersion} -o \"{outputPath}\" \"{tempFile.FilePath}\"",
                    out var stdOutput,
                    out var _);

                var textOutput = FileHelper.ReadAllTextIfExists(outputPath);

                var hasCompilationErrors = string.IsNullOrWhiteSpace(textOutput);

                FileHelper.DeleteIfExists(outputPath);

                return(new ShaderCompilerResult(
                           new ShaderCode(LanguageNames.Glsl, textOutput),
                           hasCompilationErrors ? (int?)1 : null,
                           new ShaderCompilerOutput("Output", LanguageNames.Glsl, textOutput),
                           new ShaderCompilerOutput("Build output", null, stdOutput)));
            }
        }
 private void Form_Load(object sender, EventArgs e)
 {
     {
         var camera = new Camera(
             new vec3(0, 0, 5), new vec3(0, 0, 0), new vec3(0, 1, 0),
             CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
         var rotator = new SatelliteManipulater();
         rotator.Bind(camera, this.glCanvas1);
         this.camera = camera;
         this.rotator = rotator;
     }
     {
         IBufferable bufferable = new Teapot();
         var shaderCodes = new ShaderCode[2];
         shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.vert"), ShaderType.VertexShader);
         shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Transparent.frag"), ShaderType.FragmentShader);
         var map = new PropertyNameMap();
         map.Add("in_Position", "position");
         map.Add("in_Color", "color");
         var renderer = new PickableRenderer(bufferable, shaderCodes, map, "position");
         renderer.Name = "Order-Dependent Transparent Renderer";
         renderer.Initialize();
         {
             GLSwitch blendSwitch = new BlendSwitch(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha);
             renderer.SwitchList.Add(blendSwitch);
         }
         this.renderer = renderer;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.renderer);
         frmPropertyGrid.Show();
         this.formPropertyGrid = frmPropertyGrid;
     }
 }
Exemple #16
0
        /// <summary>
        /// Create a label renderer.
        /// </summary>
        /// <param name="maxCharCount">Max char count to display for this label. Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param>
        /// <param name="labelHeight">Label height(in pixels)</param>
        /// <param name="fontTexture">Use which font to render text?</param>
        /// <returns></returns>
        public static LabelRenderer Create(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
        {
            if (fontTexture == null)
            {
                fontTexture = FontTexture.Default;
            }

            var model = new TextModel(maxCharCount);

            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\Label.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources\Label.frag"), ShaderType.FragmentShader);
            var provider = new ShaderCodeArray(shaderCodes);
            var map      = new AttributeMap();

            map.Add("in_Position", TextModel.strPosition);
            map.Add("in_UV", TextModel.strUV);

            var blendState = new BlendState(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.One);

            var renderer = new LabelRenderer(model, provider, map, blendState);

            renderer.blendState  = blendState;
            renderer.fontTexture = fontTexture;
            renderer.LabelHeight = labelHeight;

            return(renderer);
        }
Exemple #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="anchor"></param>
        /// <param name="margin"></param>
        /// <param name="size"></param>
        /// <param name="zNear"></param>
        /// <param name="zFar"></param>
        /// <param name="fontTexture"></param>
        /// <param name="maxCharCount"></param>
        public UIText(
            System.Windows.Forms.AnchorStyles anchor, System.Windows.Forms.Padding margin,
            System.Drawing.Size size, int zNear, int zFar, IFontTexture fontTexture = null, int maxCharCount = 100)
            : base(anchor, margin, size, zNear, zFar)
        {
            if (fontTexture == null)
            {
                this.fontTexture = FontTexture.Default;
            }                                          // FontResource.Default; }
            else
            {
                this.fontTexture = fontTexture;
            }

            var shaderCodes = new ShaderCode[2];

            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.TextModel.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                                                @"Resources.TextModel.frag"), ShaderType.FragmentShader);
            var provider = new ShaderCodeArray(shaderCodes);
            var map      = new AttributeMap();

            map.Add("position", TextModel.strPosition);
            map.Add("uv", TextModel.strUV);
            var model    = new TextModel(maxCharCount);
            var renderer = new Renderer(model, provider, map);

            this.textModel = model;
            this.Renderer  = renderer;
        }
 internal ShaderCompilerResult(bool success, ShaderCode pipeableCode, int?selectedOutputIndex, params ShaderCompilerOutput[] outputs)
 {
     Success             = success;
     PipeableOutput      = pipeableCode;
     SelectedOutputIndex = selectedOutputIndex;
     Outputs             = outputs;
 }
        public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var stage = GetStageFlag(arguments.GetString("ShaderStage"));
            var core  = arguments.GetString("Core");

            var args = string.Empty;

            if (shaderCode.Language == LanguageNames.SpirV)
            {
                var spirVEntryPoint = arguments.GetString("EntryPoint");

                args += "--spirv ";
                args += $"--spirv_entrypoint_name {spirVEntryPoint}";
            }

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                ProcessHelper.Run(
                    CommonParameters.GetBinaryPath("mali", arguments, "malisc.exe"),
                    $"{stage} -c {core} {args} {tempFile.FilePath}",
                    out var stdOutput,
                    out var stdError);

                return(new ShaderCompilerResult(
                           true,
                           null,
                           null,
                           new ShaderCompilerOutput("Output", null, stdOutput)));
            }
        }
Exemple #20
0
        /// <summary>
        /// Create a label renderer.
        /// </summary>
        /// <param name="maxCharCount">Max char count to display for this label. Careful to set this value because greater <paramref name="maxCharCount"/> means more space ocupied in GPU nemory.</param>
        /// <param name="labelHeight">Label height(in pixels)</param>
        /// <param name="fontTexture">Use which font to render text?</param>
        /// <returns></returns>
        public static LabelRenderer Create(int maxCharCount = 64, int labelHeight = 32, IFontTexture fontTexture = null)
        {
            if (fontTexture == null) { fontTexture = FontTexture.Default; }

            var model = new TextModel(maxCharCount);

            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                @"Resources\Label.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(
                @"Resources\Label.frag"), ShaderType.FragmentShader);

            var map = new AttributeMap();
            map.Add("in_Position", TextModel.strPosition);
            map.Add("in_UV", TextModel.strUV);

            var blendState = new BlendState(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.One);

            var renderer = new LabelRenderer(model, shaderCodes, map, blendState);
            renderer.blendState = blendState;
            renderer.fontTexture = fontTexture;
            renderer.LabelHeight = labelHeight;

            return renderer;
        }
 public MovableRenderer(IBufferable bufferable, ShaderCode[] shaderCodes,
     PropertyNameMap propertyNameMap, string positionNameInIBufferable,
     params GLSwitch[] switches)
     : base(bufferable, shaderCodes, propertyNameMap, positionNameInIBufferable, switches)
 {
     this.Scale = 1.0f;
 }
Exemple #22
0
        protected override void DoInitialize()
        {
            {
                // Initialize our compute program
                var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\SimpleComputeRenderer\compute.comp"), ShaderType.ComputeShader);
                this.computeProgram = shaderCode.CreateProgram();
            }
            {
                // Initialize our resetProgram
                var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\SimpleComputeRenderer\computeReset.comp"), ShaderType.ComputeShader);
                this.computeResetProgram = shaderCode.CreateProgram();
            }
            {
                // This is the texture that the compute program will write into
                var texture = new Texture(TextureTarget.Texture2D,
                                          new TexStorage2DImageFiller(8, OpenGL.GL_RGBA32F, 256, 256),
                                          new NullSampler());
                texture.Initialize();
                this.outputImage = texture;
            }
            {
                this.GroupX = 1;
                this.GroupY = 1;
                this.GroupZ = 1;
            }
            base.DoInitialize();

            this.SetUniform("output_image", this.outputImage);
        }
        protected override void DoInitialize()
        {
            {
                // particleSimulator-fountain.comp is also OK.
                var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\ParticleSimulatorRenderer\particleSimulator.comp"), ShaderType.ComputeShader);
                this.computeProgram = shaderCode.CreateProgram();
            }
            {
                Buffer buffer = this.positionBuffer;
                Texture texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
                texture.Initialize();
                this.positionTexture = texture;
            }
            {
                Buffer buffer = this.velocityBuffer;
                Texture texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
                texture.Initialize();
                this.velocityTexture = texture;
            }
            {
                const int length = 64;
                UniformBuffer buffer = UniformBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
                buffer.Bind();
                OpenGL.BindBufferBase((BindBufferBaseTarget)BufferTarget.UniformBuffer, 0, buffer.BufferId);
                buffer.Unbind();
                this.attractorBuffer = buffer;

                OpenGL.CheckError();
            }
        }
        protected override void DoInitialize()
        {
            {
                // particleSimulator-fountain.comp is also OK.
                var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\ParticleSimulatorRenderer\particleSimulator.comp"), ShaderType.ComputeShader);
                this.computeProgram = shaderCode.CreateProgram();
            }
            {
                GLBuffer buffer  = this.positionBuffer;
                Texture  texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
                texture.Initialize();
                this.positionTexture = texture;
            }
            {
                GLBuffer buffer  = this.velocityBuffer;
                Texture  texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
                texture.Initialize();
                this.velocityTexture = texture;
            }
            {
                const int     length = 64;
                UniformBuffer buffer = UniformBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
                buffer.Bind();
                glBindBufferBase((uint)BindBufferBaseTarget.UniformBuffer, 0, buffer.BufferId);
                buffer.Unbind();
                this.attractorBuffer = buffer;

                OpenGL.CheckError();
            }
        }
Exemple #25
0
        /// <summary>
        /// Creates a texture constant.
        /// </summary>
        internal ConstantOperation([NotEmpty] string name, PinFormat texture, PinFormat textureFormat, [NotNull] ShaderCode scope)
        {
            this.name  = name;
            this.scope = scope;

            output = new Pin(texture, textureFormat, Pin.NotArray, this);
        }
Exemple #26
0
        /// <summary>
        /// Creates a non-fixed constant.
        /// </summary>
        internal ConstantOperation([NotEmpty] string name, PinFormat fmt, uint size, [NotNull] ShaderCode scope)
        {
            this.name  = name;
            this.scope = scope;

            // We create the pin.
            output = new Pin(fmt, size, this);
        }
Exemple #27
0
 static BackgroundStarsRenderer()
 {
     staticShaderCodes    = new ShaderCode[2];
     staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\PointSprite.vert"), ShaderType.VertexShader);
     staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\PointSprite.frag"), ShaderType.FragmentShader);
     map = new PropertyNameMap();
     map.Add("position", "position");
 }
Exemple #28
0
        protected override void DoInitialize()
        {
            var shaderCode = new ShaderCode(File.ReadAllText(
                                                @"shaders\ImageProcessingRenderer\ImageProcessing.comp"), ShaderType.ComputeShader);
            ShaderProgram computeProgram = shaderCode.CreateProgram();

            this.computeProgram = computeProgram;
        }
 private BillboardRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
     this.Width = 1.0f; this.Height = 0.125f;
     this.Percentage = new vec2(0.2f, 0.05f);
     this.PixelSize = new ivec2(100, 10);
 }
 private UniformArrayRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, params GLState[] switches)
     : base(model, shaderCodes, attributeMap, switches)
 {
     var groundRenderer = GroundRenderer.Create(new GroundModel(20));
     groundRenderer.Scale = new vec3(10, 10, 10);
     this.groundRenderer = groundRenderer;
 }
Exemple #31
0
 static AnalyzedBillboardRenderer()
 {
     staticShaderCodes    = new ShaderCode[2];
     staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"08AnalyzedBillboard\AnalyzedBillboard.vert"), ShaderType.VertexShader);
     staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"08AnalyzedBillboard\AnalyzedBillboard.frag"), ShaderType.FragmentShader);
     map = new PropertyNameMap();
     map.Add("position", "position");
 }
 static AnalyzedPointSpriteRenderer()
 {
     staticShaderCodes = new ShaderCode[2];
     staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"08AnalyzedPointSprite\AnalyzedPointSprite.vert"), ShaderType.VertexShader);
     staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"08AnalyzedPointSprite\AnalyzedPointSprite.frag"), ShaderType.FragmentShader);
     map = new PropertyNameMap();
     map.Add("position", "position");
 }
 static SimpleComputeRenderer()
 {
     staticShaderCodes    = new ShaderCode[2];
     staticShaderCodes[0] = new ShaderCode(File.ReadAllText(@"04SimpleCompute\compute.vert"), ShaderType.VertexShader);
     staticShaderCodes[1] = new ShaderCode(File.ReadAllText(@"04SimpleCompute\compute.frag"), ShaderType.FragmentShader);
     map = new PropertyNameMap();
     map.Add(SimpleCompute.strPosition, "position");
 }
        protected override void DoInitialize()
        {
            var shaderCode = new ShaderCode(File.ReadAllText(
            @"shaders\ImageProcessingRenderer\ImageProcessing.comp"), ShaderType.ComputeShader);
            ShaderProgram computeProgram = shaderCode.CreateProgram();

            this.computeProgram = computeProgram;
        }
Exemple #35
0
        public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var args = string.Empty;

            switch (shaderCode.Language)
            {
            case LanguageNames.Hlsl:
                args += $" --function {arguments.GetString("EntryPoint")}";
                args += $" --profile {arguments.GetString("TargetProfile")}";
                args += $" -s hlsl --api {arguments.GetString("Api")}";
                break;

            case LanguageNames.Dxbc:
                args += " -s dxbc --api dx11";
                break;

            case LanguageNames.Dxil:
                args += " -s dxbc --api dx12";
                break;

            default:
                throw new InvalidOperationException();
            }

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                var outputPrefix = $"{Path.ChangeExtension(tempFile.FilePath, null)}out";

                ProcessHelper.Run(
                    CommonParameters.GetBinaryPath("intelshaderanalyzer", arguments, "IntelShaderAnalyzer.exe"),
                    $"{args} \"{tempFile.FilePath}\" --isa \"{outputPrefix}\"",
                    out var stdOutput,
                    out _);

                var hasCompilationErrors = !string.IsNullOrWhiteSpace(stdOutput);

                var outputFileNamePrefix = Path.GetFileNameWithoutExtension(outputPrefix);

                var outputs = new List <ShaderCompilerOutput>();
                foreach (var file in Directory.GetFiles(Path.GetDirectoryName(outputPrefix), outputFileNamePrefix + "*.asm"))
                {
                    outputs.Add(new ShaderCompilerOutput(
                                    Path.GetFileNameWithoutExtension(file).Substring(outputFileNamePrefix.Length),
                                    null,
                                    File.ReadAllText(file)));

                    File.Delete(file);
                }

                outputs.Add(new ShaderCompilerOutput("Errors", null, hasCompilationErrors ? stdOutput : "<No compilation errors>"));

                return(new ShaderCompilerResult(
                           !hasCompilationErrors,
                           null,
                           hasCompilationErrors ? (int?)outputs.Count : null,
                           outputs.ToArray()));
            }
        }
Exemple #36
0
        public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                var outputPath = $"{tempFile.FilePath}.out";

                var compressionLevelArgs = string.Empty;
                switch (arguments.GetString("CompressionLevel"))
                {
                case "0":
                    compressionLevelArgs = "-a0 -d14 -fb32";
                    break;

                case "1":
                    compressionLevelArgs = "-a0 -d16 -fb32";
                    break;

                case "2":
                    compressionLevelArgs = "-a0 -d18 -fb32";
                    break;

                case "3":
                    compressionLevelArgs = "-a0 -d20 -fb32";
                    break;

                case "4":
                    compressionLevelArgs = "-a0 -d22 -fb32";
                    break;

                case "5":
                    compressionLevelArgs = "-a1 -d24 -fb32";
                    break;

                case "6":
                    compressionLevelArgs = "-a1 -d25 -fb32";
                    break;
                }

                ProcessHelper.Run(
                    CommonParameters.GetBinaryPath("lzma", arguments, "lzma.exe"),
                    $"e \"{tempFile.FilePath}\" \"{outputPath}\" {compressionLevelArgs}",
                    out var stdOutput,
                    out var _);

                var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath);

                FileHelper.DeleteIfExists(outputPath);

                return(new ShaderCompilerResult(
                           true,
                           new ShaderCode(outputLanguage, binaryOutput),
                           null,
                           new ShaderCompilerOutput("Output", null, stdOutput)));
            }
        }
 private HemisphereLightingRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable,
     params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.LightPosition = new vec3(0, 2, 0);
     this.SkyColor = new vec3(1, 0, 0);
     this.GroundColor = new vec3(0, 1, 0);
 }
 public static SimpleComputeRenderer Create()
 {
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\SimpleComputeRenderer\compute.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\SimpleComputeRenderer\compute.frag"), ShaderType.FragmentShader);
     var map = new AttributeMap();
     map.Add("position", SimpleCompute.strPosition);
     return new SimpleComputeRenderer(new SimpleCompute(), shaderCodes, map);
 }
Exemple #39
0
        private void Form02OrderIndependentTransparency_Load(object sender, EventArgs e)
        {
            {
                var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                camera.Position = new vec3(0, 0, 5);
                camera.Target   = new vec3(0, 0, 0);
                camera.UpVector = new vec3(0, 1, 0);
                var rotator = new SatelliteRotator(camera);
                this.camera  = camera;
                this.rotator = rotator;
            }
            {
                var shaderCodes = new ShaderCode[2];
                shaderCodes[0] = new ShaderCode(File.ReadAllText(@"12Billboard\Cube.vert"), ShaderType.VertexShader);
                shaderCodes[1] = new ShaderCode(File.ReadAllText(@"12Billboard\Cube.frag"), ShaderType.FragmentShader);
                var map = new PropertyNameMap();
                map.Add("in_Position", "position");
                map.Add("in_Color", "color");
                var cubeRenderer = new PickableRenderer(new Cube(), shaderCodes, map, "position");
                cubeRenderer.Initialize();
                this.cubeRenderer = cubeRenderer;
            }
            {
                var shaderCodes = new ShaderCode[2];
                shaderCodes[0] = new ShaderCode(File.ReadAllText(@"12Billboard\billboard.vert"), ShaderType.VertexShader);
                shaderCodes[1] = new ShaderCode(File.ReadAllText(@"12Billboard\billboard.frag"), ShaderType.FragmentShader);
                var map = new PropertyNameMap();
                map.Add("squareVertices", "position");
                var billboardRenderer = new Renderer(new BillboardModel(), shaderCodes, map);
                billboardRenderer.Initialize();
                var texture = new sampler2D();
                var bitmap  = new Bitmap(@"12Billboard\ExampleBillboard.png");
                texture.Initialize(bitmap);
                bitmap.Dispose();
                billboardRenderer.SetUniform("myTextureSampler", new samplerValue(BindTextureTarget.Texture2D, texture.Id, OpenGL.GL_TEXTURE0));

                this.billboardRenderer = billboardRenderer;
            }
            {
                var UIRoot = new GLControl(this.glCanvas1.Size, -100, 100);
                UIRoot.Initialize();
                this.uiRoot = UIRoot;

                var glAxis = new GLAxis(AnchorStyles.Right | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(70, 70), -100, 100);
                glAxis.Initialize();
                this.glAxis = glAxis;

                UIRoot.Controls.Add(glAxis);
            }
            {
                var frmPropertyGrid = new FormProperyGrid();
                frmPropertyGrid.DisplayObject(this.glAxis);
                frmPropertyGrid.Show();
                this.formPropertyGrid = frmPropertyGrid;
            }
        }
Exemple #40
0
        private static bool RunTint(string exePath, ShaderCode code, string stage, string entryPoint, string outputLanguage,
                                    out byte[] output, out string error)
        {
            var args = new List <string>();

            switch (outputLanguage)
            {
            case LanguageNames.SpirV:
                args.Add("--format spirv");
                break;

            case LanguageNames.SpirvAssembly:
                args.Add("--format spvasm");
                break;

            case LanguageNames.Wgsl:
                args.Add("--format wgsl");
                break;

            case LanguageNames.Metal:
                args.Add("--format msl");
                break;

            case LanguageNames.Hlsl:
                args.Add("--format hlsl");
                break;
            }

            if (stage != AllShaderStages)
            {
                args.Add($"-ep {stage} {entryPoint}");
            }

            using (var inputFile = TempFile.FromShaderCode(code))
            {
                var outputFile = $"{inputFile.FilePath}.o";

                args.Add($"-o {outputFile}");
                args.Add(inputFile);

                ProcessHelper.Run(
                    exePath,
                    String.Join(" ", args),
                    out var stdOutput,
                    out var stdError);

                output = FileHelper.ReadAllBytesIfExists(outputFile);
                FileHelper.DeleteIfExists(outputFile);
                error = stdError;
                if (output == null && error == "")
                {
                    error = (stdOutput != "") ? stdOutput : "<no output>";
                }
                return(error == "");
            }
        }
Exemple #41
0
        public void DAGUsageCases2()
        {
            // We first initialize our shader.
            ShaderCode code = new ShaderCode(BindingStage.VertexShader);
            {
                // We write a simple Tranform code:
                code.InputOperation.AddInput(PinComponent.Position, PinFormat.Floatx3);
                Pin positon = code.InputOperation.PinAsOutput(PinComponent.Position);

                // We first need to expand our position to float4 (adding 1 at the end).
                ExpandOperation expand = new ExpandOperation(PinFormat.Floatx4, ExpandType.AddOnesAtW);
                expand.BindInputs(positon);
                Pin expPosition = expand.Outputs[0];

                // We now create constant transform matrix.
                ConstantOperation mvpConstant = code.CreateConstant("MVP", PinFormat.Float4x4);
                Pin MVP = mvpConstant.Outputs[0];

                // We multiply matrix and pin.
                MultiplyOperation mul = new MultiplyOperation();
                mul.BindInputs(MVP, expPosition);
                Pin transPosition = mul.Outputs[0];

                // We just bind transformed position to output.
                code.OutputOperation.AddComponentAndLink(PinComponent.Position, transPosition);
            }

            // We create constant buffer manually.
            ConstantBufferLayoutBuilder builder = new ConstantBufferLayoutBuilder();

            builder.AppendElement("MVP", PinFormat.Float4x4, Pin.NotArray);
            ConstantBufferLayout layout = builder.CreateLayout();

            // We now fill the data.
            FixedShaderParameters parameters = code.FixedParameters;

            parameters.AppendLayout(layout);
            if (!parameters.IsDefined)
            {
                throw new Exception();
            }

            GraphicsDevice device = InitializeDevice();

            // We have all parameters defined, compile the shader.
            VShader shader = code.Compile(device, parameters) as VShader;

            // Shader expects data in constant buffers.
            TypelessBuffer     buffer         = new TypelessBuffer(Usage.Default, BufferUsage.ConstantBuffer, CPUAccess.Write, GraphicsLocality.DeviceOrSystemMemory, 4 * 4 * 4);
            ConstantBufferView constantBuffer = buffer.CreateConstantBuffer(layout);

            // We fill the buffer.
            constantBuffer.Map(MapOptions.Write);
            constantBuffer.SetConstant("MVP", Math.Matrix.Matrix4x4f.Identity);
            constantBuffer.UnMap();
        }
Exemple #42
0
 public static GroundRenderer Create(GroundModel model)
 {
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Ground.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Ground.frag"), ShaderType.FragmentShader);
     var map = new AttributeMap();
     map.Add("in_Position", GroundModel.strPosition);
     var renderer = new GroundRenderer(model, shaderCodes, map);
     return renderer;
 }
Exemple #43
0
        public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments)
        {
            var args = $"-entry {arguments.GetString("EntryPoint")}";

            args += $" -profile {arguments.GetString("Profile")}";

            var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName);

            switch (outputLanguage)
            {
            case LanguageNames.Glsl:
                args += " -target glsl";
                break;

            case LanguageNames.Hlsl:
                args += " -target hlsl";
                break;

            case LanguageNames.Cuda:
                args += " -target cuda";
                break;

            case LanguageNames.Cpp:
                args += " -target cpp";
                break;

            case LanguageNames.Ptx:
                args += " -target ptx";
                break;
            }

            using (var tempFile = TempFile.FromShaderCode(shaderCode))
            {
                var outputPath = $"{tempFile.FilePath}.out";

                ProcessHelper.Run(
                    CommonParameters.GetBinaryPath("slang", arguments, "slangc.exe"),
                    $"\"{tempFile.FilePath}\" -o \"{outputPath}\" {args}",
                    out var _,
                    out var stdError);

                var hasCompilationErrors = !string.IsNullOrWhiteSpace(stdError);

                var textOutput = FileHelper.ReadAllTextIfExists(outputPath);

                FileHelper.DeleteIfExists(outputPath);

                return(new ShaderCompilerResult(
                           !hasCompilationErrors,
                           new ShaderCode(outputLanguage, textOutput),
                           hasCompilationErrors ? (int?)1 : null,
                           new ShaderCompilerOutput("Output", outputLanguage, textOutput),
                           new ShaderCompilerOutput("Errors", null, hasCompilationErrors ? stdError : "<No compilation errors>")));
            }
        }
        private void Form_Load(object sender, EventArgs e)
        {
            {
                var camera = new Camera(
                    new vec3(0, 0, 5), new vec3(0, 0, 0), new vec3(0, 1, 0),
                    CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                this.camera = camera;
                var cameraManipulater = new SatelliteManipulater();
                cameraManipulater.Bind(camera, this.glCanvas1);
                this.cameraManipulater = cameraManipulater;
                var arcballManipulater = new ArcBallManipulater();
                arcballManipulater.Bind(camera, this.glCanvas1);
                this.arcballManipulater = arcballManipulater;
            }
            {
                const int      gridsPer2Unit = 20;
                const int      scale         = 2;
                GroundRenderer ground        = GroundRenderer.Create(new GroundModel(gridsPer2Unit * scale));
                ground.Initialize();
                ground.Scale = scale;
                this.ground  = ground;
            }
            {
                var shaderCodes = new ShaderCode[2];
                shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\Teapot.vert"), ShaderType.VertexShader);
                shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\Teapot.frag"), ShaderType.FragmentShader);
                var map = new PropertyNameMap();
                map.Add("in_Position", "position");
                map.Add("in_Color", "color");
                var teapotRenderer = new Renderer(new Teapot(), shaderCodes, map);
                teapotRenderer.Initialize();
                this.teapotRenderer = teapotRenderer;
            }
            {
                var UIRoot = new UIRoot();
                UIRoot.Initialize();
                this.uiRoot = UIRoot;

                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(128, 128), -100, 100);
                uiAxis.Initialize();
                this.uiAxis = uiAxis;

                UIRoot.Children.Add(uiAxis);
            }
            {
                var frmPropertyGrid = new FormProperyGrid(this.teapotRenderer);
                frmPropertyGrid.Show();
            }
            {
                var frmPropertyGrid = new FormProperyGrid(this.glCanvas1);
                frmPropertyGrid.Show();
            }
        }
 private DirectonalLightRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable,
     params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.AmbientLightColor = new vec3(0.2f);
     this.DirectionalLightDirection = new vec3(1);
     this.DirectionalLightColor = new vec3(1);
     //this.HalfVector = new vec3(1);
     this.Shininess = 10.0f;
     this.Strength = 1.0f;
 }
        public static ZeroAttributeRenderer Create()
        {
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\ZeroAttributeRenderer\ZeroAttribute.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\ZeroAttributeRenderer\ZeroAttribute.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();// no items in this map.
            var model = new ZeroAttributeModel(DrawMode.TriangleStrip, 0, 4);
            var renderer = new ZeroAttributeRenderer(model, shaderCodes, map, new PointSpriteState());
            renderer.ModelSize = new vec3(2.05f, 2.05f, 0.01f);

            return renderer;
        }
 private void InitBackfaceRenderer()
 {
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(File.ReadAllText(@"10RaycastVolumeRender\backface.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(File.ReadAllText(@"10RaycastVolumeRender\backface.frag"), ShaderType.FragmentShader);
     var map = new PropertyNameMap();
     map.Add(RaycastModel.strPosition, RaycastModel.strPosition);
     map.Add(RaycastModel.strBoundingBox, RaycastModel.strBoundingBox);
     this.backfaceRenderer = new Renderer(model, shaderCodes, map);
     this.backfaceRenderer.Initialize();
     this.backfaceRenderer.SwitchList.Add(new CullFaceSwitch(CullFaceMode.Front, true));
 }
 // you can replace PointCloudModel with IBufferable in the method's parameter.
 public static RandomPointsRenderer Create(RandomPointsModel model)
 {
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\RandomPoints.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\RandomPoints.frag"), ShaderType.FragmentShader);
     var map = new CSharpGL.AttributeMap();
     map.Add("in_Position", RandomPointsModel.position);
     var renderer = new RandomPointsRenderer(model, shaderCodes, map);
     renderer.ModelSize = model.Lengths;
     //renderer.stateList.Add(new PointSizeState(10));
     return renderer;
 }
Exemple #49
0
 internal static LightRenderer Create(Teapot model, vec3 lengths, string positionNameInIBufferable)
 {
     var shaderCodes = new ShaderCode[2];
     shaderCodes[0] = new ShaderCode(System.IO.File.ReadAllText(@"shaders\LightRenderer\Light.vert"), ShaderType.VertexShader);
     shaderCodes[1] = new ShaderCode(System.IO.File.ReadAllText(@"shaders\LightRenderer\Light.frag"), ShaderType.FragmentShader);
     var map = new AttributeMap();
     map.Add("in_Position", Teapot.strPosition);
     map.Add("in_Normal", Teapot.strNormal);
     //map.Add("in_Color", Teapot.strColor);
     var renderer = new LightRenderer(model, shaderCodes, map, positionNameInIBufferable);
     renderer.Lengths = lengths;
     return renderer;
 }
        public static SimplexNoiseRenderer Create()
        {
            var model = new Sphere(1, 180, 360);
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\SimplexNoise.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\SimplexNoise.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("in_Position", Sphere.strPosition);
            var renderer = new SimplexNoiseRenderer(model, shaderCodes, map, Sphere.strPosition);
            renderer.ModelSize = model.Lengths;

            return renderer;
        }
        public static ShaderToyRenderer Create()
        {
            var model = new Cube();
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\ShaderToy.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\ShaderToy.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("in_Position", Cube.strPosition);
            var renderer = new ShaderToyRenderer(model, shaderCodes, map);
            renderer.ModelSize = model.Lengths;

            return renderer;
        }
        public static KleinBottleRenderer Create(KleinBottleModel model)
        {
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\KleinBottleRenderer\KleinBottle.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\KleinBottleRenderer\KleinBottle.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("in_Position", KleinBottleModel.strPosition);
            map.Add("in_TexCoord", KleinBottleModel.strTexCoord);
            var renderer = new KleinBottleRenderer(model, shaderCodes, map, KleinBottleModel.strPosition);
            renderer.ModelSize = model.Lengths;

            return renderer;
        }
        public static PointSpriteRenderer Create(int particleCount)
        {
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\PointSprite.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\PointSprite.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("position", PointSpriteModel.strposition);
            var model = new PointSpriteModel(particleCount);
            var renderer = new PointSpriteRenderer(model, shaderCodes, map, new PointSpriteState());
            renderer.ModelSize = model.Lengths;

            return renderer;
        }
        public static GreyFilterRenderer Create()
        {
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\GreyFilterRenderer\GreyFilter.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\GreyFilterRenderer\GreyFilter.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("a_vertex", GreyFilterModel.strPosition);
            map.Add("a_texCoord", GreyFilterModel.strTexCoord);
            var model = new GreyFilterModel();
            var renderer = new GreyFilterRenderer(model, shaderCodes, map, new PointSpriteState());
            renderer.ModelSize = model.Lengths;

            return renderer;
        }
        private Renderer InitRaycastRenderer()
        {
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\RaycastVolumeRenderer\raycasting.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\RaycastVolumeRenderer\raycasting.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("position", RaycastModel.strposition);
            map.Add("boundingBox", RaycastModel.strcolor);
            var raycastRenderer = new Renderer(model, shaderCodes, map);
            raycastRenderer.Initialize();
            raycastRenderer.StateList.Add(new CullFaceState(CullFaceMode.Back, true));

            return raycastRenderer;
        }
        public static HemisphereLightingRenderer Create()
        {
            var model = new Teapot();
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\HemisphereLighting\HemisphereLighting.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\HemisphereLighting\HemisphereLighting.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("inPosition", Teapot.strPosition);
            map.Add("inNormal", Teapot.strNormal);

            var renderer = new HemisphereLightingRenderer(model, shaderCodes, map, Teapot.strPosition);
            renderer.ModelSize = model.Size;
            return renderer;
        }
        public static UniformArrayRenderer Create()
        {
            var model = new Teapot();
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\UniformArrayRenderer\UniformArray.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\UniformArrayRenderer\UniformArray.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();
            map.Add("vPos", Teapot.strPosition);
            map.Add("vColor", Teapot.strColor);
            var renderer = new UniformArrayRenderer(model, shaderCodes, map);
            renderer.ModelSize = model.Size;

            return renderer;
        }
        public static BufferBlockRenderer Create()
        {
            //var model = new Teapot();
            //var model = new ZeroAttributeModel(DrawMode.Triangles, 0, vertexCount);
            var model = new BufferBlockModel();
            var shaderCodes = new ShaderCode[2];
            shaderCodes[0] = new ShaderCode(File.ReadAllText(@"shaders\BufferBlockRenderer\BufferBlock.vert"), ShaderType.VertexShader);
            shaderCodes[1] = new ShaderCode(File.ReadAllText(@"shaders\BufferBlockRenderer\BufferBlock.frag"), ShaderType.FragmentShader);
            var map = new AttributeMap();// no vertex attribute.
            var renderer = new BufferBlockRenderer(model, shaderCodes, map);
            renderer.ModelSize = new vec3(2, 2, 2);// model.Lengths;

            return renderer;
        }
        public static InnerImageProcessingRenderer Create(string textureFilename = @"Textures\edgeDetection.bmp")
        {
            var model = new ImageProcessingModel();
            ShaderCode[] simpleShader = new ShaderCode[2];
            simpleShader[0] = new ShaderCode(File.ReadAllText(@"shaders\ImageProcessingRenderer\ImageProcessing.vert"), ShaderType.VertexShader);
            simpleShader[1] = new ShaderCode(File.ReadAllText(@"shaders\ImageProcessingRenderer\ImageProcessing.frag"), ShaderType.FragmentShader);
            var propertyNameMap = new AttributeMap();
            propertyNameMap.Add("vert", "position");
            propertyNameMap.Add("uv", "uv");
            var renderer = new InnerImageProcessingRenderer(
                model, simpleShader, propertyNameMap, ImageProcessingModel.strposition);
            renderer.textureFilename = textureFilename;

            return renderer;
        }
 private PointLightRenderer(IBufferable model, ShaderCode[] shaderCodes,
     AttributeMap attributeMap, string positionNameInIBufferable,
     params GLState[] switches)
     : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches)
 {
     this.Ambient = new vec3(0.2f);
     this.LightPosition = new vec3(400);
     this.LightColor = new vec3(1);
     //this.HalfVector = new vec3(1);
     this.Shininess = 10.0f;
     this.Strength = 1.0f;
     this.ConstantAttenuation = 0.2f;
     this.LinearAttenuation = 0.0f;
     this.QuadraticAttenuation = 0.0f;
 }