Ogre iphone shaders

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Ogre iphone shaders

Post by goshua »

hi all,

i am wondering if this is possible to use ogre shaders to deport to gpu some image processing algorithms on an iphone
looks like it is possible : http://www.ogre3d.org/tikiwiki/Orange+S ... e=Cookbook
but i am looking for portable shaders, and it seems that we can use CG and HLSL shaders with ogre
i would like to know if i can then use GLSL shaders since HLSL should be compatible with on a iphone by using ogre 3D
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

Absolutely, but the GLES 2 rendersystem is only in the 1.8 branch.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre iphone shaders

Post by goshua »

shaders are only available with GLES 2 or i can use SDK1.7.2 to program shaders ? or is this rather a question of shaders language version ?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

Ogre 1.7 does not include the GL ES 2 rendersystem. GL ES 1 doesn't support shaders.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre iphone shaders

Post by goshua »

switching to 1.8 then :)
ty
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre iphone shaders

Post by goshua »

since am running ogre 1.8 on iphone now, i just tried to apply a basic shader i found there :
http://www.ogre3d.org/tikiwiki/Orange+S ... escription
to the demo robot i display
so i added orangeshader.cg & orangeshader.material to my resource path and tried to apply the shader with the following line :

Code: Select all

m_poEntity = m_poSceneManager->createEntity( "Robot", "robot.mesh" );
m_poEntity->setMaterialName( "shader/orange" );
but it generates a crash and log tells me that :

Code: Select all

WARNING: material shader/orange has no supportable Techniques and will be blank. Explanation: 
Pass 0: Fragment program shader/orangeFP cannot be used - not supported.
is it due to the shader format & i should try another shader language instead ?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

Cg is not supported, yet. You'll have to go with GLSL ES for now.
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10

Re: Ogre iphone shaders

Post by DanielSefton »

masterfalcon wrote:Cg is not supported, yet. You'll have to go with GLSL ES for now.
I thought Assaf recently added support for it? Or is that not working on iPhone yet?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

It's not entirely working yet.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre iphone shaders

Post by goshua »

i am trying so to run the glsl version of that shader, sorry if this is very basic btu this is my first experience with shaders
so i still use :

Code: Select all

m_poEntity = m_poSceneManager->createEntity( "Robot", "robot.mesh" );
m_poEntity->setMaterialName( "shader/orange" );
with the 2 following files :

- orangeshader.material :

Code: Select all

fragment_program shader/orangeFP glsles
 {
     source orangeshader.glsles
 }
 
 material shader/orange
 {
     technique
     {
         pass
         {
             fragment_program_ref shader/orangeFP
             {
             }
             texture_unit
             {
             }
         }
     }
 }
- orangeshader.glsles :

Code: Select all

 void main()
 {
     gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
 }
code crashes at launch
app seems to parse the shader from log :"Parsing script orangeshader.material"
but debugger tells me :

Code: Select all

#0	0x00570f18 in Ogre::GLSLESLinkProgram::compileAndLink at iostream:77
any idea why it is crashing ?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

Hmm. It definitely shouldn't crash, regardless of the compilation status. Try adding "profiles glsles" to your program definition. We'll see if that helps.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre iphone shaders

Post by goshua »

doesn't help to add "profiles glsles" :

Code: Select all

fragment_program shader/orangeFP glsles
 {
     source orangeshader.glsles
     profiles glsles
 }
 
 material shader/orange
 {
     technique
     {
         pass
         {
             fragment_program_ref shader/orangeFP
             {
             }
             texture_unit
             {
             }
         }
     }
 }
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

I haven't had coffee yet, but there's also some stuff missing that GLSL ES is more picky about than it's desktop cousin. Namely, version and precision defaults.

Code: Select all

#version 100

precision mediump int;
precision mediump float;
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre iphone shaders

Post by goshua »

i modified orangeshader.glsles that way :

Code: Select all

#version 100

precision mediump int;
precision mediump float;

void main()
{
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
but still crashes * scratching head *
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

Oh, here we go. Another difference between desktop and mobile GLSL is that programs must have one vertex and one fragment shader attached, no more, no less. If you add a trivial vertex shader in there as well, that should(hopefully) take care of the crash.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre iphone shaders

Post by goshua »

great doesn't crash anymore, ty :)

still my 3d "shadered" object doesn't appear anymore, and i don't see what the matter is, now this is mostly about shaders programming i guess
i got now 3 files :

- orangeshader.material

Code: Select all

fragment_program shader/orangeFP glsles
 {
     source orangeFragmentShader.glsles
     profiles glsles
 }
 
 vertex_program shader/orangeVP glsles
 {
     source orangeVertexShader.glsles
     profiles glsles
 }
 
 material shader/orange
 {
     technique
     {
         pass
         {
             fragment_program_ref shader/orangeFP
             {
             }
             
             vertex_program_ref shader/orangeVP
             {
             }
         }
     }
 }
 
- orangeFragmentShader.glsles

Code: Select all

#version 100

precision mediump int;
precision mediump float;

void main()
{
	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
- orangeVertexShader.glsles

Code: Select all

#version 100

precision mediump int;
precision mediump float;

void main()
{
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

Even more fun. Neither gl_ModelViewProjectionMatrix nor gl_Vertex are defined in GLSL ES. You will need to pass them in as uniforms. The sample browser media files should be a good resource for getting some shaders and materials up and running.
User avatar
goshua
Halfling
Posts: 92
Joined: Wed Jun 01, 2005 10:33 am

Re: Ogre iphone shaders

Post by goshua »

yay got a red robot now :D
ty very much
meximex
Gnoblar
Posts: 1
Joined: Tue Aug 02, 2011 2:46 pm

Re: Ogre iphone shaders

Post by meximex »

Hi guys,
any updates on the shaders in iOS?

Is it possible now?

Do you have an idea when 1.8 will come?
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Ogre iphone shaders

Post by masterfalcon »

No idea on timeline for 1.8 but you can certainly use it. Shaders work great.