RT Shader System Component (RTSS)

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
User avatar
Mattan Furst
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 260
Joined: Tue Jan 01, 2008 11:28 am
Location: Israel

Re: RT Shader System Component (RTSS)

Post by Mattan Furst » Sun Jun 05, 2011 5:55 am

@Nir Hasson
In my project I have a specific implementation of per-pixel lighting sub-render state (SRS). An implementation which is not part of Ogre. I've looked into the implementation of NormalMapLighting SRS. NormalMapLighting SRS implements both the functionality of changing the normal and then the functionality of calculating the per pixel lighting derived from that normal change.

Would it be possible to let the NormalMapLighting calculate the change to the normal only and then let the per-pixel lighting SRS take over?
Would that be a better implementation? and if so can I change the implementation?
0 x
it's turtles all the way down

Lax
Gnome
Posts: 355
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: RT Shader System Component (RTSS)

Post by Lax » Tue Jul 19, 2011 3:23 pm

Hi,

i've got the following material file:

Code: Select all

// case1 single pass material override.
material Material/SOLID/TEX/Case1.png : RTSS/NormalMapping_SinglePass
{	
	technique
	{			
		pass
		{	
			// Override the diffuse map.
			texture_unit
			{
				texture case1_bump.png
			}	
										
			// Override the normal map.
 			rtshader_system
 			{	 	 						
 				lighting_stage normal_map case1_norm.png tangent_space 0 bilinear 1 -1.0	
 			}
		}				
	}
}
to apply the normal_map tangent space shader, the system needs the normal map texture. I see in the examples, that the texture is specified directly:

Code: Select all

pNormalMapSubRS->setNormalMapTextureName("case1_norm.png");	
But I would like to do this dynamic. So my question is, how to get the "case1_norm.png" from the rtshader_system section in the material file?

Thanks in advance
0 x

Lax
Gnome
Posts: 355
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 8

Re: RT Shader System Component (RTSS)

Post by Lax » Fri Jul 22, 2011 12:36 pm

Maybe I need to rewrite my question. I need the normal map of the rtshader_system section in the material file, but I don't know how to get access to this section by code. I researched the library and found out, that this is managed somehow about a translator and an abstractproperty node but I could nowhere to be found the usage. I do this by an pseudo code example:

Code: Select all

//Parameter[0] would be "lighting_stage", Parameter[1] = "normal_map" and Parameter[2] = "case1_norm.png"
Ogre::String strNormalmap = ...getPass()->getRtShaderSection()->getParameter[2]->getName();
This necessity only occurs since you have to set the NormalMap file in order to execute the normalmap shader of the RTShaderSystem.
0 x

User avatar
cose
Halfling
Posts: 46
Joined: Thu Jul 24, 2008 5:48 pm
Location: Marseille
Contact:

Re: RT Shader System Component (RTSS)

Post by cose » Tue Jul 26, 2011 3:30 pm

Hi Nir, im trying to use the rts system with normal maps, im trying to use the 'scale' macro within rtshader_system.
im able to scale the texture unit but not the normal map. could you let me know how to scale the normal map ?
thx !

Code: Select all

material Floor2
{
	technique
	{
		pass
		{
			ambient 0.588235 0.588235 0.588235 1
			diffuse 0.588235 0.588235 0.588235 1
			specular 1 1 1 1 32

			texture_unit
			{
				texture floor2_map.jpg
				scale 0.1 0.1
			}

			rtshader_system
			{	 	
				lighting_stage normal_map floor2_nmap.jpg tangent_space 0 bilinear 1 -1.0
				scale 0.1 0.1 <<---- no effect
			}

		}
	}
}
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1193
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 74

Re: RT Shader System Component (RTSS)

Post by al2950 » Tue Jul 26, 2011 4:05 pm

@cose & @Lax

Guys, this post is already 18 pages long! Please ask questions in a separate posts in the help forum, that way others who have similar issues to you can find solutions much easier. When you have created a new post in the help forum, I will do my best to answer your questions :D
0 x

11011001
Gnoblar
Posts: 12
Joined: Thu May 21, 2009 12:40 pm
Contact:

Re: RT Shader System Component (RTSS)

Post by 11011001 » Wed Jan 18, 2012 1:45 am

The RTShaderSystem does not support the following from within a material file:
- a normal, FF style pass
- a second pass, with special fragment and vertex shaders

Is there a mechanism to get that second pass working, from within the material file? Could such a mechanism be added if it does not already exist?
0 x

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel

Re: RT Shader System Component (RTSS)

Post by Assaf Raman » Wed Jan 18, 2012 1:58 am

Are you sure?
Can you provide a sample?
0 x
Watch out for my OGRE related tweets here.

11011001
Gnoblar
Posts: 12
Joined: Thu May 21, 2009 12:40 pm
Contact:

Re: RT Shader System Component (RTSS)

Post by 11011001 » Wed Jan 18, 2012 2:24 am

This is on iOS 5, with the latest Ogre 1.8 from Mercurial.

Material File:

Code: Select all

vertex_program fresnel_vs_glsles glsles
{
	source fresnel_Vp.glsles
	
	default_params
	{
		param_named_auto worldViewProj worldviewproj_matrix
	}
}

fragment_program fresnel_ps_glsles glsles
{
	source fresnel_Fp.glsles
	
	default_params {
		param_named glowColour float3 1.0 1.0 1.0
		// bigger exponent, thinner edges
		param_named glowExpo float  2.5
		param_named alpha float  0.5
	}
}

vertex_program fresnel_vs2 unified
{
	delegate fresnel_vs_glsles
	//delegate fresnel_vs_cg
}

fragment_program fresnel_ps2 unified
{
	delegate fresnel_ps_glsles
	//delegate fresnel_ps_cg
}

material cg/fresnel/rbc 
{
	technique 
	{
		pass 
		{
			ambient 0.8 0.8 0.8
			diffuse 0.8 0.8 0.8
			specular 0.1 0.1 0.1 12.5
			
			texture_unit
			{
				texture rbc_512x512.png
				scale 0.01 0.01
			}
		}
		
		pass
		{
			scene_blend add
			depth_check on
			lighting on
			
			vertex_program_ref fresnel_vs2 
			{
				param_named inflate	float 1
				param_named_auto world world_matrix
				param_named_auto worldViewProj worldviewproj_matrix

				param_named_auto worldInverseTranspose    inverse_transpose_world_matrix
				param_named_auto inverseView inverse_view_matrix
			}
			
			fragment_program_ref fresnel_ps2 
			{		
			}
		}
	}   
}
Vertex Shader:

Code: Select all

#version 100

precision mediump int;
precision mediump float;

attribute vec4 position;
attribute vec4 normal;


uniform float inflate;
uniform mat4 world;
uniform mat4 worldViewProj;
uniform mat4 worldInverseTranspose;
uniform mat4 inverseView;

varying vec3 worldNormal;
varying vec3 worldView;

void main()
{
	gl_Position = worldViewProj * position;
	
    vec4 pos = position;
    pos += inflate + normalize(vec4(normal.xyz, 0));
    
    vec4 pw = world * pos;
    
    worldNormal = (worldInverseTranspose * normal).xyz;
    worldView = normalize(vec3(inverseView[0].w, inverseView[1].w, inverseView[2].w) - pw.xyz);
}


Fragment:

Code: Select all

#version 100

precision mediump int;
precision mediump float;

uniform vec3 glowColour;
uniform float glowExpo;
uniform float alpha;

varying vec4 colour;
varying vec3 worldNormal;
varying vec3 worldView;

void main()
{
	vec3 n = normalize(worldNormal);
	vec3 v = normalize(worldView);

	float edge = 1.0 - dot(n, v);
	edge = pow(edge, glowExpo) * alpha;
	
	vec3 result = edge * glowColour;	

	gl_FragColor = vec4(result, edge);
}

0 x

User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
Contact:

Re: RT Shader System Component (RTSS)

Post by duststorm » Fri Aug 24, 2012 3:27 am

Is there a way to limit the number of lights that can affect a material (and let the light sorting do the rest)?
I would like to have many lights spread across my scene without the CG compiler choking on too many defined constants.
0 x
Developer @ MakeHuman.org

al2950
OGRE Expert User
OGRE Expert User
Posts: 1193
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 74

Re: RT Shader System Component (RTSS)

Post by al2950 » Fri Aug 24, 2012 10:27 am

0 x

User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
Contact:

Re: RT Shader System Component (RTSS)

Post by duststorm » Fri Aug 24, 2012 8:46 pm

Thanks! That's exactly what I needed. Now how come I didn't find that the first time around? ;)
0 x
Developer @ MakeHuman.org

Post Reply