Same shader source for OpenGL and DirectX11 mode

Problems building or running the engine, queries about how to use features etc.
Post Reply
sasmaster
Gnoblar
Posts: 9
Joined: Sun Jun 27, 2021 4:09 pm

Same shader source for OpenGL and DirectX11 mode

Post by sasmaster »

Ogre Version: 1.2 :?:
Operating System: Windows 10 :?:
Render System:OpenGL/DirectX 11 :?:


Hi Ogre devs. I am working on an app where I implement PBR shading. I used GLTF2 example provided by the Ogre Samples.
It works fine in OpenGL mode. Now I tried to switch to DirectX11 ,getting white surface and Ogre spits the following warning:
Ogre: Warning: material glTF2/PBR has no supportable Techniques and will be blank. Explanation:
Pass 0: fragment program glTF2/PBR_fs cannot be used - compile error.
Now, I am new to Ogre material ecosystem,but I skimmed through the setup of the PBR sample's pbr.program and it seems like
the same vertex/fragment shader source files are supposed to be used both for GLSL and for HLSL:

Code: Select all

  vertex_program glTF2/PBR_vs hlsl glsl glsles
{
	source pbr-vert.glsl
    preprocessor_defines HAS_NORMALS,HAS_TANGENTS,HAS_UV
}

fragment_program glTF2/PBR_fs_glsl glsl
{
	source pbr-frag.glsl
    preprocessor_defines MANUAL_SRGB,SRGB_FAST_APPROXIMATION,HAS_NORMALS,HAS_TANGENTS,HAS_BASECOLORMAP,HAS_NORMALMAP,HAS_EMISSIVEMAP,HAS_METALROUGHNESSMAP,HAS_OCCLUSIONMAP,USE_IBL,USE_TEX_LOD
}

fragment_program glTF2/PBR_fs_hlsl hlsl glsles
{
	source pbr-frag.glsl
	target ps_2_a
    preprocessor_defines MANUAL_SRGB,SRGB_FAST_APPROXIMATION,HAS_NORMALS,HAS_TANGENTS,HAS_BASECOLORMAP,HAS_NORMALMAP,HAS_EMISSIVEMAP,HAS_METALROUGHNESSMAP,HAS_OCCLUSIONMAP,USE_IBL
}

fragment_program glTF2/PBR_fs unified
{
	delegate glTF2/PBR_fs_glsl
	delegate glTF2/PBR_fs_hlsl
}
I ran through the official docs and haven't found any example like this.
Here https://ogrecave.github.io/ogre/api/1.1 ... grams.html
it looks like each fragment_program uses different source file, hlsl or glsl. On the other hand, the GLSL code in GLTF2/PBR sample doesn't look
like "pure" GLSL so one may imply it gets translated into API specific syntax before being compiled.
I need help on this one. Do I have to write separate, API specific shader source code per rendering API or this is something else?
Thanks.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Same shader source for OpenGL and DirectX11 mode

Post by paroj »

see https://www.ogre3d.org/2020/07/26/ogre- ... eplacement

you probably used some syntax not covered by UnifiedShader when modifying pbr-frag
sasmaster
Gnoblar
Posts: 9
Joined: Sun Jun 27, 2021 4:09 pm

Re: Same shader source for OpenGL and DirectX11 mode

Post by sasmaster »

Is there a way to get a more detailed shader error log?
So basically what you say if the shader written according to the "UnifiedShader" API it is supposed to work ok on both GL and D3D?
Where can I find a ref and limitation of the UnifiedShader API?
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Same shader source for OpenGL and DirectX11 mode

Post by paroj »

sasmaster wrote: Mon Jul 26, 2021 7:43 pm Is there a way to get a more detailed shader error log?
there should be the output of the shader compiler further up in the log.
If not, try enabling the D3D11 debug layer.
sasmaster wrote: Mon Jul 26, 2021 7:43 pm So basically what you say if the shader written according to the "UnifiedShader" API it is supposed to work ok on both GL and D3D?
yes
sasmaster wrote: Mon Jul 26, 2021 7:43 pm Where can I find a ref and limitation of the UnifiedShader API?
use the source, luke!
https://github.com/OGRECave/ogre/blob/m ... edShader.h
sasmaster
Gnoblar
Posts: 9
Joined: Sun Jun 27, 2021 4:09 pm

Re: Same shader source for OpenGL and DirectX11 mode

Post by sasmaster »

Okay,I fixed it. If moving up the log text the shader compiler errors are there. For other people here the major points to write GLSL/HLSL compatible shader code:

1.Try to use more modern target such as ps_3_0 and higher otherwise you can run out of instructions very fast (especially if doing PBR stuff)

2. No implicit numeric conversions : float f = someFloat + 1; won't work. Do someFloat + 1.0;

3. No vec2,vec3,vec4 single component constructors. Must always pass param per compoment: ve3(1.0,1.0,1.0)

4. Some operators available in GLSL are not available in HLSL. For example: lessThanEqual() used to optimize branching doesn't have counterpart in GLSL. Must workout the code differently.

Thanks for help.
Post Reply