[SOLVED]material's fragment shader doesn't start

Problems building or running the engine, queries about how to use features etc.
User avatar
paul424
Gnome
Posts: 377
Joined: Thu May 24, 2012 7:16 pm
x 18

[SOLVED]material's fragment shader doesn't start

Post by paul424 »

Ogre Version: : 1 12 13:
Operating System: :Linux Tumbleweed:
Render System: :OpenGL3+

Hello, I have this Dirt wall tile for my game , prepared in blender and exported by ogre-exporter:
Here it is how itlooks in ogre-meshviewer [ Clearly it works here !]
Image

Here it how it looks in the game menu, after being copied over with proper materials and shaders to respective directories ?
Image

What might be wrong ? I suspect tangents , but they are properly recreated with code :

Code: Select all

    if(!Ogre::MeshManager::getSingleton().resourceExists(meshName,"Graphics"))
        Ogre::MeshManager::getSingleton().load(meshName,"Graphics");

Ogre::MeshPtr meshPtr = Ogre::MeshManager::getSingleton().getByName(meshName,"Graphics");

unsigned short src, dest;
if (!meshPtr->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
{
    meshPtr->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
} 

Ogre::Entity* ent = mSceneManager->createEntity(entityName, meshPtr);


Clearly the fragment program does not kick in.... but there is not a trace of error in Ogre.log

Code: Select all

// Dirt
// import RTSS/NormalMapping_MultiPass from "RTShaderSystem.material"


vertex_program myDirtTileVertexShader glsl
{
  source DirtTile.vert
    default_params
    {
        param_named_auto projectionMatrix projection_matrix
        param_named_auto viewMatrix view_matrix
        param_named_auto worldMatrix world_matrix
        param_named_auto lightMatrix texture_worldviewproj_matrix          
}
} fragment_program myDirtTileFragmentShader glsl { source DirtTile.frag default_params { param_named_auto ambientLightColour ambient_light_colour param_named_auto lightDiffuseColour light_diffuse_colour 0.0 param_named_auto lightSpecularColour light_specular_colour 0.0 param_named_auto lightPos light_position 0.0 0.0 0.0 0.0 param_named_auto cameraPosition camera_position param_named_auto diffuseSurface surface_diffuse_colour param_named shadowingEnabled bool false
} } material Dirt //: RTSS/NormalMapping_MultiPass {
technique { pass { vertex_program_ref myDirtTileVertexShader { } fragment_program_ref myDirtTileFragmentShader { param_named decalmap int 0 param_named normalmap int 1 param_named shadowmap int 2 } // We use blending, so that we can see the underlying texture. texture_unit decalmap { texture Dirt.png } texture_unit normalmap { texture DirtNormal.png } texture_unit shadowmap { content_type shadow tex_address_mode clamp filtering bilinear } } }

Code: Select all

#version 330  core


uniform sampler2D decalmap;
uniform sampler2D normalmap;
uniform sampler2D shadowmap;

uniform vec4 ambientLightColour;
uniform vec4 lightDiffuseColour; 
uniform vec4 lightSpecularColour;
uniform vec4 lightPos;
uniform vec4 cameraPosition;
uniform vec4 diffuseSurface;
uniform bool shadowingEnabled;
in vec2 out_UV0;
in vec2 out_UV1;
in vec3 FragPos;
in vec4 VertexPos; 
in mat3 TBN;
 
out vec4 color;

void main (void)  
{
vec3 texelColor = texture(decalmap, out_UV0.st).rgb; // compute Normal vec3 Normal = texture(normalmap, out_UV1.st).rgb; Normal.xyz = 2 * Normal.xyz - (1.0,1.0,1.0); Normal = normalize(TBN * Normal);
vec4 shadow = vec4(1.0, 1.0, 1.0,1.0); vec4 tmpVertexPos = VertexPos; // compute shadowmap if(shadowingEnabled){ if(tmpVertexPos.z > 0 ){ tmpVertexPos /= tmpVertexPos.w; shadow = texture(shadowmap, tmpVertexPos.xy); } } // compute lightDir vec3 lightDir = normalize(lightPos.xyz - FragPos*lightPos.w); // compute Specular vec3 viewDirection = normalize( cameraPosition.xyz - FragPos); vec3 reflectedLightDirection = normalize(reflect(-1.0*lightDir.xyz,Normal)); float spec = max(dot(reflectedLightDirection, viewDirection ), 0.0) ; spec = pow(spec,16); vec3 specular = spec * lightSpecularColour.rgb; // compute Diffuse float diff = max(dot(lightDir,Normal), 0.0); vec3 diffuse = diff * lightDiffuseColour.rgb; vec3 result; // precompute the lighting term vec3 lightingTerm = (diffuse + specular + ambientLightColour.rgb/2.0 )*shadow.rgb; if(diffuseSurface != vec4(1.0,1.0,1.0,1.0)) result = lightingTerm * mix(texelColor, diffuseSurface.rgb,0.5); else result = lightingTerm * texelColor; color = vec4(result.xyz, 1.0); }

EDIT: I have tried diffrent materials , but they don't work as expect, I always recive one color blob....

Last edited by paul424 on Fri Jul 12, 2024 8:39 pm, edited 1 time in total.
User avatar
paul424
Gnome
Posts: 377
Joined: Thu May 24, 2012 7:16 pm
x 18

Re: material's fragment shader doesn't start

Post by paul424 »

:D :D :D :D :D :D :D

Last edited by paul424 on Fri Jul 12, 2024 6:08 pm, edited 1 time in total.
User avatar
paul424
Gnome
Posts: 377
Joined: Thu May 24, 2012 7:16 pm
x 18

Re: material's fragment shader doesn't start

Post by paul424 »

Let's look at the picture :
Image

using the simplest texturing shader I get this in two separate Dirt material TIles..... one of them is one big brown blob so one cannot ever infere it's shape.

Code: Select all

#version 330  core


uniform sampler2D decalmap;
uniform sampler2D normalmap;
uniform sampler2D shadowmap;

uniform vec4 ambientLightColour;
uniform vec4 lightDiffuseColour; 
uniform vec4 lightSpecularColour;
uniform vec4 lightPos;
uniform vec4 cameraPosition;
uniform vec4 diffuseSurface;
uniform bool shadowingEnabled;
in vec2 out_UV0;
in vec2 out_UV1;
in vec3 FragPos;
in vec4 VertexPos; 
in mat3 TBN;
 
out vec4 color;

void main (void)  
{
vec3 texelColor = texture(decalmap, out_UV0.st).rgb; color = vec4(texelColor.rgb, 1.0); }
User avatar
paul424
Gnome
Posts: 377
Joined: Thu May 24, 2012 7:16 pm
x 18

Re: material's fragment shader doesn't start

Post by paul424 »

And of course , in ogre-meshviewer everything looks fine.
Simple pass through the uv coordinates shader like this

Code: Select all



#version 330  core


uniform sampler2D decalmap;
uniform sampler2D normalmap;
uniform sampler2D shadowmap;

uniform vec4 ambientLightColour;
uniform vec4 lightDiffuseColour; 
uniform vec4 lightSpecularColour;
uniform vec4 lightPos;
uniform vec4 cameraPosition;
uniform vec4 diffuseSurface;
uniform bool shadowingEnabled;
in vec2 out_UV0;
in vec2 out_UV1;
in vec3 FragPos;
in vec4 VertexPos; 
in vec4 fragmentLocalPosition;
in mat3 TBN;
 
out vec4 color;

void main (void)  
{
vec3 texelColor = texture(decalmap, out_UV0.st).rgb; color = vec4(out_UV0.rg, 0.4, 1.0); }

yields such and such image :
Image

User avatar
paul424
Gnome
Posts: 377
Joined: Thu May 24, 2012 7:16 pm
x 18

Re: material's fragment shader doesn't start

Post by paul424 »

Here's the troublesome FogOfWar.mesh mesh : https://fastupload.io/056e1e9126c0e4e4

EDIT : After a closer examination another FogOfWar.mesh was lurking in another path, that's why it was immune to export changes in blender , because the game engine always have picked up this particular file. I feel really dumb, but couldn't OGRE engine whistle and bell when there is such conflict in resource files ? Something like : Warning : " At least two version of resource RESOURCE_NAME are in the gruop GROUP_NAME, the resource with the filepath such and such would be used ....."

paroj
OGRE Team Member
OGRE Team Member
Posts: 2106
Joined: Sun Mar 30, 2014 2:51 pm
x 1132

Re: [SOLVED]material's fragment shader doesn't start

Post by paroj »

such a warning makes sense. added: https://github.com/OGRECave/ogre/pull/3156