예제 #1
0
 protected override void OnAttach(IRenderTechnique technique)
 {
     ModelConstBuffer = technique.ConstantBufferPool.Register(bufferDesc);
 }
예제 #2
0
 /// <summary>
 /// During attatching render core. Create all local resources. Use Collect(resource) to let object be released automatically during Detach().
 /// </summary>
 /// <param name="technique"></param>
 /// <returns></returns>
 protected abstract bool OnAttach(IRenderTechnique technique);
예제 #3
0
 /// <summary>
 /// During attatching render core. Create all local resources. Use Collect(resource) to let object be released automatically during Detach().
 /// </summary>
 /// <param name="technique"></param>
 /// <returns></returns>
 protected override bool OnAttach(IRenderTechnique technique)
 {
     ModelConstBuffer = technique.ConstantBufferPool.Register(GetModelConstantBufferDescription());
     return(true);
 }
 protected override bool OnAttach(IRenderTechnique technique)
 {
     BoneSkinSB = Collect(new StructuredBufferProxy(Matrix.SizeInBytes, false));
     return(true);
 }
 /// <summary>
 /// Called when [attach].
 /// </summary>
 /// <param name="technique">The technique.</param>
 /// <returns></returns>
 protected override bool OnAttach(IRenderTechnique technique)
 {
     outlineShaderPass = technique[OutlinePassName];
     return(base.OnAttach(technique));
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextureSharedPhongMaterialVariables"/> class. This construct will be using the PassName pass into constructor only.
 /// </summary>
 /// <param name="passName">Name of the pass.</param>
 /// <param name="manager">The manager.</param>
 /// <param name="technique"></param>
 /// <param name="material">The material.</param>
 public TextureSharedPhongMaterialVariables(string passName, IEffectsManager manager, IRenderTechnique technique, PhongMaterialCore material)
     : this(manager, technique, material)
 {
     DefaultShaderPassName = passName;
     fixedPassName         = true;
 }
예제 #7
0
 protected override bool OnAttach(IRenderTechnique technique)
 {
     depthPrepassCore = new DepthPrepassCore();
     depthPrepassCore.Attach(technique);
     return(true);
 }
예제 #8
0
 public override MaterialVariable CreateMaterialVariables(IEffectsManager manager, IRenderTechnique technique)
 {
     return(new TextureSharedPhongMaterialVariables(manager, technique, this));
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhongMaterialVariables"/> class. This construct will be using the PassName pass into constructor only.
 /// </summary>
 /// <param name="passName">Name of the pass.</param>
 /// <param name="manager">The manager.</param>
 /// <param name="technique"></param>
 /// <param name="material">The material.</param>
 public PhongMaterialVariables(string passName, IEffectsManager manager, IRenderTechnique technique, PhongMaterialCore material)
     : this(manager, technique, material, passName)
 {
 }
예제 #10
0
 public PassOnlyMaterialVariable(string passName, IRenderTechnique technique)
     : base(technique.EffectsManager, technique, DefaultMeshConstantBufferDesc)
 {
     this.passName = passName;
     MaterialPass  = technique[passName];
 }
예제 #11
0
 protected override bool OnAttach(IRenderTechnique technique)
 {
     mtWeightsB = new StructuredBufferProxy(sizeof(float), false);
     return(true);
 }
예제 #12
0
 public override MaterialVariable CreateMaterialVariables(IEffectsManager manager, IRenderTechnique technique)
 {
     return(new PassOnlyMaterialVariable(DefaultPassNames.NormalVector, technique));
 }
        public GenericMaterialVariable(IEffectsManager manager, IRenderTechnique technique,
                                       GenericMaterialCore materialCore, ConstantBufferDescription constantBufferDescription,
                                       string materialShaderPassName = DefaultPassNames.Default,
                                       string shadowShaderPassName   = DefaultPassNames.ShadowPass,
                                       string wireframePassName      = DefaultPassNames.Wireframe)
            : base(manager, technique, constantBufferDescription, materialCore)
        {
            core            = materialCore;
            materialPass    = technique[materialShaderPassName];
            shadowPass      = technique[shadowShaderPassName];
            wireframePass   = technique[wireframePassName];
            shaderResources = new KeyValuePair <int, ShaderResourceViewProxy> [materialPass.PixelShader.ShaderResourceViewMapping.Count];

            for (int i = 0; i < materialPass.PixelShader.ShaderResourceViewMapping.Count; ++i)
            {
                var mapping = materialPass.PixelShader.ShaderResourceViewMapping.Mappings[i];
                resourceIdxDict.Add(mapping.Value.Description.Name, i);
                shaderResources[i] = new KeyValuePair <int, ShaderResourceViewProxy>(mapping.Key, null);
            }

            samplerResources = new KeyValuePair <int, SamplerStateProxy> [materialPass.PixelShader.SamplerMapping.Count];

            for (int i = 0; i < materialPass.PixelShader.SamplerMapping.Count; ++i)
            {
                var mapping = materialPass.PixelShader.SamplerMapping.Mappings[i];
                samplerIdxDict.Add(mapping.Value.Name, i);
                samplerResources[i] = new KeyValuePair <int, SamplerStateProxy>(mapping.Key, null);
            }

            foreach (var texture in materialCore.TextureDict)
            {
                SetTexture(texture.Key, texture.Value);
            }

            foreach (var sampler in materialCore.SamplerDict)
            {
                SetSampler(sampler.Key, sampler.Value);
            }

            foreach (var prop in materialCore.FloatDict)
            {
                WriteValue(prop.Key, prop.Value);
            }
            foreach (var prop in materialCore.Vector2Dict)
            {
                WriteValue(prop.Key, prop.Value);
            }
            foreach (var prop in materialCore.Vector3Dict)
            {
                WriteValue(prop.Key, prop.Value);
            }
            foreach (var prop in materialCore.Vector4Dict)
            {
                WriteValue(prop.Key, prop.Value);
            }
            foreach (var prop in materialCore.MatrixDict)
            {
                WriteValue(prop.Key, prop.Value);
            }
            materialCore.UpdatingResource += MaterialCore_UpdatingResource;
        }
예제 #14
0
        public Graphics(UserControl control, SceneTime time, ShadingTechnique technique)
        {
            Assert.NotNull(control);
            Assert.NotNull(time);

            IsDisposed = false;
            CurrentShadingTechnique = technique;

            if (GL.GetCurrent(false) != null || GetCurrent(false) != null)
            {
                var error = "Only one NetGL view per thread is now supported. Try launching 3D view in different thread.";
                Log.Error(error);
                throw new InvalidOperationException(error);
            }

            _control = control;
            _time    = time;

            try {
                _glContext = new GL(_control.Handle);
            }
            catch {
                Dispose();
                throw;
            }

            _currentContext.Value = this;

            _glContext.Enable(EnableCap.DepthTest);
            _glContext.Enable(EnableCap.Texture2D);
            _glContext.Enable(EnableCap.CullFace);
            _glContext.Enable(EnableCap.ProgramPointSize);
            _glContext.Enable(EnableCap.PointSprite);
            _glContext.CullFace(MaterialFace.Back);
            _glContext.FrontFace(FrontFaceDirection.CounterClockwise);
            _glContext.BlendEquation(BlendEquations.FuncAdd);
            _glContext.BlendFunc(BlendMode.SrcAlpha, BlendMode.OneMinusSrcAlpha);

            _glContext.SwapInterval(_swapInterval);

            _globalUniforms   = new GlobalUniformsBufferObject();
            _standartUniforms = new StandardUniformsBufferObject();
            _defaultMaterial  = new Material(MaterialType.DiffuseColor);
            _blankTexture     = new Texture2();
            _blankTexture.SetImage(new byte[4] {
                255, 0, 255, 255
            }, new Size(1, 1), Core.PixelFormat.Rgba, Core.PixelInternalFormat.Rgba8);
            _quadShader = new QuadShader();

            _displayQuadVao = CreateDisplayQuadVao();

            switch (CurrentShadingTechnique)
            {
            case ShadingTechnique.Forward:
                _renderTechnique = new ForwardRender();
                break;

            case ShadingTechnique.Deferred:
                _renderTechnique = new DeferredRender();
                break;

            default:
                throw new NotSupportedException(CurrentShadingTechnique.ToString());
            }

            ScreenSize = _control.ClientSize;
        }
예제 #15
0
 public bool Attach(IRenderTechnique technique)
 {
     MaterialPass = technique[passName];
     return(!MaterialPass.IsNULL);
 }
 /// <summary>
 /// Called when [attach].
 /// </summary>
 /// <param name="technique">The technique.</param>
 /// <returns></returns>
 protected override bool OnAttach(IRenderTechnique technique)
 {
     // globalTransformCB = technique.EffectsManager.ConstantBufferPool.Register(DefaultBufferNames.GlobalTransformCB, GlobalTransformStruct.SizeInBytes);
     CreateRasterState(rasterDescription, true);
     return(true);
 }
예제 #17
0
 public override MaterialVariable CreateMaterialVariables(IEffectsManager manager, IRenderTechnique technique)
 {
     return(new DiffuseMaterialVariables(DefaultPassNames.ViewCube, manager, technique, this));
 }
예제 #18
0
 public override MaterialVariable CreateMaterialVariables(IEffectsManager manager, IRenderTechnique technique)
 {
     return(new LineArrowMaterialVariable(manager, manager.GetTechnique(DefaultRenderTechniqueNames.LinesArrowHeadTail), this));
 }
예제 #19
0
 protected abstract void OnAttach(IRenderTechnique technique);
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LineMaterialVariable"/> class.
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <param name="technique">The technique.</param>
 /// <param name="materialCore">The material core.</param>
 /// <param name="defaultPassName">Default pass name</param>
 public LineArrowMaterialVariable(IEffectsManager manager, IRenderTechnique technique, LineArrowHeadMaterialCore materialCore,
                                  string defaultPassName = DefaultPassNames.Default)
     : base(manager, technique, materialCore, defaultPassName)
 {
     this.material = materialCore;
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DiffuseMaterialVariables"/> class. This construct will be using the PassName pass into constructor only.
 /// </summary>
 /// <param name="passName">Name of the pass.</param>
 /// <param name="manager">The manager.</param>
 /// <param name="technique"></param>
 /// <param name="material">The material.</param>
 public DiffuseMaterialVariables(string passName, IEffectsManager manager, IRenderTechnique technique,
                                 DiffuseMaterialCore material)
     : this(manager, technique, material)
 {
     MaterialPass = technique[passName];
 }
#pragma warning restore CS0067
        public bool Attach(IRenderTechnique technique)
        {
            return(false);
        }
예제 #23
0
 public override MaterialVariable CreateMaterialVariables(IEffectsManager manager, IRenderTechnique technique)
 {
     return(new PointMaterialVariable(manager, technique, this));
 }
예제 #24
0
 /// <summary>
 /// Creates the material variables.
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <param name="technique">The technique.</param>
 /// <returns></returns>
 public abstract MaterialVariable CreateMaterialVariables(IEffectsManager manager, IRenderTechnique technique);
예제 #25
0
 protected override bool OnAttach(IRenderTechnique technique)
 {
     return(true);
 }
예제 #26
0
 protected override bool OnAttach(IRenderTechnique technique)
 {
     MTWeightsB = Collect(new StructuredBufferProxy(sizeof(float), false));
     cbMorphTarget.Attach(technique);
     return(true);
 }
예제 #27
0
 public override MaterialVariable CreateMaterialVariables(IEffectsManager manager, IRenderTechnique technique)
 {
     return(new VolumeMaterialVariable <T>(manager, technique, this, DefaultPassName)
     {
         OnCreateTexture = (material, effectsManager) => { return OnCreateTexture(effectsManager); }
     });
 }
예제 #28
0
 protected override bool OnAttach(IRenderTechnique technique)
 {
     return(base.OnAttach(technique));
 }
 public override MaterialVariable CreateMaterialVariables(IEffectsManager manager, IRenderTechnique technique)
 {
     return(new GenericMeshMaterialVariable(manager, technique, this, cbDescription,
                                            MaterialPassName, ShadowPassName, ""));
 }
예제 #30
0
            public override void Render(RenderContext context, DeviceContextProxy deviceContext)
            {
                EnsureTextureResources((int)context.ActualWidth, (int)context.ActualHeight, deviceContext);
                int texScale = (int)offScreenTextureSize;

                using (var ds = context.GetOffScreenDS(offScreenTextureSize, DEPTHFORMAT))
                {
                    using (var rt0 = context.GetOffScreenRT(offScreenTextureSize, RENDERTARGETFORMAT))
                    {
                        using (var rt1 = context.GetOffScreenRT(offScreenTextureSize, SSAOTARGETFORMAT))
                        {
                            int w = (int)(context.ActualWidth / texScale);// Make sure to set correct viewport width/height by quality
                            int h = (int)(context.ActualHeight / texScale);
                            deviceContext.SetRenderTarget(ds, rt0, w, h, true, new Color4(0, 0, 0, 1), true, DepthStencilClearFlags.Depth);
                            IRenderTechnique currTechnique = null;
                            ShaderPass       ssaoPass1     = ShaderPass.NullPass;
                            var frustum = context.BoundingFrustum;
                            for (int i = 0; i < context.RenderHost.PerFrameOpaqueNodesInFrustum.Count; ++i)
                            {
                                var node = context.RenderHost.PerFrameOpaqueNodesInFrustum[i];
                                if (currTechnique != node.EffectTechnique)
                                {
                                    currTechnique = node.EffectTechnique;
                                    ssaoPass1     = currTechnique[DefaultPassNames.MeshSSAOPass];
                                }
                                if (ssaoPass1.IsNULL)
                                {
                                    continue;
                                }
                                node.RenderDepth(context, deviceContext, ssaoPass1);
                            }

                            var invProjection = context.ProjectionMatrix.Inverted();
                            ssaoParam.InvProjection = invProjection;
                            ssaoParam.NoiseScale    = new Vector2(w / 4f, h / 4f);
                            ssaoParam.Radius        = radius;
                            ssaoParam.TextureScale  = texScale;
                            ssaoCB.ModelConstBuffer.UploadDataToBuffer(deviceContext, (stream) =>
                            {
                                stream.WriteRange(kernels);
                                stream.Write(ssaoParam);
                            });
                            deviceContext.SetRenderTargetOnly(rt1);
                            ssaoPass.BindShader(deviceContext);
                            ssaoPass.BindStates(deviceContext, StateType.All);
                            ssaoPass.PixelShader.BindTexture(deviceContext, ssaoTexSlot, rt0);
                            ssaoPass.PixelShader.BindTexture(deviceContext, noiseTexSlot, ssaoNoise);
                            ssaoPass.PixelShader.BindTexture(deviceContext, depthSlot, ds);
                            ssaoPass.PixelShader.BindSampler(deviceContext, surfaceSampleSlot, surfaceSampler);
                            ssaoPass.PixelShader.BindSampler(deviceContext, noiseSamplerSlot, noiseSampler);
                            deviceContext.Draw(4, 0);

                            ssaoPass.PixelShader.BindTexture(deviceContext, depthSlot, null);

                            deviceContext.SetRenderTarget(ssaoView, width, height);
                            ssaoBlur.BindShader(deviceContext);
                            ssaoBlur.BindStates(deviceContext, StateType.All);
                            ssaoBlur.PixelShader.BindTexture(deviceContext, ssaoTexSlot, rt1);
                            ssaoBlur.PixelShader.BindSampler(deviceContext, surfaceSampleSlot, blurSampler);
                            deviceContext.Draw(4, 0);
                            context.SharedResource.SSAOMap = ssaoView;

                            context.RenderHost.SetDefaultRenderTargets(false);
                            deviceContext.SetShaderResource(PixelShader.Type, ssaoTexSlot, ssaoView);
                        }
                    }
                }
            }