About Store Forum Documentation Contact



Post Reply 
Textures & Scene Modification
Author Message
Chris Offline
Member

Post: #1
Textures & Scene Modification
Hi,

I'm trying to get a specific fun camera-like feature working in my game.

I want to take a picture/image of the world and render it to a texture of a mesh (not necessarily in realtime, just every now and then). Also I want to have control over which world objects can be hidden and shown in this picture.

Is this possible with Esenthel?

Thanks,
Chris
03-27-2010 09:14 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Textures & Scene Modification
Hello,

Yes you can use Renderer.capture for this


example:

Bool inside_shot=false; // global

Obj::draw
{
if(!inside_shot) ..
}

void MakeShot()
{
inside_shot=true;
Renderer(ShotRender);
Renderer.capture(image,...)
inside_shot=false;
}
void Draw()
{
if(make_shot)MakeShot();

// .. here standard draw code

}
03-28-2010 12:23 AM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #3
RE: Textures & Scene Modification
Thanks for this - it worked great and was very fun smile

Also, i'm trying to modify the positions of my mesh in a vertex shader. But, just to be awkward, rather than doing it from bones with the skinning example, i'm trying to do it from a rgb colour value - accessing the vertex's colour from a UVW lookup on a texture/reference image.

Specifically: I want to access the rgb colour of the vertex's relevant UVW coordinate, and set the position based on some calculations on this colour value.

I've tried:

Code:
Image img;

...

// vertex input
VtxInput vtx,
Vec  inTex:TEXCOORD0,

// output
out Vec4 outVtx:POSITION

...

Vec view_space_pos=Tex(img,inTex).rgb;
outVtx=Project(view_space_pos);

But with this I get error X4532: cannot map expression to vertex shader instruction set. I'm not even sure if it's possible, any ideas?

Edit: And is there anyway to get autocomplete working with shaders? I currently just have the shader source file in my project with "exclude from build" set to Yes.

Thanks,
Take care,
Chris
(This post was last modified: 04-27-2010 05:06 PM by Chris.)
04-27-2010 05:04 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Textures & Scene Modification
Hello,

You shouldn't declare additinal vertex input
Code:
VtxInput vtx,
Vec  inTex:TEXCOORD0,

but use vtx.tex

also you've used Vec for tex coords, while it should be Vec2 (tex coords in EE are 2 dimensional only)
if you need 3 dimensional you'd need to encode .z component into second tex coord set -
Vec tex=Vec(vtx.tex(), vtx.tex1().x);

and Tex macro accepts Vec2 coords
04-27-2010 05:10 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Textures & Scene Modification
Quote:And is there anyway to get autocomplete working with shaders? I currently just have the shader source file in my project with "exclude from build" set to Yes.
I also have the shaders inside VS project with exclude from build = yes,
shader extension set to .cpp
and autocomplete is working.

Check if you have under project settings
"C/C++ \ General \ Additional Include Directories = $(ProjectDir)"

If that won't help then I don't have an idea.
04-27-2010 05:16 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #6
RE: Textures & Scene Modification
Hi,

Thanks for your awesomely fast reply. After reading that they worked for you, I tried deleting the .ncb file from my project and restarting visual studio, and the autocomplete works smile

I'm having some problems understanding it. This compiles:

Code:
Vec tex=Vec(vtx.tex(), vtx.tex1().x);

outTex=vtx.tex();
outPos=tex;
outVtx=Project(tex);

but displays nothing. So vtx.tex() copies the output texture coordinates? Then do I need to feed these into a Tex(...).rgb call to get the 3 colour values from the image texture, and then I need to set outPos = Vec3ColourValues; to get what i'm after?

Sorry for being so slow with this,
Take care,
Chris
04-27-2010 05:42 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Textures & Scene Modification
do you have a 2D source image?

if yes, then you need just


void VS
(
VtxInput vtx,
out Vec4 outVtx:POSITION
)
{
Vec2 tex_coord=vtx.tex();
Vec4 tex_value=Tex(image,tex_coord);

Vec pos=tex_value.rgb; // set RGB as XYZ position
pos=TransformPos(pos); // transform by object+camera matrix

outVtx=Project(pos);
}


something like that
04-27-2010 06:26 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #8
RE: Textures & Scene Modification
Really appreciate the conversion code,

Code:
/******************************************************************************/
#include "Main.h"
/******************************************************************************/
Image image;
/******************************************************************************/
// VERTEX SHADER
/******************************************************************************/
void Test_VS
(
    VtxInput vtx,
    out Vec4 outVtx: POSITION
) {
    Vec2 tex_coord = vtx.tex();
    Vec4 tex_value = Tex(image, tex_coord);

    Vec pos = tex_value.rgb; // set RGB as XYZ position
    pos = TransformPos(pos); // transform by object+camera matrix

    outVtx = Project(pos);
}

...

In source:

        case RM_BLEND:
        {
         if(ShaderImage *si=GetShaderImage("image"))si->set(projection);
        }break;

I tried compiling and I get the same error which has been stopping me -

I'm still getting error X4532: cannot map expression to vertex shader instruction set

(only using SM 3, as it says SM 2 doesn't support the texture lookups).
04-27-2010 06:40 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Textures & Scene Modification
oh yeah, VS doesn't support anisotropic filtering and mip mapping when reading textures
you must specify the LOD, try using TexLod(image,tex_coord); // to use 0-th Lod
04-27-2010 07:17 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #10
RE: Textures & Scene Modification
Awesome, you rock!

Can I also rack your brain for something else, lets say I want to generate the inverse from a mesh - i.e. generate an image from mesh UVW's whose rgb values represent local 3d coordinates - would this have to be performed by raytracing on the CPU? Or would their be a way to get it from using the GPU?

Cheers
04-27-2010 07:24 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #11
RE: Textures & Scene Modification
this would be rather complex

the easiest way would be to iterate all vertexes, store vertex XYZ position into texture RGB at vertex UV coordinates

mark written pixel as "valid" (in some helper memory)

having the texture filled with some "valid" and some "invalid", you should also then set the "invalid" pixels (which were not set yet) - just locate the nearest "valid" pixel and copy the value
04-27-2010 07:31 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #12
RE: Textures & Scene Modification
Thank you very much for your suggestion, i'll work on it tomorrow after some sleep.

Time for me to learn how to use your Texture/Image structs smile

Yeah, cheers again Grzegorz - you've greatly simplified my work today.
04-27-2010 07:38 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #13
RE: Textures & Scene Modification
Hi. I'm attempting your complex suggestion; iterating all vertexes, storing their XYZ position into texture RGB at vertex UV coordinates

And have gotten a little stuck between reading UV coords from vertex's into a 2d image.

Here's my code:
Code:
Img.create2D(2048,2048, IMAGE_A8R8G8B8, 1);

...

void GenerateImg(Ptr) {
    if(Img.lock()) { // lock texture for editing
        // First set the image to be black:
        FREPD(y, Img.y()) // iterate through all y's
        FREPD(x, Img.x()) { // iterate through all x's
            Img.color(x, y, Color(255, 0, 0, 0)); // set image color at (x,y) coordinates
        }

        // Iterate the mesh, storing the 3d vertex coords, and the 2d vertex coords
        REP(body->base(0).vtx.num) {
            Vec2 uvw = *(body->base(0).vtx.tex0 + i);
            Vec  xyz = *(body->base(0).vtx.pos + i);
>>>         Img.color(uvw.x*255, uvw.y *255, Color(255, 255, 255 ,255)); // test paint white
        }
        Img.unlock(); // unlock
    }
}

EDIT: I solved it! (Apart from some artifacts like random tearing between joints) I needed to do an xyz += 0.5; for some reason.

Thanks
(This post was last modified: 04-29-2010 10:13 AM by Chris.)
04-28-2010 03:36 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #14
RE: Textures & Scene Modification
Hi,

1. I have another slight problem. Something's wrong with my mesh reconstruction code, have you seen anything like this before: (it misses out triangles sometimes, e.g. the foot of the alien, or on my low poly char it seems very frequently).

2. Also, when I project the uv coordinates into 3d space, it draws different parts of them on both sides. Very strange - any ideas what this is too, or if its related?

   
ABOVE: Alien with triangle's on foot missing.
   
ABOVE: A really low poly char, with many triangles missing.

My code probably won't be of much use here, but I just recreate a mesh from some maths, and eventually draw it again on the GPU.
(This post was last modified: 05-05-2010 03:12 PM by Chris.)
05-05-2010 03:07 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #15
RE: Textures & Scene Modification
maybe you somehow not process quads?

you can use quadToTri method to convert all quads into triangles

apart from that, I don't have any other idea
05-05-2010 03:12 PM
Find all posts by this user Quote this message in a reply
Post Reply