Beispiel #1
0
            public QuadShaderDeviceData(DX11RenderContext context)
            {
                string     basepath = "VVVV.DX11.Nodes.effects.quad.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);

                quadshader      = new DX11ShaderInstance(context, effect);
                texturevariable = quadshader.Effect.GetVariableBySemantic("INPUTTEXTURE").AsResource();
                samplervariable = quadshader.Effect.GetVariableBySemantic("SAMPLERSTATE").AsSampler();

                Quad quad = new Quad();

                quad.Size = new Vector2(1.0f);

                quadgeometry = context.Primitives.QuadNormals(quad);

                quadlayouts = new List <InputLayout>();
                for (int i = 0; i < 4; i++)
                {
                    InputLayout layout;
                    quadshader.SelectTechnique(i);

                    bool res = quadgeometry.ValidateLayout(quadshader.GetPass(0), out layout);
                    quadlayouts.Add(layout);
                }
            }
 public override void Apply(DX11ShaderInstance shaderinstance, DX11RenderSettings settings)
 {
     if (settings.ReadBuffer != null)
     {
         shaderinstance.SetByName(this.Name, settings.ReadBuffer.SRV);
     }
 }
Beispiel #3
0
        public override void SetVariable(DX11ShaderInstance shaderinstance, int slice)
        {
            if (this.pin.PluginIO.IsConnected)
            {
                if (this.pin.IsChanged)
                {
                    if (this.state != null)
                    {
                        this.state.Dispose(); this.state = null;
                    }
                }

                if (this.state == null || this.state.Disposed)
                {
                    this.state = SamplerState.FromDescription(shaderinstance.RenderContext.Device, this.pin[0]);
                }
                shaderinstance.SetByName(this.Name, this.state);
            }
            else
            {
                if (this.state != null)
                {
                    this.state.Dispose();
                    this.state = null;
                    shaderinstance.SetByName(this.Name, this.state);
                }
            }
        }
Beispiel #4
0
        public void SetEffect(DX11Effect shader)
        {
            //Create
            if (this.shader == null)
            {
                this.shader = shader;

                if (shader.IsCompiled)
                {
                    this.shaderinstance = new DX11ShaderInstance(this.context, shader.ByteCode);
                    this.UpdateTechnique();
                }
            }
            else
            {
                if (shader.IsCompiled)
                {
                    //Update shader
                    if (shader != this.shader)
                    {
                        //Dispose old effect if applicable
                        this.shader = shader;
                        if (this.shaderinstance != null)
                        {
                            this.shaderinstance.Dispose();
                        }
                        this.shaderinstance = new DX11ShaderInstance(this.context, shader.ByteCode);
                        this.UpdateTechnique();

                        this.DisposeLayouts();
                    }
                }
            }
        }
 public void Apply(DX11ShaderInstance instance, DX11RenderSettings settings, DX11ObjectRenderSettings objectsettings)
 {
     foreach (string rv in this.variables.Keys)
     {
         this.variables[rv].Apply(instance, settings, objectsettings);
     }
 }
        public override void Apply(DX11ShaderInstance shaderinstance, DX11RenderSettings settings, DX11ObjectRenderSettings obj)
        {
            if (obj.Geometry != null)
            {
                if (obj.Geometry.HasBoundingBox)
                {
                    Vector3 min = obj.Geometry.BoundingBox.Minimum;

                    Vector3 scale = obj.Geometry.BoundingBox.Maximum - obj.Geometry.BoundingBox.Minimum;
                    scale.X = scale.X != 0.0f ? scale.X : 1.0f;
                    scale.Y = scale.Y != 0.0f ? scale.Y : 1.0f;
                    scale.Z = scale.Z != 0.0f ? scale.Z : 1.0f;

                    Matrix m = Matrix.Scaling(scale);

                    m.M41 = min.X;
                    m.M42 = min.Y;
                    m.M43 = min.Z;
                    shaderinstance.SetByName(this.Name, Matrix.Invert(m));
                }
                else
                {
                    shaderinstance.SetByName(this.Name, m);
                }
            }
            else
            {
                shaderinstance.SetByName(this.Name, m);
            }
        }
 public void ApplySlice(DX11ShaderInstance instance, int slice)
 {
     foreach (IShaderPin sp in spreadedpins)
     {
         sp.SetVariable(instance, slice);
     }
 }
        public override Action <int> CreateAction(DX11ShaderInstance instance)
        {
            var sv = instance.Effect.GetVariableByName(this.Name).AsResource();

            List <EffectScalarVariable> sizeOfVar = new List <EffectScalarVariable>();

            for (int i = 0; i < instance.Effect.Description.GlobalVariableCount; i++)
            {
                var v = instance.Effect.GetVariableByIndex(i);
                if (v.GetVariableType().Description.TypeName == "uint" && v.Description.Semantic == "SIZEOF" && v.Reference(this.Name))
                {
                    sizeOfVar.Add(v.AsScalar());
                }
            }
            if (sizeOfVar.Count == 0)
            {
                return((i) =>
                {
                    var resource = this.GetResource(instance.RenderContext, i);
                    sv.SetResource(resource != null ? resource.SRV : null);
                });
            }
            else
            {
                return((i) =>
                {
                    var resource = this.GetResource(instance.RenderContext, i);
                    sv.SetResource(resource != null ? resource.SRV : null);
                    for (int j = 0; j < sizeOfVar.Count; j++)
                    {
                        sizeOfVar[j].Set(resource != null ? resource.ElementCount : 0);
                    }
                });
            }
        }
Beispiel #9
0
        public override Action <int> CreateAction(DX11ShaderInstance instance)
        {
            var sv = instance.Effect.GetVariableByName(this.Name).AsResource();

            List <EffectVectorVariable> sizeOfVar    = new List <EffectVectorVariable>();
            List <EffectVectorVariable> invSizeOfVar = new List <EffectVectorVariable>();

            for (int i = 0; i < instance.Effect.Description.GlobalVariableCount; i++)
            {
                var v = instance.Effect.GetVariableByIndex(i);
                if (v.GetVariableType().Description.TypeName == "float3" && v.Description.Semantic == "SIZEOF" && v.Reference(this.Name))
                {
                    sizeOfVar.Add(v.AsVector());
                }
                if (v.GetVariableType().Description.TypeName == "float3" && v.Description.Semantic == "INVSIZEOF" && v.Reference(this.Name))
                {
                    invSizeOfVar.Add(v.AsVector());
                }
            }
            if (sizeOfVar.Count == 0 && invSizeOfVar.Count == 0)
            {
                return((i) =>
                {
                    var res = this.GetResource(instance.RenderContext, i);
                    sv.SetResource(res != null ? res.SRV : null);
                });
            }
            else
            {
                return((i) =>
                {
                    var resource = this.GetResource(instance.RenderContext, i);
                    sv.SetResource(resource != null ? resource.SRV : null);

                    if (resource != null)
                    {
                        for (int j = 0; j < sizeOfVar.Count; j++)
                        {
                            sizeOfVar[j].Set(new Vector3(resource.Width, resource.Height, resource.Depth));
                        }
                        for (int j = 0; j < invSizeOfVar.Count; j++)
                        {
                            invSizeOfVar[j].Set(new Vector3(1.0f / resource.Width, 1.0f / resource.Height, 1.0f / resource.Depth));
                        }
                    }
                    else
                    {
                        for (int j = 0; j < sizeOfVar.Count; j++)
                        {
                            sizeOfVar[j].Set(new Vector3(1, 1, 1));
                        }
                        for (int j = 0; j < invSizeOfVar.Count; j++)
                        {
                            invSizeOfVar[j].Set(new Vector3(1, 1, 1));
                        }
                    }
                });
            }
        }
        public ImageShaderInfo(DX11ShaderInstance shader)
        {
            var effect = shader.Effect;

            this.techniqueInfo = new ImageShaderTechniqueInfo[effect.Description.TechniqueCount];

            int maxPassCount = 0;

            for (int i = 0; i < this.techniqueInfo.Length; i++)
            {
                this.techniqueInfo[i] = new ImageShaderTechniqueInfo(effect.GetTechniqueByIndex(i));
                maxPassCount          = this.techniqueInfo[i].PassCount > maxPassCount ? this.techniqueInfo[i].PassCount : maxPassCount;
            }

            //Set list of max pass count
            this.passResultVariableArray = new List <EffectResourceVariable> [maxPassCount];


            for (int i = 0; i < effect.Description.GlobalVariableCount; i++)
            {
                EffectVariable var = effect.GetVariableByIndex(i);

                if (var.GetVariableType().Description.TypeName == "Texture2D")
                {
                    EffectResourceVariable rv = var.AsResource();

                    if (rv.Description.Semantic == "INITIAL")
                    {
                        this.initialTextureVariables.Add(rv);
                    }
                    if (rv.Description.Semantic == "PREVIOUS")
                    {
                        this.previousTextureVariables.Add(rv);
                    }
                    if (rv.Description.Semantic == "DEPTHTEXTURE")
                    {
                        this.depthTextureVariables.Add(rv);
                    }

                    //If semantic starts with passresult
                    if (rv.Description.Semantic.StartsWith("PASSRESULT"))
                    {
                        string sidx = rv.Description.Semantic.Substring(10);
                        int    pridx;
                        if (int.TryParse(sidx, out pridx))
                        {
                            if (pridx < maxPassCount)
                            {
                                if (this.passResultVariableArray[pridx] == null)
                                {
                                    this.passResultVariableArray[pridx] = new List <EffectResourceVariable>();
                                }
                                this.passResultVariableArray[pridx].Add(rv);
                            }
                        }
                    }
                }
            }
        }
Beispiel #11
0
        public void ApplyGlobal(DX11ShaderInstance instance)
        {
            //this.globalsettings = settings;

            this.rendervariables.Apply(instance, this.globalsettings);

            this.shaderpins.Preprocess(instance);
        }
Beispiel #12
0
        public TextureArraySetSlice(DX11RenderContext context)
        {
            this.context = context;
            this.shader  = ShaderUtils.GetShader(context, "SetSlice");

            this.quad = context.Primitives.FullScreenQuad;
            this.quad.ValidateLayout(this.shader.GetPass(0), out this.layout);
        }
 public void Apply(DX11ShaderInstance instance, DX11RenderSettings settings)
 {
     foreach (string rv in this.variables.Keys)
     {
         IRenderVariable var = this.variables[rv];
         var.Apply(instance, settings);
     }
 }
Beispiel #14
0
 public void Dispose()
 {
     if (this.shaderInstance != null)
     {
         this.shaderInstance.Dispose();
         this.shaderInstance = null;
     }
 }
        public override void Apply(DX11ShaderInstance shaderinstance, DX11RenderSettings settings)
        {
            Vector2 v = new Vector2(settings.RenderWidth, settings.RenderHeight);

            v.X = 1.0f / v.X;
            v.Y = 1.0f / v.Y;
            shaderinstance.SetByName(this.Name, v);
        }
Beispiel #16
0
        public override void SetVariable(DX11ShaderInstance shaderinstance, int slice)
        {
            ISpread <T> f = this.pin[slice];

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = f[i];
            }
            this.UpdateShaderValue(shaderinstance);
        }
Beispiel #17
0
        public void Update(DX11RenderContext context)
        {
            if (shaderSample == null)
            {
                shaderSample = new DX11ShaderInstance(context, effectSample);
                shaderLoad   = new DX11ShaderInstance(context, effectLoad);
            }

            DX11ShaderInstance instance = this.pixelCoords[0] ? shaderLoad : shaderSample;

            if (this.mipLevel.SliceCount > 1)
            {
                instance.SelectTechnique("ConstantLevel");
            }
            else
            {
                instance.SelectTechnique("DynamicLevel");
            }

            int totalCount;

            if (this.mipLevel.SliceCount > 1)
            {
                totalCount = SpreadUtils.SpreadMax(this.coordinates, this.mipLevel);

                instance.SetByName("UvCount", this.coordinates.SliceCount);
                instance.SetByName("LevelCount", this.mipLevel.SliceCount);
            }
            else
            {
                totalCount = this.coordinates.SliceCount;
                instance.SetByName("MipLevel", this.mipLevel[0]);
            }

            this.coordinateBuffer = this.coordinateBuffer.GetOrResize(context.Device, this.coordinates.SliceCount, 8);
            this.levelBuffer      = this.levelBuffer.GetOrResize(context.Device, this.mipLevel.SliceCount, 4);

            this.writeBuffer    = this.writeBuffer.GetOrResize(context.Device, totalCount, 16);
            this.readbackBuffer = this.readbackBuffer.GetOrResize(context.Device, totalCount, 16);

            instance.SetByName("TotalCount", totalCount);
            instance.SetByName("uvBuffer", coordinateBuffer.SRV);
            if (this.mipLevel.SliceCount > 1)
            {
                instance.SetByName("uvLevelBuffer", levelBuffer.SRV);
            }


            instance.SetByName("inputTexture", this.textureInput[0][context].SRV);
            instance.SetByName("OutputBuffer", writeBuffer.UAV);

            instance.ApplyPass(0);

            context.CurrentDeviceContext.CopyResource(this.writeBuffer.Buffer, this.readbackBuffer.Buffer);
        }
 protected override void ApplyVariable(string name, DX11ShaderInstance instance)
 {
     if (this.ResetCounter)
     {
         instance.SetByName(name, this.Data.UAV, this.Counter);
     }
     else
     {
         instance.SetByName(name, this.Data.UAV);
     }
 }
Beispiel #19
0
 public override void SetVariable(DX11ShaderInstance shaderinstance, int slice)
 {
     if (this.pin.IsConnected)
     {
         shaderinstance.SetByName(this.Name, this.GetSRV(shaderinstance.RenderContext, slice));
     }
     else
     {
         shaderinstance.SetByName(this.Name, this.GetDefaultSRV(shaderinstance.RenderContext));
     }
 }
 private ShaderResourceView GetView(DX11ShaderInstance shaderinstance, int slice)
 {
     if (this.pin.IsConnected)
     {
         return(this.GetSRV(shaderinstance.RenderContext, slice));
     }
     else
     {
         return(this.GetDefaultSRV(shaderinstance.RenderContext));
     }
 }
Beispiel #21
0
 /// <summary>
 /// Try to find a custom semantic to a particular instance
 /// </summary>
 /// <param name="instance">Shader instance</param>
 /// <param name="variables">Custom variable list</param>
 /// <returns>If not mandatory, always return true, else, return true only if bound</returns>
 public bool Apply(DX11ShaderInstance instance, List <IDX11CustomRenderVariable> variables)
 {
     foreach (IDX11CustomRenderVariable variable in variables)
     {
         if (variable.TypeName == this.TypeName && variable.Semantic == this.Semantic)
         {
             this.ApplyVariable(variable.Name, instance);
             return(true);
         }
     }
     //Not bound
     return(!this.Mandatory);
 }
        public override Action <int> CreateAction(DX11ShaderInstance instance)
        {
            var sv = instance.Effect.GetVariableByName(this.Name).AsVector();

            return((i) =>
            {
                Vector4 c = new Vector4((float)colorPtr[(i * 4) % colorCnt],
                                        (float)colorPtr[(i * 4 + 1) % colorCnt],
                                        (float)colorPtr[(i * 4 + 2) % colorCnt],
                                        (float)colorPtr[(i * 4 + 3) % colorCnt]);
                sv.Set(c);
            });
        }
        public override Action <int> CreateAction(DX11ShaderInstance instance)
        {
            var sv = instance.Effect.GetVariableByName(this.Name).AsResource();

            List <EffectVectorVariable> sizeOfVar    = new List <EffectVectorVariable>();
            List <EffectVectorVariable> invSizeOfVar = new List <EffectVectorVariable>();
            List <EffectMatrixVariable> aspectVar    = new List <EffectMatrixVariable>();
            List <AspectRatioMode>      aspectMode   = new List <AspectRatioMode>();

            for (int i = 0; i < instance.Effect.Description.GlobalVariableCount; i++)
            {
                var v = instance.Effect.GetVariableByIndex(i);
                if (v.GetVariableType().Description.TypeName == "float2" && v.Description.Semantic == "SIZEOF" && v.Reference(this.Name))
                {
                    sizeOfVar.Add(v.AsVector());
                }
                if (v.GetVariableType().Description.TypeName == "float2" && v.Description.Semantic == "INVSIZEOF" && v.Reference(this.Name))
                {
                    invSizeOfVar.Add(v.AsVector());
                }
                if (v.GetVariableType().Description.TypeName == "float4x4" && v.Description.Semantic == "ASPECTOF" && v.Reference(this.Name))
                {
                    aspectVar.Add(v.AsMatrix());
                    aspectMode.Add(v.AspectMode());
                }
            }
            if (sizeOfVar.Count == 0 && invSizeOfVar.Count == 0 && aspectMode.Count == 0)
            {
                return((i) => { sv.SetResource(this.GetResource(instance.RenderContext, i).SRV); });
            }
            else
            {
                return((i) =>
                {
                    var resource = this.GetResource(instance.RenderContext, i);
                    sv.SetResource(resource.SRV);
                    for (int j = 0; j < sizeOfVar.Count; j++)
                    {
                        sizeOfVar[j].Set(new Vector2(resource.Width, resource.Height));
                    }
                    for (int j = 0; j < invSizeOfVar.Count; j++)
                    {
                        invSizeOfVar[j].Set(new Vector2(1.0f / resource.Width, 1.0f / resource.Height));
                    }
                    for (int j = 0; j < aspectVar.Count; j++)
                    {
                        aspectVar[j].SetMatrix(AspectUtils.AspectMatrix(new Vector2(resource.Width, resource.Height), aspectMode[i]));
                    }
                });
            }
        }
Beispiel #24
0
 public override void SetVariable(DX11ShaderInstance shaderinstance, int slice)
 {
     if (this.pin.IsConnected)
     {
         using (var state = SamplerState.FromDescription(shaderinstance.RenderContext.Device, this.pin[slice]))
         {
             shaderinstance.SetByName(this.Name, state);
         }
     }
     else
     {
         shaderinstance.Effect.GetVariableByName(this.Name).AsSampler().UndoSetSamplerState(0);
     }
 }
Beispiel #25
0
        protected override void UpdateShaderValue(DX11ShaderInstance shaderinstance)
        {
            DataStream ds = new DataStream(4 * this.array.Length * sizeof(float), true, true);

            for (int i = 0; i < this.array.Length; i++)
            {
                ds.Write <Vector3>(this.array[i]);
                ds.Write(0.0f);
            }

            ds.Position = 0;
            shaderinstance.Effect.GetVariableByName(this.Name).SetRawValue(ds, (int)ds.Length);
            ds.Dispose();
        }
Beispiel #26
0
        public override void SetVariable(DX11ShaderInstance shaderinstance, int slice)
        {
            if (!uvspace)
            {
                shaderinstance.SetByName(this.Name, this.pin[slice]);
            }
            else
            {
                Matrix m = pin[slice];
                //m.M42 = -m.M42;
                m = Matrix.Translation(-0.5f, -0.5f, 0.0f) * m * Matrix.Translation(0.5f, 0.5f, 0.0f);

                shaderinstance.SetByName(this.Name, m);
            }
        }
Beispiel #27
0
            public ShaderDeviceData(DX11RenderContext context)
            {
                string basepath = "VVVV.DX11.Nodes.effects.DrawFullScreen.fx";

                using (DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath))
                {
                    shaderInstance = new DX11ShaderInstance(context, effect);

                    inputTextureVariable = shaderInstance.Effect.GetVariableBySemantic("INPUTTEXTURE").AsResource();
                    colorVariable        = shaderInstance.Effect.GetVariableBySemantic("COLOR").AsVector();
                    samplerVariable      = shaderInstance.Effect.GetVariableBySemantic("TEXTURESAMPLER").AsSampler();
                    texTransformVariable = shaderInstance.Effect.GetVariableBySemantic("TEXTUREMATRIX").AsMatrix();
                    pass = shaderInstance.CurrentTechnique.GetPassByIndex(0);
                }
            }
Beispiel #28
0
 private ShaderResourceView[] GetViews(DX11ShaderInstance shaderinstance, int slice)
 {
     ShaderResourceView[] data = new ShaderResourceView[array.Length];
     for (int i = 0; i < array.Length; i++)
     {
         try
         {
             data[i] = this.GetSRV(shaderinstance, slice, i);
         }
         catch
         {
             data[i] = null;
         }
     }
     return(data);
 }
        public override Action <DX11RenderSettings> CreateAction(DX11ShaderInstance shader)
        {
            var sv = shader.Effect.GetVariableByName(this.Name).AsResource();

            return((s) =>
            {
                if (shader.RenderContext.RenderTargetStack.Current.ReadonlyDepth)
                {
                    var ds = shader.RenderContext.RenderTargetStack.Current.DepthStencil;
                    sv.SetResource(((IDX11ReadableResource)ds).SRV);
                }
                else
                {
                    sv.SetResource(null);
                }
            });
        }
Beispiel #30
0
 public override void SetVariable(DX11ShaderInstance shaderinstance, int slice)
 {
     //ISpread<U> f = this.pin[slice];
     ShaderResourceView[] data = new ShaderResourceView[array.Length];
     for (int i = 0; i < array.Length; i++)
     {
         try
         {
             data[i] = this.GetSRV(shaderinstance, slice, i);
         }
         catch
         {
             data[i] = null;
         }
     }
     shaderinstance.SetByName(this.Name, data);
 }