예제 #1
0
 public void WriteBuffer(VFXUniformMapper mapper)
 {
     foreach (var buffer in mapper.buffers)
     {
         var name = mapper.GetName(buffer);
         WriteLineFormat("{0} {1};", VFXExpression.TypeToCode(buffer.valueType), name);
     }
 }
예제 #2
0
 public void WriteTexture(VFXUniformMapper mapper)
 {
     foreach (var texture in mapper.textures)
     {
         WriteLineFormat("{0} {1};", VFXExpression.TypeToCode(texture.valueType), mapper.GetName(texture));
         WriteLineFormat("SamplerState sampler{0};", mapper.GetName(texture));
     }
 }
예제 #3
0
 public void WriteTexture(VFXUniformMapper mapper)
 {
     foreach (var texture in mapper.textures)
     {
         string name = mapper.GetName(texture);
         WriteLineFormat("{0} {1};", VFXExpression.TypeToCode(texture.valueType), name);
         WriteLineFormat("SamplerState sampler{0};", name);
         WriteLineFormat("float4 {0}_TexelSize;", name);
     }
 }
예제 #4
0
        public void WriteCBuffer(VFXUniformMapper mapper, string bufferName)
        {
            var uniformValues = mapper.uniforms
                                .Where(e => !e.IsAny(VFXExpression.Flags.Constant | VFXExpression.Flags.InvalidOnCPU)) // Filter out constant expressions
                                .OrderByDescending(e => VFXValue.TypeToSize(e.valueType));

            var uniformBlocks = new List <List <VFXExpression> >();

            foreach (var value in uniformValues)
            {
                var block = uniformBlocks.FirstOrDefault(b => b.Sum(e => VFXValue.TypeToSize(e.valueType)) + VFXValue.TypeToSize(value.valueType) <= 4);
                if (block != null)
                {
                    block.Add(value);
                }
                else
                {
                    uniformBlocks.Add(new List <VFXExpression>()
                    {
                        value
                    });
                }
            }

            if (uniformBlocks.Count > 0)
            {
                WriteLineFormat("CBUFFER_START({0})", bufferName);
                Indent();

                int paddingIndex = 0;
                foreach (var block in uniformBlocks)
                {
                    int currentSize = 0;
                    foreach (var value in block)
                    {
                        string type = VFXExpression.TypeToUniformCode(value.valueType);
                        string name = mapper.GetName(value);
                        if (name.StartsWith("unity_")) //Reserved unity variable name (could be filled manually see : VFXMotionVector)
                        {
                            continue;
                        }

                        currentSize += VFXExpression.TypeToSize(value.valueType);

                        WriteLineFormat("{0} {1};", type, name);
                    }

                    WritePadding(4, currentSize, ref paddingIndex);
                }

                Deindent();
                WriteLine("CBUFFER_END");
            }
        }
예제 #5
0
        public void WriteBuffer(VFXUniformMapper mapper, ReadOnlyDictionary <VFXExpression, Type> usageGraphicsBuffer)
        {
            foreach (var buffer in mapper.buffers)
            {
                var name = mapper.GetName(buffer);

                if (buffer.valueType == VFXValueType.Buffer && usageGraphicsBuffer.TryGetValue(buffer, out var type))
                {
                    if (type == null)
                    {
                        throw new NullReferenceException("Unexpected null type in graphicsBuffer usage");
                    }

                    var structureName = GetStructureName(type);
                    WriteLineFormat("StructuredBuffer<{0}> {1};", structureName, name);
                }
                else
                {
                    WriteLineFormat("{0} {1};", VFXExpression.TypeToCode(buffer.valueType), name);
                }
            }
        }