virtual Ogre::GpuProgramPtr generateFragmentShader(Perm permutation) { /// Create shader if (mMasterSource.empty()) { Ogre::DataStreamPtr ptrMasterSource = Ogre::ResourceGroupManager::getSingleton().openResource( "DeferredShading/post/LightMaterial_ps.cg" , Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); assert(ptrMasterSource.isNull()==false); mMasterSource = ptrMasterSource->getAsString(); } assert(mMasterSource.empty()==false); // Create name Ogre::String name = mBaseName+Ogre::StringConverter::toString(permutation)+"_ps"; // Create shader object Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram( name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "cg", Ogre::GPT_FRAGMENT_PROGRAM); ptrProgram->setSource(mMasterSource); ptrProgram->setParameter("entry_point","main"); ptrProgram->setParameter("profiles","ps_2_x arbfp1"); // set up the preprocessor defines // Important to do this before any call to get parameters, i.e. before the program gets loaded ptrProgram->setParameter("compile_arguments", getPPDefines(permutation)); setUpBaseParameters(ptrProgram->getDefaultParameters()); return Ogre::GpuProgramPtr(ptrProgram); }
virtual Ogre::GpuProgramPtr generateFragmentShader(Perm permutation) { /// Create shader if (mMasterSource.empty()) { Ogre::DataStreamPtr ptrMasterSource; if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles")) ptrMasterSource = Ogre::ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsles", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); else ptrMasterSource = Ogre::ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsl", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); assert(ptrMasterSource.isNull()==false); mMasterSource = ptrMasterSource->getAsString(); } assert(mMasterSource.empty()==false); // Create name Ogre::String name = mBaseName+Ogre::StringConverter::toString(permutation)+"_ps"; // Create shader object Ogre::HighLevelGpuProgramPtr ptrProgram; if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles")) { ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsles", Ogre::GPT_FRAGMENT_PROGRAM); ptrProgram->setParameter("profiles", "glsles"); } else { ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM); ptrProgram->setParameter("profiles", "glsl150"); } ptrProgram->setSource(mMasterSource); // set up the preprocessor defines // Important to do this before any call to get parameters, i.e. before the program gets loaded ptrProgram->setParameter("preprocessor_defines", getPPDefines(permutation)); setUpBaseParameters(ptrProgram->getDefaultParameters()); // Bind samplers Ogre::GpuProgramParametersSharedPtr params = ptrProgram->getDefaultParameters(); int numSamplers = 0; params->setNamedConstant("Tex0", (int)numSamplers++); params->setNamedConstant("Tex1", (int)numSamplers++); if(permutation & LightMaterialGenerator::MI_SHADOW_CASTER) params->setNamedConstant("ShadowTex", (int)numSamplers++); return Ogre::GpuProgramPtr(ptrProgram); }
void OgreImGui::createMaterial() { static const char* vertexShaderSrcD3D11 = { "cbuffer vertexBuffer : register(b0) \n" "{\n" "float4x4 ProjectionMatrix; \n" "};\n" "struct VS_INPUT\n" "{\n" "float2 pos : POSITION;\n" "float4 col : COLOR0;\n" "float2 uv : TEXCOORD0;\n" "};\n" "struct PS_INPUT\n" "{\n" "float4 pos : SV_POSITION;\n" "float4 col : COLOR0;\n" "float2 uv : TEXCOORD0;\n" "};\n" "PS_INPUT main(VS_INPUT input)\n" "{\n" "PS_INPUT output;\n" "output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\n" "output.col = input.col;\n" "output.uv = input.uv;\n" "return output;\n" "}" }; static const char* pixelShaderSrcD3D11 = { "struct PS_INPUT\n" "{\n" "float4 pos : SV_POSITION;\n" "float4 col : COLOR0;\n" "float2 uv : TEXCOORD0;\n" "};\n" "sampler sampler0;\n" "Texture2D texture0;\n" "\n" "float4 main(PS_INPUT input) : SV_Target\n" "{\n" "float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \n" "return out_col; \n" "}" }; static const char* vertexShaderSrcD3D9 = { "uniform float4x4 ProjectionMatrix; \n" "struct VS_INPUT\n" "{\n" "float2 pos : POSITION;\n" "float4 col : COLOR0;\n" "float2 uv : TEXCOORD0;\n" "};\n" "struct PS_INPUT\n" "{\n" "float4 pos : POSITION;\n" "float4 col : COLOR0;\n" "float2 uv : TEXCOORD0;\n" "};\n" "PS_INPUT main(VS_INPUT input)\n" "{\n" "PS_INPUT output;\n" "output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\n" "output.col = input.col;\n" "output.uv = input.uv;\n" "return output;\n" "}" }; static const char* pixelShaderSrcSrcD3D9 = { "struct PS_INPUT\n" "{\n" "float4 pos : SV_POSITION;\n" "float4 col : COLOR0;\n" "float2 uv : TEXCOORD0;\n" "};\n" "sampler2D sampler0;\n" "\n" "float4 main(PS_INPUT input) : SV_Target\n" "{\n" "float4 out_col = input.col.bgra * tex2D(sampler0, input.uv); \n" "return out_col; \n" "}" }; static const char* vertexShaderSrcGLSL = { // See https://www.khronos.org/opengl/wiki/Core_Language_(GLSL)#OpenGL_and_GLSL_versions "#version 130\n" "uniform mat4 ProjectionMatrix; \n" "in vec2 vertex;\n" "in vec2 uv0;\n" "in vec4 colour;\n" "out vec2 Texcoord;\n" "out vec4 col;\n" "void main()\n" "{\n" "gl_Position = ProjectionMatrix* vec4(vertex.xy, 0.f, 1.f);\n" "Texcoord = uv0;\n" "col = colour;\n" "}" }; static const char* pixelShaderSrcGLSL = { // See https://www.khronos.org/opengl/wiki/Core_Language_(GLSL)#OpenGL_and_GLSL_versions "#version 130\n" "in vec2 Texcoord;\n" "in vec4 col;\n" "uniform sampler2D sampler0;\n" "out vec4 out_col;\n" "void main()\n" "{\n" "out_col = col * texture(sampler0, Texcoord); \n" "}" }; //create the default shadows material Ogre::HighLevelGpuProgramManager& mgr = Ogre::HighLevelGpuProgramManager::getSingleton(); Ogre::HighLevelGpuProgramPtr vertexShaderUnified = mgr.getByName("imgui/VP"); Ogre::HighLevelGpuProgramPtr pixelShaderUnified = mgr.getByName("imgui/FP"); Ogre::HighLevelGpuProgramPtr vertexShaderD3D11 = mgr.getByName("imgui/VP/D3D11"); Ogre::HighLevelGpuProgramPtr pixelShaderD3D11 = mgr.getByName("imgui/FP/D3D11"); Ogre::HighLevelGpuProgramPtr vertexShaderD3D9 = mgr.getByName("imgui/VP/D3D9"); Ogre::HighLevelGpuProgramPtr pixelShaderD3D9 = mgr.getByName("imgui/FP/D3D9"); Ogre::HighLevelGpuProgramPtr vertexShaderGL = mgr.getByName("imgui/VP/GL130"); Ogre::HighLevelGpuProgramPtr pixelShaderGL = mgr.getByName("imgui/FP/GL130"); if (vertexShaderUnified.isNull()) { vertexShaderUnified = mgr.createProgram("imgui/VP",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,"unified",Ogre::GPT_VERTEX_PROGRAM); } if (pixelShaderUnified.isNull()) { pixelShaderUnified = mgr.createProgram("imgui/FP",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,"unified",Ogre::GPT_FRAGMENT_PROGRAM); } Ogre::UnifiedHighLevelGpuProgram* vertexShaderPtr = static_cast<Ogre::UnifiedHighLevelGpuProgram*>(vertexShaderUnified.get()); Ogre::UnifiedHighLevelGpuProgram* pixelShaderPtr = static_cast<Ogre::UnifiedHighLevelGpuProgram*>(pixelShaderUnified.get()); if (vertexShaderD3D11.isNull()) { vertexShaderD3D11 = mgr.createProgram("imgui/VP/D3D11", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "hlsl", Ogre::GPT_VERTEX_PROGRAM); vertexShaderD3D11->setParameter("target", "vs_4_0"); vertexShaderD3D11->setParameter("entry_point", "main"); vertexShaderD3D11->setSource(vertexShaderSrcD3D11); vertexShaderD3D11->load(); vertexShaderPtr->addDelegateProgram(vertexShaderD3D11->getName()); } if (pixelShaderD3D11.isNull()) { pixelShaderD3D11 = mgr.createProgram("imgui/FP/D3D11", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "hlsl", Ogre::GPT_FRAGMENT_PROGRAM); pixelShaderD3D11->setParameter("target", "ps_4_0"); pixelShaderD3D11->setParameter("entry_point", "main"); pixelShaderD3D11->setSource(pixelShaderSrcD3D11); pixelShaderD3D11->load(); pixelShaderPtr->addDelegateProgram(pixelShaderD3D11->getName()); } if (vertexShaderD3D9.isNull()) { vertexShaderD3D9 = mgr.createProgram("imgui/VP/D3D9", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "hlsl", Ogre::GPT_VERTEX_PROGRAM); vertexShaderD3D9->setParameter("target", "vs_2_0"); vertexShaderD3D9->setParameter("entry_point", "main"); vertexShaderD3D9->setSource(vertexShaderSrcD3D9); vertexShaderD3D9->load(); vertexShaderPtr->addDelegateProgram(vertexShaderD3D9->getName()); } if (pixelShaderD3D9.isNull()) { pixelShaderD3D9 = mgr.createProgram("imgui/FP/D3D9", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "hlsl", Ogre::GPT_FRAGMENT_PROGRAM); pixelShaderD3D9->setParameter("target", "ps_2_0"); pixelShaderD3D9->setParameter("entry_point", "main"); pixelShaderD3D9->setSource(pixelShaderSrcSrcD3D9); pixelShaderD3D9->load(); pixelShaderPtr->addDelegateProgram(pixelShaderD3D9->getName()); } if (vertexShaderGL.isNull()) { vertexShaderGL = mgr.createProgram("imgui/VP/GL130", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM); vertexShaderGL->setSource(vertexShaderSrcGLSL); vertexShaderGL->load(); vertexShaderPtr->addDelegateProgram(vertexShaderGL->getName()); } if (pixelShaderGL.isNull()) { pixelShaderGL = mgr.createProgram("imgui/FP/GL130", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM); pixelShaderGL->setSource(pixelShaderSrcGLSL); pixelShaderGL->load(); pixelShaderGL->setParameter("sampler0","int 0"); pixelShaderPtr->addDelegateProgram(pixelShaderGL->getName()); } Ogre::MaterialPtr imguiMaterial = Ogre::MaterialManager::getSingleton().create("imgui/material", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); mPass = imguiMaterial->getTechnique(0)->getPass(0); mPass->setFragmentProgram("imgui/FP"); mPass->setVertexProgram("imgui/VP"); mPass->setCullingMode(Ogre::CULL_NONE); mPass->setDepthFunction(Ogre::CMPF_ALWAYS_PASS); mPass->setLightingEnabled(false); mPass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); mPass->setSeparateSceneBlendingOperation(Ogre::SBO_ADD,Ogre::SBO_ADD); mPass->setSeparateSceneBlending(Ogre::SBF_SOURCE_ALPHA,Ogre::SBF_ONE_MINUS_SOURCE_ALPHA,Ogre::SBF_ONE_MINUS_SOURCE_ALPHA,Ogre::SBF_ZERO); mPass->createTextureUnitState()->setTextureName("ImguiFontTex"); }
Ogre::GpuProgramPtr GBufferMaterialGeneratorImpl::generateVertexShader(MaterialGenerator::Perm permutation) { Ogre::StringStream ss; ss << "void ToGBufferVP(" << std::endl; ss << " float4 iPosition : POSITION," << std::endl; ss << " float3 iNormal : NORMAL," << std::endl; Ogre::uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8; for (Ogre::uint32 i=0; i<numTexCoords; i++) { ss << " float2 iUV" << i << " : TEXCOORD" << i << ',' << std::endl; } if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << " float3 iTangent : TANGENT0," << std::endl; } //TODO : Skinning inputs ss << std::endl; ss << " out float4 oPosition : POSITION," << std::endl; #ifdef WRITE_LINEAR_DEPTH ss << " out float3 oViewPos : TEXCOORD0," << std::endl; #else ss << " out float oDepth : TEXCOORD0," << std::endl; #endif ss << " out float3 oNormal : TEXCOORD1," << std::endl; int texCoordNum = 2; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << " out float3 oTangent : TEXCOORD" << texCoordNum++ << ',' << std::endl; ss << " out float3 oBiNormal : TEXCOORD" << texCoordNum++ << ',' << std::endl; } for (Ogre::uint32 i=0; i<numTexCoords; i++) { ss << " out float2 oUV" << i << " : TEXCOORD" << texCoordNum++ << ',' << std::endl; } ss << std::endl; ss << " uniform float4x4 cWorldViewProj," << std::endl; ss << " uniform float4x4 cWorldView" << std::endl; ss << " )" << std::endl; ss << "{" << std::endl; ss << " oPosition = mul(cWorldViewProj, iPosition);" << std::endl; ss << " oNormal = mul(cWorldView, float4(iNormal,0)).xyz;" << std::endl; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << " oTangent = mul(cWorldView, float4(iTangent,0)).xyz;" << std::endl; ss << " oBiNormal = cross(oNormal, oTangent);" << std::endl; } #ifdef WRITE_LINEAR_DEPTH ss << " oViewPos = mul(cWorldView, iPosition).xyz;" << std::endl; #else ss << " oDepth = oPosition.w;" << std::endl; #endif for (Ogre::uint32 i=0; i<numTexCoords; i++) { ss << " oUV" << i << " = iUV" << i << ';' << std::endl; } ss << "}" << std::endl; Ogre::String programSource = ss.str(); Ogre::String programName = mBaseName + "VP_" + Ogre::StringConverter::toString(permutation); #if OGRE_DEBUG_MODE Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource); #endif // Create shader object Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram( programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "cg", Ogre::GPT_VERTEX_PROGRAM); ptrProgram->setSource(programSource); ptrProgram->setParameter("entry_point","ToGBufferVP"); ptrProgram->setParameter("profiles","vs_1_1 arbvp1"); const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters(); params->setNamedAutoConstant("cWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); params->setNamedAutoConstant("cWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX); ptrProgram->load(); return Ogre::GpuProgramPtr(ptrProgram); }
Ogre::GpuProgramPtr GBufferMaterialGeneratorImpl::generateFragmentShader(MaterialGenerator::Perm permutation) { Ogre::StringStream ss; ss << "void ToGBufferFP(" << std::endl; #ifdef WRITE_LINEAR_DEPTH ss << " float3 iViewPos : TEXCOORD0," << std::endl; #else ss << " float1 iDepth : TEXCOORD0," << std::endl; #endif ss << " float3 iNormal : TEXCOORD1," << std::endl; int texCoordNum = 2; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << " float3 iTangent : TEXCOORD" << texCoordNum++ << ',' << std::endl; ss << " float3 iBiNormal : TEXCOORD" << texCoordNum++ << ',' << std::endl; } Ogre::uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8; for (Ogre::uint32 i=0; i<numTexCoords; i++) { ss << " float2 iUV" << i << " : TEXCOORD" << texCoordNum++ << ',' << std::endl; } ss << std::endl; ss << " out float4 oColor0 : COLOR0," << std::endl; ss << " out float4 oColor1 : COLOR1," << std::endl; ss << std::endl; int samplerNum = 0; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << " uniform sampler sNormalMap : register(s" << samplerNum++ << ")," << std::endl; } Ogre::uint32 numTextures = permutation & GBufferMaterialGenerator::GBP_TEXTURE_MASK; for (Ogre::uint32 i=0; i<numTextures; i++) { ss << " uniform sampler sTex" << i << " : register(s" << samplerNum++ << ")," << std::endl; } if (numTextures == 0 || permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR) { ss << " uniform float4 cDiffuseColour," << std::endl; } #ifdef WRITE_LINEAR_DEPTH ss << " uniform float cFarDistance," << std::endl; #endif ss << " uniform float cSpecularity" << std::endl; ss << " )" << std::endl; ss << "{" << std::endl; if (numTexCoords > 0 && numTextures > 0) { ss << " oColor0.rgb = tex2D(sTex0, iUV0);" << std::endl; if (permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR) { ss << " oColor0.rgb *= cDiffuseColour.rgb;" << std::endl; } } else { ss << " oColor0.rgb = cDiffuseColour.rgb;" << std::endl; } ss << " oColor0.a = cSpecularity;" << std::endl; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << " float3 texNormal = (tex2D(sNormalMap, iUV0)-0.5)*2;" << std::endl; ss << " float3x3 normalRotation = float3x3(iTangent, iBiNormal, iNormal);" << std::endl; ss << " oColor1.rgb = normalize(mul(texNormal, normalRotation));" << std::endl; } else { ss << " oColor1.rgb = normalize(iNormal);" << std::endl; } #ifdef WRITE_LINEAR_DEPTH ss << " oColor1.a = length(iViewPos) / cFarDistance;" << std::endl; #else ss << " oColor1.a = iDepth;" << std::endl; #endif ss << "}" << std::endl; Ogre::String programSource = ss.str(); Ogre::String programName = mBaseName + "FP_" + Ogre::StringConverter::toString(permutation); #if OGRE_DEBUG_MODE Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource); #endif // Create shader object Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram( programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "cg", Ogre::GPT_FRAGMENT_PROGRAM); ptrProgram->setSource(programSource); ptrProgram->setParameter("entry_point","ToGBufferFP"); ptrProgram->setParameter("profiles","ps_2_0 arbfp1"); const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters(); params->setNamedAutoConstant("cSpecularity", Ogre::GpuProgramParameters::ACT_SURFACE_SHININESS); if (numTextures == 0 || permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR) { params->setNamedAutoConstant("cDiffuseColour", Ogre::GpuProgramParameters::ACT_SURFACE_DIFFUSE_COLOUR); } #ifdef WRITE_LINEAR_DEPTH //TODO : Should this be the distance to the far corner, not the far clip distance? params->setNamedAutoConstant("cFarDistance", Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE); #endif ptrProgram->load(); return Ogre::GpuProgramPtr(ptrProgram); }
Ogre::GpuProgramPtr GBufferMaterialGeneratorImpl::generateVertexShader(MaterialGenerator::Perm permutation) { Ogre::StringStream ss; if(mIsGLSL) { int shadingLangVersion = Ogre::Root::getSingleton().getRenderSystem()->getNativeShadingLanguageVersion(); const char *inSemantic = shadingLangVersion >= 150 ? "in" : "attribute"; const char *outSemantic = shadingLangVersion >= 150 ? "out" : "varying"; if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles")) { ss << "#version 300 es" << std::endl; ss << "precision mediump int;" << std::endl; ss << "precision mediump float;" << std::endl; } else ss << "#version " << shadingLangVersion << std::endl; ss << inSemantic << " vec4 vertex;" << std::endl; ss << inSemantic << " vec3 normal;" << std::endl; Ogre::uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8; for (Ogre::uint32 i = 0; i < numTexCoords; i++) { ss << inSemantic << " vec2 uv" << i << ';' << std::endl; } if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << inSemantic << " vec3 tangent;" << std::endl; } //TODO : Skinning inputs ss << std::endl; #ifdef WRITE_LINEAR_DEPTH ss << outSemantic << " vec3 oViewPos;" << std::endl; #else ss << outSemantic << " float oDepth;" << std::endl; #endif ss << outSemantic << " vec3 oNormal;" << std::endl; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << outSemantic << " vec3 oTangent;" << std::endl; ss << outSemantic << " vec3 oBiNormal;" << std::endl; } for (Ogre::uint32 i = 0; i < numTexCoords; i++) { ss << outSemantic << " vec2 oUv" << i << ";" << std::endl; } ss << std::endl; ss << "uniform mat4 cWorldViewProj;" << std::endl; ss << "uniform mat4 cWorldView;" << std::endl; ss << "void main()" << std::endl; ss << "{" << std::endl; ss << " gl_Position = cWorldViewProj * vertex;" << std::endl; ss << " oNormal = (cWorldView * vec4(normal,0)).xyz;" << std::endl; if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) { ss << " oTangent = (cWorldView * vec4(tangent,0)).xyz;" << std::endl; ss << " oBiNormal = cross(oNormal, oTangent);" << std::endl; } #ifdef WRITE_LINEAR_DEPTH ss << " oViewPos = (cWorldView * vertex).xyz;" << std::endl; #else ss << " oDepth = gl_Position.w;" << std::endl; #endif for (Ogre::uint32 i=0; i<numTexCoords; i++) { ss << " oUv" << i << " = uv" << i << ';' << std::endl; } ss << "}" << std::endl; Ogre::String programSource = ss.str(); Ogre::String programName = mBaseName + "VP_" + Ogre::StringConverter::toString(permutation); #if OGRE_DEBUG_MODE Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource); #endif // Create shader object Ogre::HighLevelGpuProgramPtr ptrProgram; if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles")) { ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsles", Ogre::GPT_VERTEX_PROGRAM); ptrProgram->setParameter("syntax", "glsles"); } else { ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM); } ptrProgram->setSource(programSource); const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters(); params->setNamedAutoConstant("cWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); params->setNamedAutoConstant("cWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX); ptrProgram->load(); return Ogre::GpuProgramPtr(ptrProgram); } else {