Creating a Second Camera

I’ve added lighting to my main scene however it’s interfering with the black/green rendering done by the second camera (see above).

I’d like to turn off lighting for the second camera.

I thought I might be able to do it using LightAttrib::make_all_off():

// Setup the render state for the second camera.
	CPT(RenderState) initial_state = RenderState::make(ColorAttrib::make_flat(Colorf(0, 0, 0, 1)), 1);
	initial_state = initial_state->add_attrib(TextureAttrib::make_off(), 1);
	initial_state = initial_state->add_attrib(LightAttrib::make_all_off(), 1);
	occlusionCamera->set_initial_state(initial_state);
	CPT(RenderState) green_state = RenderState::make(ColorAttrib::make_flat(Colorf(0, 1, 0, 1)), 1);
	green_state = green_state->add_attrib(LightAttrib::make_all_off(), 1);
	occlusionCamera->set_tag_state_key("aux");
	occlusionCamera->set_tag_state("green", green_state);
	sourceNodePath.set_tag("aux", "green");
	occlusionCameraNodePath = window->get_camera_group().attach_new_node(occlusionCamera);

however this doesn’t work as it makes the entire scene black (I think that’s what’s happening).

How do I get the black/green rendering back?

Turning off lighting won’t make the scene black. When lighting is off, it’s a special case, and the scene is considered fully lit (as if there were a fully bright ambient light).

However, this attrib will make the scene black:
ColorAttrib::make_flat(Colorf(0, 0, 0, 1))

David

At the moment I’ve got a simple test app using the code shown above to render the scene into a second window in black/green. This works properly with some simple models that I created in Blender.

However, when I used the same code with some models that I came across online, I’m getting a greyscale image without any green at all.

Is there something in the .egg file that could cause this to happen (normal mapping, mipmapping, etc.)?

A material setting in the egg file can override any color you specify in the scene graph, unless you also specify a MaterialAttrib at runtime (or disable lighting).

David

There are materials in the files that I’m using which are affecting the rendering. I’ve removed them from the .egg files and that’s fixed the problem.

I’ve fixed the black/green rendering for the second camera however when the main scene is lit, the lighting is affecting the second camera.

The object that’s green is rotating and each face is being lit differently as it rotates so each face is a different shade of green (faces away from the light are darker). Is there a way to switch off the lighting for the second camera so that the green cube is rendered as a single color? The code I’m using is shown below.

	// Setup the offscreen buffer.
	const string bufferName("myBuffer");
	PT(GraphicsWindow) gw = window->get_graphics_window(); 
	PT(GraphicsStateGuardian) gsg = gw->get_gsg();
	PT(GraphicsOutput) buffer; 
	buffer = gsg->get_engine()->make_buffer(gw, bufferName, 0, OCCLUSION_WINDOW_SIZE, OCCLUSION_WINDOW_SIZE);
	
	// Setup the camera for the offscreen buffer.
	PT(Camera) newCamera = new Camera("secondCamera");	
	
	// Setup the render state for the second camera.
	CPT(RenderState) initial_state = RenderState::make(ColorAttrib::make_flat(Colorf(0, 0, 0, 1)), 1);
	initial_state = initial_state->add_attrib(TextureAttrib::make_off(), 1);
	newCamera->set_initial_state(initial_state);
	CPT(RenderState) green_state = RenderState::make(ColorAttrib::make_flat(Colorf(0, 1, 0, 1)), 1);
	newCamera->set_tag_state_key("aux");
	newCamera->set_tag_state("green", green_state);
	sourceVector.at(0).set_tag("aux", "green");
	NodePath newCameraNP;
	newCameraNP = window->get_camera_group().attach_new_node(newCamera);
	cameraVector.push_back(newCameraNP);
	
	// Connect the buffer and the camera.
	DisplayRegion *region = buffer->make_display_region(); 
	region->set_camera(newCameraNP);
	region->set_active(true);
	
	// Setup the output texture.
	WindowProperties props;
	props.set_size(OCCLUSION_WINDOW_SIZE, OCCLUSION_WINDOW_SIZE);
	//props.set_undecorated(true);
	int flags = GraphicsPipe::BF_require_window;
	WindowFramework *texWindow = framework.open_window(props, flags, gsg->get_pipe(), gsg); 
	tbuf = new Texture("tbuf"); 
	textureVector.push_back(tbuf);
	buffer->add_render_texture(tbuf, GraphicsOutput::RTM_copy_ram); 
	CardMaker cm("cm"); 
	cm.set_frame(-1, 1, -1, 1); 
	NodePath card(cm.generate()); 
	card.reparent_to(texWindow->get_render_2d());
	card.set_texture(tbuf);
1 Like
initial_state = initial_state->add_attrib(LightAttrib::make_all_off(), 1);

David