Пример #1
0
        // return all the uniform mappings with a given uniform type
        public UniformMapping[] GetUniformMappingsOfType(UniformMapping.UniformType type)
        {
            List <UniformMapping> result = new List <UniformMapping>();

            foreach (UniformMapping mapping in uniformMappings)
            {
                if (mapping.uniformType == type)
                {
                    result.Add(mapping);
                }
            }
            return(result.ToArray());
        }
Пример #2
0
        public UniformMappedData[] GetUniformDatasOfTypeFromMaterial(UniformMapping.UniformType type, Material material)
        {
            // ensure the material and shader is valid
            if (material == null || material.shader == null)
            {
                return(null);
            }

            UniformMapping[]         texmappings = GetUniformMappingsOfType(type);
            List <UniformMappedData> results     = new List <UniformMappedData>();

            foreach (UniformMapping mapping in texmappings)
            {
                results.Add(new UniformMappedData(mapping, material));
            }
            return(results.ToArray());
        }
Пример #3
0
        //
        // function for creating a template shadermapping json file for a specific shader

        public static ShaderMapping CreateTemplateForShader(Shader shader)
        {
            ShaderMapping mapping = new ShaderMapping()
            {
                unityShaderName = shader.name,
                shaders         = new List <ShaderResource>()
                {
                    new ShaderResource()
                    {
                        sourceFile = shader.name, stages = VkShaderStageFlagBits.VK_SHADER_STAGE_VERTEX_BIT | VkShaderStageFlagBits.VK_SHADER_STAGE_FRAGMENT_BIT
                    }
                }
            };

            mapping.vertexDependancies = new List <VertexAttributeDependancies>
            {
                new VertexAttributeDependancies {
                    attributeType = VertexAttribute.Position, dependantDefines = new List <string> {
                        "ALL"
                    }
                },
                new VertexAttributeDependancies {
                    attributeType = VertexAttribute.Normal, dependantDefines = new List <string> {
                        "VSG_LIGHTING", "VSG_NORMAL_MAP"
                    }
                },
                new VertexAttributeDependancies {
                    attributeType = VertexAttribute.Tangent, dependantDefines = new List <string> {
                        "VSG_NORMAL_MAP"
                    }
                },
                new VertexAttributeDependancies {
                    attributeType = VertexAttribute.Color, dependantDefines = new List <string> {
                        "NONE"
                    }
                },
                new VertexAttributeDependancies {
                    attributeType = VertexAttribute.TexCoord0, dependantDefines = new List <string> {
                        "VSG_DIFFUSE_MAP", "VSG_NORMAL_MAP"
                    }
                }
            };

            for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
            {
                ShaderUtil.ShaderPropertyType proptype = ShaderUtil.GetPropertyType(shader, i);
                string propname = ShaderUtil.GetPropertyName(shader, i);

                if (proptype == ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    TextureDimension texdims = ShaderUtil.GetTexDim(shader, i);

                    UniformMapping.UniformType textype = UniformMapping.UniformType.UnkownUniform;
                    switch (texdims)
                    {
                    case TextureDimension.Tex2D:
                    {
                        textype = UniformMapping.UniformType.Texture2DUniform;
                        break;
                    }

                    case TextureDimension.Tex2DArray:
                    {
                        textype = UniformMapping.UniformType.Texture2DArrayUniform;
                        break;
                    }

                    default: break;
                    }

                    if (textype == UniformMapping.UniformType.UnkownUniform)
                    {
                        continue;
                    }

                    mapping.uniformMappings.Add(new UniformMapping()
                    {
                        unityPropName = propname, uniformType = textype
                    });
                }
                else if (proptype == ShaderUtil.ShaderPropertyType.Float || proptype == ShaderUtil.ShaderPropertyType.Range)
                {
                    mapping.uniformMappings.Add(new UniformMapping()
                    {
                        unityPropName = propname, uniformType = UniformMapping.UniformType.FloatUniform
                    });
                }
                else if (proptype == ShaderUtil.ShaderPropertyType.Vector)
                {
                    mapping.uniformMappings.Add(new UniformMapping()
                    {
                        unityPropName = propname, uniformType = UniformMapping.UniformType.Vec4Uniform
                    });
                }
                else if (proptype == ShaderUtil.ShaderPropertyType.Color)
                {
                    mapping.uniformMappings.Add(new UniformMapping()
                    {
                        unityPropName = propname, uniformType = UniformMapping.UniformType.ColorUniform
                    });
                }
            }
            return(mapping);
        }