Skip to content

Commit

Permalink
HLMS: unify GLSL/ES PBS Shaders, now requiring glsl300 on ES
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Nov 16, 2016
1 parent 2e0b5cd commit f4d4168
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 481 deletions.
1 change: 1 addition & 0 deletions Components/HLMS/include/OgreHlmsPbsMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ namespace Ogre
protected:

bool mCanHardwareGamma;
bool mIsGLES;

ColourValue mAlbedo;
ColourValue mF0;
Expand Down
5 changes: 3 additions & 2 deletions Components/HLMS/src/OgreHlmsDatablock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ namespace Ogre
//-----------------------------------------------------------------------------------
void HlmsDatablock::reload()
{
String path = mTamplateName + FilePatterns[mShaderType] + "." + mLanguage + "t";
mTemplate.setTemplateFileName(path);
StringStream ss;
ss << mTamplateName << FilePatterns[mShaderType] << "." << (mLanguage == "glsles" ? "glsl" : mLanguage) << "t";
mTemplate.setTemplateFileName(ss.str());

mHash = mTemplate.getHash() + mShaderType + calcHash(mLanguage) + calcHash(mProfilesList);
}
Expand Down
13 changes: 9 additions & 4 deletions Components/HLMS/src/OgreHlmsPbsMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ namespace Ogre
_samplers[ST_D2_F0].init("d2_f0", true, true);


RenderSystem* rs = Root::getSingleton().getRenderSystem();
const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities();

String language = "";
if (rs->getCapabilities()->isShaderProfileSupported("hlsl"))
if (caps->isShaderProfileSupported("hlsl"))
{
language = "hlsl";
mVertexDatablock.addProfile("vs_3_0");
mFragmentDatablock.addProfile("ps_3_0");
}
else if (rs->getCapabilities()->isShaderProfileSupported("glsl"))
else if (caps->isShaderProfileSupported("glsl"))
{
language = "glsl";
}
Expand All @@ -77,13 +77,15 @@ namespace Ogre
language = "glsles";
}

mIsGLES = language == "glsles";

mVertexDatablock.setLanguage(language);
mFragmentDatablock.setLanguage(language);

mVertexDatablock.setTemplateName("PBS");
mFragmentDatablock.setTemplateName("PBS");

mCanHardwareGamma = Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_HW_GAMMA);
mCanHardwareGamma = caps->hasCapability(RSC_HW_GAMMA);
}
//-----------------------------------------------------------------------------------
PbsMaterial::PbsMaterial(const PbsMaterial &obj)
Expand Down Expand Up @@ -195,6 +197,9 @@ namespace Ogre

mPropertyMap.setProperty("lights_count", mDirectionalLightCount + mPointLightCount + mSpotLightCount);

// tell the shader some details about the render system
mPropertyMap.setProperty("is_gles", mIsGLES);

// tell the shader if the hardware supports hardware gamma correction or not
mPropertyMap.setProperty("hw_gamma_read", mCanHardwareGamma);

Expand Down
4 changes: 2 additions & 2 deletions Components/HLMS/src/OgreHlmsShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ namespace Ogre
HighLevelGpuProgramPtr gpuProgram = HighLevelGpuProgramManager::getSingleton().createProgram(name,
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, dataBlock->getLanguage(), dataBlock->getShaderType());

gpuProgram->setParameter("entry_point", "main");

gpuProgram->setSource(code);

if (dataBlock->getLanguage() == "hlsl")
{
gpuProgram->setParameter("entry_point", "main");

// HLSL program requires specific target profile settings - we have to split the profile string.
const StringVector& profilesList = dataBlock->getProfileList();
StringVector::const_iterator it = profilesList.begin();
Expand Down
Loading

0 comments on commit f4d4168

Please sign in to comment.