I need to exclude object from camera view so it will not be visible by one camera and visible by another. Is it possible by script?

2

(2 replies, posted in General)

Set blend mode to alpha and it worked. Thanks a lot anael.

Hi i'm trying to make texture transparent and gl_FragColor = vec4(pixel.r,pixel.g,pixel.b,0.2) wont do the trick. Tried to do this with color but it just wont make it transparent. I'm using .png image and it has no transparent parts. Is it possible to make it partly transparent by shader? Please advice

Hi. I tried to use lua enableRenderToTexture() function and player screen wont show up(jams the screen). Also i tried to use it before and within onsceneupdate function and its the same. Maybe someone can advice me how to use it properly. Thanks


my code:

Camera = getCurrentCamera()
enableRenderToTexture(Camera,"maps/3dlabs.png",256,256)

Thanks for advice anael. I'l try to work with that.

Hi, im trying to implement water and i'm looking for a way to render scene from camera for reflection. Maybe someone can help me with code sample c++ if any exists.
There is a function:

virtual void MRenderingContext::sendTextureImage(MImage *image, bool mipMap, bool filter, bool compress)=0;

But it takes a MImage as parameter. Is there a way to convert to MImage like

MTextureRef * colorTexture = camera->getRenderColorTexture();

7

(4 replies, posted in General)

I'm happy to announce that shader code worked fine. Thanks anael for help. This is the final working code:

VERT shader:

//VERT

attribute vec3 Vertex;
attribute vec2 TexCoord0;

varying vec2 TexCoord;  

uniform mat4 TextureMatrix[8];
uniform mat4 ProjModelViewMatrix;

void main(void) 
{  
    TexCoord = vec2(TextureMatrix[0] * vec4(TexCoord0, 1.0,1.0));  
    gl_Position = ProjModelViewMatrix * vec4(Vertex,1.0);  
} 

FRAG shader:

//FRAG shader

uniform float Time;
uniform sampler2D Texture[8];

  
varying vec2 TexCoord;  

void main(void) 
{  
    gl_FragColor = texture(Texture[0], vec2(TexCoord.x+Time,TexCoord.y));
}   

For the ones that will be implementing the code, they will need a code that updates the "Time" variable. C++ or hopefully lua in the future.

8

(4 replies, posted in General)

Hi anael. How can i check it? In documentation it says its void(returns no value). Sorry for being stupid...

I done this calll:

gl_FragColor=vec4(Time,1.0,1.0,1.0);

It had no effect. Seems Time is not being passed. What else i can do?

9

(4 replies, posted in General)

Hi, i have this shader and i want texture to scroll x direction, but something is wrong and texture wont move. I'm new to shaders, please help


VERT:
attribute vec3 Vertex;
attribute vec2 TexCoord0;

varying vec2 TexCoord; 

uniform mat4 TextureMatrix[8];
uniform mat4 ModelViewMatrix;
uniform mat4 ProjModelViewMatrix;

void main(void)

    TexCoord = vec2(TextureMatrix[0] * vec4(TexCoord0, 1.0,1.0)); 
   
    gl_Position = ProjModelViewMatrix * vec4(Vertex,1.0); 


FRAG:

uniform sampler2D Texture[8];

uniform float Time; 
varying vec2 TexCoord; 

void main(void) { 
    vec4 texel = texture2D(Texture[0], vec2(TexCoord.x + 100.0, TexCoord.y)); 
    //vec4 texel = texture(Texture[0], vec2(TexCoord.x + Time,0.0)); 

    gl_FragColor = texel;
    //gl_FragColor=vec4(1.0,1.0,1.0,1.0);
}   

I have time implemented in behaviour dll and its set to <time+=0.1>. But for some reason it doesnt scroll the texture. Setting 0.5f instead of time scrolls the texture. This is my dll code:

.......
void MyBehavior::update(void)
{
    MEngine * engine = MEngine::getInstance();

    MRenderingContext *render = engine->getRenderingContext();

    MGame * game = engine->getGame();

    MLevel * level = engine->getLevel();

    MScene * scene = level->getCurrentScene();

    MOEntity* entity = scene->getEntityByName("Entity0");

    MMesh * mesh = entity->getMesh();

    // check if the game is running, removing thif test will enable In-Editor update (like for the lookAt behavior)
    if(! game->isRunning())
        return;

    // get the associated parent object (who is using this behavior)
    MObject3d * parent = getParentObject();

    // lets rotate the parent object around the z axis, using our custom "rotationSpeed" variable
    //parent->addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed);
    if (time > 1.0)
    {
        time = 0.0;
    }
    else
    {
        time += 0.1;
    }

    MMaterial * material = mesh->getMaterial(0);
    if (material)
    {
        MFXRef * FXRef = material->getFXRef();
        if (FXRef)
        {
            unsigned int fxId = FXRef->getFXId();
            render->bindFX(fxId);

            // send uniform variable
            render->sendUniformFloat(fxId, "Time", &time);

            render->bindFX(0);
        }
    }
}
........

So as far as i understand i have to create a "Game.ll" and create a behaviour?
One more question-how do you get "mesh" and "render"?

Hi. Is it possible by some way to pass variable to shader by script? For examle time.

12

(5 replies, posted in General)

Thanks anael. Code worked. Had to make small changes. Thats the code that worked:


VERT:

attribute vec3 Vertex;
attribute vec3 Normal;
attribute vec3 Tangent;
attribute vec3 color;

attribute vec2 TexCoord0;
attribute vec2 TexCoord1;
attribute vec2 TexCoord2;
attribute vec2 TexCoord3;

uniform mat4 TextureMatrix[4];
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ProjModelViewMatrix;

// custom varyings interpolated to the pixel shader
varying vec2 texCoord;
varying vec4 position, Color;

// vert main
void main(void)
{
    position = ModelViewMatrix * vec4(Vertex, 1.0);
    texCoord = (TextureMatrix[0] * vec4(TexCoord0, 1.0, 1.0)).xy;
    Color = vec4(color, 1.0);

    gl_Position = ProjModelViewMatrix * vec4(Vertex, 1.0);
}

FRAG:

uniform float time;
uniform sampler2D Texture[8];

float radius = .5;
varying vec2 texCoord;

void main()
{
    float t = clamp(time / 6., 0., 1.);

    vec2 coords = texCoord.st;
    vec2 dir = coords - vec2(.5);
   
    float dist = distance(coords, vec2(.5));
    vec2 offset = dir * (sin(dist * 80. - time*15.) + .5) / 30.;

    vec2 texCoord = coords + offset;
    vec4 diffuse = texture2D(Texture[0], texCoord);


    gl_FragColor = diffuse * (1. - t);
}

13

(5 replies, posted in General)

Hi anael. I'm totaly new to shaders. How else i can write this code?

    gl_FrontColor  = gl_Color;
    gl_TexCoord[0] = gl_MultiTexCoord0;

Another question would be, why shaders not working on fixed renderer?

14

(5 replies, posted in General)

Hi, im learning glsl. I want to create a water ripple on the plane, but in maratis it looks just white color. Can someboady tell me whats wrong with this code:

VERT shader
attribute vec3 Vertex;
//attribute vec3 Color;

uniform mat4 ProjModelViewMatrix;
 
void main()
{
    gl_Position    = ProjModelViewMatrix * vec4(Vertex, 1.0);
    gl_FrontColor  = gl_Color;
    gl_TexCoord[0] = gl_MultiTexCoord0;
}

FRAG shader

uniform float time;

uniform sampler2D Texture[8];

float radius = .5;

void main()
{
    float t = clamp(time / 6., 0., 1.);

    vec2 coords = gl_TexCoord[0].st;
    vec2 dir = coords - vec2(.5);
   
    float dist = distance(coords, vec2(.5));
    vec2 offset = dir * (sin(dist * 80. - time*15.) + .5) / 30.;

    vec2 texCoord = coords + offset;
    vec4 diffuse = texture2D(Texture[0], texCoord);

    //vec4 mixin = texture2D(Texture[1], texCoord);

    gl_FragColor = diffuse * (1. - t);
}

15

(10 replies, posted in General)

I applied camera to object, but when i press "W" or "S" key camera moves independently from object. Why this is happening? Any sugestions, this is my code:

void Test::move(float speed)
{
        MEngine * engine = MEngine::getInstance();
        MLevel * level = engine->getLevel();
        MScene * scene = level->getCurrentScene();
        MObject3d * parent = getParentObject();
        MOEntity * entity = (MOEntity *)parent;
        MOCamera *camera = scene->getCurrentCamera();
        MInputContext * input = engine->getInputContext();
        MPhysicsContext * physCont = engine->getPhysicsContext();
        MPhysicsProperties * phyProps = entity->getPhysicsProperties();

        MVector3 rot = entity->getTransformedRotation();

        camera->setPosition(parent->getTransformedPosition());
        
        if(input->isKeyPressed("W"))
        {
            MVector3 dir;
            dir.x = sin(rot.y)*speed;
            dir.y = cos(rot.y)*speed;
            dir.z = sin(rot.y)*speed;
            
            
            physCont->addCentralForce(phyProps->getCollisionObjectId(), dir);

        }
        if(input->isKeyPressed("S"))
        {
            MVector3 dir;
            dir.x = sin(rot.y)*(-speed);
            dir.y = cos(rot.y)*(-speed);
            dir.z = sin(rot.y)*(-speed);
            
            
            physCont->addCentralForce(phyProps->getCollisionObjectId(), dir);
        }
        
        if(input->isKeyPressed("A"))
        {
            MVector3 dir,rotation;
            dir=parent->getEulerRotation();

            parent->setAxisAngleRotation(MVector3(0,0,1),dir.z+1);
        }

}

16

(10 replies, posted in General)

Thanks Anael. Collision worked. I used box for collision shape, and sponza for level. I have modified function slightly. So far i have:

void Test::move(float speed)
{
        MEngine * engine = MEngine::getInstance();
        MLevel * level = engine->getLevel();
        MScene * scene = level->getCurrentScene();
        MObject3d * parent = getParentObject();
        MOEntity * entity = (MOEntity *)parent;
       
        MPhysicsContext * physCont = engine->getPhysicsContext();
        MVector3 rot = entity->getTransformedRotation();
        MPhysicsProperties * phyProps = entity->getPhysicsProperties(); // use parent physics prop if you want to move the parent

        MVector3 dir;
        dir.x = sin(rot.y)*speed;
        dir.y = cos(rot.y)*speed;
        dir.z = sin(rot.y)*speed;

        physCont->addCentralForce(phyProps->getCollisionObjectId(), dir);
}

17

(10 replies, posted in General)

Hi, Anael. I have physics enabled in editor, but not in code. Actually have no idea how to do this in code, so if you have time for this, please post it for me. What i'm trying to achieve is to stop entity from moving when it collides with something(anything in level like wall or other entity) and of course bactrack or slide when collision occurs. I tried

if (physCont->isObjectInCollision(phyProps->getCollisionObjectId()) == 0) // 0 collisions so move
{
    parent->setPosition(pos);
}

but without sucess. Object still moves threw the wall. I tried to add

phyProps->setCollisionShape(M_COLLISION_SHAPE_BOX);

but still nothing. What i'm missing?

18

(10 replies, posted in General)

Hi, im making a plugin in c++ and want entity to colide with level mesh and stop moving when it collided. What functions i should use? I'm using isObjectInCollision, but it doesnt behave as i expected(just rotates with mouse movement). Actually i cant find description for this function, so i'm not sure what it does. How to find that collision occured?  Please help. Currently i have:

void Player::move(MObject3d * parent,MScene * scene,MEngine * engine,float speed)
{
        MVector3 pos=parent->getTransformedPosition();
        MVector3 rot=parent->getTransformedRotation();
        MOEntity* ent= scene->getEntityByName("Player");
        MPhysicsContext * physCont = engine->getPhysicsContext();
        MPhysicsProperties * phyProps = ent->getPhysicsProperties();

        pos.x += sin(rot.y)*speed;
        pos.y += cos(rot.y)*speed;
        pos.z += sin(rot.y)*speed;

        if (physCont->isObjectInCollision(phyProps->getCollisionObjectId())>0)
        {
            parent->setPosition(pos);
        }
}

19

(11 replies, posted in General)

Finally got it working! Makefile did it. Thanks a lot for your help guys

Had to change LDFLAGS= -shared -Wl to LDFLAGS= -shared -Wall. makefile reported error and put <tab> before all @

20

(11 replies, posted in General)

Just thinking, maybe someone knows a proven way to compile it under Ubuntu linux using gcc without CodeBlocks. Can you post a command line to compile this project.

21

(11 replies, posted in General)

Did everything just as you said. Compiled WaterGameDemo with Game.so name, im using 32 bit OS Ubuntu linux, Maratis version is 3.21 also 32 bit, libraries and includes i used are from Maratis SDK folder, i did not compiled Maratis(just downloaded), used Codeblocks for compiler, compiled in Relese mode. Code is used from tutorial, nothing added - nothing removed, dll is in the same directory as .mproj. But still the same. Maybe i'm missing something...

22

(11 replies, posted in General)

Compiled in both versions debug/release, named it Game.so and tried libGame.so, but its still the same... Thanks for correcting the link com3D. I took out the dot. It works now

23

(11 replies, posted in General)

Tried renaming libGame.so to Game.so and plugin is in the project directory with the .mproj file, but still nothing. Size of plugin is 238.3kb
I have uploaded the project here http://skywriter.freeoda.com/SimpleGamePlugin.zip If someone could check it, i would be gratelly thankfull.

24

(11 replies, posted in General)

Hi Sponk. My OS is 32 bit Ubuntu 13.04. I'm new to codeblocks and c++ programming. What this flag does and how can i set it? I checked codeblocks under build options/compiler flags, but didnt find such flag

25

(11 replies, posted in General)

Hi everyone . I have compiled a dll of SimpleGamePlugin under linux ubuntu using codeblocks. The name  of dll was libGame.so. I followed the tutorial of creating simple game plugin, but when i lounched the editor behavior was not visible. Actually it is not visible for any plugin(tried SimpleWaterDemo). Anyboady knows why? Is it working at linux at all?