Ogre Version: 14.3.4
Operating System: Windows 10
Render System: DirectX 11
Hey everyone,
I'm currently exploring Ogre a bit deeper, especially around materials. I found the PBR example in the SampleBrowser and started applying it to all my entities. For testing purposes, I'm using every map available in the material, and so far everything is working great.
However, the last thing I'm trying to implement is a Displacement Map, and that's where things are not going so well. I only understand the basics of shaders, so I've been using ChatGPT to help me through the process.
Here are the changes it suggested:
Changes to .material file:
At the beginning:
Code: Select all
set $Displacement white.png
set $DisplacementScale 0.05
In the vertex_program_ref glTF2/PBR_vs block:
Code: Select all
param_named u_DisplacementScale float $DisplacementScale
param_named u_DisplacementSampler int 8
preprocessor_defines HAS_NORMALS;HAS_UV;HAS_TANGENTS
Changes to pbr-vert.glsl:
In OGRE_UNIFORMS:
Code: Select all
uniform sampler2D u_DisplacementSampler;
uniform float u_DisplacementScale;
In the vertex shader's main function (MAIN_DECLARATION):
Code: Select all
MAIN_DECLARATION
{
vec4 pos = mul(u_ModelMatrix, position);
v_Position = vec3(pos.xyz) / pos.w;
#ifdef HAS_NORMALS
#ifdef HAS_TANGENTS
vec3 normalW = normalize(mul(u_ModelMatrix, vec4(normal.xyz, 0.0)).xyz);
vec3 tangentW = normalize(mul(u_ModelMatrix, vec4(tangent.xyz, 0.0)).xyz);
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
v_TBN = mtxFromCols(tangentW, bitangentW, normalW);
#else // HAS_TANGENTS != 1
v_Normal = normalize(vec3(mul(u_ModelMatrix, vec4(normal.xyz, 0.0))));
v_Normal = normalW;
#endif
#endif
#ifdef HAS_UV
v_UV = uv0;
#else
v_UV = vec2(0.,0.);
#endif
vec4 worldPos = mul(u_ModelMatrix, position);
#ifdef HAS_DISPLACEMENTMAP
float displacement = texture(u_DisplacementSampler, v_UV).r;
worldPos.xyz += normalW * (displacement * u_DisplacementScale);
#endif
gl_Position = mul(u_MVPMatrix, worldPos);
}
After all these changes, when I try to run the application I get this error:
Code: Select all
Pass 0: vertex program glTF2/PBR_vs cannot be used - compile error
Does anyone know what might be causing this and how to fix it?
Notes:
I verified that HAS_DISPLACEMENTMAP is defined in the .program file.
The texture unit "Displacement" is added to the material.
Shader code seems to compile fine in other contexts.
Thanks in advance for any help