Esempio n. 1
0
//--------------------------------------------------
void Scene::render()
{
	static int frameCount = -1;

	// now update the cube map
	// because our scene is pretty much static, we need to do this
	// every couple of frames only
	
	// uncomment this if you implemented environment mapping
	frameCount = (frameCount + 1) % 500;
	if (frameCount == 0)
	{
		updateCubeMap();
	}
  //

	switch (shadowMode)
	{
	default:
		renderNormal();
		break;
	case 1:
		renderShadowVolumes();
		break;
	case 2:
	case 3:
		renderShadowMapping();
    break;
	}
}
Esempio n. 2
0
	void SubEntityYZ::renderWithEffect()
	{
		_renderSystem->setVertexDeclaration(_entity->_vdt);
		//_renderSystem->setRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

		HRESULT hr;

		u32 effectNum = 0;
		// Apply the technique contained in the effect 
		_effect->begin(&effectNum);

		for (u32 i = 0; i < effectNum; ++i)
		{
			_effect->beginPass(i);

			renderNormal();

			_effect->endPass();
		}

		_effect->end();
	}
Esempio n. 3
0
void Renderer::renderFrame() {

    float step_repeat = glo_elapsed_frames % 1000 / 20.0;

    for(int j = 0; j < camera.canvas.height; j++) {
        for(int i = 0; i < camera.canvas.width; i++) {
            Color acc = renderNormal(i, j, camera, *this);

//            // prepare for intersect
//            Ray primaryRay;
//            camera.getRayThroughCanvasAt(i, j, &primaryRay);
//            IntersectData data = IntersectData();
//            bool primaryRayHit = false;
//            for(int k = 0; k < scene.objects.size(); k++) {
//                IntersectType type = scene.objects[k]->intersect(primaryRay, &data);
//                if(type == HIT) {
//                    data.nearestObject = scene.objects[k];
//                    primaryRayHit = true;
//                }
//            }
//
//            Color acc = Color(0,0,0);
//
//            Point3 lightPos(4*sin(step_repeat),
//                         2.0*sin(1.5*step_repeat)+2,
//                         4*cos(step_repeat)-5);
//
//            if(!primaryRayHit) { // primary ray MISS
//                acc = Color(0,0,0);
//            } else { // primary ray HIT; send secondary ray
//
//                // prepare light sphere
//                Object *lightSphere = scene.objects[1];
//                lightSphere->position = lightPos;
//
//                // construct secondary ray
//                Ray secondaryRay;
//                secondaryRay.position = primaryRay.position + data.t*primaryRay.direction;
//                secondaryRay.direction = (lightSphere->position - secondaryRay.position).normalize();
//
//                // prepare to fire ray
//                IntersectData secondaryIntersectData;
//                bool isBlocked = false;
//                bool isLight = false;
//                for(int k = 0; k < scene.objects.size(); k++) {
//                    IntersectType type = scene.objects[k]->intersect(secondaryRay, &secondaryIntersectData);
//                    if(type == HIT) {
//                        secondaryIntersectData.nearestObject = scene.objects[k];
//                        isBlocked = true;
//                        if(scene.objects[k] == lightSphere) {
//                            isBlocked = false;
//                            isLight = true;
//                        }
//                    }
//                }
//
//                if(!isBlocked) { // NOT BLOCKED. Compute normal color
//                    Vector3 n = data.nearestObject->getNormalAt(primaryRay.position + data.t*primaryRay.direction);
//                    Color c = data.nearestObject->material->color;
//
//                    float dot = (n * primaryRay.direction) * (n * secondaryRay.direction);
//                    dot = dot < 0 ? -dot : dot;
//                    acc = Color(c.r*dot, c.g*dot, c.b*dot);
//
//                    float brightenBy = 0.5;
//                    acc.r = acc.r < (1.0f - (acc.r*brightenBy)) ? acc.r + (acc.r*brightenBy) : 1.0;
//                    acc.g = acc.g < (1.0f - (acc.g*brightenBy)) ? acc.g + (acc.g*brightenBy) : 1.0;
//                    acc.b = acc.b < (1.0f - (acc.b*brightenBy)) ? acc.b + (acc.b*brightenBy) : 1.0;
//                } else { // BLOCKED.  Compute shadow
//                    acc = Color(0,0,0);
//                }
//            }

            camera.canvas.setPixel(i, j, acc);
        }
    }
}