Ejemplo n.º 1
0
        /// <summary>
        /// Public translation interface.
        /// Translates the given method to GLSL
        /// </summary>
        /// <param name="s">Shader type definition.</param>
        /// <param name="m">A method representing a shader to translate.</param>
        /// <param name="attr">The shader type as attribute (either FragmentShaderAttribute or VertexShaderAttribute</param>
        /// <param name="type">The shader type as ShaderType</param>
        /// <returns>The translated GLSL shader source</returns>
        public FunctionDescription Transform(TypeDefinition s, MethodDefinition m, CustomAttribute attr,
            ShaderType type)
        {
            if (s == null)
                throw new ArgumentNullException("s");

            if (m == null)
                throw new ArgumentNullException("m");

            if (attr == null)
                throw new ArgumentNullException("attr");

            var ctx = new DecompilerContext(s.Module)
            {
                CurrentType = s,
                CurrentMethod = m,
                CancellationToken = CancellationToken.None
            };

            var d = AstMethodBodyBuilder.CreateMethodBody(m, ctx);

            var glsl = new GlslVisitor(d, attr, ctx);

            _functions.UnionWith(glsl.Functions);

            var entry = (bool)attr.ConstructorArguments.FirstOrDefault().Value;
            var sig = entry ? "void main()" : GlslVisitor.GetSignature(m);

            var code = glsl.Result;
            var desc = new FunctionDescription(entry ? "main" : Shader.GetMethodName(m), sig + code, entry, type);

            _dependencies.UnionWith(glsl.Dependencies);

            return desc;
        }
Ejemplo n.º 2
0
        public static int compileShader(ShaderType shaderType, String shaderSource)
        {
            int shaderHandle = GL.CreateShader(shaderType);

            if (shaderHandle != 0)
            {
                // Pass in the shader source.
                GL.ShaderSource(shaderHandle, shaderSource);

                // Compile the shader.
                GL.CompileShader(shaderHandle);

                // Get the compilation status.
                int[] compileStatus = new int[1];
                GL.GetShader(shaderHandle,ShaderParameter.CompileStatus, compileStatus);

                // If the compilation failed, delete the shader.
                if (compileStatus[0] == 0)
                {
                    string shaderInfoLog = GL.GetShaderInfoLog(shaderHandle);
                    MessageBox.Show("Error creating shader: " + shaderInfoLog);
                    GL.DeleteShader(shaderHandle);
                    shaderHandle = 0;
                }
            }

            if (shaderHandle == 0)
            {
                 MessageBox.Show("Error creating shader.");
            }

            return shaderHandle;
        }
	void OnGUI() {
		const int height = 20;
		int width = (int)position.width;// -16;
		
		pmdFile = EditorGUI.ObjectField(
			new Rect(0, 0, width, height), "PMD File" , pmdFile, typeof(Object), false);
		
		// シェーダの種類
		shader_type = (ShaderType)EditorGUI.EnumPopup(new Rect(0, height, width, height), "Shader Type", shader_type);

		// 剛体を入れるかどうか
		rigidFlag = EditorGUI.Toggle(new Rect(0, height * 2, width / 2, height), "Rigidbody", rigidFlag);

		// Mecanimを使うかどうか
		use_mecanim = EditorGUI.Toggle(new Rect(0, height * 3, width / 2, height), "Use Mecanim", use_mecanim);

		// IKを使うかどうか
		use_ik = EditorGUI.Toggle(new Rect(0, height * 4, width / 2, height), "Use IK", use_ik);
		
		int buttonHeight = height * 5;
		if (pmdFile != null) {
			if (GUI.Button(new Rect(0, buttonHeight, width / 2, height), "Convert")) {
				new PMDLoaderScript(pmdFile, shader_type, rigidFlag, use_mecanim, use_ik);
				pmdFile = null;		// 読み終わったので空にする 
			}
		} else {
			EditorGUI.LabelField(new Rect(0, buttonHeight, width, height), "Missing", "Select PMD File");
		}
	}
Ejemplo n.º 4
0
 public ShaderException(string message, string shaderLog, string shaderSource, ShaderType shaderType)
     : base(message)
 {
     ShaderLog = shaderLog;
     ShaderSource = shaderSource;
     ShaderType = shaderType;
 }
Ejemplo n.º 5
0
        public static Shader FromFile(ShaderType type, string fileName)
        {
            Shader shader = new Shader(type, string.Empty);
            shader.LoadSource(fileName);

            return shader;
        }
Ejemplo n.º 6
0
        public static int CompileShader(ShaderType type, string source)
        {
            int shader = GL.CreateShader(type);
            GL.ShaderSource(shader, source);
            GL.CompileShader(shader);
            int compileResult;
            GL.GetShader(shader, ShaderParameter.CompileStatus, out compileResult);
            if (compileResult == 0)
            {
                int infoLogLength;
                GL.GetShader(shader, ShaderParameter.InfoLogLength, out infoLogLength);
                string infolog;
                GL.GetShaderInfoLog(shader, out infolog);
                GL.DeleteShader(shader);
                //std::vector<GLchar> infoLog(infoLogLength);
                //glGetShaderInfoLog(shader, infoLog.size(), NULL, &infoLog[0]);

                //std::cerr << "shader compilation failed: " << &infoLog[0];

                //glDeleteShader(shader);
                shader = 0;
            }

            return shader;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets shader's source code for color coded picking.
        /// </summary>
        /// <param name="shaderType"></param>
        /// <returns></returns>
        private static string GetShaderSource(ShaderType shaderType)
        {
            string result = string.Empty;

            switch (shaderType)
            {
                case ShaderType.VertexShader:
                    if (vertexShader == null)
                    {
                        vertexShader = ManifestResourceLoader.LoadTextFile(@"Resources.Highlight.vert");
                    }
                    result = vertexShader;
                    break;
                case ShaderType.FragmentShader:
                    if (fragmentShader == null)
                    {
                        fragmentShader = ManifestResourceLoader.LoadTextFile(@"Resources.Highlight.frag");
                    }
                    result = fragmentShader;
                    break;
                default:
                    throw new NotImplementedException();
            }

            return result;
        }
Ejemplo n.º 8
0
		protected Shader(Shader original) :
			base(original)
		{
			this.Identifier = original.Identifier;
			this.type = original.type;
			original.Identifier = 0;
		}
Ejemplo n.º 9
0
 public int CreateShader(ShaderType shaderType)
 {
     GraphicsContext.Assert();
     int shader = GL.CreateShader(shaderType);
     OpenGlErrorHelper.CheckGlError();
     return shader;
 }
Ejemplo n.º 10
0
 public static int CreateShader(string shaderSource, ShaderType type){
   int shaderHandle = GL.CreateShader( type );
   GL.ShaderSource( shaderHandle, shaderSource );
   GL.CompileShader( shaderHandle );
   Console.WriteLine(GL.GetShaderInfoLog(shaderHandle));
   return shaderHandle;
 }
Ejemplo n.º 11
0
		protected int CompileShaderObject(ShaderType type, string name)
		{
			string ext = type == ShaderType.VertexShader ? "vert" : "frag";
			string filename = "glsl{0}{1}.{2}".F(Path.DirectorySeparatorChar, name, ext);
			string code;
			using (var file = new StreamReader(GlobalFileSystem.Open(filename)))
				code = file.ReadToEnd();

			var shader = GL.CreateShader(type);
			ErrorHandler.CheckGlError();
			GL.ShaderSource(shader, code);
			ErrorHandler.CheckGlError();
			GL.CompileShader(shader);
			ErrorHandler.CheckGlError();
			int success;
			GL.GetShader(shader, ShaderParameter.CompileStatus, out success);
			ErrorHandler.CheckGlError();
			if (success == (int)All.False)
			{
				int len;
				GL.GetShader(shader, ShaderParameter.InfoLogLength, out len);
				var log = new StringBuilder(len);
				unsafe
				{
					GL.GetShaderInfoLog(shader, len, null, log);
				}

				Log.Write("graphics", "GL Info Log:\n{0}", log.ToString());
				throw new InvalidProgramException("Compile error in shader object '{0}'".F(filename));
			}

			return shader;
		}
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a shader from a string of shader source code.
        /// </summary>
        /// <param name="shaderCode">The source code for the shader.</param>
        /// <param name="shaderType">Same as the argument to glCreateShader. For example ShaderType.VertexShader
        ///                          or ShaderType.FragmentShader.</param>
        public Shader(string shaderCode, ShaderType shaderType)
        {
            _object = 0;
            _refCount = 0;

            //create the shader object
            _object = GL.CreateShader(shaderType);
            if (_object == 0)
                throw new Exception("glCreateShader failed");

            //set the source code
            GL.ShaderSource(_object, shaderCode);

            // compile
            GL.CompileShader(_object);

            // throw exception if compile error occurred
            int status;
            GL.GetShader(_object, ShaderParameter.CompileStatus, out status);
            if (status == 0) {
                string msg = "Compile failure in shader: ";

                string strInfoLog;
                GL.GetShaderInfoLog((int)_object, out strInfoLog);
                msg += strInfoLog;

                GL.DeleteShader(_object);
                _object = 0;
                throw new Exception(msg);
            }

            _refCount = 1;
        }
Ejemplo n.º 13
0
		private static int CreateCompiledSubShader(ShaderType shaderType, string subShaderCode)
		{
			uint shaderHandle = GLCore.CreateShader(shaderType);
			GLHelper.ShaderSource(shaderHandle, subShaderCode.Replace("precision mediump float;", ""));
			GLCore.CompileShader(shaderHandle);
			return (int)shaderHandle;
		}
Ejemplo n.º 14
0
 public ShaderFile(ShaderType type, string filename, string friendlyName)
     : base(type)
 {
     this.filename = filename;
     this.friendlyName = friendlyName;
     this.fileWatcher = new FileModifiedWatcher(filename);
 }
Ejemplo n.º 15
0
        public Shader(string name, string file, ShaderType type)
        {
            this.ShaderName = name;
            this.ShaderFile = file;

            switch (type)
            {
            case ShaderType.VertexShader:
                this.HasVertexShader = true;
                break;
            case ShaderType.FragmentShader:
                this.HasFragmentShader = true;
                break;
            case ShaderType.GeometryShader:
                this.HasGeometryShader = true;
                break;
            case ShaderType.TessControlShader:
                this.HasTessControlShader = true;
                break;
            case ShaderType.TessEvaluationShader:
                this.HasTessEvaluationShader = true;
                break;
            case ShaderType.ComputeShader:
                this.HasComputeShader = true;
                break;
            }
        }
Ejemplo n.º 16
0
 public Shader(ShaderType type, string shaderCode)
 {
     Type = type;
     ShaderCode = shaderCode;
     ReplaceLayoutLocations();
     ID = CreateShader(type, ShaderCode);
 }
Ejemplo n.º 17
0
 public static string ReadShader(string path, ShaderType type)
 {
     string extension = string.Empty;
     switch (type)
     {
         case ShaderType.FragmentShader:
             extension = ".frag";
             break;
         case ShaderType.VertexShader:
             extension = ".vert";
             break;
         case ShaderType.GeometryShader:
             extension = ".geom";
             break;
         case ShaderType.TessEvaluationShader:
             extension = ".tess";
             break;
         case ShaderType.TessControlShader:
             extension = ".tctrl";
             break;
         case ShaderType.ComputeShader:
             extension = ".comp";
             break;
     }
     string output = File.ReadAllText(Directory.GetCurrentDirectory() + "/" + path + extension);
     return output;
 }
Ejemplo n.º 18
0
        internal Shader(ShaderType type, string filename)
        {
            Type = type;
            Filename = filename;

            Handle = GL.CreateShader(Type);
        }
Ejemplo n.º 19
0
 public FunctionDescription(string name, string body, bool entryPoint, ShaderType type)
 {
     Name = name;
     EntryPoint = entryPoint;
     Body = body;
     Type = type;
 }
Ejemplo n.º 20
0
        int LoadShader(ShaderType type, string source)
        {
            int shader = GL.CreateShader(type);
            if (shader == 0)
                throw new InvalidOperationException("Unable to create shader");

            int length = 0;
            GL.ShaderSource(shader, 1, new string[] { source }, (int[])null);
            GL.CompileShader(shader);

            int compiled = 0;
            GL.GetShader(shader, ShaderParameter.CompileStatus, out compiled);
            if (compiled == 0)
            {
                length = 0;
                GL.GetShader(shader, ShaderParameter.InfoLogLength, out length);
                if (length > 0)
                {
                    var log = new StringBuilder(length);
                    GL.GetShaderInfoLog(shader, length, out length, log);
                    Console.WriteLine("Couldn't compile shader: " + log.ToString());
                }

                GL.DeleteShader(shader);
                throw new InvalidOperationException("Unable to compile shader of type : " + type.ToString());
            }

            return shader;
        }
Ejemplo n.º 21
0
 public void Load(string path, ShaderType type, string version = "")
 {
     var source = IO.ASCIIFileHelper.ReadFileToEnd(path);
     source = version + "\n" + source;
     var name = Path.GetFileNameWithoutExtension(path);
     Load(source, name, type);
 }
        /// <summary>
        /// Constructor to create a new ShaderBuilder instance.
        /// </summary>
        /// <param name="type">The shader type to generate the source for</param>
        /// <param name="twoDimensional">If true, some helper code for two dimensional shaders will be included</param>
        /// <param name="parent">Previous shader in the pipeline (if any)</param>
        public ShaderBuilder(ShaderType type, bool twoDimensional, ShaderBuilder parent = null)
        {
            Type = type;
            _twoDimensional = twoDimensional;

            // Prepare an empty list of OpenGL extensions
            _extensions = new List<String>();

            // Set up variable lists
            _uniforms = new List<ShaderVariable>();
            _attribs = new List<ShaderVariable>();
            _varyings = new List<ShaderVariable>();

            if (type == ShaderType.VertexShader && twoDimensional) {
                AddUniform(ShaderVarType.Vec2, "screen_resolution");
            }

            // If the builder is given a parent, copy any outputs
            // from that shader as inputs for this one
            if (parent != null) {
                foreach (var vary in parent._varyings) {
                    AddVarying(vary.Type, vary.Identifier);
                }
            }

            Logic = "";

            // Default fragment colour output variable identifier
            FragOutIdentifier = "out_colour";
        }
Ejemplo n.º 23
0
        public static bool CompileShader(ShaderType type, string file, out int shader)
        {
            string src = System.IO.File.ReadAllText(file);
            shader = GL.CreateShader(type);
            GL.ShaderSource(shader, 1, new string[] { src }, (int[])null);
            GL.CompileShader(shader);
            #if DEBUG
            int logLength = 0;
            GL.GetShader (shader, ShaderParameter.InfoLogLength, out logLength);
            if (logLength > 0)
            {
                var infoLog = new System.Text.StringBuilder ();
                GL.GetShaderInfoLog (shader, logLength, out logLength, infoLog);
                Console.WriteLine ("Shader compile log:\n{0}", infoLog);
            }
            #endif
            int status = 0;
            GL.GetShader(shader, ShaderParameter.CompileStatus, out status);
            if (status == 0)
            {
                GL.DeleteShader(shader);
                return false;
            }

            return true;
        }
Ejemplo n.º 24
0
 NShaderType(Object T)
 {
     if (T is VertexShaderTag)
         value = ShaderType.VertexShader;
     else if (T is FragmentShaderTag)
         value = ShaderType.FragmentShader;
     else throw new ArgumentException("Invalid parameter: " + T.GetType().Name);
 }
Ejemplo n.º 25
0
 public ShaderFile Load(string fileName, ShaderType shaderType)
 {
     var path = Path.Combine(this.pathPrefix, fileName);
     if (this.appendExtensionsForSingleFiles)
         path = this.appendExtension(path, shaderType);
     
     return new ShaderFile(shaderType, path, fileName);
 }
Ejemplo n.º 26
0
        public SSShader(ShaderType type, string shaderName, string shaderProgramText)
        {
            this.type = type;
            this.shaderProgramText = shaderProgramText;
            this.shaderName = shaderName;

            this.loadShader();
        }
Ejemplo n.º 27
0
        public ShaderComponent(ShaderType type, string filename)
        {
            this.type = type;
            this.filename = filename;
            this.id = GL.CreateShader(this.type);

            this.load();
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Create a shader using a stream as the source and a ShaderType parameter.
 /// </summary>
 /// <param name="shaderType">The shader type (fragment or vertex)</param>
 /// <param name="source">The stream for the shader.</param>
 public Shader(ShaderType shaderType, Stream source) {
     if (shaderType == ShaderType.Vertex) {
         shader = new SFML.Graphics.Shader(source, null);
     }
     else {
         shader = new SFML.Graphics.Shader(null, source);
     }
 }
Ejemplo n.º 29
0
 public ResourceShader( string name, string source, ShaderType shaderType )
     : base(name)
 {
     this.type = ResourceType.SHADER;
       this.shader = new Shader( name, source, shaderType );
       this.shader.resource = this;
       this.IsValid = true;
 }
Ejemplo n.º 30
0
 private void loadShader(String code, ShaderType type, out int address)
 {
     address = GL.CreateShader(type);
     GL.ShaderSource(address, code);
     GL.CompileShader(address);
     GL.AttachShader(ProgramID, address);
     Console.WriteLine(GL.GetShaderInfoLog(address));
 }
 protected abstract bool CreateShader(byte[] data, ShaderType type);
Ejemplo n.º 32
0
 public unsafe partial void GetShaderPrecisionFormat([Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] PrecisionType precisiontype, [Count(Count = 2), Flow(FlowDirection.Out)] int *range, [Count(Count = 1), Flow(FlowDirection.Out)] int *precision);
Ejemplo n.º 33
0
 public static unsafe void GetProgramStage(this ArbShaderSubroutine thisApi, [Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] ProgramStagePName pname, [Count(Count = 1), Flow(FlowDirection.Out)] Span <int> values)
 {
     // SpanOverloader
     thisApi.GetProgramStage(program, shadertype, pname, out values.GetPinnableReference());
 }
Ejemplo n.º 34
0
 public partial void GetActiveSubroutineUniform([Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] SubroutineParameterName pname, [Count(Computed = "pname"), Flow(FlowDirection.Out)] out int values);
        protected static int LoadShaderFromFile(string filename, ShaderType type, out bool hasFailed)
        {
            Stream stream = new FileStream(filename, FileMode.Open);

            return(LoadShaderFromStream(stream, type, out hasFailed));
        }
Ejemplo n.º 36
0
    private void Start()
    {
        originalPosition = transform.position;
        rectTr           = GetComponent <RectTransform>();
        image            = GetComponent <Image>();
        material         = image.material;

        if (BattleManager.isTutorial)
        {
            image.sprite   = BGSquare;
            image.type     = Image.Type.Simple;
            image.color    = Color.black;
            image.material = null;
            return;
        }

        tileType = (!isTitleScreen) ? chooseRandomTileType() : TileType.SQUARE;
        switch (tileType)
        {
        case TileType.TRIANGLE:
            image.sprite = BGTriangle;
            tileSizeX    = 391;
            tileSizeY    = 341;
            break;

        case TileType.SQUARE:
            image.sprite         = BGSquare;
            transform.localScale = Random.Range(1.75f, 3f) * Vector2.one;
            tileSizeX            = tileSizeY = 77;
            if (isTitleScreen)
            {
                image.type = Image.Type.Simple;
            }
            break;

        case TileType.HEXAGON:
            image.sprite         = BGHexagon;
            transform.localScale = Random.Range(.5f, 1.1f) * Vector2.one;
            tileSizeX            = 551;
            tileSizeY            = 639;
            break;

        case TileType.DODECAGON:
            image.sprite = BGDodecagon;
            tileSizeX    = 463;
            tileSizeY    = 403;
            break;
        }

        movementType = (!isTitleScreen) ? chooseRandomMovementType() : MovementType.SLIDE;
        switch (movementType)
        {
        case MovementType.SLIDE:
            // Tiles have a set width and height, so restart cycles after those lengths
            // The length must be measured in absolute units, so transform it from canvas units first
            scrollMaxLengthX = GetComponent <RectTransform>().TransformPoint(tileSizeX, 0, 0).x
                               - GetComponent <RectTransform>().TransformPoint(0, 0, 0).x;
            scrollMaxLengthY = GetComponent <RectTransform>().TransformPoint(0, tileSizeY, 0).y
                               - GetComponent <RectTransform>().TransformPoint(0, 0, 0).y;

            // Choose random speed/direction
            scrollSpeed         = (!isTitleScreen) ? Random.Range(0.5f, 1.75f) : 0f;
            horizontalDirection = (Random.Range(0, 2) == 0) ? Vector2.right : Vector2.left;
            verticalDirection   = (Random.Range(0, 2) == 0) ? Vector2.up : Vector2.down;
            break;

        case MovementType.ROTATE:
            rotationSpeed     = Random.Range(0.035f, 0.045f);
            rotationTime      = Random.Range(14.5f, 21.5f);
            lowerScale        = Random.Range(0.75f, 1.1f);
            upperScale        = Random.Range(0.55f, 1.25f);
            rotationDirection = (Random.Range(0, 2) == 0) ? Vector3.forward : Vector3.back;
            break;
        }

        shaderType = (!isTitleScreen) ? chooseRandomShader() : ShaderType.BILINEAR_GRADIENT;
        switch (shaderType)
        {
        case ShaderType.RGB_CYCLE:
            material.shader = Shader.Find("Custom/RGBCycleShader");
            material.SetFloat("_Duration", Random.Range(4f, 10f));
            material.SetFloat("_Overlap", Random.Range(.15f, .4f));
            int invertValue = (Random.Range(0, 2) == 0) ? 0 : 1;
            material.SetFloat("_Invert", invertValue);
            break;

        case ShaderType.CMY_CYCLE:
            material.shader = Shader.Find("Custom/CMYCycleShader");
            material.SetFloat("_Duration", Random.Range(6.5f, 9f));
            invertValue = (Random.Range(0, 2) == 0) ? 0 : 1;
            material.SetFloat("_Invert", invertValue);
            break;

        case ShaderType.LINEAR_GRADIENT:
            material.shader = Shader.Find("Custom/LinearGradientShader");
            material.SetFloat("_Duration", Random.Range(4f, 7f));
            material.SetFloat("_ROffset", Mathf.Floor(Random.Range(0f, 2f)));
            material.SetFloat("_GOffset", Mathf.Floor(Random.Range(2f, 4f)));
            material.SetFloat("_BOffset", Mathf.Floor(Random.Range(4f, 6f)));
            material.SetFloat("_Direction", Random.Range(0, 2));
            break;

        case ShaderType.BILINEAR_GRADIENT:
            material.shader = Shader.Find("Custom/BilinearGradientShader");
            material.SetFloat("_Duration", Random.Range(4f, 7f));
            material.SetFloat("_ROffset", Mathf.Floor(Random.Range(0f, 2f)));
            material.SetFloat("_GOffset", Mathf.Floor(Random.Range(2f, 4f)));
            material.SetFloat("_BOffset", Mathf.Floor(Random.Range(4f, 6f)));
            material.SetFloat("_Phase", Random.Range(0f, 60f));
            break;

        case ShaderType.CIRCLE_GRADIENT:
            material.shader = Shader.Find("Custom/CircleGradientShader");
            material.SetFloat("_Duration", Random.Range(4f, 12f));
            material.SetFloat("_CenterX", .5f);
            material.SetFloat("_CenterY", .5f);
            break;

        case ShaderType.DOUBLE_LINEAR_GRADIENT:
            material.shader = Shader.Find("Custom/DoubleLinearGradientShader");
            material.SetFloat("_Duration1", Random.Range(3f, 6f));
            material.SetFloat("_Duration2", Random.Range(5f, 9f));
            material.SetFloat("_ROffset", Mathf.Floor(Random.Range(0f, 2f)));
            material.SetFloat("_GOffset", Mathf.Floor(Random.Range(2f, 4f)));
            material.SetFloat("_BOffset", Mathf.Floor(Random.Range(4f, 6f)));
            material.SetFloat("_Direction", Random.Range(0, 2));
            break;

        case ShaderType.MOVING_CIRCLES:
            material.shader = Shader.Find("Custom/MovingCirclesShader");
            string[] colors = new string[] { "R", "G", "B", "C", "M", "Y" };
            // Assign random starting positions/scales for each color
            foreach (string color in colors)
            {
                material.SetVector("_Center" + color, new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f)));
                material.SetFloat("_Radius" + color, Random.Range(0.15f, 0.35f));
                StartCoroutine(moveCircle(color));
                StartCoroutine(scaleCircle(color));
            }
            break;
        }
    }
Ejemplo n.º 37
0
        /// <summary>
        /// GameObjectを作成する
        /// </summary>
        /// <param name='format'>内部形式データ</param>
        /// <param name='shader_type'>シェーダーの種類</param>
        /// <param name='use_rigidbody'>剛体を使用するか</param>
        /// <param name='use_mecanim'>Mecanimを使用するか</param>
        /// <param name='use_ik'>IKを使用するか</param>
        /// <param name='scale'>スケール</param>
        public static GameObject CreateGameObject(PMDFormat format, ShaderType shader_type, bool use_rigidbody, bool use_mecanim, bool use_ik, float scale)
        {
            PMDConverter converter = new PMDConverter();

            return(converter.CreateGameObject_(format, shader_type, use_rigidbody, use_mecanim, use_ik, scale));
        }
Ejemplo n.º 38
0
 public Shader(Device device, ShaderType type)
 {
     this.type = type;
     handle    = Orbital_Video_Vulkan_Shader_Create(device.handle);
 }
 public void VisitShader(string name, uint offset, bool visible, ShaderType type, uint pluginLine)
 {
     WriteBasicValue("uint32", name, offset, visible);
 }
Ejemplo n.º 40
0
 public static unsafe void GetActiveSubroutineUniform(this ArbShaderSubroutine thisApi, [Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] SubroutineParameterName pname, [Count(Computed = "pname"), Flow(FlowDirection.Out)] Span <int> values)
 {
     // SpanOverloader
     thisApi.GetActiveSubroutineUniform(program, shadertype, index, pname, out values.GetPinnableReference());
 }
Ejemplo n.º 41
0
 public static unsafe void GetActiveSubroutineName(this ArbShaderSubroutine thisApi, [Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] uint bufSize, [Count(Count = 1), Flow(FlowDirection.Out)] Span <uint> length, [Count(Parameter = "bufSize"), Flow(FlowDirection.Out)] Span <string> name)
 {
     // SpanOverloader
     thisApi.GetActiveSubroutineName(program, shadertype, index, bufSize, out length.GetPinnableReference(), out name.GetPinnableReference());
 }
Ejemplo n.º 42
0
 public static int ToProgramMask(this ShaderType _this)
 {
     return(1 << (int)_this);
 }
Ejemplo n.º 43
0
 protected Shader(IGL gl, uint handle, ShaderType type)
 {
     this.gl     = gl;
     this.handle = handle;
     this.type   = type;
 }
Ejemplo n.º 44
0
        private GameObject CreateGameObject_(PMDFormat format, ShaderType shader_type, bool use_rigidbody, bool use_mecanim, bool use_ik, float scale)
        {
            format_           = format;
            shader_type_      = shader_type;
            use_rigidbody_    = use_rigidbody;
            use_mecanim_      = use_mecanim;
            use_ik_           = use_ik;
            scale_            = scale;
            root_game_object_ = new GameObject(format_.name);

            Mesh mesh = CreateMesh();                                   // メッシュの生成・設定

            Material[]   materials = CreateMaterials();                 // マテリアルの生成・設定
            GameObject[] bones     = CreateBones();                     // ボーンの生成・設定

            // バインドポーズの作成
            BuildingBindpose(mesh, materials, bones);

            MMDEngine engine = root_game_object_.AddComponent <MMDEngine>();

            //スケール・エッジ幅
            engine.scale                   = scale_;
            engine.outline_width           = default_outline_width;
            engine.material_outline_widths = Enumerable.Repeat(1.0f, materials.Length).ToArray();

            // IKの登録
            if (use_ik_)
            {
                engine.ik_list = EntryIKSolver(bones);
            }

            // 剛体関連
            if (use_rigidbody_)
            {
                try
                {
                    var rigids = CreateRigids(bones);
                    AssignRigidbodyToBone(bones, rigids);
                    SetRigidsSettings(bones, rigids);
                    GameObject[] joints = SettingJointComponent(bones, rigids);
                    GlobalizeRigidbody(joints);

                    // 非衝突グループ
                    List <int>[] ignoreGroups = SettingIgnoreRigidGroups(rigids);
                    int[]        groupTarget  = GetRigidbodyGroupTargets(rigids);

                    MMDEngine.Initialize(engine, groupTarget, ignoreGroups, rigids);
                }
                catch { }
            }

            // Mecanim設定
            if (use_mecanim_)
            {
                AvatarSettingScript avatar_setting = new AvatarSettingScript(root_game_object_, bones);
                avatar_setting.SettingHumanAvatar();

                string path      = format_.folder + "/";
                string name      = GetFilePathString(format_.name);
                string file_name = path + name + ".avatar.asset";
                avatar_setting.CreateAsset(file_name);
            }
            else
            {
                root_game_object_.AddComponent <Animation>();                   // アニメーション追加
            }

            return(root_game_object_);
        }
Ejemplo n.º 45
0
 public ShaderSrc(ShaderType type, string srcPath)
 {
     SrcPath = srcPath;
     Type    = type;
 }
Ejemplo n.º 46
0
 public Shader(ShaderType type, GLSLViewModel parent)
 {
     ShaderType = type;
 }
 public abstract unsafe uint CreateShaderProgram([Flow(FlowDirection.In)] ShaderType type, [Flow(FlowDirection.In)] uint count, [Count(Parameter = "count"), Flow(FlowDirection.In)] char **strings);
Ejemplo n.º 48
0
        bool AttachShader(ShaderBuilder builder, string source, ShaderType type, string resource)
        {
            if (type == ShaderType.TessControlShader)
            {
                HasTesselation = true;
            }
            //source = source.Replace(maxNumberOfLights_name, maxNumberOfLights.ToString());

            int handle = GL.CreateShader(type); MyGL.Check();


            GL.ShaderSource(handle, source); MyGL.Check();

            GL.CompileShader(handle); MyGL.Check();

            string logInfo;

            GL.GetShaderInfoLog(handle, out logInfo); MyGL.Check();
            if (logInfo.Length > 0)
            {
                Log.Error($"Error occured during compilation of {type} from '{resource}'");
                Log.Error(logInfo);
                try
                {
                    var lines = logInfo.Split('\n');
                    for (int i = 0; i < lines.Length; i++)
                    {
                        var line = lines[i];
                        if (line.Contains("(") && line.Contains(")"))
                        {
                            var fileIdAndLineNumber = line.TakeStringBefore(")");
                            var fileId     = fileIdAndLineNumber.TakeStringBefore("(");
                            var lineNumber = fileIdAndLineNumber.TakeStringAfter("(");
                            var fileName   = builder.includedFiles[int.Parse(fileId, CultureInfo.InvariantCulture)];

                            line = line.Replace(fileIdAndLineNumber, fileName + "(" + lineNumber);

                            lines[i] = line;
                        }
                    }
                    logInfo = lines.Join('\n');
                    Log.Error("niceifed:");
                    Log.Error(logInfo);
                }
                catch (Exception e)
                {
                    Log.Error("failed to niceify error:" + e);
                }
                return(false);
            }

            int statusCode = 0;

            GL.GetShader(handle, ShaderParameter.CompileStatus, out statusCode); MyGL.Check();
            if (statusCode != 1)
            {
                var error = GL.GetShaderInfoLog(handle); MyGL.Check();
                //Log.Error(type.ToString() + " :: " + source + "\n" + error + "\n in file: " + resource);
                return(false);
            }

            GL.AttachShader(ShaderProgramHandle, handle); MyGL.Check();


            return(true);
        }
Ejemplo n.º 49
0
        private static void ParseFile(string path)
        {
            List <ShaderWrapper> localShaders = new List <ShaderWrapper>();
            List <Tuple <string, int, int, int> > computeRegisters = new List <Tuple <String, int, int, int> >();
            ShaderFile sf = m_AllShaderFiles[GetFileNameFromPath(path)];

            sf.m_DirectlyIncludedFiles.Clear();
            sf.m_FlattenedFiles.Clear();

            using (StreamReader sr = new StreamReader(path))
            {
                while (!sr.EndOfStream)
                {
                    String line                   = sr.ReadLine();
                    Match  matchShaderRegex       = m_RegexWrapper.shaderRegex.Match(line);
                    Match  matchCbufferRegex      = m_RegexWrapper.cbufferRegex.Match(line);
                    Match  matchSamplerRegex      = m_RegexWrapper.samplerRegex.Match(line);
                    Match  matchNumThreadsRegex   = m_RegexWrapper.numThreadsRegex.Match(line);
                    Match  matchGlobalDefineRegex = m_RegexWrapper.globalDefineRegex.Match(line);
                    Match  matchIncludeRegex      = m_RegexWrapper.includeRegex.Match(line);

                    if (matchIncludeRegex.Success)
                    {
                        string includeName = matchIncludeRegex.Groups[1].Value;
                        sf.m_DirectlyIncludedFiles.Add(includeName);
                    }

                    if (matchGlobalDefineRegex.Success)
                    {
                        string defineName = matchGlobalDefineRegex.Groups[1].Value;
                        float  value      = Single.Parse(matchGlobalDefineRegex.Groups[2].Value, CultureInfo.InvariantCulture);

                        if (m_GlobalDefineValues.ContainsKey(defineName))
                        {
                            m_GlobalDefineValues[defineName] = value;
                        }
                        else
                        {
                            m_GlobalDefineValues.Add(defineName, value);
                        }
                    }

                    if (matchCbufferRegex.Success)
                    {
                        Match globalBufferMatch = m_RegexWrapper.globalBufferRegex.Match(line);
                        Match registerMatch     = m_RegexWrapper.registerRegex.Match(line);
                        if (!registerMatch.Success)
                        {
                            throw new Exception("Unable to find register for constant buffer");
                        }
                        int cbufferRegister = Int32.Parse(registerMatch.Groups[1].Value);

                        // We have a new cbuffer
                        string cbufferName = matchCbufferRegex.Groups[1].Value;

                        string cbufferText = "";
                        while (!sr.EndOfStream)
                        {
                            line = sr.ReadLine();
                            if (line.Contains('{'))
                            {
                                continue;
                            }

                            if (line.Contains('}'))
                            {
                                if (m_ConstantBuffers.ContainsKey(cbufferName))
                                {
                                    m_ConstantBuffers[cbufferName].ParseConstantBuffer(cbufferText, cbufferRegister, globalBufferMatch.Success);
                                }
                                else
                                {
                                    CustomConstantBufferDefinition myNewConstantBuffer =
                                        new CustomConstantBufferDefinition(
                                            cbufferName,
                                            cbufferText,
                                            cbufferRegister,
                                            globalBufferMatch.Success,
                                            path);

                                    m_ConstantBuffers.Add(cbufferName, myNewConstantBuffer);
                                }
                                break;
                            }

                            cbufferText += line.Trim() + "\n";
                        }

                        continue;
                    }

                    if (matchShaderRegex.Success)
                    {
                        // We have a new shader
                        string     shaderType    = matchShaderRegex.Groups[1].Value;
                        string     shaderName    = matchShaderRegex.Groups[2].Value;
                        string     shaderEntry   = matchShaderRegex.Groups[3].Value;
                        string     shaderDefines = matchShaderRegex.Groups[4].Value;
                        ShaderType type          = ShaderType.PixelShader;

                        switch (shaderType.ToLower())
                        {
                        case "pixel": type = ShaderType.PixelShader;
                            break;

                        case "vertex": type = ShaderType.VertexShader;
                            break;

                        case "compute": type = ShaderType.ComputeShader;
                            break;

                        case "geometry": type = ShaderType.GeometryShader;
                            break;
                        }

                        HashSet <string> defines = new HashSet <String>();

                        if (shaderDefines.Length > 0)
                        {
                            var tokens = shaderDefines.Split(new String[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
                            for (int i = 1; i < tokens.Length; ++i)
                            {
                                defines.Add(tokens[i]);
                            }
                        }

                        ShaderWrapper newShader = new ShaderWrapper()
                        {
                            m_ShaderFile  = sf,
                            m_ShaderName  = shaderName,
                            m_ShaderType  = type,
                            m_ShaderEntry = shaderEntry,
                            m_Defines     = defines
                        };

                        localShaders.Add(newShader);
                    }

                    if (matchNumThreadsRegex.Success)
                    {
                        int threadsX = Int32.Parse(matchNumThreadsRegex.Groups[1].Value);
                        int threadsY = Int32.Parse(matchNumThreadsRegex.Groups[2].Value);
                        int threadsZ = Int32.Parse(matchNumThreadsRegex.Groups[3].Value);

                        string nextLine = sr.ReadLine();
                        var    tokens   = nextLine.Split(new String[] { " ", "(" }, StringSplitOptions.RemoveEmptyEntries);

                        computeRegisters.Add(new Tuple <String, int, int, int>(tokens[1], threadsX, threadsY, threadsZ));
                    }

                    if (matchSamplerRegex.Success)
                    {
                        string samplerType     = matchSamplerRegex.Groups[1].Value;
                        string samplerName     = matchSamplerRegex.Groups[2].Value;
                        string samplerRegister = matchSamplerRegex.Groups[3].Value;

                        m_SamplerStates[Int32.Parse(samplerRegister)] = SamplerStates.GetSamplerStateForName(samplerName);
                    }
                }
            }

            foreach (var shader in localShaders)
            {
                if (m_Shaders.ContainsKey(shader.m_ShaderName))
                {
                    m_Shaders[shader.m_ShaderName] = shader;
                }
                else
                {
                    m_Shaders.Add(shader.m_ShaderName, shader);
                }

                // CompileShader(shader);
                if (shader.m_ShaderCompilationTask != null)
                {
                    throw new Exception("Already compiling");
                }

                shader.m_ShaderCompilationTask = Task.Factory.StartNew(() => CompileShader(shader));
            }

            sf.m_FlattenedFiles.Add(sf.m_FileName);
            sf.m_FlattenedFiles.UnionWith(sf.m_DirectlyIncludedFiles);

            foreach (var registers in computeRegisters)
            {
                var shaderFit = localShaders.Where
                                    (shader => shader.m_ShaderEntry == registers.Item1);

                foreach (var fittingShader in shaderFit)
                {
                    fittingShader.m_ThreadsX = registers.Item2;
                    fittingShader.m_ThreadsY = registers.Item3;
                    fittingShader.m_ThreadsZ = registers.Item4;
                }
            }
        }
Ejemplo n.º 50
0
 public unsafe partial void GetActiveSubroutineUniform([Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] ARB pname, [Count(Computed = "pname"), Flow(FlowDirection.Out)] int *values);
        public static int LoadShaderFromEmbeddedResource(string name, ShaderType type, out bool hasFailed)
        {
            Stream stream = typeof(Program).Assembly.GetManifestResourceStream(name);

            return(LoadShaderFromStream(stream, type, out hasFailed));
        }
Ejemplo n.º 52
0
 public partial void GetActiveSubroutineName([Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] uint bufSize, [Count(Count = 1), Flow(FlowDirection.Out)] out uint length, [Count(Parameter = "bufSize"), Flow(FlowDirection.Out)] out string name);
Ejemplo n.º 53
0
 public partial void GetShaderPrecisionFormat([Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] ARB precisiontype, [Count(Count = 2), Flow(FlowDirection.Out)] out int range, [Count(Count = 1), Flow(FlowDirection.Out)] out int precision);
Ejemplo n.º 54
0
 public abstract ushort GetStageIndex([Flow(FlowDirection.In)] ShaderType shadertype);
 public static unsafe void GetShaderPrecisionFormat(this ArbES2Compatibility thisApi, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] PrecisionType precisiontype, [Count(Count = 2), Flow(FlowDirection.Out)] Span <int> range, [Count(Count = 1), Flow(FlowDirection.Out)] Span <int> precision)
 {
     // SpanOverloader
     thisApi.GetShaderPrecisionFormat(shadertype, precisiontype, out range.GetPinnableReference(), out precision.GetPinnableReference());
 }
Ejemplo n.º 56
0
 public SSShader(ShaderType type, string shaderName, string shaderProgramText)
 {
     this.type = type;
     this.shaderProgramText = shaderProgramText;
     this.shaderName        = shaderName;
 }
Ejemplo n.º 57
0
 public static unsafe void GetUniformSubroutine(this ArbShaderSubroutine thisApi, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] int location, [Count(Count = 1), Flow(FlowDirection.Out)] Span <uint> @params)
 {
     // SpanOverloader
     thisApi.GetUniformSubroutine(shadertype, location, out @params.GetPinnableReference());
 }
Ejemplo n.º 58
0
 public ShaderGL3(ShaderType type)
 {
     shaderObject = GL.CreateShader(type);
     GhostManager.Gen();
     this.type = type;
 }
Ejemplo n.º 59
0
 public static unsafe int GetSubroutineUniformLocation(this ArbShaderSubroutine thisApi, [Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] ReadOnlySpan <byte> name)
 {
     // SpanOverloader
     return(thisApi.GetSubroutineUniformLocation(program, shadertype, in name.GetPinnableReference()));
 }
Ejemplo n.º 60
0
 public static unsafe void UniformSubroutines(this ArbShaderSubroutine thisApi, [Flow(FlowDirection.In)] ShaderType shadertype, [Flow(FlowDirection.In)] uint count, [Count(Parameter = "count"), Flow(FlowDirection.In)] ReadOnlySpan <uint> indices)
 {
     // SpanOverloader
     thisApi.UniformSubroutines(shadertype, count, in indices.GetPinnableReference());
 }