public static bool NeedDestroy(this EffectVariable var, IWorldRenderVariable shadervar) { //For pins, if type/elements or now has a semantic, we need to recreate the pin return(var.GetVariableType().Description.TypeName != shadervar.TypeName || var.GetVariableType().Description.Elements != shadervar.Elements || var.Description.Semantic != shadervar.Semantic); }
// System.Collections.Generic.SortedDictionary<int,Vector2> public void RebuildTextureCache() { texturecache.Clear(); passindex.Clear(); for (int i = 0; i < this.shader.DefaultEffect.Description.GlobalVariableCount; i++) { EffectVariable var = this.shader.DefaultEffect.GetVariableByIndex(i); if (var.GetVariableType().Description.TypeName == "Texture2D") { EffectResourceVariable rv = var.AsResource(); texturecache.Add(rv); } if (var.GetVariableType().Description.TypeName == "float" || var.GetVariableType().Description.TypeName == "int") { if (var.Description.Semantic == "PASSINDEX") { passindex.Add(var.AsScalar()); } if (var.Description.Semantic == "PASSITERATIONINDEX") { passiterindex.Add(var.AsScalar()); } } } }
public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex) { EffectVariable annotation = EffectParseHelper.getAnnotation(variable, "Object", "string"); if (annotation == null || string.IsNullOrWhiteSpace(annotation.AsString().GetString())) { throw new InvalidMMEEffectShaderException( string.Format( "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されませんでした。", variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name, variable.Description.Semantic)); } string objectStr = annotation.AsString().GetString().ToLower(); ObjectAnnotationType type; switch (objectStr) { case "camera": type = ObjectAnnotationType.Camera; break; case "light": type = ObjectAnnotationType.Light; break; default: throw new InvalidMMEEffectShaderException( string.Format( "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されたのは,「string object=\"{3}\"でした。(スペルミス?)" , variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name, variable.Description.Semantic, objectStr)); } return(GetSubscriberInstance(type)); }
public AbstractWorldRenderVariable(EffectVariable var) { this.Name = var.Description.Name; this.TypeName = var.GetVariableType().Description.TypeName; this.Semantic = var.Description.Semantic; this.Elements = var.GetVariableType().Description.Elements; }
/// <summary> /// If the matrix each examine the Camera or Light? /// </summary> /// <param name="variable"></param> /// <param name="context"></param> /// <param name="effectManager"></param> /// <param name="semanticIndex"></param> /// <param name="effect">Effect of test</param> /// <param name="index">Inspect variable index</param> /// <returns></returns> public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex) { string obj; EffectVariable annotation = EffectParseHelper.getAnnotation(variable, "Object", "string"); obj = annotation == null ? "" : annotation.AsString().GetString(); //The annotation is not present""とする if (string.IsNullOrWhiteSpace(obj)) { return(GetSubscriberInstance(ObjectAnnotationType.Camera)); } switch (obj.ToLower()) { case "camera": return(GetSubscriberInstance(ObjectAnnotationType.Camera)); case "light": return(GetSubscriberInstance(ObjectAnnotationType.Light)); case "": throw new InvalidMMEEffectShaderException( string.Format( "変数「{0} {1}:{2}」には、アノテーション「string Object=\"Camera\"」または、「string Object=\"Light\"」が必須ですが指定されませんでした。", variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name, variable.Description.Semantic)); default: throw new InvalidMMEEffectShaderException( string.Format( "変数「{0} {1}:{2}」には、アノテーション「string Object=\"Camera\"」または、「string Object=\"Light\"」が必須ですが指定されたのは「string Object=\"{3}\"」でした。(スペルミス?)", variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name, variable.Description.Semantic, obj)); } }
public AbstractRenderVariable(EffectVariable var) { this.variable = var; this.Name = var.Description.Name; this.TypeName = var.GetVariableType().Description.TypeName; this.Semantic = var.Description.Semantic; this.Elements = var.GetVariableType().Description.Elements; }
public static bool IsWorldRenderVariable(EffectVariable var) { string semantic = var.Description.Semantic; string type = var.GetVariableType().Description.TypeName; bool array = var.GetVariableType().Description.Elements > 0; return(worldregistry.ContainsType(type, semantic, array)); }
public static bool IsWorldRenderVariable(EffectVariable var) { string semantic = var.Description.Semantic; string type = var.GetVariableType().Description.TypeName; bool array = var.GetVariableType().Description.Elements > 0; return worldregistry.ContainsType(type, semantic, array); }
public static bool IsShaderPin(EffectVariable var) { string semantic = var.Description.Semantic; string type = var.GetVariableType().Description.TypeName; bool array = var.GetVariableType().Description.Elements > 0; return((stdregistry.ContainsType(type) || arrayregistry.ContainsType(type)) && semantic == ""); //|| semanticregistry.ContainsType(type, semantic, array)) && (semantic != "IMMUTABLE"); }
public static bool IsShaderPin(EffectVariable var) { string semantic = var.Description.Semantic; string type = var.GetVariableType().Description.TypeName; bool array = var.GetVariableType().Description.Elements > 0; return ((stdregistry.ContainsType(type) || arrayregistry.ContainsType(type)) && semantic == ""); //|| semanticregistry.ContainsType(type, semantic, array)) && (semantic != "IMMUTABLE"); }
public void Initialize(IIOFactory factory, EffectVariable variable) { this.factory = factory; this.PinName = variable.UiName(); this.visible = variable.Visible(); this.TypeName = variable.GetVariableType().Description.TypeName; this.Elements = variable.GetVariableType().Description.Elements; this.Name = variable.Description.Name; this.CreatePin(variable); }
public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex) { bool isVector3 = variable.GetVariableType().Description.TypeName.ToLower().Equals("float3"); if (!NeedAnnotation.Contains(Semantics)) { return(GetSubscriberInstance(TargetObject.UnUsed, isVector3)); } EffectVariable objectAnnotation = EffectParseHelper.getAnnotation(variable, "Object", "string"); if (objectAnnotation == null) { throw new InvalidMMEEffectShaderException( string.Format("このセマンティクス\"{0}\"にはアノテーション「Object」が必須ですが、記述されませんでした。", Semantics)); } string annotation = objectAnnotation.AsString().GetString().ToLower(); if (!string.IsNullOrWhiteSpace(annotation)) { switch (annotation) { case "geometry": return(GetSubscriberInstance(TargetObject.Geometry, isVector3)); case "light": return(GetSubscriberInstance(TargetObject.Light, isVector3)); default: throw new InvalidMMEEffectShaderException(string.Format("アノテーション\"{0}\"は認識されません。", annotation)); } } throw new InvalidMMEEffectShaderException( string.Format("このセマンティクス\"{0}\"にはアノテーション「Object」が必須ですが、記述されませんでした。", Semantics)); }
public static bool Match(this EffectVariable var, IShaderPin shadervar) { //For pins, if type/elements or now has a semantic, we need to recreate the pin bool res = var.GetVariableType().Description.TypeName == shadervar.TypeName && var.GetVariableType().Description.Elements == shadervar.Elements && var.Description.Name == shadervar.Name && var.Description.Semantic == ""; //Check if need to change shader type if (res && shadervar is IMultiTypeShaderPin) { res = ((IMultiTypeShaderPin)shadervar).ChangeType(var); } return(res); }
/// <summary> /// Ignore the case of name annotation, to get /// </summary> /// <param name="variable">To get the effect variables</param> /// <param name="target">Annotation name</param> /// <param name="typeName">Expected type</param> /// <returns>Annotation</returns> public static EffectVariable getAnnotation(EffectVariable variable, string target, string typeName) { string name = target.ToLower(); string[] valid = name.Split('/'); for (int i = 0; i < variable.Description.AnnotationCount; i++) { EffectVariable val = variable.GetAnnotationByIndex(i); string typeString = val.Description.Name.ToLower(); if (typeString == name) { if ( !valid.Contains(typeString) && !String.IsNullOrWhiteSpace(typeString)) { throw new InvalidMMEEffectShaderException( string.Format( "変数「{0} {1}:{2}」に適用されたアノテーション「{3} {4}」はアノテーションの型が正しくありません。期待した型は{5}でした。", variable.GetVariableType().Description.TypeName, variable.Description.Name, variable.Description.Semantic, val.GetVariableType().Description.TypeName, val.Description.Name, getExpectedTypes(valid, val.Description.Name))); } return(val); } } return(null); }
public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime, MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass) { LoopByCountFunction func = new LoopByCountFunction(); func.runtime = runtime; if (string.IsNullOrWhiteSpace(value)) { throw new InvalidMMEEffectShaderException("LoopByCount=;は指定できません。int,float,boolいずれかの変数名を伴う必要があります。"); } EffectVariable rawVariable = manager.EffectFile.GetVariableByName(value); string typeName = rawVariable.GetVariableType().Description.TypeName.ToLower(); int loopCount = 0; switch (typeName) { case "bool": case "int": loopCount = rawVariable.AsScalar().GetInt(); break; case "float": loopCount = (int)rawVariable.AsScalar().GetFloat(); break; default: throw new InvalidMMEEffectShaderException("LoopByCountに指定できる変数の型はfloat,int,boolのいずれかです。"); } func.loopCount = loopCount; return(func); }
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); } } } } } }
public static IShaderPin GetShaderPin(EffectVariable var, IPluginHost host, IIOFactory iofactory) { string semantic = var.Description.Semantic; string type = var.GetVariableType().Description.TypeName; bool array = var.GetVariableType().Description.Elements > 0; //Exclude if immutable if (semantic != "") { return null; } if (array) { return arrayregistry.CreatePin(type, var, host, iofactory); } else { return stdregistry.CreatePin(type, var, host, iofactory); } }
public MaterialVariableInfo(string semantics, EffectVariable variable) { if (semantics == "SPECULARPOWER" || semantics == "EMISSIVE" || semantics == "TOONCOLOR") { this.Target = TargetObject.UnUsed; this.VariableType = variable.GetVariableType(); } }
public static IShaderPin GetShaderPin(EffectVariable var, IPluginHost host, IIOFactory iofactory) { string semantic = var.Description.Semantic; string type = var.GetVariableType().Description.TypeName; bool array = var.GetVariableType().Description.Elements > 0; //Exclude if immutable if (semantic != "") { return(null); } if (array) { return(arrayregistry.CreatePin(type, var, host, iofactory)); } else { return(stdregistry.CreatePin(type, var, host, iofactory)); } }
protected override void CreatePin(EffectVariable var) { if (var.AsInterface() != null) { if (var.LinkClasses().Length == 0) { if (var.GetVariableType().Description.Elements == 0) { /*InterfaceShaderPin ip = new InterfaceShaderPin(var, this.host, this.iofactory); * ip.ParentEffect = this.shader.DefaultEffect; * this.shaderpins.Add(var.Description.Name, ip);*/ } } else { RestrictedInterfaceShaderPin rp = new RestrictedInterfaceShaderPin(); rp.Initialize(this.iofactory, var); rp.ParentEffect = this.shader.DefaultEffect; this.shaderpins.Add(var.Description.Name, rp); } return; } //Search for render variable first if (ShaderPinFactory.IsRenderVariable(var)) { IRenderVariable rv = ShaderPinFactory.GetRenderVariable(var, this.host, this.iofactory); this.rendervariables.Add(rv.Name, rv); } else if (ShaderPinFactory.IsWorldRenderVariable(var)) { IWorldRenderVariable wv = ShaderPinFactory.GetWorldRenderVariable(var, this.host, this.iofactory); this.worldvariables.Add(wv.Name, wv); } else if (ShaderPinFactory.IsShaderPin(var)) { IShaderPin sp = traverseResult().Pins[var.Description.Name]; sp.Initialize(iofactory, var); if (sp != null) { this.shaderpins.Add(sp.Name, sp); } } else { if (var.Description.Semantic != "IMMUTABLE" && var.Description.Semantic != "") { this.customvariables.Add(new DX11CustomRenderVariable(var)); } } }
// System.Collections.Generic.SortedDictionary<int,Vector2> public void RebuildTextureCache() { texturecache.Clear(); for (int i = 0; i < this.shader.DefaultEffect.Description.GlobalVariableCount; i++) { EffectVariable var = this.shader.DefaultEffect.GetVariableByIndex(i); if (var.GetVariableType().Description.TypeName == "Texture2D") { EffectResourceVariable rv = var.AsResource(); texturecache.Add(rv); } } }
public DX11CustomRenderVariable(EffectVariable var) { this.Name = var.Description.Name; this.TypeName = var.GetVariableType().Description.TypeName; this.Semantic = var.Description.Semantic; var ha = var.GetAnnotationByName("help"); if (ha != null) { this.Help = ha.AsString().GetString(); } else { this.Help = ""; } }
/// <summary> /// テクスチャのアノテーション解釈に一般的に必要な項目を取得するメソッド /// </summary> /// <param name="variable">エフェクト変数</param> /// <param name="context">レンダーコンテキスト</param> /// <param name="defaultFormat"></param> /// <param name="defaultViewPortRatio"></param> /// <param name="width">テクスチャの幅</param> /// <param name="height">テクスチャの高さ</param> /// <param name="depth">テクスチャの深さ(ない場合は-1)</param> /// <param name="mip">mipレベル</param> /// <param name="textureFormat">指定されているフォーマット</param> public static void GetBasicTextureAnnotations(EffectVariable variable, RenderContext context, Format defaultFormat, Vector2 defaultViewPortRatio, bool isTextureSubscriber, out int width, out int height, out int depth, out int mip, out Format textureFormat) { width = -1; height = -1; depth = -1; mip = 0; textureFormat = defaultFormat; EffectVariable rawWidthVal = EffectParseHelper.getAnnotation(variable, "width", "int"); EffectVariable rawHeightVal = EffectParseHelper.getAnnotation(variable, "height", "int"); EffectVariable rawDepthVal = EffectParseHelper.getAnnotation(variable, "depth", "int"); if (rawWidthVal != null) { width = rawWidthVal.AsScalar().GetInt(); } if (rawHeightVal != null) { height = rawHeightVal.AsScalar().GetInt(); } if (rawDepthVal != null) { depth = rawDepthVal.AsScalar().GetInt(); } EffectVariable rawViewportRatio = EffectParseHelper.getAnnotation(variable, "viewportratio", "float2"); if (rawViewportRatio != null) { if (width != -1 || height != -1 || depth != -1) { throw new InvalidMMEEffectShaderException( string.Format("変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。", variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name)); } else { Vector4 rawRatio = rawViewportRatio.AsVector().GetVector(); Viewport vp = context.DeviceManager.Context.Rasterizer.GetViewports()[0]; width = (int)(vp.Width * rawRatio.X); height = (int)(vp.Height * rawRatio.Y); } } EffectVariable rawDimensions = EffectParseHelper.getAnnotation(variable, "dimension", "uint2/uint3"); if (rawDimensions != null) { if (width != -1 || height != -1 || depth != -1) { throw new InvalidMMEEffectShaderException( string.Format( "変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。", variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name)); } else { string typeName = rawDimensions.GetVariableType().Description.TypeName.ToLower(); if (typeName == "int2") { int[] rawDimension = rawDimensions.AsVector().GetIntVectorArray(2); width = rawDimension[0]; height = rawDimension[1]; } else { int[] rawDimension = rawDimensions.AsVector().GetIntVectorArray(3); width = rawDimension[0]; height = rawDimension[1]; depth = rawDimension[2]; } } } if (width == -1 || height == -1) { if (defaultViewPortRatio != Vector2.Zero) { Viewport port = context.DeviceManager.Context.Rasterizer.GetViewports()[0]; width = (int)(port.Width * defaultViewPortRatio.X); height = (int)(port.Height * defaultViewPortRatio.Y); } else { if (!isTextureSubscriber) { throw new InvalidMMEEffectShaderException(string.Format("width,heightのどちらかの指定は必須です。")); } } } EffectVariable rawMipLevel = EffectParseHelper.getAnnotation(variable, "MipLevels", "int"); EffectVariable rawLevel = EffectParseHelper.getAnnotation(variable, "levels", "int"); if (rawMipLevel != null && rawLevel != null) { throw new InvalidMMEEffectShaderException( string.Format("変数「{0} {1}」のミップマップレベルが重複して指定されています。「int Miplevels」、「int Levels」は片方しか指定できません。", variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name)); } else if (rawMipLevel != null || rawLevel != null) { EffectVariable mipVal = rawMipLevel ?? rawLevel; mip = mipVal.AsScalar().GetInt(); } EffectVariable rawFormat = EffectParseHelper.getAnnotation(variable, "format", "string"); if (rawFormat != null) { string formatString = rawFormat.AsString().GetString(); textureFormat = TextureFormat(formatString); } }
public ImageShaderPass(EffectPass pd) { this.Mips = false; this.CustomFormat = false; this.ScaleVector = new Vector2(1, 1); this.DoScale = false; this.Reference = eImageScaleReference.Previous; this.BlendPreset = ""; this.DepthPreset = ""; this.UseDepth = false; this.HasState = false; this.KeepTarget = false; this.Absolute = false; this.IterationCount = 1; this.ComputeData = new ImageComputeData(pd); EffectVariable var = pd.GetAnnotationByName("format"); if (var.IsValid) { string fmt = var.AsString().GetString(); this.CustomFormat = true; this.Format = (SlimDX.DXGI.Format)Enum.Parse(typeof(SlimDX.DXGI.Format), fmt, true); } var = pd.GetAnnotationByName("mips"); if (var.IsValid) { bool b = var.AsScalar().GetFloat() > 0.5f; this.Mips = b; } var = pd.GetAnnotationByName("scale"); if (var.IsValid) { if (var.GetVariableType().Description.Class == ShaderVariableClass.Scalar) { float s = var.AsScalar().GetFloat(); this.ScaleVector = new Vector2(s, s); this.DoScale = true; } if (var.GetVariableType().Description.Class == ShaderVariableClass.Vector) { Vector4 s = var.AsVector().GetVector(); this.ScaleVector = new Vector2(s.X, s.Y); this.DoScale = true; } var = pd.GetAnnotationByName("absolute"); if (var.IsValid && var.GetVariableType().Description.Class == ShaderVariableClass.Scalar) { this.Absolute = var.AsScalar().GetFloat() > 0.5f; } } var = pd.GetAnnotationByName("initial"); if (var.IsValid) { bool b = var.AsScalar().GetFloat() > 0.5f; this.Reference = b ? eImageScaleReference.Initial : eImageScaleReference.Previous; } var = pd.GetAnnotationByName("iterations"); if (var.IsValid) { try { int i = var.AsScalar().GetInt(); this.IterationCount = Math.Max(1, i); } catch { } } var = pd.GetAnnotationByName("clear"); if (var.IsValid) { bool b = var.AsScalar().GetFloat() > 0.5f; this.Clear = b; } var = pd.GetAnnotationByName("usedepth"); if (var.IsValid) { bool b = var.AsScalar().GetFloat() > 0.5f; this.UseDepth = b; } var = pd.GetAnnotationByName("keeptarget"); if (var.IsValid) { bool b = var.AsScalar().GetFloat() > 0.5f; this.KeepTarget = b; } var = pd.GetAnnotationByName("hasstate"); if (var.IsValid) { bool b = var.AsScalar().GetFloat() > 0.5f; this.HasState = b; } var = pd.GetAnnotationByName("blendpreset"); if (var.IsValid) { string blend = var.AsString().GetString(); this.BlendPreset = blend; } var = pd.GetAnnotationByName("depthpreset"); if (var.IsValid) { string depth = var.AsString().GetString(); this.DepthPreset = depth; } }
public static IWorldRenderVariable GetWorldRenderVariable(EffectVariable var, IPluginHost host, IIOFactory iofactory) { return worldregistry.CreatePin(var.GetVariableType().Description.TypeName, var.Description.Semantic, var.GetVariableType().Description.Elements > 0, var, host, iofactory); }
public void Initialize(IIOFactory factory, EffectVariable variable) { this.TypeName = variable.GetVariableType().Description.TypeName; this.Elements = variable.GetVariableType().Description.Elements; this.Name = variable.Description.Name; }
public void CheckType(EffectVariable variable) { EffectType type = variable.GetVariableType(); string typeName = type.Description.TypeName.ToLower(); VariableType valType; switch (typeName) { case "float4x4": valType = VariableType.Float4x4; break; case "float4": valType = VariableType.Float4; break; case "float3": valType = VariableType.Float3; break; case "float2": valType = VariableType.Float2; break; case "float": valType = VariableType.Float; break; case "uint": valType = VariableType.Uint; break; case "texture2d": valType = VariableType.Texture2D; break; case "texture": valType = VariableType.Texture; break; case "texture3d": valType = VariableType.Texture3D; break; case "texturecube": valType = VariableType.TextureCUBE; break; case "int": valType = VariableType.Int; break; case "bool": valType = VariableType.Bool; break; case "cbuffer": valType = VariableType.Cbuffer; break; default: throw new InvalidMMEEffectShaderException( string.Format("定義済みセマンティクス「{0}」に対して不適切な型「{1}」が使用されました。これは「{2}」であるべきセマンティクスです。", this.Semantics, typeName, getSupportedTypes())); } if (!this.Types.Contains(valType)) { throw new InvalidMMEEffectShaderException( string.Format("定義済みセマンティクス「{0}」に対して不適切な型「{1}」が使用されました。これは「{2}」であるべきセマンティクスです。", this.Semantics, typeName, getSupportedTypes())); } }
private void ParseStandardGlobal(Effect effect, EffectVariable sg) { if (!sg.Description.Name.ToLower().Equals("script")) { throw new InvalidMMEEffectShaderException( string.Format("STANDARDGLOBALセマンティクスの指定される変数名は\"Script\"である必要があります、指定された変数名は\"{0}\"でした。", sg.Description.Name)); } if (!sg.GetVariableType().Description.TypeName.ToLower().Equals("float")) { throw new InvalidMMEEffectShaderException( string.Format("STANDARDGLOBALセマンティクスの指定される変数型は\"float\"である必要があります、指定された変数名は\"{0}\"でした。", sg.GetVariableType().Description.TypeName.ToLower())); } if (sg.AsScalar().GetFloat() != 0.8f) { throw new InvalidMMEEffectShaderException( string.Format("STANDARDGLOBALセマンティクスの指定される値は\"0.8\"である必要があります、指定された値は\"{0}\"でした。", sg.AsScalar().GetFloat())); } //ScriptOutput analysis EffectVariable soVal = EffectParseHelper.getAnnotation(sg, "ScriptOutput", "string"); if (soVal != null) { if (!soVal.AsString().GetString().Equals("color")) { throw new InvalidMMEEffectShaderException( string.Format( "STANDARDGLOBALセマンティクスの指定される変数のアノテーション「string ScriptOutput」は、\"color\"でなくてはなりません。指定された値は\"{0}\"でした。", soVal.AsString().GetString().ToLower())); } } EffectVariable scVal = EffectParseHelper.getAnnotation(sg, "ScriptClass", "string"); if (scVal != null) { string sc = scVal.AsString().GetString(); switch (sc.ToLower()) { case "object": this.ScriptClass = ScriptClass.Object; break; case "scene": this.ScriptClass = ScriptClass.Scene; break; case "sceneorobject": this.ScriptClass = ScriptClass.SceneOrObject; break; default: throw new InvalidMMEEffectShaderException( string.Format( "STANDARDGLOBALセマンティクスの指定される変数のアノテーション「string ScriptClass」は、\"object\",\"scene\",\"sceneorobject\"でなくてはなりません。指定された値は\"{0}\"でした。(スペルミス?)", sc.ToLower())); } } EffectVariable sorVal = EffectParseHelper.getAnnotation(sg, "ScriptOrder", "string"); if (sorVal != null) { string sor = sorVal.AsString().GetString(); switch (sor.ToLower()) { case "standard": this.ScriptOrder = ScriptOrder.Standard; break; case "preprocess": this.ScriptOrder = ScriptOrder.Preprocess; break; case "postprocess": this.ScriptOrder = ScriptOrder.Postprocess; break; default: throw new InvalidMMEEffectShaderException( string.Format( "STANDARDGLOBALセマンティクスの指定される変数のアノテーション「string ScriptOrder」は、\"standard\",\"preprocess\",\"postprocess\"でなくてはなりません。指定された値は\"{0}\"でした。(スペルミス?)", sor.ToLower())); } } EffectVariable scrVal = EffectParseHelper.getAnnotation(sg, "Script", "string"); if (scrVal != null) { this.StandardGlobalScript = scrVal.AsString().GetString(); if (string.IsNullOrEmpty(this.StandardGlobalScript)) { for (int i = 0; i < effect.Description.TechniqueCount; i++) { this.SortedTechnique.Add(effect.GetTechniqueByIndex(i)); } } else { string[] scriptChunks = this.StandardGlobalScript.Split(';'); if (scriptChunks.Length == 1) { throw new InvalidMMEEffectShaderException( string.Format("STANDARDGLOBALセマンティクスの指定される変数のスクリプト「{0}」は読み込めませんでした。\";\"が足りません。", this.StandardGlobalScript)); } string targetScript = scriptChunks[scriptChunks.Length - 2]; //Non-script with a final semicolon is ignored if (this.StandardGlobalScript.IndexOf("?") == -1) //When not found { string[] args = targetScript.Split('='); if (args.Length > 2) { throw new InvalidMMEEffectShaderException( string.Format("STANDARDGLOBALセマンティクスの指定される変数のスクリプト「{0}」は読み込めませんでした。\"=\"の数が多すぎます。", targetScript)); } if (!args[0].ToLower().Equals("technique")) { throw new InvalidMMEEffectShaderException( string.Format( "STANDARDGLOBALセマンティクスの指定される変数のスクリプト「{0}」は読み込めませんでした。\"{1}\"は\"Technique\"であるべきです。(スペルミス?)", targetScript, args[0])); } EffectTechnique technique = effect.GetTechniqueByName(args[1]); if (technique != null) { this.SortedTechnique.Add(technique); } else { throw new InvalidMMEEffectShaderException( string.Format( "STANDARDGLOBALセマンティクスの指定される変数のスクリプト「{0}」は読み込めませんでした。テクニック\"{1}\"は存在しません。(スペルミス?)", targetScript, args[1])); } } else //?が見つかるとき { string[] args = targetScript.Split('?'); if (args.Length == 2) { string[] techniques = args[1].Split(':'); foreach (string technique in techniques) { EffectTechnique effectTechnique = effect.GetTechniqueByName(technique); if (effectTechnique != null) { this.SortedTechnique.Add(effectTechnique); } else { throw new InvalidMMEEffectShaderException( string.Format( "STANDARDGLOBALセマンティクスの指定される変数のスクリプト「{0}」は読み込めませんでした。テクニック\"{1}\"は見つかりません。(スペルミス?)", targetScript, technique)); } } } else if (args.Length > 2) { throw new InvalidMMEEffectShaderException( string.Format("STANDARDGLOBALセマンティクスの指定される変数のスクリプト「{0}」は読み込めませんでした。\"?\"の数が多すぎます。", targetScript)); } } if (scriptChunks.Length > 2) { Debug.WriteLine( string.Format( "STANDARDGLOBALセマンティクスの指定される変数のスクリプト「{0}」では、複数回Techniqueの代入が行われていますが、最後の代入以外は無視されます。", this.StandardGlobalScript)); } } } }
public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex) { VariableType type = 0; TargetObject target = TargetObject.UnUsed; string itemName = null; string typeName = variable.GetVariableType().Description.TypeName.ToLower(); switch (typeName) { case "bool": type = VariableType.Bool; break; case "float": type = VariableType.Float; break; case "float3": type = VariableType.Float3; break; case "float4": type = VariableType.Float4; break; case "float4x4": type = VariableType.Float4x4; break; default: break; } EffectVariable nameVariable = EffectParseHelper.getAnnotation(variable, "name", "string"); if (nameVariable == null) { throw new InvalidMMEEffectShaderException( string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」に対してはアノテーション「string name」は必須ですが、指定されませんでした。", typeName, variable.Description.Name)); } string name = nameVariable.AsString().GetString(); //Selfの場合はターゲットは自分自身となる if (name.ToLower().Equals("(self)")) { isSelf = true; } else { } //TODO (OffscreenOwner)がnameに指定されたときの対応 EffectVariable itemVariable = EffectParseHelper.getAnnotation(variable, "item", "string"); if (itemVariable != null) { itemName = itemVariable.AsString().GetString(); switch (itemName.ToLower()) { case "x": target = TargetObject.X; break; case "y": target = TargetObject.Y; break; case "z": target = TargetObject.Z; break; case "xyz": target = TargetObject.XYZ; break; case "rx": target = TargetObject.Rx; break; case "ry": target = TargetObject.Ry; break; case "rz": target = TargetObject.Rz; break; case "rxyz": target = TargetObject.Rxyz; break; case "si": target = TargetObject.Si; break; case "tr": target = TargetObject.Tr; break; default: target = type == VariableType.Float ? TargetObject.FaceName : TargetObject.BoneName; break; } if (NeedFloat.Contains(target) && type != VariableType.Float) { throw new InvalidMMEEffectShaderException( string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」にはアノテーション「string item=\"{2}\"」が適用されていますが、「{2}」の場合は「float {1}:CONTROLOBJECT」である必要があります。", typeName, variable.Description.Name, itemName)); } if (NeedFloat3.Contains(target) && type != VariableType.Float3) { throw new InvalidMMEEffectShaderException( string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」にはアノテーション「string item=\"{2}\"」が適用されていますが、「{2}」の場合は「float3 {1}:CONTROLOBJECT」である必要があります。", typeName, variable.Description.Name, itemName)); } } return(new ControlObjectSubscriber(type, itemName, name, target, isSelf)); }
public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex) { TextureSubscriber subscriber = new TextureSubscriber(); int width, height, depth, mip; string typeName = variable.GetVariableType().Description.TypeName.ToLower(); string type; Format format; TextureAnnotationParser.GetBasicTextureAnnotations(variable, context, Format.B8G8R8A8_UNorm, Vector2.Zero, true, out width, out height, out depth, out mip, out format); EffectVariable rawTypeVariable = EffectParseHelper.getAnnotation(variable, "ResourceType", "string"); EffectVariable rawStringVariable = EffectParseHelper.getAnnotation(variable, "ResourceName", "string"); if (rawTypeVariable != null) { switch (rawTypeVariable.AsString().GetString().ToLower()) { case "cube": if (!typeName.Equals("texturecube")) { throw new InvalidMMEEffectShaderException("ResourceTypeにはCubeが指定されていますが、型がtextureCUBEではありません。"); } else { type = "texturecube"; } break; case "2d": if (!typeName.Equals("texture2d") && !typeName.Equals("texture")) { throw new InvalidMMEEffectShaderException("ResourceTypeには2Dが指定されていますが、型がtexture2Dもしくはtextureではありません。"); } else { type = "texture2d"; } break; case "3d": if (!typeName.Equals("texture3d")) { throw new InvalidMMEEffectShaderException("ResourceTypeには3Dが指定されていますが、型がtexture3dではありません。"); } else { type = "texture3d"; } break; default: throw new InvalidMMEEffectShaderException("認識できないResourceTypeが指定されました。"); } } else { type = typeName; } if (rawStringVariable != null) { string resourceName = rawStringVariable.AsString().GetString(); ImageLoadInformation imgInfo = new ImageLoadInformation(); Stream stream; switch (type) { case "texture2d": imgInfo.Width = width; imgInfo.Height = height; imgInfo.MipLevels = mip; imgInfo.Format = format; imgInfo.Usage = ResourceUsage.Default; imgInfo.BindFlags = BindFlags.ShaderResource; imgInfo.CpuAccessFlags = CpuAccessFlags.None; stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName); if (stream != null) { subscriber.resourceTexture = Texture2D.FromStream(context.DeviceManager.Device, stream, (int)stream.Length); } break; case "texture3d": imgInfo.Width = width; imgInfo.Height = height; imgInfo.Depth = depth; imgInfo.MipLevels = mip; imgInfo.Format = format; imgInfo.Usage = ResourceUsage.Default; imgInfo.BindFlags = BindFlags.ShaderResource; imgInfo.CpuAccessFlags = CpuAccessFlags.None; stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName); if (stream != null) { subscriber.resourceTexture = Texture3D.FromStream(context.DeviceManager.Device, stream, (int)stream.Length); } break; case "texturecube": //TODO CUBEの場合に対応する //imgInfo.Width = width; //imgInfo.Height = height; //imgInfo.Depth = depth; //imgInfo.MipLevels = mip; //imgInfo.Format = format; //imgInfo.Usage=ResourceUsage.Default; //imgInfo.BindFlags=BindFlags.ShaderResource; //imgInfo.CpuAccessFlags=CpuAccessFlags.None; //stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName); //subscriber.resourceTexture=.FromStream(context.DeviceManager.Device, stream, (int)stream.Length); break; } } subscriber.resourceView = new ShaderResourceView(context.DeviceManager.Device, subscriber.resourceTexture); return(subscriber); }
private void CreatePin(EffectVariable var) { if (var.AsInterface() != null) { if (var.LinkClasses().Length == 0) { if (var.GetVariableType().Description.Elements == 0) { /*InterfaceShaderPin ip = new InterfaceShaderPin(var, this.host, this.iofactory); ip.ParentEffect = this.shader.DefaultEffect; this.shaderpins.Add(var.Description.Name, ip);*/ } } else { RestrictedInterfaceShaderPin rp = new RestrictedInterfaceShaderPin(); rp.Initialize(this.iofactory, var); rp.ParentEffect = this.shader.DefaultEffect; this.shaderpins.Add(var.Description.Name, rp); } return; } //Search for render variable first if (ShaderPinFactory.IsRenderVariable(var)) { IRenderVariable rv = ShaderPinFactory.GetRenderVariable(var, this.host,this.iofactory); this.rendervariables.Add(rv.Name, rv); } else if (ShaderPinFactory.IsWorldRenderVariable(var)) { IWorldRenderVariable wv = ShaderPinFactory.GetWorldRenderVariable(var, this.host, this.iofactory); this.worldvariables.Add(wv.Name, wv); } else if (ShaderPinFactory.IsShaderPin(var)) { IShaderPin sp = ShaderPinFactory.GetShaderPin(var, this.host, this.iofactory); if (sp != null) { this.shaderpins.Add(sp.Name, sp); } } else { if (var.Description.Semantic != "IMMUTABLE" && var.Description.Semantic != "") { this.customvariables.Add(new DX11CustomRenderVariable(var)); } } }
public static IWorldRenderVariable GetWorldRenderVariable(EffectVariable var, IPluginHost host, IIOFactory iofactory) { return(worldregistry.CreatePin(var.GetVariableType().Description.TypeName, var.Description.Semantic, var.GetVariableType().Description.Elements > 0, var, host, iofactory)); }
public DX11CustomRenderVariable(EffectVariable var) { this.Name = var.Description.Name; this.TypeName = var.GetVariableType().Description.TypeName; this.Semantic = var.Description.Semantic; }
protected override void ProcessAttribute(InputAttribute attr, EffectVariable var) { array = new T[var.GetVariableType().Description.Elements]; attr.BinSize = array.Length; }