Esempio n. 1
0
 private void loadShader(Shader shader)
 {
     switch (shader.type)
     {
         case Shader.Type.fromFile:
             loadShaderFromFile(shader);
             break;
         case Shader.Type.fromXml:
             loadShaderXml(shader);
             break;
         case Shader.Type.fromCache:
             loadShaderFromCache(shader);
             break;
         default:
             break;
     }
 }
Esempio n. 2
0
 private void registerShader(Shader newShader)
 {
     shaderNames.Add(newShader.name, newShader.identifier);
     shaders.Add(newShader);
 }
Esempio n. 3
0
        public void loadShaderXml(Shader target)
        {
            XmlTextReader reader = new XmlTextReader(target.pointer[0]);

            string path = Path.GetDirectoryName(target.pointer[0]) + "\\";

            //target.envMapAlphaBaseTexture = false;

            gameWindow.log("parsing shader pair: " + target.name);

            target.pointer = new string[2];

            while (reader.Read())
            {
                // parsing data in material tag
                if (reader.Name == "shaderpair" && reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        if (reader.Name == "vertex")
                            target.pointer[0] = path + reader.Value;

                        else if (reader.Name == "fragment")
                            target.pointer[1] = path + reader.Value;
                    }
                    reader.MoveToElement();
                }
            }

            loadShaderFromFile(target);
        }
Esempio n. 4
0
        internal Shader fromXmlFile(string file)
        {
            string name = file.Replace(gameWindow.shaderFolder, "");

            if (!shaderNames.ContainsKey(name))
            {
                Shader curShader = new Shader();

                int identifier = shaders.Count;

                curShader.type = Shader.Type.fromXml;
                curShader.pointer = new string[] { file };
                curShader.identifier = identifier;
                curShader.name = name;
                curShader.loaded = false;

                registerShader(curShader);
                return curShader;
            }
            else
            {
                return getShader(name);
            }
        }
Esempio n. 5
0
        public void loadShaderFromCache(Shader target)
        {
            int shaderProgramHandle;

            vertexShaderHandle = GL.CreateShader(ShaderType.VertexShader);
            fragmentShaderHandle = GL.CreateShader(ShaderType.FragmentShader);

            GL.ShaderSource(vertexShaderHandle, target.vShader);
            GL.ShaderSource(fragmentShaderHandle, target.fShader);

            string log;

            GL.CompileShader(vertexShaderHandle);
            GL.GetShaderInfoLog(vertexShaderHandle, out log);
            parseLog(log,"vertexShader" + Name, target.vShader);
            gameWindow.checkGlError("loadVertexShader (" + Name + ")");

            GL.CompileShader(fragmentShaderHandle);
            GL.GetShaderInfoLog(fragmentShaderHandle, out log);
            parseLog(log, "fragmentShader" + Name, target.fShader);
            gameWindow.checkGlError("loadFragmentShader (" + Name + ")");

            Debug.WriteLine(GL.GetShaderInfoLog(vertexShaderHandle));
            Debug.WriteLine(GL.GetShaderInfoLog(fragmentShaderHandle));

            // Create program
            shaderProgramHandle = GL.CreateProgram();

            GL.AttachShader(shaderProgramHandle, vertexShaderHandle);
            GL.AttachShader(shaderProgramHandle, fragmentShaderHandle);

            GL.LinkProgram(shaderProgramHandle);

            Debug.WriteLine(GL.GetProgramInfoLog(shaderProgramHandle));

            //GL.UseProgram(shaderProgramHandle);

            gameWindow.checkGlError("loadShader");

            target.handle = shaderProgramHandle;

            getHandles(ref target);

            target.loaded = true;

            shaders[target.identifier] = target;
        }
Esempio n. 6
0
        public void loadShaderFromFile(Shader target)
        {
            string vfile = target.pointer[0];
            string ffile = target.pointer[1];

            target.vShader = readFile(vfile);
            target.fShader = readFile(ffile);

            loadShaderFromCache(target);
        }
Esempio n. 7
0
        internal Shader nameOnly()
        {
            Shader tmpShader = new Shader();

            tmpShader.name = name;

            return tmpShader;
        }
Esempio n. 8
0
        public void getHandles(ref Shader target)
        {
            int shaderProgramHandle = target.handle;

            // Set uniforms
            target.generateLocations();

            target.sunDirection = GL.GetUniformLocation(shaderProgramHandle, "sunLightStruct.direction");
            target.sunColor = GL.GetUniformLocation(shaderProgramHandle, "sunLightStruct.color");
            target.sunMatrix = GL.GetUniformLocation(shaderProgramHandle, "sunLightStruct.view_matrix");
            target.sunInnerMatrix = GL.GetUniformLocation(shaderProgramHandle, "sunLightStruct.inner_view_matrix");

            target.lightLocationsLocation = new int[maxNoLights];
            target.lightDirectionsLocation = new int[maxNoLights];
            target.lightColorsLocation = new int[maxNoLights];
            target.lightViewMatrixLocation = new int[maxNoLights];
            target.lightActiveLocation = new int[maxNoLights];
            target.lightTextureLocation = new int[maxNoLights];

            for (int i = 0; i < maxNoLights; i++)
            {
                target.lightActiveLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].active");

                target.lightLocationsLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].position");
                target.lightDirectionsLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].direction");
                target.lightColorsLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].color");

                target.lightTextureLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].texture");

                target.lightViewMatrixLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].view_matrix");
            }

            target.BoneMatixLocations = new int[maxNoBones];
            for (int i = 0; i < maxNoBones; i++)
            {
                target.BoneMatixLocations[i] = GL.GetUniformLocation(shaderProgramHandle, "bone_matrix[" + i + "]");
            }
        }
Esempio n. 9
0
 public virtual void activateDeffered(Shader shader)
 {
 }
Esempio n. 10
0
        internal void cache(ref ShaderCacheObject cacheObject)
        {
            Shader tmpShader = new Shader();

            tmpShader.name = name;
            tmpShader.vShader = vShader;
            tmpShader.fShader = fShader;

            cacheObject.shaders.Add(tmpShader);
        }
Esempio n. 11
0
 public virtual void activate(Shader shader, Drawable drawable)
 {
 }
Esempio n. 12
0
        internal void resolveShaders(ShaderLoader shaderLoader)
        {
            if (shader.name != null)
                shader = shaderLoader.getShader(shader.name);

            if (shadowshader.name != null)
                shadowshader = shaderLoader.getShader(shadowshader.name);

            if (ssnshader.name != null)
                ssnshader = shaderLoader.getShader(ssnshader.name);

            if (selectionshader.name != null)
                selectionshader = shaderLoader.getShader(selectionshader.name);

            if (definfoshader.name != null)
                definfoshader = shaderLoader.getShader(definfoshader.name);
        }
Esempio n. 13
0
        public Shader fromTextFile(string vfile, string ffile)
        {
            string name = ffile.Replace(gameWindow.shaderFolder, "");

            if (!ShaderNames.ContainsKey(ffile))
            {
                Shader curShader = new Shader();

                int identifier = Shaders.Count;

                curShader.type = Shader.TYPE_FROMFILE;
                curShader.pointer = new string[] { vfile, ffile };
                curShader.identifier = identifier;
                curShader.name = name;
                curShader.loaded = false;

                registerShader(curShader);
                return curShader;
            }
            else
            {
                return getShader(ffile);
            }
        }
Esempio n. 14
0
        public void loadShader(Shader target)
        {
            if (target.type == Shader.TYPE_FROMXML)
            {
                XmlTextReader reader = new XmlTextReader(target.pointer[0]);

                string path = Path.GetDirectoryName(target.pointer[0]) + "\\";

                //target.envMapAlphaBaseTexture = false;

                gameWindow.log("parsing shader pair: " + target.name);

                target.pointer = new string[2];

                while (reader.Read())
                {
                    // parsing data in material tag
                    if (reader.Name == "shaderpair" && reader.HasAttributes)
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.Name == "vertex")
                                target.pointer[0] = path + reader.Value;

                            else if (reader.Name == "fragment")
                                target.pointer[1] = path + reader.Value;
                        }
                        reader.MoveToElement();
                    }
                }

                target.type = Shader.TYPE_FROMFILE;
                loadShader(target);
            }
            else if (target.type == Shader.TYPE_FROMFILE)
            {
                int shaderProgramHandle;

                string vfile = target.pointer[0];
                string ffile = target.pointer[1];

                vertexShaderHandle = GL.CreateShader(ShaderType.VertexShader);
                fragmentShaderHandle = GL.CreateShader(ShaderType.FragmentShader);

                GL.ShaderSource(vertexShaderHandle, readFile(vfile));
                GL.ShaderSource(fragmentShaderHandle, readFile(ffile));

                string log;

                GL.CompileShader(vertexShaderHandle);
                GL.GetShaderInfoLog(vertexShaderHandle, out log);
                gameWindow.log("Shaderlog (" + vfile + "):" + log);
                gameWindow.checkGlError("loadShader (" + vfile + ")");

                GL.CompileShader(fragmentShaderHandle);
                GL.GetShaderInfoLog(fragmentShaderHandle, out log);
                gameWindow.log("Shaderlog (" + ffile + "):" + log);
                gameWindow.checkGlError("loadShader (" + ffile + ")");

                Debug.WriteLine(GL.GetShaderInfoLog(vertexShaderHandle));
                Debug.WriteLine(GL.GetShaderInfoLog(fragmentShaderHandle));

                // Create program
                shaderProgramHandle = GL.CreateProgram();

                GL.AttachShader(shaderProgramHandle, vertexShaderHandle);
                GL.AttachShader(shaderProgramHandle, fragmentShaderHandle);

                GL.LinkProgram(shaderProgramHandle);

                Debug.WriteLine(GL.GetProgramInfoLog(shaderProgramHandle));

                //GL.UseProgram(shaderProgramHandle);

                gameWindow.checkGlError("loadShader");

                target.handle = shaderProgramHandle;

                getHandles(ref target);

                target.loaded = true;

                Shaders[target.identifier] = target;
            }
        }
Esempio n. 15
0
        public void getHandles(ref Shader target)
        {
            int shaderProgramHandle = target.handle;

            // Set uniforms
            target.projectionMatrixLocation = GL.GetUniformLocation(shaderProgramHandle, "projection_matrix");
            target.projectionRevMatrixLocation = GL.GetUniformLocation(shaderProgramHandle, "projection_rev_matrix");
            target.modelviewMatrixLocation = GL.GetUniformLocation(shaderProgramHandle, "modelview_matrix");
            target.rotationMatrixLocation = GL.GetUniformLocation(shaderProgramHandle, "rotation_matrix");
            target.modelMatrixLocation = GL.GetUniformLocation(shaderProgramHandle, "model_matrix");
            target.rotationMatrixLocation2 = GL.GetUniformLocation(shaderProgramHandle, "rotation_matrix2");
            target.modelMatrixLocation2 = GL.GetUniformLocation(shaderProgramHandle, "model_matrix2");

            target.eyePosLocation = GL.GetUniformLocation(shaderProgramHandle, "in_eyepos");
            target.timeLocation = GL.GetUniformLocation(shaderProgramHandle, "in_time");
            target.passLocation = GL.GetUniformLocation(shaderProgramHandle, "in_pass");
            target.waterLevelLocation = GL.GetUniformLocation(shaderProgramHandle, "in_waterlevel");
            target.vectorLocation = GL.GetUniformLocation(shaderProgramHandle, "in_vector");
            target.screenSizeLocation = GL.GetUniformLocation(shaderProgramHandle, "in_screensize");
            target.renderSizeLocation = GL.GetUniformLocation(shaderProgramHandle, "in_rendersize");
            target.lightAmbientLocation = GL.GetUniformLocation(shaderProgramHandle, "in_lightambient");
            target.lightSunLocation = GL.GetUniformLocation(shaderProgramHandle, "in_lightsun");
            target.shadowQualityLocation = GL.GetUniformLocation(shaderProgramHandle, "shadow_quality");

            target.particlePos = GL.GetUniformLocation(shaderProgramHandle, "in_particlepos");
            target.particleSize = GL.GetUniformLocation(shaderProgramHandle, "in_particlesize");

            target.colorLocation = GL.GetUniformLocation(shaderProgramHandle, "in_color");
            target.modLocation = GL.GetUniformLocation(shaderProgramHandle, "in_mod");

            target.useEmitLocation = GL.GetUniformLocation(shaderProgramHandle, "use_emit");
            target.emitMapAlphaBaseTexture = GL.GetUniformLocation(shaderProgramHandle, "emit_a_base");
            target.emitMapAlphaNormalTexture = GL.GetUniformLocation(shaderProgramHandle, "emit_a_normal");
            target.emitColorLocation = GL.GetUniformLocation(shaderProgramHandle, "in_emitcolor");

            target.useSpecLocation = GL.GetUniformLocation(shaderProgramHandle, "use_spec");
            target.specMapAlphaBaseTexture = GL.GetUniformLocation(shaderProgramHandle, "spec_a_base");
            target.specMapAlphaNormalTexture = GL.GetUniformLocation(shaderProgramHandle, "spec_a_normal");
            target.specColorLocation = GL.GetUniformLocation(shaderProgramHandle, "in_speccolor");
            target.specExpLocation = GL.GetUniformLocation(shaderProgramHandle, "in_specexp");

            target.useEnvLocation = GL.GetUniformLocation(shaderProgramHandle, "use_env");
            target.envMapAlphaBaseTexture = GL.GetUniformLocation(shaderProgramHandle, "env_a_base");
            target.envMapAlphaNormalTexture = GL.GetUniformLocation(shaderProgramHandle, "env_a_normal");
            target.envTintLocation = GL.GetUniformLocation(shaderProgramHandle, "env_tint");

            target.useAlphaLocation = GL.GetUniformLocation(shaderProgramHandle, "use_alpha");
            target.refSizeLocation = GL.GetUniformLocation(shaderProgramHandle, "ref_size");
            target.blurSizeLocation = GL.GetUniformLocation(shaderProgramHandle, "blur_size");
            target.fresnelStrLocation = GL.GetUniformLocation(shaderProgramHandle, "fresnel_str");

            target.nearLocation = GL.GetUniformLocation(shaderProgramHandle, "in_near");
            target.farLocation = GL.GetUniformLocation(shaderProgramHandle, "in_far");

            target.hudElementSize = GL.GetUniformLocation(shaderProgramHandle, "in_hudsize");
            target.hudElementPos = GL.GetUniformLocation(shaderProgramHandle, "in_hudpos");
            target.hudElementColor = GL.GetUniformLocation(shaderProgramHandle, "in_hudcolor");
            target.hudElementValue = GL.GetUniformLocation(shaderProgramHandle, "in_hudvalue");

            target.lightLocationsLocation = new int[maxNoLights];
            target.lightDirectionsLocation = new int[maxNoLights];
            target.lightColorsLocation = new int[maxNoLights];
            target.lightViewMatrixLocation = new int[maxNoLights];
            target.lightActiveLocation = new int[maxNoLights];
            target.lightTextureLocation = new int[maxNoLights];

            target.LightCountLocation = GL.GetUniformLocation(shaderProgramHandle, "in_no_lights");
            target.curLightLocation = GL.GetUniformLocation(shaderProgramHandle, "curLight");
            target.sunDirection = GL.GetUniformLocation(shaderProgramHandle, "sunLightStruct.direction");
            target.sunColor = GL.GetUniformLocation(shaderProgramHandle, "sunLightStruct.color");
            target.sunMatrix = GL.GetUniformLocation(shaderProgramHandle, "sunLightStruct.view_matrix");
            target.sunInnerMatrix = GL.GetUniformLocation(shaderProgramHandle, "sunLightStruct.inner_view_matrix");

            for (int i = 0; i < maxNoLights; i++)
            {
                target.lightActiveLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].active");

                target.lightLocationsLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].position");
                target.lightDirectionsLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].direction");
                target.lightColorsLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].color");

                target.lightTextureLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].texture");

                target.lightViewMatrixLocation[i] = GL.GetUniformLocation(shaderProgramHandle, "lightStructs[" + i + "].view_matrix");
            }
        }