Hi, Thanks for porting this
At first i was having problems with getting the Gorilla UI to work in 2.1 using DX11 since the shaders were out of date for the hlsl and it did not render on screen; in fact it crashed a lot lol

.
OpenGl3+ was working fine though, so in order to make it work with DX11, I had to make these changes.
Here is the new hlsl shader for
gorilla2D.hlsl
Code: Select all
struct VS_INPUT
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR0;
};
struct PS_INPUT
{
float4 gl_Position : SV_Position;
float2 uv : TEXCOORD0;
float4 color : TEXCOORD1;
};
PS_INPUT main_vp( VS_INPUT input,
uniform matrix worldViewProj )
{
PS_INPUT outVs;
outVs.gl_Position = mul(worldViewProj, input.vertex);
outVs.uv = input.uv;
outVs.color = input.color;
return outVs;
}
Texture2D atlas : register(t0);
SamplerState samplerState : register(s0);
float4 main_fp( PS_INPUT inPs) : SV_Target
{
return atlas.Sample(samplerState, inPs.uv) * inPs.color;
}
For the material, i changed the profiles being used to a more modern profile setup
Gorilla2D.material
Code: Select all
vertex_program gorilla2DVPHLSL hlsl
{
source gorilla2D.hlsl
entry_point main_vp
target vs_5_0 vs_4_0 vs_4_0_level_9_1 vs_4_0_level_9_3
}
fragment_program gorilla2DFPHLSL hlsl
{
source gorilla2D.hlsl
entry_point main_fp
target ps_5_0 ps_4_0 ps_4_0_level_9_1 ps_4_0_level_9_3
}
vertex_program gorilla2DVPGLSL glsl
{
source gorilla2DVP.glsl
}
fragment_program gorilla2DFPGLSL glsl
{
source gorilla2DFP.glsl
}
vertex_program gorilla2DVPGLSLES glsles
{
source gorilla2DVP.glsles
}
fragment_program gorilla2DFPGLSLES glsles
{
source gorilla2DFP.glsles
}
// Unified definition
vertex_program gorilla2DVP unified
{
delegate gorilla2DVPGLSLES
delegate gorilla2DVPHLSL
delegate gorilla2DVPGLSL
}
fragment_program gorilla2DFP unified
{
delegate gorilla2DFPGLSLES
delegate gorilla2DFPHLSL
delegate gorilla2DFPGLSL
}
material Gorilla2D21
{
technique
{
pass
{
depth_check off
depth_write off
diffuse vertexcolour
scene_blend alpha_blend
vertex_program_ref gorilla2DVP
{
}
fragment_program_ref gorilla2DFP
{
}
}
}
}
Changing the shader alone did not help as it crashed due a "Null Program Bound". I got around this by first loading the "Gorilla2D21" material before cloning.
(File) Gorilla.cpp - (Function) void TextureAtlas::_create2DMaterial()
Code: Select all
void TextureAtlas::_create2DMaterial()
{
Ogre::MaterialPtr baseMat = Ogre::MaterialManager::getSingletonPtr()->getByName("Gorilla2D21");
if (!baseMat->isLoaded()) baseMat->load();
std::string matName = "Gorilla2D." + mTexture->getName();
m2DMaterial = baseMat->clone(matName);
m2DPass = m2DMaterial->getTechnique(0)->getPass(0);
Ogre::TextureUnitState* texUnit = m2DPass->createTextureUnitState();
m2DPass->setVertexColourTracking(Ogre::TVC_DIFFUSE);
m2DPass->getTextureUnitState(0)->setTexture(mTexture);
}
Still it wasn't loading

I ended up looking into CEGUI and found they used a hlms cache to drop the shaders into the rendersystem manually, so i adapted this into Gorilla and managed to make DX11 render from using it.
The snippet was creating a hlms cache that is set into the rendersystem using the vertex and fragment program setup in the material. It worked in both OpenGL and DX11.
Here is the full function:
(File) Gorilla.cpp - (Function) void Screen::_prepareRenderSystem()
Code: Select all
void Screen::_prepareRenderSystem()
{
mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY);
mRenderSystem->_setViewMatrix(Ogre::Matrix4::IDENTITY);
mSceneMgr->_setPass(mAtlas->get2DPass());
#ifdef GORILLA_V21
mRenderSystem->_setHlmsBlendblock(mAtlas->get2DPass()->getBlendblock());
// Create a hlmscache and drop the shaders into the hlms manually.
Ogre::HlmsCache hlmsCache;
hlmsCache.vertexShader = mAtlas->get2DPass()->getVertexProgram();
hlmsCache.pixelShader = mAtlas->get2DPass()->getFragmentProgram();
mRenderSystem->_setProgramsFromHlms(&hlmsCache);
#endif
}
After putting these together, i ended up with gorilla working in 2.1 with both GL and DX11. I am quite happy with the result even if it isn't completely correct but it works great
Thanks again for porting this in the first place and i hope this helps a few who are having DX11 issues with Gorilla and Ogre3D 2.1
Please bear in mind that i am not running the Gorilla Compositor system and have it built into my own compositor chain using:
p.s. the shaders for the 3D gorilla will need the worldprojview matrix, but it is essentially the same. I haven't used the 3D version of gorilla yet and have heard there are some issues related to it being viewed, so maybe the code above may help.
Also, Here is the entire shaders folder to help some people
Thanks again
Edit: Fixed some messed up bbcodes
