Ejemplo n.º 1
0
        public SSMesh_SphereICO(int divisions, SSMainShaderProgram shaderPgm, SSTexture texture)
        {
            this.shaderPgm = shaderPgm;
            this.texture   = texture;

            this._Create(divisions);
        }
Ejemplo n.º 2
0
        protected void setMaterialState(SSMainShaderProgram mainShader)
        {
            GL.Enable(EnableCap.ColorMaterial); // turn off per-vertex color
            GL.Color4(this.MainColor);

            // setup the base color values...
            GL.Material(MaterialFace.Front, MaterialParameter.Ambient, AmbientMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, DiffuseMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Specular, SpecularMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Emission, EmissionMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Shininess, ShininessMatColor);

            if (textureMaterial != null)
            {
                if (mainShader != null)
                {
                    mainShader.SetupTextures(textureMaterial);
                }
                else
                {
                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.Enable(EnableCap.Texture2D);
                    if (textureMaterial.ambientTex != null || textureMaterial.diffuseTex != null)
                    {
                        // fall back onto the diffuse texture in the absence of ambient
                        SSTexture tex = textureMaterial.ambientTex ?? textureMaterial.diffuseTex;
                        GL.BindTexture(TextureTarget.Texture2D, tex.TextureID);
                    }
                    else
                    {
                        GL.BindTexture(TextureTarget.Texture2D, 0);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public SSScene(SSMainShaderProgram main                 = null,
                SSPssmShaderProgram pssm                 = null,
                SSInstanceShaderProgram instance         = null,
                SSInstancePssmShaderProgram instancePssm = null)
 {
     renderConfig = new SSRenderConfig(main, pssm, instance, instancePssm);
 }
Ejemplo n.º 4
0
 public SSScene(SSMainShaderProgram main                          = null,
                SSPssmShaderProgram pssm                          = null,
                SSInstanceShaderProgram instance                  = null,
                SSInstancePssmShaderProgram instancePssm          = null,
                Dictionary <string, SSShaderProgram> otherShaders = null)
 {
     renderConfig = new SSRenderConfig(main, pssm, instance, instancePssm, otherShaders);
 }
Ejemplo n.º 5
0
 protected void setDefaultShaderState(SSMainShaderProgram pgm)
 {
     if (pgm != null)
     {
         pgm.Activate();
         pgm.UniObjectWorldTransform = this.worldMat;
         pgm.SetupTextures();
     }
 }
Ejemplo n.º 6
0
        public SSRenderConfig(SSMainShaderProgram main,
							  SSPssmShaderProgram pssm,
							  SSInstanceShaderProgram instance,
							  SSInstancePssmShaderProgram instancePssm)
        {
            mainShader = main;
            pssmShader = pssm;
            instanceShader = instance;
            instancePssmShader = instancePssm;
        }
Ejemplo n.º 7
0
 public SSRenderConfig(SSMainShaderProgram main,
                       SSPssmShaderProgram pssm,
                       SSInstanceShaderProgram instance,
                       SSInstancePssmShaderProgram instancePssm)
 {
     mainShader         = main;
     pssmShader         = pssm;
     instanceShader     = instance;
     instancePssmShader = instancePssm;
 }
Ejemplo n.º 8
0
 protected void setDefaultShaderState(SSMainShaderProgram pgm)
 {
     if (pgm != null)
     {
         pgm.Activate();
         pgm.UniObjectWorldTransform = this.worldMat;
         pgm.UniReceivesShadow       = renderState.receivesShadows;
         pgm.UniSpriteOffsetAndSize(0f, 0f, 1f, 1f);
         pgm.SetupTextures(textureMaterial);
     }
 }
Ejemplo n.º 9
0
 protected void setDefaultShaderState(SSMainShaderProgram pgm, SSRenderConfig config)
 {
     if (pgm != null)
     {
         pgm.Activate();
         pgm.UniObjectWorldTransform = this.worldMat;
         pgm.UniReceivesShadow       = renderState.receivesShadows;
         pgm.UniSpriteOffsetAndSize(0f, 0f, 1f, 1f);
         pgm.UniShowWireframes = (config.drawWireframeMode == WireframeMode.GLSL_SinglePass);
         pgm.SetupTextures(textureMaterial);
     }
 }
Ejemplo n.º 10
0
 private void configureDrawShader(SSRenderConfig renderConfig, SSMainShaderProgram pgm)
 {
     if (pgm != null)
     {
         pgm.Activate();
         pgm.UniPoissonSamplingEnabled = renderConfig.usePoissonSampling;
         if (renderConfig.usePoissonSampling)
         {
             pgm.UniNumPoissonSamples = renderConfig.numPoissonSamples;
         }
     }
 }
Ejemplo n.º 11
0
        public SSRenderConfig(SSMainShaderProgram main,
							  SSPssmShaderProgram pssm,
							  SSInstanceShaderProgram instance,
							  SSInstancePssmShaderProgram instancePssm,
                              Dictionary<string, SSShaderProgram> other
        )
        {
            mainShader = main;
            pssmShader = pssm;
            instanceShader = instance;
            instancePssmShader = instancePssm;
            otherShaders = other;
        }
Ejemplo n.º 12
0
 public SSRenderConfig(SSMainShaderProgram main,
                       SSPssmShaderProgram pssm,
                       SSInstanceShaderProgram instance,
                       SSInstancePssmShaderProgram instancePssm,
                       Dictionary <string, SSShaderProgram> other
                       )
 {
     mainShader         = main;
     pssmShader         = pssm;
     instanceShader     = instance;
     instancePssmShader = instancePssm;
     otherShaders       = other;
 }
Ejemplo n.º 13
0
 private void configureDrawShader(ref SSRenderConfig renderConfig, SSMainShaderProgram pgm, Matrix4[] vp)
 {
     if (pgm == null)
     {
         return;
     }
     pgm.Activate();
     pgm.UniNumShadowMaps = 1;
     if (renderConfig.usePoissonSampling)
     {
         Vector2[] poissonScales = { new Vector2(1f) };
         pgm.UniPoissonScaling = poissonScales;
     }
     pgm.UniShadowMapVPs = vp;
 }
Ejemplo n.º 14
0
 protected void configureDrawShader(SSRenderConfig renderConfig, SSMainShaderProgram pgm)
 {
     if (pgm == null)
     {
         return;
     }
     pgm.Activate();
     pgm.UniNumShadowMaps = c_numberOfSplits;
     if (renderConfig.usePoissonSampling)
     {
         pgm.UniPoissonScaling = m_poissonScaling;
     }
     pgm.UniShadowMapVPs = m_shadowViewProjBiasMatrices;
     pgm.UniPssmSplits   = m_viewSplits;
 }
Ejemplo n.º 15
0
        private void _renderSetupGLSL(SSRenderConfig renderConfig, SSMainShaderProgram shaderPgm, SSMeshOBJSubsetData subset)
        {
            // Step 1: setup GL rendering modes...

            // GL.Enable(EnableCap.Lighting);

            // GL.Enable(EnableCap.Blend);
            // GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            // GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

            // Step 2: setup our material mode and paramaters...

            if (renderConfig.drawingShadowMap)
            {
                // assume SSObject.Render has setup our materials properly for the shadowmap Pass
                // TODO: find a better way to do this!
                return;
            }

            SSColorMaterial.applyColorMaterial(subset.colorMaterial);
            if (shaderPgm == null)
            {
                SSShaderProgram.DeactivateAll();

                // fixed function single-texture
                if (subset.textureMaterial.diffuseTex != null)
                {
                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, subset.textureMaterial.diffuseTex.TextureID);
                }
            }
            else
            {
                shaderPgm.Activate();
                shaderPgm.SetupTextures(subset.textureMaterial);
            }
        }
Ejemplo n.º 16
0
 protected void setDefaultShaderState(SSMainShaderProgram pgm, SSRenderConfig config)
 {
     if (pgm != null) {
         pgm.Activate();
         pgm.UniObjectWorldTransform = this.worldMat;
         pgm.UniReceivesShadow = renderState.receivesShadows;
         pgm.UniSpriteOffsetAndSize(0f, 0f, 1f, 1f);
         pgm.UniShowWireframes = (config.drawWireframeMode == WireframeMode.GLSL_SinglePass);
         pgm.UniLighted = renderState.lighted;
         pgm.SetupTextures(textureMaterial);
     }
 }
Ejemplo n.º 17
0
        public SSScene(SSMainShaderProgram main = null,
					   SSPssmShaderProgram pssm = null,
					   SSInstanceShaderProgram instance = null,
					   SSInstancePssmShaderProgram instancePssm = null)
        {
            renderConfig = new SSRenderConfig (main, pssm, instance, instancePssm);
        }
Ejemplo n.º 18
0
 protected void setDefaultShaderState(SSMainShaderProgram pgm)
 {
     if (pgm != null) {
         pgm.Activate();
         pgm.UniObjectWorldTransform = this.worldMat;
         pgm.UniReceivesShadow = renderState.receivesShadows;
         pgm.UniSpriteOffsetAndSize(0f, 0f, 1f, 1f);
         pgm.SetupTextures(textureMaterial);
     }
 }
Ejemplo n.º 19
0
        private void _renderSetupGLSL(SSRenderConfig renderConfig, SSMainShaderProgram shaderPgm, SSMeshOBJSubsetData subset)
        {
            // Step 1: setup GL rendering modes...

            // GL.Enable(EnableCap.Lighting);

            // GL.Enable(EnableCap.Blend);
            // GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            // GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

            // Step 2: setup our material mode and paramaters...

            if (renderConfig.drawingShadowMap) {
                // assume SSObject.Render has setup our materials properly for the shadowmap Pass
                // TODO: find a better way to do this!
                return;
            }

             			if (shaderPgm == null) {
                SSShaderProgram.DeactivateAll ();

                // fixed function single-texture
                if (subset.TextureMaterial.diffuseTex != null) {
                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, subset.TextureMaterial.diffuseTex.TextureID);
                }
            } else {
                shaderPgm.Activate();
                shaderPgm.SetupTextures(subset.TextureMaterial);
            }
        }
Ejemplo n.º 20
0
        private void _renderSetupGLSL(ref SSRenderConfig renderConfig, SSMeshOBJSubsetData subset)
        {
            // Step 1: setup GL rendering modes...

            GL.Enable(EnableCap.CullFace);
            // GL.Enable(EnableCap.Lighting);

            // GL.Enable(EnableCap.Blend);
            // GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            // GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

            // Step 2: setup our material mode and paramaters...

            GL.Color3(System.Drawing.Color.White);              // clear the vertex color to white..

            SSMainShaderProgram shaderPgm = renderConfig.BaseShader;

            if (renderConfig.drawingShadowMap)
            {
                // assume SSObject.Render has setup our materials properly for the shadowmap Pass
                // TODO: find a better way to do this!
                return;
            }

            if (shaderPgm == null)
            {
                SSShaderProgram.DeactivateAll();
                GL.Disable(EnableCap.CullFace);

                // fixed function single-texture
                GL.Disable(EnableCap.Texture2D);
                if (subset.diffuseTexture != null)
                {
                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, subset.diffuseTexture.TextureID);
                }
            }
            else
            {
                // activate GLSL shader
                shaderPgm.Activate();

                // bind our texture-images to GL texture-units
                // http://adriangame.blogspot.com/2010/05/glsl-multitexture-checklist.html

                // these texture-unit assignments are hard-coded in the shader setup

                GL.ActiveTexture(TextureUnit.Texture0);
                if (subset.diffuseTexture != null)
                {
                    GL.BindTexture(TextureTarget.Texture2D, subset.diffuseTexture.TextureID);
                    shaderPgm.u_DiffTexEnabled = true;
                }
                else
                {
                    GL.BindTexture(TextureTarget.Texture2D, 0);
                    shaderPgm.u_DiffTexEnabled = false;
                }
                GL.ActiveTexture(TextureUnit.Texture1);
                if (subset.specularTexture != null)
                {
                    GL.BindTexture(TextureTarget.Texture2D, subset.specularTexture.TextureID);
                    shaderPgm.u_SpecTexEnabled = true;
                }
                else
                {
                    GL.BindTexture(TextureTarget.Texture2D, 0);
                    shaderPgm.u_SpecTexEnabled = false;
                }
                GL.ActiveTexture(TextureUnit.Texture2);
                if (subset.ambientTexture != null)
                {
                    GL.BindTexture(TextureTarget.Texture2D, subset.ambientTexture.TextureID);
                    shaderPgm.u_AmbTexEnabled = true;
                }
                else
                {
                    GL.BindTexture(TextureTarget.Texture2D, 0);
                    shaderPgm.u_AmbTexEnabled = false;
                }
                GL.ActiveTexture(TextureUnit.Texture3);
                if (subset.bumpTexture != null)
                {
                    GL.BindTexture(TextureTarget.Texture2D, subset.bumpTexture.TextureID);
                    shaderPgm.u_BumpTexEnabled = true;
                }
                else
                {
                    GL.BindTexture(TextureTarget.Texture2D, 0);
                    shaderPgm.u_BumpTexEnabled = false;
                }

                // reset to texture-unit 0 to be friendly..
                GL.ActiveTexture(TextureUnit.Texture0);
            }
        }
Ejemplo n.º 21
0
        /// <summary>Creates a 800x600 window with the specified title.</summary>
        public TestBenchBootstrap(string windowName)
            : base(#if false
				800, 600, 
				GraphicsMode.Default, // color format
				windowName,
				GameWindowFlags.Default,  // windowed mode 
				DisplayDevice.Default,    // primary monitor
				2, 2,  // opengl version
				GraphicsContextFlags.Debug
				#endif)
        {
            // this can be used to force other culture settings for testing..
            // System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-NL");

            this.Title = windowName;
            VSync = VSyncMode.On;
            restoreClientWindowLocation();

            Console.WriteLine("GL Version = {0}",GL.GetString(StringName.Version));
            Console.WriteLine("GL Shader Version = {0}", GL.GetString(StringName.ShadingLanguageVersion));

            // setup asset manager contexts
            // these help the asset manager find the "Asset" directy up above the bin/obj/Debug
            // output directories...
            SSAssetManager.AddAssetArchive(new SSAssetArchiveHandler_FileSystem("./Assets"));
            SSAssetManager.AddAssetArchive(new SSAssetArchiveHandler_FileSystem("../../Assets"));
            SSAssetManager.AddAssetArchive(new SSAssetArchiveHandler_FileSystem("../../../Assets"));
            SSAssetManager.AddAssetArchive(new SSAssetArchiveHandler_FileSystem("../../../../Assets"));

            mainShader = new SSMainShaderProgram(); // before mscene
            if (!mainShader.IsValid) {
                throw new Exception ("Failed to build the main shader");
            }
            pssmShader = new SSPssmShaderProgram ();
            if (!pssmShader.IsValid) {
                pssmShader = null;
            }
            instancingShader = new SSInstanceShaderProgram ();
            if (!instancingShader.IsValid) {
                instancingShader = null;
            } else {
                instancingShader.debugLocations ();
            }
            instancingPssmShader = new SSInstancePssmShaderProgram ();
            if (!instancingPssmShader.IsValid) {
                instancingPssmShader = null;
            }

            setupInput ();
            setupScene ();
            setupCamera ();
            setupEnvironment ();
            setupHUD ();
        }
Ejemplo n.º 22
0
 protected void configureDrawShader(SSRenderConfig renderConfig, SSMainShaderProgram pgm)
 {
     if (pgm == null) return;
     pgm.Activate();
     pgm.UniNumShadowMaps = c_numberOfSplits;
     if (renderConfig.usePoissonSampling) {
         pgm.UniPoissonScaling = m_poissonScaling;
     }
     pgm.UniShadowMapVPs = m_shadowViewProjBiasMatrices;
     pgm.UniPssmSplits = m_viewSplits;
 }
Ejemplo n.º 23
0
        protected void setMaterialState(SSMainShaderProgram mainShader)
        {
            GL.Enable(EnableCap.ColorMaterial); // turn off per-vertex color
            GL.Color4(this.MainColor);

            // setup the base color values...
            GL.Material(MaterialFace.Front, MaterialParameter.Ambient, AmbientMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, DiffuseMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Specular, SpecularMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Emission, EmissionMatColor);
            GL.Material(MaterialFace.Front, MaterialParameter.Shininess, ShininessMatColor);

            if (textureMaterial != null) {
                GL.ActiveTexture(TextureUnit.Texture0);
                GL.Enable(EnableCap.Texture2D);
                if (textureMaterial.ambientTex != null || textureMaterial.diffuseTex != null) {
                    // fall back onto the diffuse texture in the absence of ambient
                    SSTexture tex = textureMaterial.diffuseTex ?? textureMaterial.ambientTex;
                    GL.BindTexture(TextureTarget.Texture2D, tex.TextureID);
                } else {
                    GL.BindTexture(TextureTarget.Texture2D, 0);
                }
            }
        }
Ejemplo n.º 24
0
 private void configureDrawShader(ref SSRenderConfig renderConfig, SSMainShaderProgram pgm, Matrix4[] vp)
 {
     if (pgm == null) return;
     pgm.Activate ();
     pgm.UniNumShadowMaps = 1;
     if (renderConfig.usePoissonSampling) {
         Vector2[] poissonScales = { new Vector2 (1f) };
         pgm.UniPoissonScaling = poissonScales;
     }
     pgm.UniShadowMapVPs = vp;
 }
Ejemplo n.º 25
0
        public SSScene(SSMainShaderProgram main = null,
					   SSPssmShaderProgram pssm = null,
					   SSInstanceShaderProgram instance = null,
					   SSInstancePssmShaderProgram instancePssm = null,
                       Dictionary<string, SSShaderProgram> otherShaders = null)
        {
            renderConfig = new SSRenderConfig (main, pssm, instance, instancePssm, otherShaders);
        }
Ejemplo n.º 26
0
 private void configureDrawShader(SSRenderConfig renderConfig, SSMainShaderProgram pgm)
 {
     if (pgm != null) {
         pgm.Activate();
         pgm.UniPoissonSamplingEnabled = renderConfig.usePoissonSampling;
         if (renderConfig.usePoissonSampling) {
             pgm.UniNumPoissonSamples = renderConfig.numPoissonSamples;
         }
     }
 }