Can't make minimal material work Topic is solved

Problems building or running the engine, queries about how to use features etc.
slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Can't make minimal material work

Post by slapin »

Hi, all! I'm trying to make the following material work. No errors reported and no ideas so far... It draws blackness.

Code: Select all

material Debug/White
{
        technique
        {
                pass
                {
                        lighting off
                        depth_write off
                        ambient 1.0 1.0 1.0 1.0
                        diffuse 1.0 1.0 1.0 1.0
                        specular 1.0 1.0 1.0 1.0
                        vertex_program_ref debug_vp
                        {
                        }
                        fragment_program_ref debug_fp
                        {
                        }
                }
        }
}

Program:

Code: Select all

fragment_program debug_fp glsl glsles glslang hlsl
{
        source debug.frag
        default_params
        {
                param_named_auto ambient surface_ambient_colour
                param_named_auto diffuse surface_diffuse_colour
        }
}

vertex_program debug_vp glsl glsles glslang hlsl
{
        source debug.vert
        default_params
        {
        }
}

debug.frag

Code: Select all

OGRE_NATIVE_GLSL_VERSION_DIRECTIVE
#include <OgreUnifiedShader.h>

OGRE_UNIFORMS(uniform vec4 ambient;)
OGRE_UNIFORMS(uniform vec4 diffuse;)

MAIN_PARAMETERS
MAIN_DECLARATION
{
//    gl_FragColor = ambient * diffuse;
    gl_FragColor = vec4(0, 0, 1, 1);
}

debug.vert

Code: Select all

#include <OgreUnifiedShader.h>

OGRE_UNIFORMS(
    uniform mat4 worldViewProj;
)

MAIN_PARAMETERS
IN(vec4 vertex, POSITION)
MAIN_DECLARATION
{
    gl_Position = mul(worldViewProj, vertex);
}
slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: Can't make minimal material work

Post by slapin »

What can I do to make this work?

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: Can't make minimal material work

Post by slapin »

renderdoc draws black screen with this material enabled but no errors so far, I guess there is something fundamentally wrong with it...

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

Re: Can't make minimal material work

Post by paroj »

whats the value of worldViewProj?

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: Can't make minimal material work

Post by slapin »

paroj wrote: Fri Jun 13, 2025 11:39 pm

whats the value of worldViewProj?

All zeroes

Image

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: Can't make minimal material work

Post by slapin »

slapin wrote: Sat Jun 14, 2025 1:22 am
paroj wrote: Fri Jun 13, 2025 11:39 pm

whats the value of worldViewProj?

All zeroes

Image

Also I see that worldViewProj is not bound while vertex is bound (position is bound to same uniform index so I guess they are the same).

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: Can't make minimal material work

Post by slapin »

Fixed it!
You can congratulate me with making my first Ogre shader-based material. One can use it for simple unlit materials for debug and markers.
It is strange RTSS can't do these...
debug.program:

Code: Select all

fragment_program debug_fp glsl glsles glslang hlsl
{
        source debug.frag
        default_params
        {
                param_named_auto ambient surface_ambient_colour
                param_named_auto diffuse surface_diffuse_colour
        }
}

vertex_program debug_vp glsl glsles glslang hlsl
{
        source debug.vert
        default_params
        {
                /* I thought it was bound automagically */
                param_named_auto worldViewProj worldviewproj_matrix
        }
}

debug.vert:

Code: Select all

OGRE_NATIVE_GLSL_VERSION_DIRECTIVE
#include <OgreUnifiedShader.h>

OGRE_UNIFORMS(
    uniform mat4 worldViewProj;
)

MAIN_PARAMETERS
IN(vec4 vertex, POSITION)
IN(vec3 normal, NORMAL)
IN(vec3 tangent, TANGENT)
IN(vec3 uv0, TEXCOORD0)

MAIN_DECLARATION
{
    gl_Position = worldViewProj * vertex;
}

debug.frag

Code: Select all

OGRE_NATIVE_GLSL_VERSION_DIRECTIVE
#include <OgreUnifiedShader.h>

OGRE_UNIFORMS(uniform vec4 ambient;)
OGRE_UNIFORMS(uniform vec4 diffuse;)

MAIN_PARAMETERS
MAIN_DECLARATION
{
    gl_FragColor = ambient * diffuse;
}

Also I created my own C++ class for skybox because default skybox did not like my material and for some reason I could not inherit Ogre::SceneManager::SkyRenderer and added that
shader to the cube as material and now I can go far with it, just need to understand how to bind values from code

Code: Select all

material Skybox/Dynamic
{
        technique
        {
                pass
                {
                        lighting off
                        depth_write off
                        ambient 1.0 1.0 1.0 1.0
                        diffuse 0.0 0.0 1.0 1.0
                        specular 0.0 0.0 0.0 1.0
                        vertex_program_ref debug_vp
                        {
                        }
                        fragment_program_ref debug_fp
                        {
                        }
                }
        }
}

Now I can make dynamic sky I want. Thanks a lot!

rpgplayerrobin
Orc Shaman
Posts: 752
Joined: Wed Mar 18, 2009 3:03 am
x 421

Re: Can't make minimal material work

Post by rpgplayerrobin »

How to bind values from code:

Code: Select all

	// Check if the pass has a fragment shader
	if (pass->hasFragmentProgram())
	{
		// Check first if the named constant exists
		GpuProgramParametersSharedPtr tmpGPUParam = pass->getFragmentProgramParameters();
		std::string tmpConstant = "test_variable";
		if (tmpGPUParam->_findNamedConstantDefinition(tmpConstant, false))
			// Set the parameter
			tmpGPUParam->setNamedConstant(tmpConstant, Vector4(colour.r, colour.g, colour.b, colour.a));
	}
slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: Can't make minimal material work

Post by slapin »

Thanks a lot!