static ShaderVariableType GetVariableType(ShaderParamType paramType) { switch (paramType) { case ShaderParamType.Bool: return(ShaderVariableType.Bool); case ShaderParamType.Float: return(ShaderVariableType.Float); case ShaderParamType.Half: return(ShaderVariableType.Float); case ShaderParamType.Int: return(ShaderVariableType.Int); case ShaderParamType.Short: return(ShaderVariableType.Int); case ShaderParamType.TypeCount: return(ShaderVariableType.Int); //TODO case ShaderParamType.UInt: return(ShaderVariableType.UInt); //TODO default: throw new Exception($"Unexpected param type {paramType}"); } }
public void SetParam(ShaderParamType type, string key, string value) { switch (type) { case ShaderParamType.Color: string[] colSplit = value.Split(','); float r = colSplit.Length > 0 ? float.Parse(colSplit[0]) : 1.0f; float g = colSplit.Length > 1 ? float.Parse(colSplit[1]) : 1.0f; float b = colSplit.Length > 2 ? float.Parse(colSplit[2]) : 1.0f; float a = colSplit.Length > 3 ? float.Parse(colSplit[3]) : 1.0f; this.SetColor(key, new Color(r, g, b, a)); break; case ShaderParamType.Number: float floatval = float.Parse(value); this.SetFloat(key, floatval); break; case ShaderParamType.Texture: Texture tex = Texture.Create(value); this.SetTexture(key, tex); break; case ShaderParamType.Vector: string[] vecSplit = value.Split(','); double x = vecSplit.Length > 0 ? double.Parse(vecSplit[0]) : 0.0; double y = vecSplit.Length > 1 ? double.Parse(vecSplit[1]) : 0.0; double z = vecSplit.Length > 2 ? double.Parse(vecSplit[2]) : 0.0; this.SetVector(key, new Vector3(x, y, z)); break; } }
public VectorParameter(string name, ShaderParamType type, int index, int dimension) { Name = name; NameIndex = -1; Type = type; Index = index; Dim = (byte)dimension; }
public MatrixParameter(string name, ShaderParamType type, int index, int rowCount) { Name = name; NameIndex = -1; Type = type; Index = index; RowCount = (byte)rowCount; }
private void WriteParamData(BinaryDataWriter writer, ShaderParamType type, object data) { if (data is float) { writer.Write((float)data); } else if (data is uint) { writer.Write((uint)data); } else if (data is int) { writer.Write((int)data); } else if (data is bool) { writer.Write((bool)data); } else if (data is float[]) { writer.Write((float[])data); } else if (data is bool[]) { writer.Write((bool[])data); } else if (data is uint[]) { writer.Write((uint[])data); } else if (data is int[]) { writer.Write((int[])data); } else if (data is Srt2D) { writer.Write(((Srt2D)data).Scaling); writer.Write(((Srt2D)data).Rotation); writer.Write(((Srt2D)data).Translation); } else if (data is Srt3D) { writer.Write(((Srt3D)data).Scaling); writer.Write(((Srt3D)data).Rotation); writer.Write(((Srt3D)data).Translation); } else if (data is TexSrt) { writer.Write(((TexSrt)data).Mode, false); writer.Write(((TexSrt)data).Scaling); writer.Write(((TexSrt)data).Rotation); writer.Write(((TexSrt)data).Translation); if (type == ShaderParamType.TexSrtEx) { writer.Write(0); //pointer at runtime } } }
public VectorParameter(string name, ShaderParamType type, int index, int columns) { Name = name; NameIndex = -1; Index = index; ArraySize = 0; Type = type; Dim = (byte)columns; }
public MatrixParameter(string name, ShaderParamType type, int index, int rowCount, int columnCount) { Name = name; NameIndex = -1; Index = index; ArraySize = 0; Type = type; RowCount = (byte)rowCount; ColumnCount = (byte)columnCount; }
static void InsertKey(BfresMaterialAnim.ParamAnimGroup group, ShaderParamType type, float frame, object value) { //This method will insert tracks to the total amount of possible values for that parameter //Any unecessary values will be optimized later switch (type) { case ShaderParamType.TexSrt: case ShaderParamType.TexSrtEx: { var input = (TextureSRT)value; group.InsertKey(frame, 0, (int)input.Mode, 0, 0); group.InsertKey(frame, 4, input.ScaleX, 0, 0); group.InsertKey(frame, 8, input.ScaleY, 0, 0); group.InsertKey(frame, 12, input.Rotate, 0, 0); group.InsertKey(frame, 16, input.TranslateX, 0, 0); group.InsertKey(frame, 20, input.TranslateY, 0, 0); } break; case ShaderParamType.Float: { var input = (float)value; group.InsertKey(frame, 0, input, 0, 0); } break; case ShaderParamType.Float2: { var input = (Vector2)value; group.InsertKey(frame, 0, input.X, 0, 0); group.InsertKey(frame, 4, input.Y, 0, 0); } break; case ShaderParamType.Float3: { var input = (Vector3)value; group.InsertKey(frame, 0, input.X, 0, 0); group.InsertKey(frame, 4, input.Y, 0, 0); group.InsertKey(frame, 8, input.Z, 0, 0); } break; case ShaderParamType.Float4: { var input = (Vector4)value; group.InsertKey(frame, 0, input.X, 0, 0); group.InsertKey(frame, 4, input.Y, 0, 0); group.InsertKey(frame, 8, input.Z, 0, 0); group.InsertKey(frame, 12, input.W, 0, 0); } break; } }
private object ParseShaderParamFor(YamlNode node, ShaderParamType type) { if (!GameController.OnGodot) { throw new NotImplementedException(); } switch (type) { case ShaderParamType.Void: throw new NotSupportedException(); case ShaderParamType.Bool: return(node.AsBool()); case ShaderParamType.Int: case ShaderParamType.UInt: return(node.AsInt()); case ShaderParamType.Float: return(node.AsFloat()); case ShaderParamType.Vec2: return(node.AsVector2().Convert()); case ShaderParamType.Vec3: return(node.AsVector3().Convert()); case ShaderParamType.Vec4: try { return(node.AsColor().Convert()); } catch { var vec4 = node.AsVector4(); return(new Godot.Quat(vec4.X, vec4.Y, vec4.Z, vec4.W)); } case ShaderParamType.Sampler2D: var path = node.AsResourcePath(); var resc = IoCManager.Resolve <IResourceCache>(); return(resc.GetResource <TextureResource>(path).Texture.GodotTexture); // If something's not handled here, then that's probably because I was lazy. default: throw new NotImplementedException(); } }
private static ShaderParam CreateParam(string name, string[] lines, int index, ShaderParamType type) { var exitCondition = new Func<string, int, bool>((line, i) => line == "" || i < 0); var param = new ShaderParam { Name = name, Summary = GetValue("summary", lines, index, -1, exitCondition), MinValue = GetValue("minValue", lines, index, -1, exitCondition), MaxValue = GetValue("maxValue", lines, index, -1, exitCondition), DefaultValue = GetValue("defaultValue", lines, index, -1, exitCondition), Type = type }; return param; }
public void SetShaderParameter(string name, ShaderParamType type, object value) { ShaderParam param = new ShaderParam(); param.Name = name; param.DataValue = value; param.Type = type; if (!ShaderParams.ContainsKey(name)) { ShaderParams.Add(name, param); } else { ShaderParams[name] = param; } }
static bool CopyShaderParam(MPlug from, MPlug to, ShaderParamType spt = ShaderParamType.Color) { if (from == null || to == null) { return(false); } MPlugArray plugArr = new MPlugArray(); from.connectedTo(plugArr, true, false); if (plugArr.length == 0) { switch (spt) { case ShaderParamType.Color: { to.child(0).setFloat(from.child(0).asFloat()); to.child(1).setFloat(from.child(1).asFloat()); to.child(2).setFloat(from.child(2).asFloat()); break; } case ShaderParamType.Float: { to.setFloat(from.asFloat()); break; } } } else { MDGModifier dGModifier = new MDGModifier(); Debug.Log(from.source.partialName(true)); dGModifier.connect(from.source, to); dGModifier.doIt(); } return(true); }
public ResU.ShaderParamType SetTypeWiiU(ShaderParamType type) { return((ResU.ShaderParamType)System.Enum.Parse(typeof(ResU.ShaderParamType), type.ToString())); }
private object ReadParamData(ShaderParamType type, BinaryDataReader reader) { switch (type) { case ShaderParamType.Bool: return(reader.ReadBoolean()); case ShaderParamType.Bool2: return(reader.ReadBooleans(2)); case ShaderParamType.Bool3: return(reader.ReadBooleans(3)); case ShaderParamType.Bool4: return(reader.ReadBooleans(4)); case ShaderParamType.Float: return(reader.ReadSingle()); case ShaderParamType.Float2: return(reader.ReadSingles(2)); case ShaderParamType.Float2x2: return(reader.ReadSingles(2 * 2)); case ShaderParamType.Float2x3: return(reader.ReadSingles(2 * 3)); case ShaderParamType.Float2x4: return(reader.ReadSingles(2 * 4)); case ShaderParamType.Float3: return(reader.ReadSingles(3)); case ShaderParamType.Float3x2: return(reader.ReadSingles(3 * 2)); case ShaderParamType.Float3x3: return(reader.ReadSingles(3 * 3)); case ShaderParamType.Float3x4: return(reader.ReadSingles(3 * 4)); case ShaderParamType.Float4: return(reader.ReadSingles(4)); case ShaderParamType.Float4x2: return(reader.ReadSingles(4 * 2)); case ShaderParamType.Float4x3: return(reader.ReadSingles(4 * 3)); case ShaderParamType.Float4x4: return(reader.ReadSingles(4 * 4)); case ShaderParamType.Int: return(reader.ReadInt32()); case ShaderParamType.Int2: return(reader.ReadInt32s(2)); case ShaderParamType.Int3: return(reader.ReadInt32s(3)); case ShaderParamType.Int4: return(reader.ReadInt32s(4)); case ShaderParamType.UInt: return(reader.ReadInt32()); case ShaderParamType.UInt2: return(reader.ReadInt32s(2)); case ShaderParamType.UInt3: return(reader.ReadInt32s(3)); case ShaderParamType.UInt4: return(reader.ReadInt32s(4)); case ShaderParamType.Reserved2: return(reader.ReadBytes(2)); case ShaderParamType.Reserved3: return(reader.ReadBytes(3)); case ShaderParamType.Reserved4: return(reader.ReadBytes(4)); case ShaderParamType.Srt2D: return(new Srt2D() { Scaling = reader.ReadVector2F(), Rotation = reader.ReadSingle(), Translation = reader.ReadVector2F(), }); case ShaderParamType.Srt3D: return(new Srt3D() { Scaling = reader.ReadVector3F(), Rotation = reader.ReadVector3F(), Translation = reader.ReadVector3F(), }); case ShaderParamType.TexSrt: return(new TexSrt() { Mode = (TexSrtMode)reader.ReadInt32(), Scaling = reader.ReadVector2F(), Rotation = reader.ReadSingle(), Translation = reader.ReadVector2F(), }); case ShaderParamType.TexSrtEx: return(new TexSrtEx() { Mode = (TexSrtMode)reader.ReadInt32(), Scaling = reader.ReadVector2F(), Rotation = reader.ReadSingle(), Translation = reader.ReadVector2F(), MatrixPointer = reader.ReadUInt32(), }); } return(0); }
public void Read(AssetStream stream) { int magic = stream.ReadInt32(); if (magic != GetMagicNumber(stream.Version)) { throw new Exception($"Magic number {magic} doesn't match"); } ProgramType = (ShaderGpuProgramType)stream.ReadInt32(); int unknown1 = stream.ReadInt32(); int unknown2 = stream.ReadInt32(); int unknown3 = stream.ReadInt32(); if (IsReadUnknown4(stream.Version)) { int unknown4 = stream.ReadInt32(); } m_keywords = stream.ReadStringArray(); m_programData = stream.ReadByteArray(); stream.AlignStream(AlignType.Align4); int sourceMap = stream.ReadInt32(); int bindCount = stream.ReadInt32(); ShaderBindChannel[] channels = new ShaderBindChannel[bindCount]; for (int i = 0; i < bindCount; i++) { ShaderChannel source = (ShaderChannel)stream.ReadUInt32(); VertexComponent target = (VertexComponent)stream.ReadUInt32(); ShaderBindChannel channel = new ShaderBindChannel(source, target); channels[i] = channel; sourceMap |= 1 << (int)source; } BindChannels = new ParserBindChannels(channels, sourceMap); List <VectorParameter> vectors = new List <VectorParameter>(); List <MatrixParameter> matrices = new List <MatrixParameter>(); List <TextureParameter> textures = new List <TextureParameter>(); List <BufferBinding> buffers = new List <BufferBinding>(); List <UAVParameter> uavs = IsReadUAVParameters(stream.Version) ? new List <UAVParameter>() : null; List <SamplerParameter> samplers = IsReadSamplerParameters(stream.Version) ? new List <SamplerParameter>() : null; List <BufferBinding> constBindings = new List <BufferBinding>(); List <StructParameter> structs = IsReadStructParameters(stream.Version) ? new List <StructParameter>() : null; int paramGroupCount = stream.ReadInt32(); m_constantBuffers = new ConstantBuffer[paramGroupCount - 1]; for (int i = 0; i < paramGroupCount; i++) { vectors.Clear(); matrices.Clear(); string name = stream.ReadStringAligned(); int usedSize = stream.ReadInt32(); int paramCount = stream.ReadInt32(); for (int j = 0; j < paramCount; j++) { string paramName = stream.ReadStringAligned(); ShaderParamType paramType = (ShaderParamType)stream.ReadInt32(); int rows = stream.ReadInt32(); int dimension = stream.ReadInt32(); bool isMatrix = stream.ReadInt32() > 0; int arraySize = stream.ReadInt32(); int index = stream.ReadInt32(); if (isMatrix) { MatrixParameter matrix = IsAllParamArgs(stream.Version) ? new MatrixParameter(paramName, paramType, index, arraySize, rows) : new MatrixParameter(paramName, paramType, index, rows); matrices.Add(matrix); } else { VectorParameter vector = IsAllParamArgs(stream.Version) ? new VectorParameter(paramName, paramType, index, arraySize, dimension) : new VectorParameter(paramName, paramType, index, dimension); vectors.Add(vector); } } if (i == 0) { m_vectorParameters = vectors.ToArray(); m_matrixParameters = matrices.ToArray(); } else { ConstantBuffer constBuffer = new ConstantBuffer(name, matrices.ToArray(), vectors.ToArray(), usedSize); m_constantBuffers[i - 1] = constBuffer; } if (IsReadStructParameters(stream.Version)) { int structCount = stream.ReadInt32(); for (int j = 0; j < structCount; j++) { vectors.Clear(); matrices.Clear(); string structName = stream.ReadStringAligned(); int index = stream.ReadInt32(); int arraySize = stream.ReadInt32(); int structSize = stream.ReadInt32(); int strucParamCount = stream.ReadInt32(); for (int k = 0; k < strucParamCount; k++) { string paramName = stream.ReadStringAligned(); paramName = $"{structName}.{paramName}"; ShaderParamType paramType = (ShaderParamType)stream.ReadInt32(); int rows = stream.ReadInt32(); int dimension = stream.ReadInt32(); bool isMatrix = stream.ReadInt32() > 0; int vectorArraySize = stream.ReadInt32(); int paramIndex = stream.ReadInt32(); if (isMatrix) { MatrixParameter matrix = IsAllParamArgs(stream.Version) ? new MatrixParameter(paramName, paramType, paramIndex, vectorArraySize, rows) : new MatrixParameter(paramName, paramType, paramIndex, rows); matrices.Add(matrix); } else { VectorParameter vector = IsAllParamArgs(stream.Version) ? new VectorParameter(paramName, paramType, paramIndex, vectorArraySize, dimension) : new VectorParameter(paramName, paramType, paramIndex, dimension); vectors.Add(vector); } } StructParameter @struct = new StructParameter(structName, index, arraySize, structSize, vectors.ToArray(), matrices.ToArray()); structs.Add(@struct); } } } int paramGroup2Count = stream.ReadInt32(); for (int i = 0; i < paramGroup2Count; i++) { string name = stream.ReadStringAligned(); int type = stream.ReadInt32(); int index = stream.ReadInt32(); int extraValue = stream.ReadInt32(); if (type == 0) { TextureParameter texture; if (IsReadMultiSampled(stream.Version)) { bool isMultiSampled = stream.ReadUInt32() > 0; texture = new TextureParameter(name, index, isMultiSampled, extraValue); } else { texture = new TextureParameter(name, index, extraValue); } textures.Add(texture); } else if (type == 1) { BufferBinding binding = new BufferBinding(name, index); constBindings.Add(binding); } else if (type == 2) { BufferBinding buffer = new BufferBinding(name, index); buffers.Add(buffer); } else if (type == 3 && IsReadUAVParameters(stream.Version)) { UAVParameter uav = new UAVParameter(name, index, extraValue); uavs.Add(uav); } else if (type == 4 && IsReadSamplerParameters(stream.Version)) { SamplerParameter sampler = new SamplerParameter((uint)extraValue, index); samplers.Add(sampler); } else { throw new Exception($"Unupported parameter type {type}"); } } m_textureParameters = textures.ToArray(); m_bufferParameters = buffers.ToArray(); if (IsReadUAVParameters(stream.Version)) { m_UAVParameters = uavs.ToArray(); } if (IsReadSamplerParameters(stream.Version)) { m_samplerParameters = samplers.ToArray(); } m_constantBufferBindings = constBindings.ToArray(); if (IsReadStructParameters(stream.Version)) { m_structParameters = structs.ToArray(); } }
public VectorParameter(string name, ShaderParamType type, int index, int arraySize, int dimension) : this(name, type, index, dimension) { ArraySize = arraySize; }
private static bool IsParamDeclaration(string line, ShaderParamType shaderParamType, out string paramName) { var strippedLine = line.Replace("extern ", "").Replace("uniform ", ""); paramName = GetParamName(strippedLine); var semicolonIndex = strippedLine.IndexOf(";"); var arrayIndex = strippedLine.IndexOf("["); if (arrayIndex != -1 && arrayIndex < semicolonIndex) return false; return strippedLine.StartsWith(shaderParamType.Name + " ") && paramName != null && !paramName.Contains("("); }
/// <summary> /// /// </summary> /// <param name="writer"></param> /// <param name="reader"></param> /// <param name="Size"></param> /// <param name="type"></param> public static void WriteValue(XmlWriter writer, BinaryDataReader reader, int Size, ShaderParamType type) { switch (type) { case ShaderParamType.Bool: case ShaderParamType.Bool2: case ShaderParamType.Bool3: case ShaderParamType.Bool4: ValueBool = reader.ReadBooleans(Size / sizeof(bool)); string tempBools = ""; foreach (bool value in ValueBool) { tempBools += (value.ToString() + ','); } tempBools = tempBools.Trim(','); writer.WriteAttributeString("Value", tempBools); break; case ShaderParamType.Float: case ShaderParamType.Float2: case ShaderParamType.Float3: case ShaderParamType.Float4: case ShaderParamType.Float2x2: case ShaderParamType.Float2x3: case ShaderParamType.Float2x4: case ShaderParamType.Float4x2: case ShaderParamType.Float4x3: case ShaderParamType.Float4x4: ValueFloat = reader.ReadSingles(Size / sizeof(float)); string tempFloat = ""; foreach (float value in ValueFloat) { tempFloat += (value.ToString() + ','); } tempFloat = tempFloat.Trim(','); writer.WriteAttributeString("Value", tempFloat); break; case ShaderParamType.Int: case ShaderParamType.Int2: case ShaderParamType.Int3: case ShaderParamType.Int4: ValueInt = reader.ReadInt32s(Size / sizeof(int)); string tempInts = ""; foreach (int value in ValueInt) { tempInts += (value.ToString() + ','); } tempInts = tempInts.Trim(','); writer.WriteAttributeString("Value", tempInts); break; case ShaderParamType.Reserved2: case ShaderParamType.Reserved3: case ShaderParamType.Reserved4: ValueReserved = reader.ReadBytes(Size / sizeof(byte)); string tempBytes = ""; foreach (byte value in ValueReserved) { tempBytes += (value.ToString() + ','); } tempBytes = tempBytes.Trim(','); writer.WriteAttributeString("Value", tempBytes); break; case ShaderParamType.Srt2D: ReadSRT2D(reader); string srt2DScaling = ""; srt2DScaling += (ValueSrt2D.Scaling.X.ToString() + ','); srt2DScaling += (ValueSrt2D.Scaling.Y.ToString()); writer.WriteAttributeString("ValueScaleXY", srt2DScaling); string srt2DRot = ""; srt2DRot += (ValueSrt2D.Rotation.ToString()); writer.WriteAttributeString("ValueRotationX", srt2DRot); string srt2DTranslation = ""; srt2DTranslation += (ValueSrt2D.Translation.X.ToString() + ','); srt2DTranslation += (ValueSrt2D.Translation.Y.ToString()); writer.WriteAttributeString("ValueTranslationXY", srt2DTranslation); break; case ShaderParamType.Srt3D: ReadSRT3D(reader); string srt3DScaling = ""; srt3DScaling += (ValueSrt3D.Scaling.X.ToString() + ','); srt3DScaling += (ValueSrt3D.Scaling.Y.ToString() + ','); srt3DScaling += (ValueSrt3D.Scaling.Z.ToString()); writer.WriteAttributeString("ValueScaleXYZ", srt3DScaling); string srt3DRot = ""; srt3DRot += (ValueSrt3D.Rotation.X.ToString() + ','); srt3DRot += (ValueSrt3D.Rotation.Y.ToString() + ','); srt3DRot += (ValueSrt3D.Rotation.Z.ToString()); writer.WriteAttributeString("ValueRotationXYZ", srt3DRot); string srt3DTranslation = ""; srt3DTranslation += (ValueSrt3D.Translation.X.ToString() + ','); srt3DTranslation += (ValueSrt3D.Translation.Y.ToString() + ','); srt3DTranslation += (ValueSrt3D.Translation.Z.ToString()); writer.WriteAttributeString("ValueTranslationXYZ", srt3DTranslation); break; case ShaderParamType.TexSrt: ReadTexSrt(reader); writer.WriteAttributeString("Mode", ValueTexSrt.Mode.ToString()); string texScaling = ""; texScaling += (ValueTexSrt.Scaling.X.ToString() + ','); texScaling += (ValueTexSrt.Scaling.Y.ToString()); writer.WriteAttributeString("ValueScaleXY", texScaling); string texRot = ""; texRot += (ValueTexSrt.Rotation.ToString()); writer.WriteAttributeString("ValueRotationX", texRot); string texTranslation = ""; texTranslation += (ValueTexSrt.Translation.X.ToString() + ','); texTranslation += (ValueTexSrt.Translation.Y.ToString()); writer.WriteAttributeString("ValueTranslationXY", texTranslation); break; case ShaderParamType.TexSrtEx: ReadTexSrtEx(reader); writer.WriteAttributeString("Mode", ValueTexSrtEx.Mode.ToString()); string texExScaling = ""; texExScaling += (ValueTexSrtEx.Scaling.X.ToString() + ','); texExScaling += (ValueTexSrtEx.Scaling.Y.ToString()); writer.WriteAttributeString("ValueScaleXY", texExScaling); string texExRot = ""; texExRot += (ValueTexSrtEx.Rotation.ToString()); writer.WriteAttributeString("ValueRotationX", texExRot); string texExTranslation = ""; texExTranslation += (ValueTexSrtEx.Translation.X.ToString() + ','); texExTranslation += (ValueTexSrtEx.Translation.Y.ToString()); writer.WriteAttributeString("ValueTranslationXY", texExTranslation); writer.WriteAttributeString("MatrixPointer", ValueTexSrtEx.MatrixPointer.ToString()); break; case ShaderParamType.UInt: case ShaderParamType.UInt2: case ShaderParamType.UInt3: case ShaderParamType.UInt4: ValueUint = reader.ReadUInt32s(Size / sizeof(uint)); string tempUints = ""; foreach (uint value in ValueUint) { tempUints += (value.ToString() + ','); } tempUints = tempUints.Trim(','); writer.WriteAttributeString("Value", tempUints); break; // Invalid default: //throw new ArgumentException($"Invalid {nameof(ShaderParamType)} {type}.", nameof(type)); break; } }
public VectorParameter(string name, ShaderParamType type, int index, int arraySize, int columns) : this(name, type, index, columns) { ArraySize = arraySize; }
public ShaderParam(ShaderParamType type, string name, string longName, object value) { Type = type; Location = -1; Name = name; LongName = longName; TextureName = null; Set(value); }
internal bool TryGetShaderParamType(string paramName, out ShaderParamType shaderParamType) { return(Parameters.TryGetValue(paramName, out shaderParamType)); }
public void CopyFrom(ShaderParam param) { Type = param.Type; Name = param.Name; LongName = param.LongName; IntValue = param.IntValue; FloatValue = param.FloatValue; Vec2Value = param.Vec2Value; Vec3Value = param.Vec3Value; Vec4Value = param.Vec4Value; MatrixValue = param.MatrixValue; TexUnit = param.TexUnit; TextureName = param.TextureName; }
public void Read(AssetReader reader) { int magic = reader.ReadInt32(); if (magic != GetMagicNumber(reader.Version)) { throw new Exception($"Magic number {magic} doesn't match"); } ProgramType = (ShaderGpuProgramType)reader.ReadInt32(); int unknown1 = reader.ReadInt32(); int unknown2 = reader.ReadInt32(); int unknown3 = reader.ReadInt32(); if (HasUnknown4(reader.Version)) { int unknown4 = reader.ReadInt32(); } GlobalKeywords = reader.ReadStringArray(); if (HasLocalKeywords(reader.Version)) { LocalKeywords = reader.ReadStringArray(); } ProgramData = reader.ReadByteArray(); reader.AlignStream(); int sourceMap = reader.ReadInt32(); int bindCount = reader.ReadInt32(); ShaderBindChannel[] channels = new ShaderBindChannel[bindCount]; for (int i = 0; i < bindCount; i++) { ShaderChannel source = (ShaderChannel)reader.ReadUInt32(); VertexComponent target = (VertexComponent)reader.ReadUInt32(); ShaderBindChannel channel = new ShaderBindChannel(source, target); channels[i] = channel; sourceMap |= 1 << (int)source; } BindChannels = new ParserBindChannels(channels, sourceMap); List <VectorParameter> vectors = new List <VectorParameter>(); List <MatrixParameter> matrices = new List <MatrixParameter>(); List <TextureParameter> textures = new List <TextureParameter>(); List <VectorParameter> structVectors = new List <VectorParameter>(); List <MatrixParameter> structMatrices = new List <MatrixParameter>(); List <BufferBinding> buffers = new List <BufferBinding>(); List <UAVParameter> uavs = HasUAVParameters(reader.Version) ? new List <UAVParameter>() : null; List <SamplerParameter> samplers = HasSamplerParameters(reader.Version) ? new List <SamplerParameter>() : null; List <BufferBinding> constBindings = new List <BufferBinding>(); List <StructParameter> structs = new List <StructParameter>(); int paramGroupCount = reader.ReadInt32(); ConstantBuffers = new ConstantBuffer[paramGroupCount - 1]; for (int i = 0; i < paramGroupCount; i++) { vectors.Clear(); matrices.Clear(); structs.Clear(); string name = reader.ReadString(); int usedSize = reader.ReadInt32(); int paramCount = reader.ReadInt32(); for (int j = 0; j < paramCount; j++) { string paramName = reader.ReadString(); ShaderParamType paramType = (ShaderParamType)reader.ReadInt32(); int rows = reader.ReadInt32(); int columns = reader.ReadInt32(); bool isMatrix = reader.ReadInt32() > 0; int arraySize = reader.ReadInt32(); int index = reader.ReadInt32(); if (isMatrix) { MatrixParameter matrix = IsAllParamArgs(reader.Version) ? new MatrixParameter(paramName, paramType, index, arraySize, rows, columns) : new MatrixParameter(paramName, paramType, index, rows, columns); matrices.Add(matrix); } else { VectorParameter vector = IsAllParamArgs(reader.Version) ? new VectorParameter(paramName, paramType, index, arraySize, columns) : new VectorParameter(paramName, paramType, index, columns); vectors.Add(vector); } } if (HasStructParameters(reader.Version)) { int structCount = reader.ReadInt32(); for (int j = 0; j < structCount; j++) { structVectors.Clear(); structMatrices.Clear(); string structName = reader.ReadString(); int index = reader.ReadInt32(); int arraySize = reader.ReadInt32(); int structSize = reader.ReadInt32(); int strucParamCount = reader.ReadInt32(); for (int k = 0; k < strucParamCount; k++) { string paramName = reader.ReadString(); paramName = $"{structName}.{paramName}"; ShaderParamType paramType = (ShaderParamType)reader.ReadInt32(); int rows = reader.ReadInt32(); int columns = reader.ReadInt32(); bool isMatrix = reader.ReadInt32() > 0; int vectorArraySize = reader.ReadInt32(); int paramIndex = reader.ReadInt32(); if (isMatrix) { MatrixParameter matrix = IsAllParamArgs(reader.Version) ? new MatrixParameter(paramName, paramType, paramIndex, vectorArraySize, rows, columns) : new MatrixParameter(paramName, paramType, paramIndex, rows, columns); structMatrices.Add(matrix); } else { VectorParameter vector = IsAllParamArgs(reader.Version) ? new VectorParameter(paramName, paramType, paramIndex, vectorArraySize, columns) : new VectorParameter(paramName, paramType, paramIndex, columns); structVectors.Add(vector); } } StructParameter @struct = new StructParameter(structName, index, arraySize, structSize, structVectors.ToArray(), structMatrices.ToArray()); structs.Add(@struct); } } if (i == 0) { VectorParameters = vectors.ToArray(); MatrixParameters = matrices.ToArray(); StructParameters = structs.ToArray(); } else { ConstantBuffer constBuffer = new ConstantBuffer(name, matrices.ToArray(), vectors.ToArray(), structs.ToArray(), usedSize); ConstantBuffers[i - 1] = constBuffer; } } int paramGroup2Count = reader.ReadInt32(); for (int i = 0; i < paramGroup2Count; i++) { string name = reader.ReadString(); int type = reader.ReadInt32(); int index = reader.ReadInt32(); int extraValue = reader.ReadInt32(); if (type == 0) { TextureParameter texture; if (HasMultiSampled(reader.Version)) { uint textureExtraValue = reader.ReadUInt32(); bool isMultiSampled = (textureExtraValue & 1) == 1; byte dimension = (byte)(textureExtraValue >> 1); texture = new TextureParameter(name, index, dimension, extraValue, isMultiSampled); } else { byte dimension = unchecked ((byte)extraValue); int samplerIndex = extraValue >> 8; if (samplerIndex == 0xFFFFFF) { samplerIndex = -1; } texture = new TextureParameter(name, index, dimension, samplerIndex); } textures.Add(texture); } else if (type == 1) { BufferBinding binding = new BufferBinding(name, index); constBindings.Add(binding); } else if (type == 2) { BufferBinding buffer = new BufferBinding(name, index); buffers.Add(buffer); } else if (type == 3 && HasUAVParameters(reader.Version)) { UAVParameter uav = new UAVParameter(name, index, extraValue); uavs.Add(uav); } else if (type == 4 && HasSamplerParameters(reader.Version)) { SamplerParameter sampler = new SamplerParameter((uint)extraValue, index); samplers.Add(sampler); } else { throw new Exception($"Unupported parameter type {type}"); } } TextureParameters = textures.ToArray(); BufferParameters = buffers.ToArray(); if (HasUAVParameters(reader.Version)) { UAVParameters = uavs.ToArray(); } if (HasSamplerParameters(reader.Version)) { SamplerParameters = samplers.ToArray(); } ConstantBufferBindings = constBindings.ToArray(); if (HasStructParameters(reader.Version)) { StructParameters = structs.ToArray(); } }
public MatrixParameter(string name, ShaderParamType type, int index, int arraySize, int rowCount, int columnCount) : this(name, type, index, rowCount, columnCount) { ArraySize = arraySize; }