public static string GenerateWAlpha(ShaderGenerate SG,ShaderEffect SE, ShaderLayer SL,string Line,int Effect){ SE.Inputs[0].Float = Mathf.Round(SE.Inputs[0].Float); if (SE.Inputs[0].Get()=="0") return "fmod("+Line+",1)"; return "fmod("+Line+"*"+SE.Inputs[0].Get()+",1)"; }
public static TipoCorrezione tipoCorrezioneCorrispondente(ShaderEffect oo) { TipoCorrezione tipoCorrezione; if (oo is GrayscaleEffect) { tipoCorrezione = TipoCorrezione.BiancoNero; } else if (oo is DominantiEffect) { tipoCorrezione = TipoCorrezione.Dominante; } else if (oo is LuminositaContrastoEffect) { tipoCorrezione = TipoCorrezione.Luce; } else if (oo is SepiaEffect) { tipoCorrezione = TipoCorrezione.Sepia; } else if (oo is OldMovieEffect) { tipoCorrezione = TipoCorrezione.OldMovie; } else { throw new NotSupportedException("Effetto non riconosciuto: " + oo); } return(tipoCorrezione); }
public static string GenerateMap(ShaderGenerate SG,ShaderEffect SE, ShaderLayer SL,string Map,ref int UVDimensions,ref int TypeDimensions){ if (TypeDimensions==3){ if (UVDimensions == 1) Map = "float3("+Map+",0,0)"; if (UVDimensions == 2) Map = "float3("+Map+",0)"; UVDimensions = 3; if (SL.LayerType.Type==(int)LayerTypes.Noise) return "("+Map+"+float3("+SE.Inputs[0].Get()+","+SE.Inputs[1].Get()+","+SE.Inputs[2].Get(1f/3f)+"))"; else return "("+Map+"+float3("+SE.Inputs[0].Get()+","+SE.Inputs[1].Get()+","+SE.Inputs[2].Get(1f)+"))"; } if (TypeDimensions==2){ if (UVDimensions == 1) Map = "float2("+Map+",0)"; if (UVDimensions<3){ UVDimensions = 2; return "("+Map+"+float2("+SE.Inputs[0].Get()+","+SE.Inputs[1].Get()+"))"; } else{ return "("+Map+"+float3("+SE.Inputs[0].Get()+","+SE.Inputs[1].Get()+",0))"; } } if (TypeDimensions==1) return "("+Map+"+("+SE.Inputs[0].Get()+"))"; return Map; }
private void BindShaderEffectToControls() { ShaderEffect shaderEffect = this.CurrentShaderEffect; if (shaderEffect != null) { foreach (ShaderModelConstantRegister register in this._shaderModel.Registers) { if (register.AffiliatedControl != null) { FieldInfo fieldInfo = shaderEffect.GetType().GetField(String.Format("{0}Property", register.RegisterName), BindingFlags.Public | BindingFlags.Static); if (fieldInfo != null) { DependencyProperty dependencyProperty = fieldInfo.GetValue(null) as DependencyProperty; if (dependencyProperty != null) { string controlPropertyName = "Value"; Binding binding = new Binding(controlPropertyName) { Source = register.AffiliatedControl, Converter = new RegisterValueConverter() }; BindingOperations.SetBinding(shaderEffect, dependencyProperty, binding); } } } } } }
/// <summary> /// Renders the Xray image on the CPU. /// </summary> /// <param name="bsource"></param> /// <param name="sourceObject"></param> /// <param name="viewObject"></param> /// <param name="xrayImageEffect"></param> /// <param name="trimatEffect"></param> /// <param name="effects"></param> /// <param name="displayWidth"></param> /// <param name="displayHeight"></param> /// <param name="adornerLayerManager"></param> /// <param name="displayAnnotations"></param> /// <param name="displayMeasurements"></param> /// <returns>The newly rendered bitmap.</returns> public static BitmapSource GetRenderedXrayImage(BitmapSource bsource, SourceObject sourceObject, ViewObject viewObject, ShaderEffect xrayOrTrimateImageEffect, List <Effect> effects, double displayWidth, double displayHeight, AdornerLayerManager adornerLayerManager, bool displayAnnotations, bool displayMeasurements) { if (xrayOrTrimateImageEffect != null && xrayOrTrimateImageEffect.GetType() == typeof(XrayImageEffect)) { RenderXrayImage_XRayImageEffect(ref bsource, (XrayImageEffect)xrayOrTrimateImageEffect, sourceObject); } //else if (xrayOrTrimateImageEffect.GetType() == typeof(TrimatEffect)) //{ // RenderXrayImage_TrimatEffect(ref bsource, (TrimatEffect)xrayOrTrimateImageEffect, sourceObject, viewObject); //} foreach (Effect effect in effects) { ApplyEffectToBitmap(ref bsource, effect); } if (displayAnnotations) { RenderAnnotations(ref bsource, displayWidth, displayHeight, adornerLayerManager); } if (displayMeasurements) { RenderMeasurements(ref bsource, displayWidth, displayHeight, adornerLayerManager); } return(bsource); }
static OuterGlowEffect() { OuterGlowEffect.InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(OuterGlowEffect), 0); OuterGlowEffect.IntensityProperty = DependencyProperty.Register( "Intensity", typeof(double), typeof(OuterGlowEffect), new UIPropertyMetadata(1D, ShaderEffect.PixelShaderConstantCallback(0)) ); OuterGlowEffect.RadiusProperty = DependencyProperty.Register( "Radius", typeof(double), typeof(OuterGlowEffect), new UIPropertyMetadata(1D, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) { ShaderEffect.PixelShaderConstantCallback(1)(d, e); ((OuterGlowEffect)d).PaddingLeft = (double)e.NewValue; ((OuterGlowEffect)d).PaddingTop = (double)e.NewValue; ((OuterGlowEffect)d).PaddingRight = (double)e.NewValue; ((OuterGlowEffect)d).PaddingBottom = (double)e.NewValue; }) ); OuterGlowEffect.GlowColorProperty = DependencyProperty.Register( "GlowColor", typeof(Color), typeof(OuterGlowEffect), new UIPropertyMetadata(Color.FromArgb(255, 0, 0, 0), ShaderEffect.PixelShaderConstantCallback(2)) ); }
public void BtnLogoEnter(CodeComponent sender) { ShaderEffect effect = _gui.Children.FindNodes(node => node.Name == "fuseeLogo").First().GetComponent <ShaderEffect>(); effect.SetFxParam(UniformNameDeclarations.Albedo, (float4)ColorUint.Black); effect.SetFxParam(UniformNameDeclarations.AlbedoMix, 0.8f); }
public static ShaderColor Preview(ShaderEffect SE,ShaderColor[] OldColors,int X, int Y, int W, int H){ ShaderColor OldColor = OldColors[ShaderUtil.FlatArray(X,Y,W,H)];//GetAddBlur(SE,OldColors,X,Y,W,H,0,0); /*SE.Inputs[0].Float = Mathf.Round(SE.Inputs[0].Float); Color NewColor = OldColor; int AddCount = 0; if (SE.Inputs[3].On==false){ for(int i = (int)(-SE.Inputs[0].Float);i<=(int)(SE.Inputs[0].Float);i+=2){ if (i!=0){NewColor+=GetAddBlur(SE,OldColors,X,Y,W,H,i,i);AddCount+=1;}} for(int i = (int)(-SE.Inputs[0].Float);i<=(int)(SE.Inputs[0].Float);i+=2){ if (i!=0){NewColor+=GetAddBlur(SE,OldColors,X,Y,W,H,-i,-i);AddCount+=1;}} for(int i = (int)(-SE.Inputs[0].Float);i<=(int)(SE.Inputs[0].Float);i+=2){ if (i!=0){NewColor+=GetAddBlur(SE,OldColors,X,Y,W,H,-i,i);AddCount+=1;}} for(int i = (int)(-SE.Inputs[0].Float);i<=(int)(SE.Inputs[0].Float);i+=2){ if (i!=0){NewColor+=GetAddBlur(SE,OldColors,X,Y,W,H,i,-i);AddCount+=1;}} } for(int i = (int)(-SE.Inputs[0].Float);i<=(int)(SE.Inputs[0].Float);i++){ if (i!=0){NewColor+=GetAddBlur(SE,OldColors,X,Y,W,H,i,0);AddCount+=1;}} for(int i = (int)(-SE.Inputs[0].Float);i<=(int)(SE.Inputs[0].Float);i++){ if (i!=0){NewColor+=GetAddBlur(SE,OldColors,X,Y,W,H,0,i);AddCount+=1;}} //if (SE.Inputs[2].On==false) NewColor/=(float)((AddCount)+1); //else //NewColor/=(SE.Inputs[3].Float*4f)+1; */ return OldColor; }
internal static void SetDiffuseAlphaInShaderEffect(this ShaderEffect effect, float alpha) { var color = (float4)effect.GetEffectParam(UniformNameDeclarations.AlbedoColor); color.w = alpha; effect.SetEffectParam(UniformNameDeclarations.AlbedoColor, color); }
public static void SetUsed(ShaderGenerate SG,ShaderEffect SE){ //Debug.Log(SG.UsedMasks.ContainsKey((ShaderLayerList)SE.Inputs[0].Obj)); if (SE.Inputs[0].Obj!=null&&SG.UsedMasks.ContainsKey((ShaderLayerList)SE.Inputs[0].Obj)){ SG.UsedMasks[(ShaderLayerList)SE.Inputs[0].Obj]++; // Debug.Log(SG.UsedMasks[(ShaderLayerList)SE.Inputs[0].Obj]); } }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSEMathDistance"; SE.Name = "Maths/Distance";//+UnityEngine.Random.value.ToString(); SE.Function = ""; SE.LinePre = ""; if (BInputs==true||SE.Inputs.Count!=5){ SE.Inputs = new List<ShaderVar>(); SE.Inputs.Add(new ShaderVar("Dimensions",new string[]{"1D","2D","3D","4D"},new string[]{"","","",""},new string[]{"1D","2D","3D","4D"})); SE.Inputs.Add(new ShaderVar("X",0)); SE.Inputs.Add(new ShaderVar("Y",0)); SE.Inputs.Add(new ShaderVar("Z",0)); SE.Inputs.Add(new ShaderVar("W",0)); } SE.Inputs[1].NoSlider = true; SE.Inputs[2].NoSlider = true; SE.Inputs[3].NoSlider = true; SE.Inputs[4].NoSlider = true; if (SE.Inputs[0].Type==3) SE.UseAlpha.Float=1f; if (SE.UseAlpha.Float==2f) SE.UseAlpha.Float=0f; SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; }
public static void Activate(ShaderEffect SE,bool BInputs,ShaderLayer SL){ SE.TypeS = "SSEUVSet"; SE.Name = "Mapping/Set";//+UnityEngine.Random.value.ToString(); SE.Function = ""; SE.LinePre = ""; if (BInputs==true||SE.Inputs.Count!=2){ SE.Inputs = new List<ShaderVar>(); SE.Inputs.Add(new ShaderVar("Values (RGBA)","ListOfObjects")); SE.Inputs.Add(new ShaderVar("Scale",1)); } //if (SL!=null) //Debug.Log(SL.IsLighting); if (SL!=null) SE.Inputs[0].LightingMasks = SL.IsLighting; SE.Inputs[0].SetToMasks(null,0); SE.Inputs[0].NoInputs = true; SE.Inputs[0].RGBAMasks = true; SE.Inputs[1].NoSlider = true; SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; SE.IsUVEffect = true; }
public static ShaderEffect GetShaderEffect(RenderContext rc, float4 color) { EffectPassDeclaration[] epd = { new EffectPassDeclaration { VS = VsSimpleColor, PS = PsSimpleColor, StateSet = new RenderStateSet { AlphaBlendEnable = false, ZEnable = true } } }; var shaderEffect = new ShaderEffect(epd, new[] { new EffectParameterDeclaration { Name = "color", Value = color } }); shaderEffect.AttachToContext(rc); return(shaderEffect); }
public static Vector2 Preview(ShaderEffect SE,Vector2 UV,int width, int height){ if (SE.Inputs[0].On) UV.x=width-UV.x; if (SE.Inputs[1].On) UV.y=height-UV.y; return UV; }
public static string GenerateMap(ShaderGenerate SG,ShaderEffect SE, ShaderLayer SL,string Map,ref int UVDimensions,ref int TypeDimensions){ if (TypeDimensions==3){ if (UVDimensions == 1) Map = "float3("+Map+",0,0)"; if (UVDimensions == 2) Map = "float3("+Map+",0)"; UVDimensions = 3; return "(((float3("+SE.Inputs[0].GetMaskName()+".r,"+SE.Inputs[0].GetMaskName()+".g,"+SE.Inputs[0].GetMaskName()+".b))*"+SE.Inputs[1].Get()+"))"; } if (TypeDimensions==2){ if (UVDimensions == 1) Map = "float2("+Map+",0)"; if (UVDimensions<3){ UVDimensions = 2; return "(((float2("+SE.Inputs[0].GetMaskName()+".r,"+SE.Inputs[0].GetMaskName()+".g))*"+SE.Inputs[1].Get()+"))"; } else{ return "(((float3("+SE.Inputs[0].GetMaskName()+".r,"+SE.Inputs[0].GetMaskName()+".g,0))*"+SE.Inputs[1].Get()+"))"; } } if (TypeDimensions==1){ //if (UVDimensions==1) return "((("+SE.Inputs[0].GetMaskName()+".r)*"+SE.Inputs[1].Get()+"))"; } return Map; }
public static ShaderColor Preview(ShaderEffect SE,ShaderColor[] OldColors,int X, int Y, int W, int H){ //ShaderColor OldColor = OldColors[ShaderUtil.FlatArray(X,Y,W,H)]; Vector2 NewColor = new Vector2(0,0); if (SE.Inputs[2].Type==0) NewColor = new Vector2(OldColors[ShaderUtil.FlatArray(X,Y,W,H)].r-OldColors[ShaderUtil.FlatArray(X+((int)Mathf.Round(SE.Inputs[0].Float*W)),Y,W,H)].r, OldColors[ShaderUtil.FlatArray(X,Y,W,H)].r-OldColors[ShaderUtil.FlatArray(X,Y+((int)Mathf.Round(SE.Inputs[0].Float*H)),W,H)].r); if (SE.Inputs[2].Type==1) NewColor = new Vector2(OldColors[ShaderUtil.FlatArray(X,Y,W,H)].g-OldColors[ShaderUtil.FlatArray(X+((int)Mathf.Round(SE.Inputs[0].Float*W)),Y,W,H)].g, OldColors[ShaderUtil.FlatArray(X,Y,W,H)].g-OldColors[ShaderUtil.FlatArray(X,Y+((int)Mathf.Round(SE.Inputs[0].Float*H)),W,H)].g); if (SE.Inputs[2].Type==2) NewColor = new Vector2(OldColors[ShaderUtil.FlatArray(X,Y,W,H)].b-OldColors[ShaderUtil.FlatArray(X+((int)Mathf.Round(SE.Inputs[0].Float*W)),Y,W,H)].b, OldColors[ShaderUtil.FlatArray(X,Y,W,H)].b-OldColors[ShaderUtil.FlatArray(X,Y+((int)Mathf.Round(SE.Inputs[0].Float*H)),W,H)].b); if (SE.Inputs[2].Type==3) NewColor = new Vector2(OldColors[ShaderUtil.FlatArray(X,Y,W,H)].a-OldColors[ShaderUtil.FlatArray(X+((int)Mathf.Round(SE.Inputs[0].Float*W)),Y,W,H)].a, OldColors[ShaderUtil.FlatArray(X,Y,W,H)].a-OldColors[ShaderUtil.FlatArray(X,Y+((int)Mathf.Round(SE.Inputs[0].Float*H)),W,H)].a); NewColor *= SE.Inputs[1].Float; return new ShaderColor(NewColor.x,NewColor.y,1,1);//Mathf.Sqrt(1-(NewColor.x*NewColor.x)-(NewColor.y*NewColor.y)),1); //NewColor/=2f; //NewColor+= new Color(0.5f,0.5f,0.5f,0f); //else //NewColor/=(SE.Inputs[3].Float*4f)+1; //return NewColor; }
public void BtnLogoExit(CodeComponent sender) { ShaderEffect effect = _gui.Children.FindNodes(node => node.Name == "fuseeLogo").First().GetComponent <ShaderEffect>(); effect.SetFxParam(UniformNameDeclarations.Albedo, float4.One); effect.SetFxParam(UniformNameDeclarations.AlbedoMix, 1f); }
internal static void SetDiffuseAlphaInShaderEffect(this ShaderEffect effect, float alpha) { var color = (float4)effect.GetEffectParam(ShaderCodeBuilder.DiffuseColorName); color.w = alpha; effect.SetEffectParam(ShaderCodeBuilder.DiffuseColorName, color); }
protected internal virtual void AttachToContext(RenderContext rc) { if (RContext == rc) { return; } if (RContext != null) { TextShader.DetachFromContext(); TextShader = null; } RContext = rc; if (GUIShader != null) { GUIShader.AttachToContext(RContext); } if (FontMap != null) { CreateTextShader(rc.CreateTexture(FontMap.Image)); TextShader.AttachToContext(RContext); } Refresh(); }
protected void CreateTextShader(ITexture textAtlas) { TextShader = new ShaderEffect(new[] { new EffectPassDeclaration { VS = GUIVS, PS = TEXTPS, StateSet = new RenderStateSet { AlphaBlendEnable = true, SourceBlend = Blend.SourceAlpha, DestinationBlend = Blend.InverseSourceAlpha, ZEnable = false } } }, new[] { new EffectParameterDeclaration { Name = "tex", Value = textAtlas }, new EffectParameterDeclaration { Name = "uColor", Value = _textColor } }); }
public void SetShader(String texturePath) { var imgData = _rc.LoadImage(texturePath); _iTexture1 = _rc.CreateTexture(imgData); _shaderEffect = Shader.GetShaderEffect(_rc, _iTexture1); }
public void SetShader(float4 baseColor, String colorMapTexturePath, float4 lineColor, float2 lineWidth) { var imgData = _rc.LoadImage(colorMapTexturePath); _iTexture1 = _rc.CreateTexture(imgData); _shaderEffect = Shader.GetShaderEffect(_rc, baseColor, _iTexture1, lineColor, lineWidth); }
public static string GenerateWAlpha(ShaderGenerate SG,ShaderEffect SE, ShaderLayer SL,string Line,int Effect){ string[] Colors = new string[]{"r","g","b","a"}; string Line1 = "(("+Line+"."+Colors[SE.Inputs[2].Type]+"-"+SL.StartNewBranch(SG,SL.GCUVs(SG,SE.Inputs[0].Get(),"0","0"),Effect)+"."+Colors[SE.Inputs[2].Type]+")*"+SE.Inputs[1].Get()+")"; string Line2 = "(("+Line+"."+Colors[SE.Inputs[2].Type]+"-"+SL.StartNewBranch(SG,SL.GCUVs(SG,"0",SE.Inputs[0].Get(),"0"),Effect)+"."+Colors[SE.Inputs[2].Type]+")*"+SE.Inputs[1].Get()+")"; //string retVal = "(float4("+Line1+","+Line2+","+"sqrt((1-pow("+Line1+",2)-pow("+Line2+",2))),"+Line+".a))";///2+0.5"; string retVal = "(float4("+Line1+","+Line2+",1,"+Line+".a))";///2+0.5"; return retVal; }
} // Dispose(someObject) /// <summary> /// Dispose /// </summary> /// <param name="someObject">Some object</param> public static void Dispose(ref ShaderEffect someObject) { if (someObject != null) { someObject.Dispose(); } someObject = null; } // Dispose(someObject)
public static ShaderColor Preview(ShaderEffect SE,ShaderColor OldColor){ float Grey = Vector3.Dot(new Vector3(0.3f,0.59f,0.11f),new Vector3(OldColor.r,OldColor.g,OldColor.b)); ShaderColor NewColor = OldColor; if (Grey<SE.Inputs[0].Float) NewColor = new ShaderColor(0,0,0,OldColor.a); if (NewColor.a<SE.Inputs[0].Float) NewColor.a = 0; return NewColor; }
public static Vector2 Preview(ShaderEffect SE,Vector2 UV,int width, int height){ Color Disp = new Color(0.5f,0.5f,0.5f,0.5f); if (SE.Inputs[0].Obj!=null) Disp = ((ShaderLayerList)(SE.Inputs[0].Obj)).GetIcon().GetPixel((int)UV.x,(int)UV.y); UV.x=(Disp.r)*width*SE.Inputs[1].Float;//Mathf.Round(SE.Inputs[0].Float*width); UV.y=(Disp.g)*height*SE.Inputs[1].Float;//Mathf.Round(SE.Inputs[1].Float*height); return UV; }
public static Vector2 Preview(ShaderEffect SE,Vector2 UV,int width, int height){ if (!SE.Inputs[0].On) SE.Inputs[2].Float = SE.Inputs[1].Float; if (!SE.Inputs[0].On) SE.Inputs[3].Float = SE.Inputs[1].Float; UV.x*=SE.Inputs[1].Float; UV.y*=SE.Inputs[2].Float; return UV; }
public DrunkEffectData(ShaderEffect sfx) { ReferenceName = sfx.referenceName; Name = sfx.name; Author = sfx.author; Description = sfx.description; IsScreenSpace = sfx.isScreenSpace; PreviewImage = sfx.previewImage; Material = sfx.material; }
internal FloatShaderEffectProperty(ShaderEffect effect, int register) : base(effect, register) { m_buffer = new ConstantStreamBuffer<float>(Effect.DirectCanvas.DeviceContext.Device, 16, register, ConstantStreamBufferType.PixelShader, ResourceUsage.Dynamic, CpuAccessFlags.Write, false); }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSEMathAbs"; SE.Name = "Maths/Absolute";//+UnityEngine.Random.value.ToString(); SE.Function = ""; SE.LinePre = ""; SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; }
public static string GenerateMap(ShaderGenerate SG,ShaderEffect SE, ShaderLayer SL,string Map,ref int UVDimensions,ref int TypeDimensions){ //return "float3("+((SE.Inputs[0].On)?"1-":"")+")"; if (UVDimensions==3) return "float3("+((SE.Inputs[0].On)?"1-":"")+Map+".x,"+((SE.Inputs[1].On)?"1-":"")+Map+".y,"+((SE.Inputs[2].On)?"1-":"")+Map+".z)"; if (UVDimensions==2) return "float2("+((SE.Inputs[0].On)?"1-":"")+Map+".x,"+((SE.Inputs[1].On)?"1-":"")+Map+".y)"; if (UVDimensions==1) return ""+(((SE.Inputs[0].On)?"1-":"")+Map); return Map; }
public static ShaderColor Preview(ShaderEffect SE,ShaderColor OldColor){ ShaderColor NewColor = OldColor*new ShaderColor(SE.Inputs[0].Float,SE.Inputs[1].Float,SE.Inputs[2].Float,SE.Inputs[3].Float);// = new ShaderColor(OldColor.r+SE.Inputs[0].Float,OldColor.g+SE.Inputs[0].Float,OldColor.b+SE.Inputs[0].Float,OldColor.a+SE.Inputs[0].Float); float Grey = NewColor.r+NewColor.g+NewColor.b; if (SE.UseAlpha.Float==2f) Grey = NewColor.a; if (SE.UseAlpha.Float==1f) Grey = NewColor.r+NewColor.g+NewColor.b+NewColor.a; NewColor = new ShaderColor(Grey,Grey,Grey,Grey); return NewColor; }
public bool AddShader(String name, ShaderEffect effect) { if (!shaderEffects.ContainsKey(name)) { shaderEffects.Add(name, effect); shaderEffects[name].AttachToContext(RC); return(true); } return(false); }
public static ShaderColor Preview(ShaderEffect SE,ShaderColor OldColor){ //if (OldColor.r<0) //Debug.Log(Mathf.Sin(OldColor.r)); ShaderColor NewColor; if (SE.Inputs[0].On) NewColor = ((new ShaderColor(Mathf.Sin(OldColor.r),Mathf.Sin(OldColor.g),Mathf.Sin(OldColor.b),Mathf.Sin(OldColor.a)))+1)/2; else NewColor = ((new ShaderColor(Mathf.Sin(OldColor.r),Mathf.Sin(OldColor.g),Mathf.Sin(OldColor.b),Mathf.Sin(OldColor.a)))); //Debug.Log(NewColor.ToString()); return NewColor; }
private void ApplyEffect(ShaderEffect se) { userImage.Effect = se; sampleImage1.Effect = se; sampleImage2.Effect = se; sampleImage3.Effect = se; sampleImage4.Effect = se; sampleImage5.Effect = se; sampleUI.Effect = se; mediaUI.Effect = se; }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSESwitchNormalScale"; SE.Name = "Conversion/Descale Normal Map";//+UnityEngine.Random.value.ToString(); SE.Function = ""; SE.LinePre = ""; SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; }
public override IImmagine applica(IImmagine immagineSorgente, Correzione correzione) { // Non spostare da qui questo vettore. Deve essere istanziato ogni volta, altrimenti romper il cavolo con i thread diversi ShaderEffect [] localEffetcs = new ShaderEffect[] { new GrayscaleEffect() }; ImmagineWic iw = (ImmagineWic)immagineSorgente; BitmapSource modificata = EffectsUtil.RenderImageWithEffectsToBitmap(iw.bitmapSource, localEffetcs); return(new ImmagineWic(modificata)); }
private void ApplyEffect(ShaderEffect se) { this.UserImage.SetCurrentValue(EffectProperty, se); this.SampleImage1.SetCurrentValue(EffectProperty, se); this.SampleImage2.SetCurrentValue(EffectProperty, se); this.SampleImage3.SetCurrentValue(EffectProperty, se); this.SampleImage4.SetCurrentValue(EffectProperty, se); this.SampleImage5.SetCurrentValue(EffectProperty, se); this.SampleUi.SetCurrentValue(EffectProperty, se); this.MediaUi.SetCurrentValue(EffectProperty, se); }
public ShaderEffect GetShaderEffect(int index) { ShaderEffect shaderEffect = null; if (index < this.Count) { shaderEffect = (ShaderEffect)Activator.CreateInstance(_shaderEffectTypes[index]); } return(shaderEffect); }
internal ColorShaderEffectProperty(ShaderEffect effect, int register) : base(effect, register) { m_buffer = new ConstantStreamBuffer<Color4>(Effect.DirectCanvas.DeviceContext.Device, Marshal.SizeOf(typeof(Color4)), register, ConstantStreamBufferType.PixelShader, ResourceUsage.Dynamic, CpuAccessFlags.Write, false); }
public static string GenerateGeneric(ShaderEffect SE,string line){ string Grey = line; if (SE.Inputs[0].Type==0) Grey = line+".r-"+SE.Inputs[1].Get(); if (SE.Inputs[0].Type==1) Grey = "distance("+line+".xy,float2("+SE.Inputs[1].Get()+","+SE.Inputs[2].Get()+"))"; if (SE.Inputs[0].Type==2) Grey = "distance("+line+".xyz,float3("+SE.Inputs[1].Get()+","+SE.Inputs[2].Get()+","+SE.Inputs[3].Get()+"))"; if (SE.Inputs[0].Type==3) Grey = "distance("+line+",float4("+SE.Inputs[1].Get()+","+SE.Inputs[2].Get()+","+SE.Inputs[3].Get()+","+SE.Inputs[4].Get()+"))"; return "(("+Grey+").rrrr)"; }
static void Main(string[] args) //fx_ps_DirectoryPath ShaderName [GeneratedNamespace] { if (args.Length < 3) { return; } string fxPath = args[0] + "\\" + args[1] + ".fx";//@"C:\Users\wenyunchun\Desktop\WpfTPL\shader\ToonShader.fx"; string psPath = args[0] + "\\" + args[1] + ".ps"; string GeneratedNamespace = args[2]; using (FileStream fs = new FileStream(fxPath, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader(fs, Encoding.UTF8)) { //string psPath = @"C:\Users\wenyunchun\Desktop\WpfTPL\shader\ToonShader.ps"; CodeParser.GeneratedNamespace = !string.IsNullOrWhiteSpace(GeneratedNamespace) ? GeneratedNamespace : "Shaders"; // || 动态命名空间 || // ShaderModel _shaderModel = CodeParser.ParseShader(psPath, sr.ReadToEnd()); CreatePixelShaderClass.shaderPath = psPath; string _csText = CreatePixelShaderClass.GetSourceText(CodeDomProvider.CreateProvider("CSharp"), _shaderModel, false); //string _vbText = CreatePixelShaderClass.GetSourceText(CodeDomProvider.CreateProvider("VisualBasic"), _shaderModel, false); string topath = args[0] + "\\" + args[1] + "Effect.cs"; using (FileStream fs2 = new FileStream(topath, FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs2, Encoding.UTF8)) { sw.Write(_csText); } } // || 添加动态资源文件 || // var ps = new PixelShader { UriSource = new Uri(psPath) }; Assembly autoAssembly = CreatePixelShaderClass.CompileInMemory(_csText); if (autoAssembly == null) { MessageBox.Show("Cannot compile the generated C# code.", "Compile error", MessageBoxButton.OK, MessageBoxImage.Error); //return; } else { Type type = autoAssembly.GetType(String.Format("{0}.{1}", _shaderModel.GeneratedNamespace, _shaderModel.GeneratedClassName)); //ShaderEffect se = (ShaderEffect)Activator.CreateInstance(type, new object[] { ps }); ShaderEffect se = (ShaderEffect)Activator.CreateInstance(type); Console.WriteLine(se); } } } }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSEDesaturate"; SE.Name = "Color/Desaturate";//+UnityEngine.Random.value.ToString(); SE.Function = ""; SE.Line = "float3(dot(float3(0.3,0.59,0.11),@Line))"; SE.LinePre = ""; SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; }
private static DrunkEffectData LoadSFX(byte[] bytes) { AssetBundle bundle = AssetBundle.LoadFromMemory(bytes); var shaderEffectMetadataGOPrefab = bundle.LoadAsset <GameObject>("Assets/ShaderEffectMetadata.prefab"); GameObject shaderEffectMetadataGO = UnityEngine.Object.Instantiate(shaderEffectMetadataGOPrefab); ShaderEffect shaderEffect = shaderEffectMetadataGO.GetComponent <ShaderEffect>(); DrunkEffectData data = new DrunkEffectData(shaderEffect); GameObject.Destroy(shaderEffectMetadataGO); bundle.Unload(false); return(data); }
public override IImmagine applica(IImmagine immagineSorgente, Correzione correzione) { // Purtroppo devo creare un array con un solo elemento. TODO migliorare ShaderEffect lce = (ShaderEffect)ConvertTo(correzione, typeof(ShaderEffect)); ShaderEffect [] _effetti = new ShaderEffect [] { lce }; ImmagineWic iw = (ImmagineWic)immagineSorgente; BitmapSource modificata = EffectsUtil.RenderImageWithEffectsToBitmap(iw.bitmapSource, _effetti); return(new ImmagineWic(modificata)); }
public static ShaderColor Preview(ShaderEffect SE,ShaderColor OldColor){ ShaderColor NewColor = OldColor; //NewColor*=2; //NewColor -= new Color(1,1,0,0); //NewColor = new Color(NewColor.r,NewColor.g,0,0); //NewColor = new Color(NewColor.r,NewColor.g,Mathf.Sqrt(1-(NewColor.r*NewColor.r)-(NewColor.g*NewColor.g)),1); NewColor/=2f; NewColor+= new ShaderColor(0.5f,0.5f,0.5f,0f); NewColor.a = OldColor.a; //NewColor.a = OldColor.a; return NewColor; }
public static Vector2 Preview(ShaderEffect SE,Vector2 UV,int width, int height){ Vector2 NormalUV = new Vector2(UV.x/(float)width,UV.y/(float)height); if (!SE.Inputs[0].On){ SE.Inputs[2].Float = SE.Inputs[1].Float; SE.Inputs[3].Float = SE.Inputs[1].Float; } NormalUV.x=Mathf.Round(NormalUV.x/SE.Inputs[1].Float)*SE.Inputs[1].Float; NormalUV.y=Mathf.Round(NormalUV.y/SE.Inputs[2].Float)*SE.Inputs[2].Float; //NormalUV.y=SE.Inputs[2].Float; UV = new Vector2(NormalUV.x*(float)width,NormalUV.y*(float)height); return UV; }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSEMathSin"; SE.Name = "Maths/Sine";//+UnityEngine.Random.value.ToString(); if (BInputs==true||SE.Inputs.Count!=1){ SE.Inputs = new List<ShaderVar>(); SE.Inputs.Add(new ShaderVar("0-1",true)); } SE.Function = ""; SE.LinePre = ""; SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSECAntiAliasing"; SE.Name = "Blur/Anti Aliasing";//+UnityEngine.Random.value.ToString(); if (BInputs==true||SE.Inputs.Count!=1){ SE.Inputs = new List<ShaderVar>(); SE.Inputs.Add(new ShaderVar("Quality",1f)); } SE.Inputs[0].Range0 = 1; SE.Inputs[0].Range1 = 4; SE.Inputs[0].Float = Mathf.Max(1,SE.Inputs[0].Float); SE.Inputs[0].Float = Mathf.Round(SE.Inputs[0].Float); }
static public int constructor(IntPtr l) { try { ShaderEffect o; o = new ShaderEffect(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
static ShaderEffectData LoadShaderEffectAssetBundleFromPath(string path) { AssetBundle bundle = AssetBundle.LoadFromFile(path); var loadAsset = bundle.LoadAsset <Material>("Assets/ShaderEffect.mat"); var shaderEffectMetadataGOPrefab = bundle.LoadAsset <GameObject>("Assets/ShaderEffectMetadata.prefab"); GameObject shaderEffectMetadataGO = UnityEngine.Object.Instantiate(shaderEffectMetadataGOPrefab); ShaderEffect shaderEffect = shaderEffectMetadataGO.GetComponent <ShaderEffect>(); ShaderEffectData data = new ShaderEffectData(shaderEffect); GameObject.Destroy(shaderEffectMetadataGO); bundle.Unload(false); return(data); }
public Renderer(RenderContext rc) { RC = rc; // Read the Leaves.jpg image and upload it to the GPU ImageData leaves = AssetStorage.Get <ImageData>("Leaves.jpg"); _leafTexture = RC.CreateTexture(leaves); // Initialize the shader(s) ShaderEffect = new ShaderEffect( new[] { new EffectPassDeclaration { VS = AssetStorage.Get <string>("VertexShader.vert"), PS = AssetStorage.Get <string>("PixelShader.frag"), StateSet = new RenderStateSet { ZFunc = Compare.Less //ZEnable = true, // CullMode = Cull.Clockwise, } } }, new[] { new EffectParameterDeclaration { Name = "albedo", Value = float3.One }, new EffectParameterDeclaration { Name = "shininess", Value = 1.0f }, new EffectParameterDeclaration { Name = "specfactor", Value = 1.0f }, new EffectParameterDeclaration { Name = "speccolor", Value = float3.Zero }, new EffectParameterDeclaration { Name = "ambientcolor", Value = float3.Zero }, new EffectParameterDeclaration { Name = "texture", Value = _leafTexture }, new EffectParameterDeclaration { Name = "texmix", Value = 0.0f }, }); ShaderEffect.AttachToContext(RC); }
public static ShaderColor Preview(ShaderEffect SE,ShaderColor[] OldColors,int X, int Y, int W, int H){ //Color OldColor = GetAddBlur(SE,OldColors,X,Y,W,H,0,0); float OldSE = SE.Inputs[0].Float; SE.Inputs[0].Float = Mathf.Max(0,(Mathf.Round(SE.Inputs[0].Float))-1);//Mathf.Pow(SE.Inputs[0].Float/5f,2f)*8f; float DXX = ((float)X/(SE.Inputs[0].Float*3+1))-Mathf.Floor((float)X/(SE.Inputs[0].Float*3+1)); float DYY = (((float)Y/(SE.Inputs[0].Float*3+1))-Mathf.Floor((float)Y/(SE.Inputs[0].Float*3+1))); ShaderColor NewColor = LerpBlur(DXX,DYY,GetAddBlur(SE,OldColors,X,Y,W,H,0,0),GetAddBlur(SE,OldColors,X,Y,W,H,1,0),GetAddBlur(SE,OldColors,X,Y,W,H,0,1),GetAddBlur(SE,OldColors,X,Y,W,H,1,1)); SE.Inputs[0].Float = OldSE; //OldColor = new Color(DXX,DYY,0,1); //Color NewColor = OldColor; //NewColor.a = OldColor.a; return NewColor; }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSEUVRotate"; SE.Name = "Mapping/Simple Rotate";//+UnityEngine.Random.value.ToString(); SE.Function = ""; SE.LinePre = ""; if (BInputs==true){ SE.Inputs = new List<ShaderVar>(); SE.Inputs.Add(new ShaderVar("X Rotate",new string[]{"0","90","180","270"},new string[]{"0","90","180","270"})); } SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; SE.IsUVEffect = true; }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSEMathPow"; SE.Name = "Maths/Power";//+UnityEngine.Random.value.ToString(); SE.Function = ""; SE.LinePre = ""; if (BInputs==true){ SE.Inputs = new List<ShaderVar>(); SE.Inputs.Add(new ShaderVar("Power",1)); } SE.Inputs[0].NoSlider = true; SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; }
public static void Activate(ShaderEffect SE,bool BInputs){ SE.TypeS = "SSEThreshold"; SE.Name = "Color/Threshold";//+UnityEngine.Random.value.ToString(); if (BInputs==true){ SE.Inputs = new List<ShaderVar>(); SE.Inputs.Add(new ShaderVar("Threshold",0.3f)); } SE.Inputs[0].Range0 = 0; SE.Inputs[0].Range1 = 1; SE.WorldPos = false; SE.WorldRefl = false; SE.WorldNormals = false; }
public override IImmagine applica(IImmagine immagineSorgente, Correzione correzione) { // Purtroppo devo creare un array con un solo elemento. TODO migliorare DominantiEffect de = new DominantiEffect(); de.Red = ((Dominante)correzione).rosso; de.Green = ((Dominante)correzione).verde; de.Blue = ((Dominante)correzione).blu; ShaderEffect [] _effetti = new ShaderEffect [] { de }; ImmagineWic iw = (ImmagineWic)immagineSorgente; BitmapSource modificata = EffectsUtil.RenderImageWithEffectsToBitmap(iw.bitmapSource, _effetti); return(new ImmagineWic(modificata)); }
public static ShaderEffect GetShaderEffect(RenderContext rc, float4 baseColor, ITexture colorMapTexture, float4 lineColor, float2 lineWidth) { EffectPassDeclaration[] epd = { new EffectPassDeclaration { VS = VsSimpleToonPass1, PS = PsSimpleToonPass1, StateSet = new RenderStateSet { AlphaBlendEnable = false, ZEnable = true } }, new EffectPassDeclaration { VS = VsSimpleToonPass2, PS = PsSimpleToonPass2, StateSet = new RenderStateSet { AlphaBlendEnable = false, ZEnable = true } } }; var shaderEffect = new ShaderEffect(epd, new[] { new EffectParameterDeclaration { Name = "uLineColor", Value = lineColor }, new EffectParameterDeclaration { Name = "texture1", Value = colorMapTexture }, new EffectParameterDeclaration { Name = "uLineWidth", Value = lineWidth }, new EffectParameterDeclaration { Name = "color", Value = baseColor } }); shaderEffect.AttachToContext(rc); return(shaderEffect); }
public string GetEffectName(ShaderEffect shaderEffect) { string effectName = "no effect"; if (shaderEffect != null) { var descriptionAttribute = (DescriptionAttribute)Attribute.GetCustomAttribute(shaderEffect.GetType(), typeof(DescriptionAttribute)); if (descriptionAttribute == null) { effectName = shaderEffect.GetType().Name; } else { effectName = descriptionAttribute.Description; } } return(effectName); }
protected virtual void CreateGUIShader() { GUIShader = new ShaderEffect(new[] { new EffectPassDeclaration { VS = GUIVS, PS = GUIPS, StateSet = new RenderStateSet { AlphaBlendEnable = true, SourceBlend = Blend.SourceAlpha, DestinationBlend = Blend.InverseSourceAlpha, ZEnable = true } } }, null); }