public SSPssmShaderProgram(string preprocessorDefs = null) { string glExtStr = GL.GetString(StringName.Extensions).ToLower(); if (!glExtStr.Contains("gl_ext_gpu_shader4")) { Console.WriteLine("PSSM shader not supported"); m_isValid = false; return; } m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>( Path.Combine(c_basePath, "pssm_vertex.glsl")); m_vertexShader.Prepend(preprocessorDefs); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>( Path.Combine(c_basePath, "pssm_fragment.glsl")); m_fragmentShader.Prepend(preprocessorDefs); m_fragmentShader.LoadShader(); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance <SSGeometryShader>( Path.Combine(c_basePath, "pssm_geometry.glsl")); m_geometryShader.Prepend(preprocessorDefs); m_geometryShader.LoadShader(); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3 * SSParallelSplitShadowMap.c_numberOfSplits); attach(m_geometryShader); link(); Activate(); u_shadowMapVPs = getUniLoc("shadowMapVPs"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_numShadowMaps = getUniLoc("numShadowMaps"); GL.Uniform1(u_numShadowMaps, SSParallelSplitShadowMap.c_numberOfSplits); m_isValid = checkGlValid(); }
public SSPssmShaderProgram(string preprocessorDefs = null) { string glExtStr = GL.GetString (StringName.Extensions).ToLower (); if (!glExtStr.Contains ("gl_ext_gpu_shader4")) { Console.WriteLine ("PSSM shader not supported"); m_isValid = false; return; } m_vertexShader = SSAssetManager.GetInstance<SSVertexShader>( Path.Combine(c_basePath, "pssm_vertex.glsl")); m_vertexShader.Prepend (preprocessorDefs); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance<SSFragmentShader>( Path.Combine(c_basePath, "pssm_fragment.glsl")); m_fragmentShader.Prepend (preprocessorDefs); m_fragmentShader.LoadShader(); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance<SSGeometryShader>( Path.Combine(c_basePath, "pssm_geometry.glsl")); m_geometryShader.Prepend (preprocessorDefs); m_geometryShader.LoadShader(); GL.Ext.ProgramParameter (m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter (m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter (m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3 * SSParallelSplitShadowMap.c_numberOfSplits); attach(m_geometryShader); link(); Activate(); u_shadowMapVPs = getUniLoc ("shadowMapVPs"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_numShadowMaps = getUniLoc("numShadowMaps"); GL.Uniform1(u_numShadowMaps, SSParallelSplitShadowMap.c_numberOfSplits); m_isValid = checkGlValid(); }
public SSMainShaderProgram(string preprocessorDefs = null) { // we use this method of detecting the extension because we are in a GL2.2 context if (GL.GetString(StringName.Extensions).ToLower().Contains("gl_ext_gpu_shader4")) { m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>(c_ctx, "ss4_vertex.glsl"); m_vertexShader.Prepend(preprocessorDefs); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>(c_ctx, "ss4_fragment.glsl"); m_fragmentShader.Prepend(preprocessorDefs); m_fragmentShader.LoadShader(); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance <SSGeometryShader>(c_ctx, "ss4_geometry.glsl"); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3); m_geometryShader.Prepend(preprocessorDefs); m_geometryShader.LoadShader(); attach(m_geometryShader); } else { m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>(c_ctx, "ss1_vertex.glsl"); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>(c_ctx, "ss1_fragment.glsl"); m_fragmentShader.LoadShader(); attach(m_fragmentShader); } link(); // shader is initialized now... Activate(); // reused uniform locations u_diffTexEnabled = getUniLoc("diffTexEnabled"); u_specTexEnabled = getUniLoc("specTexEnabled"); u_ambiTexEnabled = getUniLoc("ambiTexEnabled"); u_bumpTexEnabled = getUniLoc("bumpTexEnabled"); u_animateSecondsOffset = getUniLoc("animateSecondsOffset"); u_winScale = getUniLoc("WIN_SCALE"); u_showWireframes = getUniLoc("showWireframes"); u_numShadowMaps = getUniLoc("numShadowMaps"); u_shadowMapTexture = getUniLoc("shadowMapTexture"); u_poissonSamplingEnabled = getUniLoc("poissonSamplingEnabled"); u_numPoissonSamples = getUniLoc("numPoissonSamples"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_lightingMode = getUniLoc("lightingMode"); u_shadowMapVPs = getUniLoc("shadowMapVPs"); u_poissonScaling = getUniLoc("poissonScale"); u_shadowMapViewSplits = getUniLoc("shadowMapViewSplits"); UniShowWireframes = false; UniAnimateSecondsOffset = 0.0f; UniNumShadowMaps = 0; UniLightingMode = LightingMode.ShadowMapDebug; UniPoissonSamplingEnabled = true; UniNumPoissonSamples = 8; #if MAIN_SHADER_INSTANCING UniInstanceDrawEnabled = false; UniInstanceBillboardingEnabled = false; #endif // uniform locations for texture setup only int GLun_diffTex = getUniLoc("diffTex"); int GLun_specTex = getUniLoc("specTex"); int GLun_ambiTex = getUniLoc("ambiTex"); int GLun_bumpTex = getUniLoc("bumpTex"); // bind shader uniform variable handles to GL texture-unit numbers GL.Uniform1(GLun_diffTex, 0); // Texture.Texture0 GL.Uniform1(GLun_specTex, 1); // Texture.Texture1 GL.Uniform1(GLun_ambiTex, 2); // Texture.Texture2 GL.Uniform1(GLun_bumpTex, 3); // Texture.Texture3 // errors? m_isValid = checkGlValid(); }
public SSMainShaderProgram(string preprocessorDefs = null) { // we use this method of detecting the extension because we are in a GL2.2 context bool load_fallback_shader = true; // try to load SS4 shader if (GL.GetString(StringName.Extensions).ToLower().Contains("gl_ext_gpu_shader4")) { try { m_programID = GL.CreateProgram(); m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>( Path.Combine(c_basePath, "ss4_vertex.glsl")); m_vertexShader.Prepend(preprocessorDefs); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>( Path.Combine(c_basePath, "ss4_fragment.glsl")); m_fragmentShader.Prepend(preprocessorDefs); m_fragmentShader.LoadShader(); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance <SSGeometryShader>( Path.Combine(c_basePath, "ss4_geometry.glsl")); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter(m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3); m_geometryShader.Prepend(preprocessorDefs); m_geometryShader.LoadShader(); attach(m_geometryShader); load_fallback_shader = false; Console.WriteLine(" ---- SS4 shader loaded ---- "); } catch (SSShaderLoadException e) { Console.WriteLine(" ---- SS4 shader load failed... fallback to SS1 "); load_fallback_shader = true; } } // if the SS4 shader failed, load SS1 shader.... if (load_fallback_shader) { m_programID = GL.CreateProgram(); m_vertexShader = SSAssetManager.GetInstance <SSVertexShader>( Path.Combine(c_basePath, "ss1_vertex.glsl")); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance <SSFragmentShader>( Path.Combine(c_basePath, "ss1_fragment.glsl")); m_fragmentShader.LoadShader(); attach(m_fragmentShader); Console.WriteLine(" !!!! SS1 shader loaded "); } link(); // shader is initialized now... Activate(); // reused uniform locations u_diffTexEnabled = getUniLoc("diffTexEnabled"); u_specTexEnabled = getUniLoc("specTexEnabled"); u_ambiTexEnabled = getUniLoc("ambiTexEnabled"); u_bumpTexEnabled = getUniLoc("bumpTexEnabled"); u_animateSecondsOffset = getUniLoc("animateSecondsOffset"); u_winScale = getUniLoc("WIN_SCALE"); u_showWireframes = getUniLoc("showWireframes"); u_receivesShadow = getUniLoc("receivesShadow"); u_numShadowMaps = getUniLoc("numShadowMaps"); u_shadowMapTexture = getUniLoc("shadowMapTexture"); u_poissonSamplingEnabled = getUniLoc("poissonSamplingEnabled"); u_numPoissonSamples = getUniLoc("numPoissonSamples"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_lightingMode = getUniLoc("lightingMode"); u_directionalLightIndex = getUniLoc("directionalLightIndex"); u_lighted = getUniLoc("lighted"); u_shadowMapVPs = getUniLoc("shadowMapVPs"); u_poissonScaling = getUniLoc("poissonScale"); u_shadowMapViewSplits = getUniLoc("shadowMapViewSplits"); u_spriteOffsetAndSize = getUniLoc("spriteOffsetAndSize"); UniShowWireframes = false; UniAnimateSecondsOffset = 0.0f; UniNumShadowMaps = 0; UniLightingMode = LightingMode.ShadowMapDebug; UniPoissonSamplingEnabled = true; UniNumPoissonSamples = 8; UniDirectionalLightIndex = -1; // no directional light by default UniLighted = false; #if MAIN_SHADER_INSTANCING UniInstanceDrawEnabled = false; UniInstanceBillboardingEnabled = false; #endif // uniform locations for texture setup only int GLun_diffTex = getUniLoc("diffTex"); int GLun_specTex = getUniLoc("specTex"); int GLun_ambiTex = getUniLoc("ambiTex"); int GLun_bumpTex = getUniLoc("bumpTex"); // bind shader uniform variable handles to GL texture-unit numbers GL.Uniform1(GLun_diffTex, 0); // Texture.Texture0 GL.Uniform1(GLun_specTex, 1); // Texture.Texture1 GL.Uniform1(GLun_ambiTex, 2); // Texture.Texture2 GL.Uniform1(GLun_bumpTex, 3); // Texture.Texture3 // errors? m_isValid = checkGlValid(); }
public SSMainShaderProgram(string preprocessorDefs = null) { // we use this method of detecting the extension because we are in a GL2.2 context bool load_fallback_shader = true; // try to load SS4 shader if (GL.GetString(StringName.Extensions).ToLower().Contains("gl_ext_gpu_shader4")) { try { m_programID = GL.CreateProgram(); m_vertexShader = SSAssetManager.GetInstance<SSVertexShader>(c_ctx, "ss4_vertex.glsl"); m_vertexShader.Prepend (preprocessorDefs); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance<SSFragmentShader>(c_ctx, "ss4_fragment.glsl"); m_fragmentShader.Prepend (preprocessorDefs); m_fragmentShader.LoadShader(); attach(m_fragmentShader); m_geometryShader = SSAssetManager.GetInstance<SSGeometryShader>(c_ctx, "ss4_geometry.glsl"); GL.Ext.ProgramParameter (m_programID, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Triangles); GL.Ext.ProgramParameter (m_programID, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.TriangleStrip); GL.Ext.ProgramParameter (m_programID, ExtGeometryShader4.GeometryVerticesOutExt, 3); m_geometryShader.Prepend (preprocessorDefs); m_geometryShader.LoadShader(); attach(m_geometryShader); load_fallback_shader = false; Console.WriteLine(" ---- SS4 shader loaded ---- "); } catch (SSShaderLoadException e) { Console.WriteLine(" ---- SS4 shader load failed... fallback to SS1 "); load_fallback_shader = true; } } // if the SS4 shader failed, load SS1 shader.... if (load_fallback_shader) { m_programID = GL.CreateProgram(); m_vertexShader = SSAssetManager.GetInstance<SSVertexShader>(c_ctx, "ss1_vertex.glsl"); m_vertexShader.LoadShader(); attach(m_vertexShader); m_fragmentShader = SSAssetManager.GetInstance<SSFragmentShader>(c_ctx, "ss1_fragment.glsl"); m_fragmentShader.LoadShader(); attach(m_fragmentShader); Console.WriteLine(" !!!! SS1 shader loaded "); } link(); // shader is initialized now... Activate (); // reused uniform locations u_diffTexEnabled = getUniLoc("diffTexEnabled"); u_specTexEnabled = getUniLoc("specTexEnabled"); u_ambiTexEnabled = getUniLoc("ambiTexEnabled"); u_bumpTexEnabled = getUniLoc("bumpTexEnabled"); u_animateSecondsOffset = getUniLoc("animateSecondsOffset"); u_winScale = getUniLoc("WIN_SCALE"); u_showWireframes = getUniLoc("showWireframes"); u_receivesShadow = getUniLoc("receivesShadow"); u_numShadowMaps = getUniLoc("numShadowMaps"); u_shadowMapTexture = getUniLoc("shadowMapTexture"); u_poissonSamplingEnabled = getUniLoc("poissonSamplingEnabled"); u_numPoissonSamples = getUniLoc("numPoissonSamples"); u_objectWorldTransform = getUniLoc("objWorldTransform"); u_lightingMode = getUniLoc("lightingMode"); u_directionalLightIndex = getUniLoc("directionalLightIndex"); u_shadowMapVPs = getUniLoc("shadowMapVPs"); u_poissonScaling = getUniLoc("poissonScale"); u_shadowMapViewSplits = getUniLoc("shadowMapViewSplits"); u_spriteOffsetAndSize = getUniLoc("spriteOffsetAndSize"); UniShowWireframes = false; UniAnimateSecondsOffset = 0.0f; UniNumShadowMaps = 0; UniLightingMode = LightingMode.ShadowMapDebug; UniPoissonSamplingEnabled = true; UniNumPoissonSamples = 8; UniDirectionalLightIndex = -1; // no directional light by default #if MAIN_SHADER_INSTANCING UniInstanceDrawEnabled = false; UniInstanceBillboardingEnabled = false; #endif // uniform locations for texture setup only int GLun_diffTex = getUniLoc("diffTex"); int GLun_specTex = getUniLoc("specTex"); int GLun_ambiTex = getUniLoc("ambiTex"); int GLun_bumpTex = getUniLoc("bumpTex"); // bind shader uniform variable handles to GL texture-unit numbers GL.Uniform1(GLun_diffTex, 0); // Texture.Texture0 GL.Uniform1(GLun_specTex, 1); // Texture.Texture1 GL.Uniform1(GLun_ambiTex, 2); // Texture.Texture2 GL.Uniform1(GLun_bumpTex, 3); // Texture.Texture3 // errors? m_isValid = checkGlValid(); }