Need more functions in UVAnimation

View: New views
4 Messages — Rating Filter:   Alert me  

Need more functions in UVAnimation

by ZHANG Zikai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

The 'uvanimated alpha' shader was implemented as uv coordinates a
linear relation with Time. (see shader:shaders.fx vsUVAnimColor)

    vsOut.uv0 = vsIn.uv0 + (Velocity.xy * Time);

Sometimes we need the uv-animation be a little more complicated,
e.g.
    timing controlled by program;
    uv rotation.
which need a texture transformation.

I'm using nmaxtoolbox. I found that some codes about texture
transformation in nebula2 has been quoted. I tried to make the
following changes to see uv-ani working.
    a,    in nMaterialNode::RenderShader, enable the textureTransform codes
    ==code=begin============================
    // invoke shader manipulators
    if (this->GetNumAnimators() > 0)
    {
        this->InvokeAnimators(nAnimator::Shader, renderContext);
        shader->SetParams(this->shaderParams);

        // FIXME: better to check whether any nUvAnimator exist
        if (!gfxServer->GetHint(nGfxServer2::MvpOnly))
        {
            // set texture transforms
            n_assert(nGfxServer2::MaxTextureStages >= 4);
            static matrix44 m;
            this->textureTransform[0].getmatrix44(m);
            gfxServer->SetTransform(nGfxServer2::Texture0, m);
            this->textureTransform[1].getmatrix44(m);
            gfxServer->SetTransform(nGfxServer2::Texture1, m);
        }
    }
    ==code=end=============================

    b,    in renderpath xml
    change the SceneOpaque.alpha.alpha_uvanimation.mvpOnly to "No"
    ==code=begin============================
    <Sequence shader="alpha_uvanimation" technique="tUVAnimationAlpha"
firstLightAlpha="Yes" mvpOnly="No" />
    ==code=end=============================

    c,    export vector3(u,v,w) instead of vector2(u,v) as uveular and export
    (this changes a lot ralated codes both in nmaxtoolbox and in nebula2)

then I got the uv-animation can play in nviewer. But the direction and
position are different from within 3dsmax, which rotates (use the w
component) around the center of texture.

The nUvAnimatior seems never used unless I make those changes. How to
use the nUvAnimator?

ps. Sorry for my poor English.

Regard,

kaikai

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

*** NOTE: To reply to the list use "reply to all",  ***
***       to reply direct to the sender use "reply" ***
_______________________________________________
Nebuladevice-discuss mailing list
Nebuladevice-discuss@...
https://lists.sourceforge.net/lists/listinfo/nebuladevice-discuss

Re: Need more functions in UVAnimation

by Kim, Hyoun Woo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For the c), the guy who provided the uv animation patch also provided the patch
of nUvAnmator which has vector3(u,v,w) not vector2(u,v) as you've mentioned for
its parameter to make it possible to export rotation of a texture.

But we did not committed that stuff for the reason of compatibility between
community's CVS and RL's.

And now, is that time to change? :)



Cheers,

Kim, Hyoun Woo


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

*** NOTE: To reply to the list use "reply to all",  ***
***       to reply direct to the sender use "reply" ***
_______________________________________________
Nebuladevice-discuss mailing list
Nebuladevice-discuss@...
https://lists.sourceforge.net/lists/listinfo/nebuladevice-discuss

Re: Need more functions in UVAnimation

by ZHANG Zikai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2006/10/25, Kim, Hyoun Wo <kimsama@...>:
> For the c), the guy who provided the uv animation patch also provided the patch
> of nUvAnmator which has vector3(u,v,w) not vector2(u,v) as you've mentioned for
> its parameter to make it possible to export rotation of a texture.
>
> But we did not committed that stuff for the reason of compatibility between
> community's CVS and RL's.
>
> And now, is that time to change? :)

Wish it to be.

And also, max has the scale and rotation center over the center of the texture.
The nebula2's transfrom33 does not match the specialties, so I make
this change in nMaterialNode.

==code=begin==========================
//------------------------------------------------------------------------------
/**
    Perform per-instance rendering of shader. This should just apply
    shader parameters which may change from instance to instance.
*/
bool
nMaterialNode::RenderShader(nSceneServer* sceneServer, nRenderContext*
renderContext)
{
    nShader2* shader = this->refShader;
    nGfxServer2* gfxServer = nGfxServer2::Instance();

    // FIXME FIXME FIXME
    // THIS IS A LARGE PERFORMANCE BOTTLENECK!
    // NEED TO SPLIT SHADER PARAMETERS INTO STATIC "INSTANCE SET" PARAMETERS
    // AND LIGHTWEIGHT "PER-INSTANCE" PARAMETERS WHICH CAN BE ANIMATED!!!
    n_assert(sceneServer);
    n_assert(renderContext);

    // invoke shader manipulators
    if (this->GetNumAnimators() > 0)
    {
        this->InvokeAnimators(nAnimator::Shader, renderContext);
        shader->SetParams(this->shaderParams);

        // FIXME: better to check whether any nUvAnimator exist
        if (!gfxServer->GetHint(nGfxServer2::MvpOnly))
        {
            // set texture transforms
            n_assert(nGfxServer2::MaxTextureStages >= 4);
            static matrix44 m;

            // >>>HERE<<< is the change
            //this->textureTransform[0].getmatrix44(m);
            for (int i = 0; i < 2; i++)
            {
                if (this->textureTransform[i].isdirty())
                {
                    static matrix33 m3;
                    const vector2 &pos =
this->textureTransform[i].gettranslation();
                    const vector2 &scale = this->textureTransform[i].getscale();
                    const vector3 &eular =
this->textureTransform[i].geteulerrotation();
                    m3.ident();
                    m3.translate(vector2(-.5f - pos.x, pos.y - .5f));
                    m3.scale(vector3(scale.x, scale.y, 1));
                    m3.rotate_x(eular.x);
                    m3.rotate_y(eular.y);
                    m3.rotate_z(eular.z);
                    m3.translate(vector2(.5f, .5f));
                    // HACK: set dirty to false directly
                    this->textureTransform[i].setdirty(false);
                }
                this->textureTransform[i].getmatrix44(m);

gfxServer->SetTransform(nGfxServer2::TransformType(nGfxServer2::Texture0
+ i), m);
            }
        }
    }

    // set shader override parameters from render context (set
directly by application)
    shader->SetParams(renderContext->GetShaderOverrides());

    return true;
}
==code=end===========================

by applying the change, transform33 also need to change a little.
change eular from vector2 to vector3, and add a setdirty() method.
>
> Cheers,
>
> Kim, Hyoun Woo

Sincerely,

kaikai

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

*** NOTE: To reply to the list use "reply to all",  ***
***       to reply direct to the sender use "reply" ***
_______________________________________________
Nebuladevice-discuss mailing list
Nebuladevice-discuss@...
https://lists.sourceforge.net/lists/listinfo/nebuladevice-discuss

Parent Message unknown Re: Need more functions in UVAnimation

by ZHANG Zikai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2006/10/26, Kim Hyoun Woo <kimsama@...>:

> Hey,
>
> As I mentioned it yesterday, this might be helpful.
> See the attached file and #378 on Bugzilla which is available on
> http://nebuladevice.cubik.org/bugs/show_bug.cgi?id=378
>
> Cheers,
>
> Kim, Hyoun Woo.
>

hi, Kim

I think you're right, I move the implement code into the Animator and
remove some
redundant codes. Here it is.

==code=begin===========================
//------------------------------------------------------------------------------
/**
    This does the actual work of manipulate the target object.

    @param  sceneNode       object to manipulate (must be of class
nTransformNode)
    @param  renderContext   current render context
*/
void
nUvAnimator::Animate(nSceneNode* sceneNode, nRenderContext* renderContext)
{
    n_assert(sceneNode);
    n_assert(renderContext);
    n_assert(nVariable::InvalidHandle != this->channelVarHandle);
    n_assert(sceneNode->IsA(nKernelServer::Instance()->FindClass("nabstractshadernode")));

    nAbstractShaderNode* targetNode = (nAbstractShaderNode*) sceneNode;

    // get the sample time from the render context
    nVariable* var = renderContext->GetVariable(this->channelVarHandle);
    n_assert(var);
    float curTime = var->GetFloat();

    static nAnimKey<vector2> keypos;
    static nAnimKey<vector3> keyeuler;
    static nAnimKey<vector2> keyscale;
    bool bkeypos, bkeyeuler, bkeyscale;

    // sample keys
    bkeypos = this->posArray->Sample(curTime, this->loopType, keypos);
    bkeyeuler = this->eulerArray->Sample(curTime, this->loopType, keyeuler);
    bkeyscale = this->scaleArray->Sample(curTime, this->loopType, keyscale);

    int texLayer;
    for (texLayer = 0; texLayer < nGfxServer2::MaxTextureStages; texLayer++)
    {
        // manipulate target object
        if (bkeypos)
        {
            targetNode->SetUvPos(texLayer, keypos.GetValue());
        }
        if (bkeyeuler)
        {
            targetNode->SetUvEuler(texLayer, keyeuler.GetValue());
        }
        if (bkeyscale)
        {
            targetNode->SetUvScale(texLayer, keyscale.GetValue());
        }
    }

    // apply the texture transforms
    nGfxServer2 *gfxServer = nGfxServer2::Instance();
    if (!gfxServer->GetHint(nGfxServer2::MvpOnly))
    {
        // set texture transforms
        n_assert(nGfxServer2::MaxTextureStages >= 4);

        // inorder to match the 3dsmax uv-animation
        static matrix33 m3;
        static matrix44 m;
        m3.ident();
        m3.translate(vector2(-.5f - keypos.GetValue().x,
keypos.GetValue().y - .5f));
        m3.scale(vector3(keyscale.GetValue().x, keyscale.GetValue().y, 1));
        m3.rotate_x(keyeuler.GetValue().x);
        m3.rotate_y(keyeuler.GetValue().y);
        m3.rotate_z(keyeuler.GetValue().z);
        m3.translate(vector2(.5f, .5f));
        m.set(m3.M11, m3.M12, m3.M13, 0,
            m3.M21, m3.M22, m3.M23, 0,
            m3.M31, m3.M32, m3.M33, 0,
            0, 0, 0, 1);

        gfxServer->SetTransform(nGfxServer2::Texture0, m);
        gfxServer->SetTransform(nGfxServer2::Texture1, m);
    }
}
==code=end========================

Regard,

kaikai

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

*** NOTE: To reply to the list use "reply to all",  ***
***       to reply direct to the sender use "reply" ***
_______________________________________________
Nebuladevice-discuss mailing list
Nebuladevice-discuss@...
https://lists.sourceforge.net/lists/listinfo/nebuladevice-discuss
LightInTheBox - Buy quality products at wholesale price!