Does Iphone support shadow

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
pengliu1980
Gnoblar
Posts: 2
Joined: Wed Mar 16, 2011 2:49 pm

Does Iphone support shadow

Postby pengliu1980 » Wed Mar 16, 2011 2:57 pm

Hi Guys!

I use Ogre 1.7.2 with IOS 4.
When i run my test app on Iphone Simulator , i got a warning,
WARNING: Stencil shadows were requested, but this device does not have a hardware stencil. Shadows disabled.

And there's no shadow be displayed .

Does iphone/iphone simulator supports shadow? or How can i enable shadow ?

Thank you
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Does Iphone support shadow

Postby masterfalcon » Wed Mar 16, 2011 3:08 pm

It's true, the iPhones do not support a stencil buffer. Shadows are supported but only shader based and in the 1.8 branch.
0 x

pengliu1980
Gnoblar
Posts: 2
Joined: Wed Mar 16, 2011 2:49 pm

Re: Does Iphone support shadow

Postby pengliu1980 » Wed Mar 16, 2011 3:35 pm

Thank you masterfalcon .

Let me try Ogre 1.8 :)
0 x

fanlansen
Gnoblar
Posts: 18
Joined: Tue Jun 29, 2010 9:28 am

Re: Does Iphone support shadow

Postby fanlansen » Thu Jun 02, 2011 2:20 pm

Does Shadow need OpenGLES 2 ?
I used ogre1.8 + iOS 4.1 + iTouch 2nd + OpenGLES 1.x ,
Ogre.cfg setting: FASS=2
All demo has no shadow ,and black instead .
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Does Iphone support shadow

Postby masterfalcon » Thu Jun 02, 2011 2:48 pm

Yes, that's correct. Only texture shadows with GL ES 2.0
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Mon Aug 29, 2011 5:47 pm

But apple suggests to use shadow volumes as the primary shadowing technique on iOS devices. There is a video and slides with explanation how to do it on GL ES 2.0 at WWDC2010, https://developer.apple.com/devcenter/download.action?path=/wwdc_2010/wwdc_2010_video_assets__pdfs/417__opengl_es_shading__advanced_rendering.pdf.
There is a desceription how to do it.

I performed shadowmapping on the iphone but got very low perfonmance. I followed that article

http://www.ogre3d.org/tikiwiki/Depth+Shadow+Mapping&structure=Cookbook

just ported the shaders to GLSL ES and integrated that shader to my lightmapping shader.Here is my initialization code:

Code: Select all

       
        Ogre::Light* spotLight = sceneManager->createLight("spotLight");
        spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
        spotLight->setDiffuseColour(1.0, 1.0, 1.0);
        spotLight->setSpecularColour(0, 0, 1.0);
       
        spotLight->setDirection(-1, -1, -1);
        spotLight->setPosition(Ogre::Vector3(600, 600, 400));
       
        spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(90));
       
        sceneManager->setShadowTextureSelfShadow(false);
        // Set the caster material which uses the shaders defined above
        sceneManager->setShadowTextureCasterMaterial("Ogre/DepthShadowmap/Caster/Float");
        sceneManager->setShadowTextureSize(1024);
        // Set the pixel format to floating point
        sceneManager->setShadowTexturePixelFormat(Ogre::PF_FLOAT32_R);
        // You can switch this on or off, I suggest you try both and see which works best for you
        sceneManager->setShadowCasterRenderBackFaces(false);
        sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);


Shadows were too pixeladed even if i used 2048 texture for a shadowmap.

And the last question: does ogre use the gl_oes_depth_texture for shadow mapping? If no is it very hard to add?
Do anybody has similar problems?
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Does Iphone support shadow

Postby masterfalcon » Tue Aug 30, 2011 6:25 am

There could be a couple things at play here.

1. You might need to optimize your shaders.
2. PF_FLOAT32_R gets you the format GL_LUMINANCE. Therefore the format is not DEPTH_COMPONENT and the data type is UNSIGNED_BYTE instead of UNSIGNED_INT or SHORT. I don't know what would be the best way to accomplish this. There have been multiple discussions about this before and the result is to just use float textures because they are handled in a more consistent way across implementations. But there may be driver optimizations made for the depth formats.

I can work on adding these float formats since they've been supported since at least iOS 4.3(probably earlier, I haven't looked).
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Tue Aug 30, 2011 10:12 am

is it very hard to add the stencil shadows for iphone port? i read that iphone has the stencil buffer and apple suggests to use that technique? i can try to add it myself, just want a hint where to start.
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Does Iphone support shadow

Postby masterfalcon » Tue Aug 30, 2011 5:41 pm

The support is already there if the hardware supports it. In addition, stencil buffer attachments for FBO's are supported. If I recall, some hardware does not have a stencil buffer.
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Tue Aug 30, 2011 7:39 pm

I tried to apply simple shadowing example from Tutorial2:

mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);

got "Stencil shadows are not supported on this hardware" on ipod4, ios4.3.

I'm using the revision of ogre1.8 from April, 2011.

Redards, Victor
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Does Iphone support shadow

Postby masterfalcon » Wed Aug 31, 2011 2:09 am

Well, there ya go. No hardware stencil buffer. I didn't think any of the hardware supported it. So you'll have to use texture shadows.

I'll have to re-watch that session to see what they're talking about again.
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Wed Aug 31, 2011 11:42 am

I can help with integrating
0 x

warmi
Gnoll
Posts: 674
Joined: Sun May 27, 2007 3:56 am
Location: USA

Re: Does Iphone support shadow

Postby warmi » Thu Sep 01, 2011 9:09 am

masterfalcon wrote:Well, there ya go. No hardware stencil buffer. I didn't think any of the hardware supported it. So you'll have to use texture shadows.

I'll have to re-watch that session to see what they're talking about again.


It does. You just have to use GL_DEPTH24_STENCIL8_OES - i.e packed together with depth buffer.
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Thu Sep 01, 2011 12:45 pm

should i write my own plugin?
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Does Iphone support shadow

Postby masterfalcon » Thu Sep 01, 2011 6:06 pm

No, the packed depth/stencil format is already supported.
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Fri Sep 02, 2011 9:55 am

Just created the test app and enabled shadowing

Code: Select all

OgreFramework::getSingletonPtr()->m_pSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
   
   OgreFramework::getSingletonPtr()->m_pSceneMgr->createLight("Light")->setPosition(75,75,75);
    OgreFramework::getSingletonPtr()->m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
    OgreFramework::getSingletonPtr()->m_pSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
   m_pCubeEntity = OgreFramework::getSingletonPtr()->m_pSceneMgr->createEntity("Cube", "ogrehead.mesh");
   m_pCubeNode = OgreFramework::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode("CubeNode");
   m_pCubeNode->attachObject(m_pCubeEntity);



Code: Select all

WARNING: Stencil shadows were requested, but this device does not have a hardware stencil. Shadows disabled.


What type of shadows should i use?
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Tue Sep 06, 2011 5:08 pm

Just run the shadows sample. the GUI says Technique Stencil, Lighting:Additive, but when i put a breakpoint on Shadows.h,

Code: Select all

if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_HWSTENCIL))
        {
            mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); //bp
            mCurrentShadowTechnique = SHADOWTYPE_STENCIL_ADDITIVE;
        }
        else
        {
            mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);//bp
            mCurrentShadowTechnique = SHADOWTYPE_TEXTURE_MODULATIVE;
        }


i trapped to the second.
So could anybody explain me is the setcil shadows mean the approach used in Gamasutra's acticle about shadows on iphone, or hardware packed depth/stencil buffer is not yet supported there?
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Does Iphone support shadow

Postby masterfalcon » Tue Sep 06, 2011 5:38 pm

The method mentioned in the Gamasutra article was never committed because I never received a patch.

The type of stencil shadows that are used in Ogre currently depend on a separate hardware stencil buffer, which is different that a stencil render buffer attachment. I haven't checked specifically if the packed formats are working on iOS for shadows, but they are supposed to be supported.
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Mon Sep 12, 2011 5:47 pm

i have created a simple app to test the ipod4 stencil buffer. I created an app from xcode gl template and draw this picture. Quad is drawn first and triangle is drawn after is with less depth. Here is a code:

Code: Select all

- (void)createFramebuffer
{
    if (context && !defaultFramebuffer) {
        [EAGLContext setCurrentContext:context];
       
        // Create default framebuffer object.
        glGenFramebuffers(1, &defaultFramebuffer);
        glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
       
        // Create color render buffer and allocate backing store.
        glGenRenderbuffers(1, &colorRenderbuffer);
               
        glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
        [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth);
        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight);
       
        GLint stencil1;
        glGetIntegerv(GL_DEPTH_BITS, &stencil1);
       
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
       
        glGenRenderbuffers(1, &depthStencilRenderBuffer);
        glGenRenderbuffers(1, &stencilRenderBuffer);
        glBindRenderbuffer(GL_RENDERBUFFER, depthStencilRenderBuffer);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, framebufferWidth, framebufferHeight);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthStencilRenderBuffer);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthStencilRenderBuffer);
       
        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
            NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
        GLint stencil;
        glGetIntegerv(GL_STENCIL_BITS, &stencil);
    }
}


Code: Select all

void drawTriangle()
{
    static const GLfloat vertices[] = {
        -1.0f, -1.0f,0.1,
        1.0f, -1.0f,0.2,
        0.0f,  1.0f,0.4
    };
   
    static const GLubyte colors[] = {
        255, 0,   0, 255,
        255,   0, 0, 255,
        255,     0,   0,   255
    };
   
    glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, vertices);
    glEnableVertexAttribArray(ATTRIB_VERTEX);
    glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, 1, 0, colors);
    glEnableVertexAttribArray(ATTRIB_COLOR);
    glDrawArrays(GL_TRIANGLES, 0, 3);
}

- (void)drawFrame
{
    [(EAGLView *)self.view setFramebuffer];
   
    // Replace the implementation of this method to do your own custom drawing.
       
    static GLfloat scaleMatrix4f[] = {
        0.0f,0.0f,0.0f,0.0f,
        0.0f,0.0f,0.0f,0.0f,
        0.0f,0.0f,0.0f,0.0f,
        0.0f,0.0f,0.0f,1.0f
    };
   
    static float transY = 0.0f;
   
    glClearColor(0.5f, 1.0f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
   
    if ([context API] == kEAGLRenderingAPIOpenGLES2)
    {
        // Use shader program.
        glUseProgram(program);
       
        // Update uniform value.
        glUniform1f(uniforms[UNIFORM_TRANSLATE], (GLfloat)transY);
        buildScaleMatrix(0.2, .2, 1, scaleMatrix4f);
        glUniformMatrix4fv(uniforms[UNIFORM_SCALEMATRIX], 16, GL_FALSE, scaleMatrix4f);
        //transY += 0.075f;   
       
        // Update attribute values.
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LESS);
        glEnable(GL_STENCIL_TEST);
        glStencilFunc(GL_EQUAL, 0, 0xFF);
        glStencilOp(GL_ZERO, GL_ZERO, GL_INCR);
       
        drawQuad();
        buildScaleMatrix(0.1, .4, 1, scaleMatrix4f);
        glUniformMatrix4fv(uniforms[UNIFORM_SCALEMATRIX], 16, GL_FALSE, scaleMatrix4f);
        glStencilFunc(GL_EQUAL, 1, 0xFF);
        glStencilOp(GL_ZERO, GL_ZERO, GL_INCR);
        glDepthFunc(GL_GREATER);
        drawTriangle();
        // Validate program before drawing. This is a good check, but only really necessary in a debug build.
        // DEBUG macro must be defined in your debug configurations if that's not already the case.
#if defined(DEBUG)
        if (![self validateProgram:program]) {
            NSLog(@"Failed to validate program: %d", program);
            return;
        }
#endif
    }


IMG_0633.PNG
Last edited by blackmonster on Mon Sep 12, 2011 5:55 pm, edited 1 time in total.
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Mon Sep 12, 2011 5:53 pm

i also found that ogre detects a stencil buffer support in OgreGLeS2renderSystem in such a way:

Code: Select all

        glGetIntegerv(GL_STENCIL_BITS, &stencil);
        GL_CHECK_ERROR;

        if(stencil)
        {
            rsc->setCapability(RSC_HWSTENCIL);
         rsc->setCapability(RSC_TWO_SIDED_STENCIL);
            rsc->setStencilBufferBitDepth(stencil);
        }



I tried to do the same in my test app and here is a result:

When i call glGetIntegerv(GL_STENCIL_BITS, &stencil); BEFORE the FBO is created and stencil(depthbuffer) is attached, it returns zero in stencil variable.
And when i call this routine AFTER the FBO init code (as shpwn above) i get stencil == 8 as should be because iphone 8-bit stencil buffer

The next step i tried was to comment that code in OgreGLES2RenderSystem.cpp and write

Code: Select all

  // Check for hardware stencil support and set bit depth
        GLint stencil=8;


I got a lot of ruun-time errors most caused my abscence of fragment program.
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Mon Sep 12, 2011 9:19 pm

Just added a stencil buffer to OgreEagles2Context:

Code: Select all

#endif
        {
            glGenRenderbuffers(1, &mDepthRenderbuffer);
            GL_CHECK_ERROR
            glBindRenderbuffer(GL_RENDERBUFFER, mDepthRenderbuffer);
            GL_CHECK_ERROR
            glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, mBackingWidth, mBackingHeight);
            GL_CHECK_ERROR
            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepthRenderbuffer);
            GL_CHECK_ERROR
            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mDepthRenderbuffer);
            GL_CHECK_ERROR
        }


the situation didn't change. sample browser crashes at

Code: Select all

GLSLESLinkProgram::GLSLESLinkProgram(GLSLESGpuProgram* vertexProgram, GLSLESGpuProgram* fragmentProgram)
        : mVertexProgram(vertexProgram)
      , mFragmentProgram(fragmentProgram)
      , mUniformRefsBuilt(false)
        , mLinked(false)
      , mTriedToLinkAndFailed(false)
   {
      // init CustomAttributesIndexs
      for(size_t i = 0 ; i < VES_COUNT; i++)
         for(size_t j = 0 ; j < OGRE_MAX_TEXTURE_COORD_SETS; j++)
      {
         mCustomAttributesIndexes[i][j] = NULL_CUSTOM_ATTRIBUTES_INDEX;
      }
       
        if (!mVertexProgram || !mFragmentProgram)
        {
            OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR,
                        "Attempted to create a shader program without both a vertex and fragment program.",
                        "GLSLESLinkProgram::GLSLESLinkProgram");
        }
   }
Last edited by blackmonster on Mon Sep 19, 2011 11:27 pm, edited 1 time in total.
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Mon Sep 19, 2011 10:34 pm

i got shadows working!!!!!!
0 x

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
Contact:

Re: Does Iphone support shadow

Postby Wolfmanfx » Mon Sep 19, 2011 10:36 pm

You mean stencil shadows with the gles1 rs?
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Mon Sep 19, 2011 10:55 pm

i mean stencil shadows with ogre 1.8 GLES 2.0 on iphone 3gs+
0 x

blackmonster
Halfling
Posts: 55
Joined: Tue May 17, 2011 11:20 am

Re: Does Iphone support shadow

Postby blackmonster » Mon Sep 19, 2011 10:56 pm

but should also work with 1.7.3 on gles 1.1
0 x


Return to “Mobile Devices”

Who is online

Users browsing this forum: No registered users and 2 guests