PDA

View Full Version : What the camera sees, the camera projects?


ThePriest
10-12-2006, 03:02 AM
This may seem a little out of reach for Cinema, but It's an idea i've had to demostrate a simple cloaking device.

Is it possible to project what the camera is viewing onto a visible polygon selection or if need be a seperate object, without rendering numerous times?


For example - Camera 1 Render to Object 1 - etc etc

Per-Anders
10-12-2006, 03:13 AM
Not without first writing a shader to do it (though it's not particularly hard to implement as a shader, either calculate a camera ray for each u/v coordinate and sample, or create a render from the camera POV first in the shader to generate a bitmap).

ThePriest
10-12-2006, 03:18 AM
I'm no programmer, so seemingly out of luck.

Would you be up for the task? :)

Per-Anders
10-12-2006, 04:02 AM
I'm no programmer, so seemingly out of luck.

Would you be up for the task? :)

Hmm? sure, here's a 5 minute job, have fun with it

//Camera Ray Shader
//Per-Anders Edwards 2006

#include "c4d.h"
#define ID_CAMERARAYSHADER 1020311

struct CameraRayData
{
Real xres, yres;
};

class CameraRayShader : public ShaderData
{
public:
CameraRayData dat;

virtual Vector Output (PluginShader *chn, ChannelData *cd);
virtual LONG InitRender (PluginShader *chn, InitRenderStruct *irs);

static NodeData *Alloc(void) { return gNew CameraRayShader; }
};

Vector CameraRayShader::Output(PluginShader *chn, ChannelData *cd)
{
if (!cd || !cd->vd) return 1.0f;

VolumeData *vd = cd->vd;
if (vd->raydepth >= 10) return 0.0f;
Ray ray = Ray();
vd->GetRay(vd->uvw.x * dat.xres, vd->uvw.y * dat.yres, &ray);

SurfaceIntersection si;
return vd->TraceColor(&ray, MAXREAL, NOTOK, &si);
}

LONG CameraRayShader::InitRender(PluginShader *chn, InitRenderStruct *irs)
{
BaseContainer *data = chn->GetDataInstance();
if (!data) return LOAD_NOMEM;

if (!irs || !irs->vd) return LOAD_NOMEM;
RayParameter *rp = irs->vd->GetRayParameter();
if (!rp) return LOAD_NOMEM;
dat.xres = rp->xres;
dat.yres = rp->yres;

return LOAD_OK;
}

Bool RegisterCameraRayShader(void)
{
// decide by name if the plugin shall be registered - just for user convenience
String name="Camera Shader";
return RegisterShaderPlugin(ID_CAMERARAYSHADER,name,0,CameraRayShader::Alloc,"",1000);
}

ThePriest
10-12-2006, 06:04 AM
Very nice, I'll look to figure out how to assign a camera to each respective material,
but this is a great start.


Thank you.

ThePriest
10-12-2006, 06:15 AM
Doesn't seem to do what I thought it would with this scene,
being that the camera view inside the metaball isn't rendering on the plane.

Such a plugin if re-worked to perfection, could prove to beneficial for Motion graphics and a lot more. I'd definitely pay $30-$40 for it.

ThePriest
10-12-2006, 06:25 AM
This would be a more applicable idea of what I had in mind.

tcastudios
10-12-2006, 05:17 PM
Hmm? sure, here's a 5 minute job, have fun with it

I'm trying to! But I've never dealt with ShaderPlugins so....where/how do we add it?
Looks as a great asset!

Cheers
Lennart

Per-Anders
10-12-2006, 07:29 PM
@tca - It's just a standard shader but it's a pc only .cdl compile, put the plugin in your folder and pick the shader from the shaders list in any material/texture slot. The source is there so if your'e on a mac you can download XCode, bung it into a C4DSDK project and compile it (don't forget to add the registration declaration and call to the main.cpp).

@ThePriest - It does what you asked for at first. If you want other cameras all you have to do is make an interface with a link for your camera then calculate the ray direction using the Tangent of half of the uv multiplied by half of the cameras FOV. I don't know if i'll have time to do this, but the source is right there for anyone else to mess around with, it's pretty simple to make shaders in C4D.

tcastudios
10-12-2006, 07:36 PM
@tca - It's just a standard shader but it's a pc only .cdl compile, put the plugin in your folder and pick the shader from the shaders list in any material/texture slot. The source is there so if your'e on a mac you can download XCode, bung it into a C4DSDK project and compile it (don't forget to add the registration declaration and call to the main.cpp).

Ah, Thanks. I'm still only a Coffee drinker, so this must be my first try into the stronger liquids :) It'll have to wait thou..

Cheers
Lennart

ThePriest
10-12-2006, 08:42 PM
@ThePriest - It does what you asked for at first. If you want other cameras all you have to do is make an interface with a link for your camera then calculate the ray direction using the Tangent of half of the uv multiplied by half of the cameras FOV. I don't know if i'll have time to do this, but the source is right there for anyone else to mess around with, it's pretty simple to make shaders in C4D.

I don't think I explained myself properly "at first", but I'll take a look at some coffee resources and see if I can put something together later today.
Thanks

skydistortion
10-12-2006, 08:43 PM
Hi all,
I have a question also in that direction :
Let's say that I have a scene with 10 different animated cameras.
Is there a way to render the 10 different camera view automaticly in 10 different '.mov' files ?
Something like a "batch" that renders automaticly all the different camera used in a scene.
The file could be named with the name of the camera of the scene.

Cause for now, I loose a lot of time to save a different .c4d file for each camera and then using the batch render hte normal batch render.

Is there an issue ?

Geespot
10-12-2006, 08:49 PM
Thanks Per,

I once made a camera shader but it was a mess. I went through a long process of rendering a scene and the using that as the shader, I ran into lots of problems making sure a scene wouldnt render more than once. And that was just the start of the many issues I had. It was real ugly.

Never knew it would be this simple.

tcastudios
10-12-2006, 09:08 PM
Thanks Per,
Never knew it would be this simple.

Maybe ( looking down and scraping my foot) make a compile? (Looking up with puppy eyes)

Cheers
Lennart

ThePriest
10-13-2006, 04:37 AM
You can do it Per

http://files.blog-city.com/files/J05/139396/p/f/idol3.jpe

mikek
10-13-2006, 04:51 AM
This may not be what you're asking about, but I once saw a scene somewhere that used a mirrored sphere linked to the camera, and a mirrored surface acting as a viewport. The mirrored surface reflected the reflection in the sphere to act as a virtual viewport. The camera, sphere, and viewport were all kept in synch by Expresso. Not sure who created it, but whatever was in the physical scene, was rendered as usual and also in the viewport as though it was a live monitor. I'm not very astute with Expresso, so I didn't even try to understand how it worked. Just thought it looked neat!

Mike Kuykendall

paulselhi
10-13-2006, 07:00 AM
The camshader plugin crashes cinema r9.603

Artanis
10-16-2006, 05:08 AM
The camera linking sounds like a neat idea.

I keep thinking "learn the scripting, learn the scripting" but I never get around to it... anyone have any beginner/total-novice tutorials?

The camshader plugin crashes cinema r9.603Not on mine that I've seen... what are you doing to it?

paulselhi
10-16-2006, 05:17 AM
Choosing camerashader in say the color slot of a mat causes my 9.603 to crash

ThePriest
10-16-2006, 08:20 AM
I believe it would be a great plugin too, with many many uses in Motion Graphics, possibly Archviz and experimental abstract works etc.

Does anybody have the time to help with this?

CGTalk Moderation
10-16-2006, 08:20 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.