Does Iphone support shadow

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
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 11:02 pm

Can you make a patch? Screenshot would also nice :)
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 11:19 pm

i have changed 2 files:

OgreSceneManager.cpp

Code: Select all


void SceneManager::initShadowVolumeMaterials(void)
{
    /* This should have been set in the SceneManager constructor, but if you
       created the SceneManager BEFORE the Root object, you will need to call
       SceneManager::_setDestinationRenderSystem manually.
     */
    assert( mDestRenderSystem );

    if (mShadowMaterialInitDone)
        return;

    if (!mShadowDebugPass)
    {
        MaterialPtr matDebug =
            MaterialManager::getSingleton().getByName("Ogre/Debug/ShadowVolumes");
        if (matDebug.isNull())
        {
            // Create
            matDebug = MaterialManager::getSingleton().create(
                "Ogre/Debug/ShadowVolumes",
                ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
            mShadowDebugPass = matDebug->getTechnique(0)->getPass(0);
            mShadowDebugPass->setSceneBlending(SBT_ADD);
            mShadowDebugPass->setLightingEnabled(false);
            mShadowDebugPass->setDepthWriteEnabled(false);
            TextureUnitState* t = mShadowDebugPass->createTextureUnitState();
            t->setColourOperationEx(LBX_MODULATE, LBS_MANUAL, LBS_CURRENT,
                ColourValue(0.7, 0.0, 0.2));
            mShadowDebugPass->setCullingMode(CULL_NONE);

            if (mDestRenderSystem->getCapabilities()->hasCapability(
                RSC_VERTEX_PROGRAM))
            {
                ShadowVolumeExtrudeProgram::initialise();

                // Enable the (infinite) point light extruder for now, just to get some params
                mShadowDebugPass->setVertexProgram(
                    ShadowVolumeExtrudeProgram::programNames[ShadowVolumeExtrudeProgram::POINT_LIGHT]);
            mShadowDebugPass->setFragmentProgram(ShadowVolumeExtrudeProgram::frgProgramName);            
                mInfiniteExtrusionParams =
                    mShadowDebugPass->getVertexProgramParameters();
                mInfiniteExtrusionParams->setNamedAutoConstant("worldviewproj_matrix",
                    GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
                mInfiniteExtrusionParams->setNamedAutoConstant("light_position_object_space",
                    GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE);
                // Note ignored extra parameter - for compatibility with finite extrusion vertex program
                //mInfiniteExtrusionParams->setNamedAutoConstant("shadow_extrusion_distance",
               //GpuProgramParameters::ACT_SHADOW_EXTRUSION_DISTANCE);
            }   
            matDebug->compile();

        }
        else
        {
            mShadowDebugPass = matDebug->getTechnique(0)->getPass(0);

            if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_VERTEX_PROGRAM))
            {
                mInfiniteExtrusionParams = mShadowDebugPass->getVertexProgramParameters();
            }
        }
    }

    if (!mShadowStencilPass)
    {

        MaterialPtr matStencil = MaterialManager::getSingleton().getByName(
            "Ogre/StencilShadowVolumes");
        if (matStencil.isNull())
        {
            // Init
            matStencil = MaterialManager::getSingleton().create(
                "Ogre/StencilShadowVolumes",
                ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
            mShadowStencilPass = matStencil->getTechnique(0)->getPass(0);

            if (mDestRenderSystem->getCapabilities()->hasCapability(
                RSC_VERTEX_PROGRAM))
            {

                // Enable the finite point light extruder for now, just to get some params
                mShadowStencilPass->setVertexProgram(
                    ShadowVolumeExtrudeProgram::programNames[ShadowVolumeExtrudeProgram::POINT_LIGHT_FINITE]);
            mShadowStencilPass->setFragmentProgram(ShadowVolumeExtrudeProgram::frgProgramName);            
                mFiniteExtrusionParams = mShadowStencilPass->getVertexProgramParameters();
                mFiniteExtrusionParams->setNamedAutoConstant("worldviewproj_matrix",
                    GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
                mFiniteExtrusionParams->setNamedAutoConstant("light_position_object_space",
                    GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE);
                // Note extra parameter
                //mFiniteExtrusionParams->setNamedAutoConstant("shadow_extrusion_distance",
                  //  GpuProgramParameters::ACT_SHADOW_EXTRUSION_DISTANCE);
            }
            matStencil->compile();
            // Nothing else, we don't use this like a 'real' pass anyway,
            // it's more of a placeholder
        }
        else
        {
            mShadowStencilPass = matStencil->getTechnique(0)->getPass(0);

            if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_VERTEX_PROGRAM))
            {
                mFiniteExtrusionParams = mShadowStencilPass->getVertexProgramParameters();
            }
        }
    }




    if (!mShadowModulativePass)
    {

        MaterialPtr matModStencil = MaterialManager::getSingleton().getByName(
            "Ogre/StencilShadowModulationPass");
        if (matModStencil.isNull())
        {
            // Init
            matModStencil = MaterialManager::getSingleton().create(
                "Ogre/StencilShadowModulationPass",
                ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
            mShadowModulativePass = matModStencil->getTechnique(0)->getPass(0);
            mShadowModulativePass->setSceneBlending(SBF_DEST_COLOUR, SBF_ZERO);
            mShadowModulativePass->setLightingEnabled(false);
            mShadowModulativePass->setDepthWriteEnabled(false);
            mShadowModulativePass->setDepthCheckEnabled(false);
            mShadowModulativePass->setFragmentProgram("Ogre/FullScreenQuadFragmentProgram");
            mShadowModulativePass->setVertexProgram("Ogre/FullScreenQuadVertexProgram");
            TextureUnitState* t = mShadowModulativePass->createTextureUnitState();
            t->setColourOperationEx(LBX_MODULATE, LBS_MANUAL, LBS_CURRENT,
                mShadowColour);
            mShadowModulativePass->setCullingMode(CULL_NONE);
        }
        else
        {
            mShadowModulativePass = matModStencil->getTechnique(0)->getPass(0);
        }
    }
.
.
.
.
.


I moved that code to named constants, because indexed didn't work.

And in OgreShadowVolulumeExtrusionProgram:


Code: Select all

String ShadowVolumeExtrudeProgram::mFullscreenQuadFs_glsles =
    "#version 100\n"
    "precision highp float;\n"
    "precision highp int;\n"
    "precision lowp sampler2D;\n"
    "precision lowp samplerCube;\n\n"
    "uniform sampler2D quadTexture;\n"
    "varying vec4 texCoords;\n"
    "void main()\n"
    "{\n"
    "    //gl_FragColor = texture2D(quadTexture,vec2(texCoords));\n"
        "    gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
    "}\n";

   
    String ShadowVolumeExtrudeProgram::mFullscreenQuadVs_glsles =
    "#version 100\n"
    "precision highp float;\n"
    "precision highp int;\n"

    "// Directional light extrude - FINITE\n"
    "attribute vec4 uv0;\n"
    "attribute vec4 position;\n\n"
    "varying vec4 texCoords;  // texCoords\n\n"
    "void main()\n"
    "{\n"
    "\n"
    "    texCoords = uv0;\n"
    "    gl_Position = position;\n"
    "\n"
    "}\n";



and there ::

void ShadowVolumeExtrudeProgram::initialise(void)

Code: Select all


else if (syntax == "glsles")
               {
                  HighLevelGpuProgramPtr vp =
                     HighLevelGpuProgramManager::getSingleton().createProgram(
                     programNames[v], ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
                     "glsles", GPT_VERTEX_PROGRAM);
                  vp->setSource(ShadowVolumeExtrudeProgram::getProgramSource(
                     vertexProgramLightTypes[v], syntax,
                     vertexProgramFinite[v], vertexProgramDebug[v]));
                  vp->setParameter("target", syntax);
                  vp->load();

                  if (frgProgramName.empty())
                  {
                     frgProgramName = "Ogre/ShadowFrgProgram";
                     HighLevelGpuProgramPtr fp =
                        HighLevelGpuProgramManager::getSingleton().createProgram(
                        frgProgramName, ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
                        "glsles", GPT_FRAGMENT_PROGRAM);
                     fp->setSource(mGeneralFs_glsles);
                     fp->setParameter("target", "glsles");
                     fp->load();
                  }
                        //that added by me
                        HighLevelGpuProgramPtr vp1 =
                        HighLevelGpuProgramManager::getSingleton().createProgram(
                                                                                 "Ogre/FullScreenQuadVertexProgram", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
                                                                                 "glsles", GPT_VERTEX_PROGRAM);
                  vp1->setSource(mFullscreenQuadVs_glsles);
                  vp1->setParameter("target", syntax);
                  vp1->load();
                       
                        HighLevelGpuProgramPtr fp1 =
                        HighLevelGpuProgramManager::getSingleton().createProgram(
                                                                                 "Ogre/FullScreenQuadFragmentProgram", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME,
                                                                                 "glsles", GPT_FRAGMENT_PROGRAM);
                        fp1->setSource(mFullscreenQuadFs_glsles);
                        fp1->setParameter("target", "glsles");
                        fp1->load();
                       



don't forget to add stencil buffer FBO attacment as mentioned above.

I have added shaders for rendering a modulative quad programmatically, because rtshader_system failed to do it
Compiler error: unknown error in RTShaderSystem.material(23): token class, rtshader_system, unrecognized.


That's the reason why only modulative stencil shadows work.

Here is a result:
IMG_0636.PNG
IMG_0637.PNG
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 11:35 pm

the main cpu impact is made by calculating of shadow volume. i'll try to implement in on NEON using accelerate.framework. maybe someone want to help me :)?
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 20, 2011 4:30 am

I don't have the code handy at the moment, which code are you speaking of? I'm already working on some NEON optimization for skinning and might as well tack that on too. BTW, to make it portable we'll have to use inline asm(it pains me to not be able to use Accelerate but it has to be this way)
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Tue Sep 20, 2011 6:59 am

i profiled the code and saw that math and vector operations take a lot of time. so maybe the math lib can be optimized. Will try today with Accelerate.
Screen shot 2011-09-20 at 9.05.31 AM.png
Last edited by blackmonster on Tue Sep 20, 2011 7:09 am, 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 » Tue Sep 20, 2011 7:02 am

BTW, can my changes be applied to 1.8 branch? i can't submit a patch because i'm not sure that my changes are required in case of rtshader_system is enabled and works.

Parsing script RTShaderSystem.material
Compiler error: unknown error in RTShaderSystem.material(23): token class, rtshader_system, unrecognized.
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 » Tue Sep 20, 2011 7:17 am

Rtss is working this bug is fixed in the main trunk just make an update
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Tue Sep 20, 2011 7:33 am

ok, thanks, will try now
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Tue Sep 20, 2011 8:59 am

bug with vertex program assigment is not yet fixed.
app 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.", //terminate called after throwing an instance of   'Ogre::RenderingAPIException'
                        "GLSLESLinkProgram::GLSLESLinkProgram");
        }
   }
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Tue Sep 20, 2011 10:57 am

here is a patch (sourceforge hasn't yet sent me a confirmation email)
Attachments
ogre_1of1.patch.zip
(3.8 KiB) Downloaded 78 times
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Does Iphone support shadow

Postby jacmoe » Tue Sep 20, 2011 5:06 pm

What do you mean 'sourceforge' ?
Use our Mantis :
http://www.ogre3d.org/mantis/ :)
Use your forum credentials
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

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

Re: Does Iphone support shadow

Postby blackmonster » Tue Sep 20, 2011 5:23 pm

i wanted to apply a patch on ogre's threre:
https://sourceforge.net/tracker/?group_id=2997&atid=302997,
i registered and now i'm waiting for the confirmation email
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Tue Sep 20, 2011 5:29 pm

just rewrote few Ogre::Math and Ogre::Vector3 and Ogre::Vector4 functions with Accelerate.Framework (with ARM NEON support). got 47 FPS on ipod4 in release mode with the same camera and light positions as on screenshots above. Now the task is to move the sillhoute detection to it.
Also would be good if somebody pointed me how to enable SHADOWTYPE_STENCIL_ADDITIVE, because now it doesn't work due to incorrect fragment program generation in shadow volume rendering pass
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Wed Sep 21, 2011 8:41 pm

masterfalcon wrote:I don't have the code handy at the moment, which code are you speaking of? I'm already working on some NEON optimization for skinning and might as well tack that on too. BTW, to make it portable we'll have to use inline asm(it pains me to not be able to use Accelerate but it has to be this way)



are you using any intrinsics?
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 22, 2011 3:15 pm

Doing all by hand. No intrinsics.
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Thu Sep 22, 2011 5:03 pm

that's very cool. i just finished to rewrite the lightfacing function on neon intrinsics. now will make few test and if it's ok will rewrite using pure assembly
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 » Fri Sep 23, 2011 4:16 am

Already got that one down. OptimisedUtil has been my main focus since it is a huge CPU bottleneck. I'm on to optimizing the routines now.
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Fri Sep 23, 2011 8:16 am

Is there any chance for my patch to be added to ogre?
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 » Fri Sep 23, 2011 8:25 am

Quite possibly. Next time we go through the patch list I'll take a look at it.

Make sure to submit a contributor agreement too.
0 x

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

Re: Does Iphone support shadow

Postby blackmonster » Sun Sep 25, 2011 8:05 pm

here is how i did a function of light facing calculation:

Code: Select all

   void OptimisedUtilGeneral::calculateLightFacing(
        const Vector4& lightPos,
        const Vector4* faceNormals,
        char* lightFacings,
        size_t numFaces)
    {
//        for (size_t i = 0; i < numFaces; ++i)
//         {
//                     *lightFacings++ = (lightPos.dotProductStd(*faceNormals++) > 0);
//                }
        float32x4_t n0, n1, n2, n3;
        int32x4_t mask;
        float32x4_t zeroVector = vdupq_n_f32(0.0f);
        float32x4_t lp = vld1q_f32(&lightPos.x);
        float32x4x2_t tmp1, tmp2;
        size_t numIterations = numFaces / 5;
        uint32 masks[] = {0,0,0,0};
        for (size_t i = 0; i < numIterations; ++i)
        {
           
           // break;
            n0 = vld1q_f32(&faceNormals[0].x);
            n1 = vld1q_f32(&faceNormals[1].x);
            n2 = vld1q_f32(&faceNormals[2].x);
            n3 = vld1q_f32(&faceNormals[3].x);
           
           
            n0 = vmulq_f32(n0,lp);
            n1 = vmulq_f32(n1,lp);
            n2 = vmulq_f32(n2,lp);
            n3 = vmulq_f32(n3,lp);
           
            faceNormals += 4;
           
            tmp1 = vuzpq_f32(n0, n1);
            tmp2 = vuzpq_f32(n2, n3);
            n0 = vaddq_f32(tmp1.val[0], tmp1.val[1]);
            n1 = vaddq_f32(tmp2.val[0], tmp2.val[1]);
            tmp1 = vuzpq_f32(n0, n1);
            n3 = vaddq_f32(tmp1.val[0], tmp1.val[1]);
            mask = vcgtq_f32(n3, zeroVector);
            vst1q_u32(masks,mask);
            //20 cycles NEON stall. do some work on ARM
           
            *(lightFacings+4) = (lightPos.dotProductStd(*(faceNormals)) > 0);
            for (int k = 0; k< 4; k++)
                *lightFacings++ = masks[k] > 0;//(lightPos.dotProductStd(*faceNormals++) > 0);
//            *lightFacings++=(lightPos.dotProductStd(*faceNormals++) > 0);
            //vst1q_u32(masks,mask);
            //lightFacings += 4;
            faceNormals++;
            lightFacings++;
        }
        for(int i=0; i< numFaces % 5; i++)
            *lightFacings++ = (lightPos.dotProductStd(*faceNormals++) > 0);
       

    }

it works, but i haven't noticed any FPS gain, but profiler shown the 3 times lower cpu utilization in that function. maybe i'm doing the storring vector from neon to memory in a wrong way?
0 x

SufferinPup
Greenskin
Posts: 111
Joined: Tue Mar 02, 2010 11:09 pm

Re: Does Iphone support shadow

Postby SufferinPup » Mon Dec 05, 2011 11:11 pm

This thread is a bit tough to follow, what is going to be the final word for shadows on iOS for 1.8?

I tried out RC1, and in the shadow sample stencil works fine but texture shadows caused some very odd results (on an iPad2). Is stencil going to be the only option due to hardware restrictions? I'm a bit worried about generating shadow volumes for semi-complex scenes with such a low end cpu, even the latest hardware is pokey in that area. :)

As an aside, I wonder if texture-based shadows would be faster on the newer iOS hardware (A5) due to the powerful GPU.
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 » Mon Dec 05, 2011 11:28 pm

Texture shadows work. But stencil do not. The patch provided for stencil shadows had some issues. I'll try it again to see if they can be resolved.
0 x

SufferinPup
Greenskin
Posts: 111
Joined: Tue Mar 02, 2010 11:09 pm

Re: Does Iphone support shadow

Postby SufferinPup » Mon Dec 05, 2011 11:45 pm

Oh strange, thats the opposite of what I'm seeing in RC1. I'll be on the lookout for RC2! I attached some shots.

IMG_0034.PNG


IMG_0035.PNG


Great work on 1.8 though, it is super cool playing with compositors on the device.
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 » Mon Dec 05, 2011 11:48 pm

I should fix that. It's actually deceiving you. Texture shadows are actually being forced without updating the menu.
0 x

SufferinPup
Greenskin
Posts: 111
Joined: Tue Mar 02, 2010 11:09 pm

Re: Does Iphone support shadow

Postby SufferinPup » Tue Dec 06, 2011 12:04 am

Ahah yeah after playing with it more I see what you're saying. Very confusing, sorry! The compositor demo also uses texture shadows, if anyone else wants to see them in action elsewhere. :) I don't know if stencil shadows would be a win or worth spending time fixing, but I'm certainly curious about their performance vs. texture shadows on the various hardware out there.
0 x


Return to “Mobile Devices”

Who is online

Users browsing this forum: No registered users and 2 guests