Exemple #1
0
void CellularAutomata::handleMouse(bool isPressed, bool isDown, const Ray & mouseRay, const Vector2 & mousePos) {
    m_transientPlayhead.position = Vector2int16(-5, -5);
    if (m_paused) {
        Point2int16 selectedPosition(-1,-1);
        for (int x = 0; x < m_width; ++x) {
            for (int y = 0; y < m_height; ++y) {
                Vector2 normalizedCoord = Vector2(x,y) * 
                    Vector2(1.0f / (m_width - 1.0f), 1.0f / (m_height - 1.0f));
                     
                const Point3& p = normCoordTo3DPoint(normalizedCoord);
                if (intersects(mouseRay, p, collisionRadius())) {
                    selectedPosition = Vector2int16(x, y);
                }
            }
        }
        
        if (selectedPosition.x >= 0) {
 
            m_transientPlayhead.position  = selectedPosition;
            m_transientPlayhead.direction = Direction::DOWN;

            // Super hackish way to select the direction to point in based on mouse position 
            // from the center (should work on in either mode, but only tested on 2D)
            // This is the first thing due for a cleanup
            float minDistance = 10.0f; // Basically infinity...
            Vector2 normalizedCoord = Vector2(selectedPosition) *
                Vector2(1.0f / (m_width - 1.0f), 1.0f / (m_height - 1.0f)); 
            const Point3& center = normCoordTo3DPoint(normalizedCoord);
            float t = mouseRay.intersectionTime(Sphere(center, collisionRadius()));
            Point3 intersectionPoint = mouseRay.origin() + mouseRay.direction() * t;
            for (int i = 0; i < 4; ++i) {
                Vector2 npos = normalizedCoord + Vector2(vecFromDir(Direction(i)))*0.001f;
                const Point3& p = normCoordTo3DPoint(npos);
                if ((intersectionPoint - p).length() < minDistance) {
                    minDistance = (intersectionPoint - p).length();
                    m_transientPlayhead.direction = Direction(i);
                }
            }

            if (isPressed) {
                bool removed = false;
                for (int i = m_playhead.size() - 1; i >= 0; --i) {
                    if (selectedPosition == m_playhead[i].position) {
                        m_playhead.remove(i);
                        removed = true;
                        break;
                    }
                }
                
                if (!removed) {
                    m_playhead.append(m_transientPlayhead);
                }
                
            }
            
        } 
        
    }

}
Exemple #2
0
int main(int argc, const char* argv[]) {
    initGLG3D();

    GApp::Settings settings(argc, argv);

    // Change the window and other startup parameters by modifying the
    // settings class.  For example:
    settings.window.caption			= argv[0];

    // Some popular resolutions:
    // settings.window.width        = 640;  settings.window.height       = 400;
    // settings.window.width		= 1024; settings.window.height       = 768;
    settings.window.width         = 1280; settings.window.height       = 720;
    // settings.window.width        = 1920; settings.window.height       = 1080;
    // settings.window.width		= OSWindow::primaryDisplayWindowSize().x; settings.window.height = OSWindow::primaryDisplayWindowSize().y;

    // Set to true for a significant performance boost if your app can't render at 60fps,
    // or if you *want* to render faster than the display.
    settings.window.asynchronous	    = true;
    settings.depthGuardBandThickness    = Vector2int16(64, 64);
    settings.colorGuardBandThickness    = Vector2int16(16, 16);
    settings.dataDir			        = FileSystem::currentDirectory();
//    settings.screenshotDirectory	    = "../journal/";

    return App(settings).run();
}
Exemple #3
0
static Vector2int16 vecFromDir(Direction d) {
    switch(d) {
    case Direction::UP:
        return Vector2int16(0,1);
    case Direction::DOWN:
        return Vector2int16(0,-1);
    case Direction::LEFT:
        return Vector2int16(-1,0);
    case Direction::RIGHT:
        return Vector2int16(1,0);
    default:
        alwaysAssertM(false, "Invalid direction");
        return Vector2int16(0, 0);
    }
}
Exemple #4
0
void DepthOfField::apply
(RenderDevice*                  rd,
 shared_ptr<Texture>            color,
 shared_ptr<Texture>            depth,
 const shared_ptr<Camera>&      camera,
 Vector2int16                   trimBandThickness) {

    if ((camera->depthOfFieldSettings().model() == DepthOfFieldModel::NONE) || ! camera->depthOfFieldSettings().enabled()) {
        const shared_ptr<Framebuffer>& f = rd->framebuffer();
        const shared_ptr<Framebuffer::Attachment>& a = f->get(Framebuffer::COLOR0);

        if (isNull(f) || (a->texture() != color)) {
            Texture::copy(color, a->texture(), 0, 0, Vector2int16(0, 0), CubeFace::POS_X, CubeFace::POS_X, rd, false);
        }

        // Exit abruptly because DoF is disabled
        return;
    }

    alwaysAssertM(color, "Color buffer may not be NULL");
    alwaysAssertM(depth, "Depth buffer may not be NULL");

    if (isNull(m_artistCoCShader)) {
        reloadShaders();
    }
    resizeBuffers(color, trimBandThickness);

    computeCoC(rd, color, depth, camera, trimBandThickness);
    blurPass(rd, m_packedBuffer, m_horizontalFramebuffer, m_horizontalShader, camera);
    blurPass(rd, m_tempBlurBuffer, m_verticalFramebuffer, m_verticalShader, camera);
    composite(rd, m_packedBuffer, m_blurBuffer, trimBandThickness);
}
Exemple #5
0
int main(int argc, const char* argv[]) {
    GApp::Settings settings(argc, argv);
    
    settings.window.width       = 1280; 
    settings.window.height      = 720;
    settings.window.caption     = "G3D Deferred Shading Sample";
    settings.colorGuardBandThickness = Vector2int16(0, 0);
    settings.depthGuardBandThickness = Vector2int16(64, 64);
    
#   ifdef G3D_WINDOWS
    if (! FileSystem::exists("deferred.pix", false)) {
        // Running on Windows, building from the G3D.sln project
        chdir("../samples/deferredShading");
    }
#   endif
    
    return App(settings).run();
}
Exemple #6
0
int main(int argc, const char* argv[]) {
    {
        G3DSpecification g3dSpec;
        g3dSpec.audio = false;
        initGLG3D(g3dSpec);
    }

    VRApp::Settings settings(argc, argv);
    settings.vr.debugMirrorMode = //VRApp::DebugMirrorMode::NONE;//
        VRApp::DebugMirrorMode::PRE_DISTORTION;

    settings.vr.disablePostEffectsIfTooSlow = false;

    settings.window.caption             = argv[0];

    // The debugging on-screen window, and the size of the 2D HUD virtual layer in VR in pixels.
    // Because DK2 is relatively low resolution, don't make this too large.
    settings.window.width               = 1280; settings.window.height       = 700;

    // Full screen minimizes latency (we think), but when debugging (even in release mode) 
    // it is convenient to not have the screen flicker and change focus when launching the app.
    settings.window.fullScreen          = false;
    settings.window.resizable           = false;
    settings.window.framed              = ! settings.window.fullScreen;

    // Oculus already provides a huge guard band
    settings.hdrFramebuffer.depthGuardBandThickness    = Vector2int16(0, 0);
    settings.hdrFramebuffer.colorGuardBandThickness    = Vector2int16(0, 0);

    // Async must be true for VR
    settings.window.asynchronous        = true;

    settings.renderer.deferredShading   = true;
    settings.renderer.orderIndependentTransparency = true;

    settings.dataDir                    = FileSystem::currentDirectory();
    settings.screenshotDirectory        = "";

    const int result = App(settings).run();
    
    return result;
}
Exemple #7
0
int main(int argc, const char* argv[]) {
    initGLG3D();

#   ifdef G3D_WINDOWS
      if (! FileSystem::exists("phong.pix", false) && FileSystem::exists("G3D.sln", false)) {
          // The program was started from within Visual Studio and is
          // running with cwd = G3D/VC10/.  Change to
          // the appropriate sample directory.
          chdir("../samples/pixelShader/data-files");
      } else if (FileSystem::exists("data-files")) {
          chdir("data-files");
      }
#   endif

    GApp::Settings settings(argc, argv);  
    settings.colorGuardBandThickness  = Vector2int16(0, 0);
    settings.depthGuardBandThickness  = Vector2int16(0, 0);

    return App(settings).run();
}
Exemple #8
0
int main(int argc, const char* argv[]) {
    {
        G3DSpecification g3dSpec;
        g3dSpec.audio = false;
        initGLG3D(g3dSpec);
    }

    GApp::Settings settings(argc, argv);

    // Change the window and other startup parameters by modifying the
    // settings class.  For example:
    settings.window.caption             = argv[0];
    // settings.window.debugContext     = true;

    // settings.window.width              =  854; settings.window.height       = 480;
    // settings.window.width            = 1024; settings.window.height       = 768;
    settings.window.width            = 1280; settings.window.height       = 720;

//    settings.window.width               = 1920; settings.window.height       = 1080;
    // settings.window.width            = OSWindow::primaryDisplayWindowSize().x; settings.window.height = OSWindow::primaryDisplayWindowSize().y;
    settings.window.fullScreen          = false;
    settings.window.resizable           = ! settings.window.fullScreen;
    settings.window.framed              = ! settings.window.fullScreen;

#	ifdef G3D_DEBUG
		settings.window.debugContext = true;
#	endif

    // Set to true for a significant performance boost if your app can't render at 60fps,
    // or if you *want* to render faster than the display.
    settings.window.asynchronous        = false;

    settings.hdrFramebuffer.depthGuardBandThickness    = Vector2int16(0, 0);
    settings.hdrFramebuffer.colorGuardBandThickness    = Vector2int16(0, 0);
    settings.dataDir                    = FileSystem::currentDirectory();
    settings.screenshotDirectory        = "";

	//settings.window.defaultIconFilename		= "icon.png";

    return App(settings).run();
}
Exemple #9
0
int main(int argc, const char* argv[]) {
    initGLG3D();

    GApp::Settings settings(argc, argv);
    
    // Has to be small to avoid overloading the network
    settings.window.caption      = argv[0];
    settings.window.width        = 1280; 
    settings.window.height       = 720;
    settings.guardBandThickness  = Vector2int16(0, 0);
    
    return ChatApp(settings).run();
}
Exemple #10
0
void testFullRender(bool generateGoldStandard) {
    initGLG3D();

    GApp::Settings settings;

    settings.window.caption			= "Test Renders";
    settings.window.width        = 1280; settings.window.height       = 720;
    settings.film.preferredColorFormats.clear();
    settings.film.preferredColorFormats.append(ImageFormat::RGB32F());

	// Enable vsync.  Disable for a significant performance boost if your app can't render at 60fps,
	// or if you *want* to render faster than the display.
	settings.window.asynchronous	= false;
    settings.depthGuardBandThickness    = Vector2int16(64, 64);
    settings.colorGuardBandThickness    = Vector2int16(16, 16);
    settings.dataDir				= FileSystem::currentDirectory();
    if(generateGoldStandard) { // Warning! Do not change these directories without changing the App... it relies on these directories to tell what mode we are in
        settings.screenshotDirectory	= "../data-files/RenderTest/GoldStandard";
    } else {
        settings.screenshotDirectory	= "../data-files/RenderTest/Results";
    }  
    int result = App(settings).run();
    testAssertM(result == 0 ,"App failed to run");
}
Exemple #11
0
void App::onGraphics3D(RenderDevice* rd, Array<shared_ptr<Surface> >& allSurfaces) {
    // This implementation is equivalent to the default GApp's. It is repeated here to make it
    // easy to modify rendering. If you don't require custom rendering, just delete this
    // method from your application and rely on the base class.

    if (! scene()) {
        return;
    }
	
    m_gbuffer->setSpecification(m_gbufferSpecification);
    m_gbuffer->resize(m_framebuffer->width(), m_framebuffer->height());
    m_gbuffer->prepare(rd, activeCamera(), 0, -(float)previousSimTimeStep(), m_settings.hdrFramebuffer.depthGuardBandThickness, m_settings.hdrFramebuffer.colorGuardBandThickness);

	
	m_renderer->render(rd, m_framebuffer, m_depthPeelFramebuffer, scene()->lightingEnvironment(), m_gbuffer, allSurfaces);
	

    // Debug visualizations and post-process effects
    rd->pushState(m_framebuffer); {

		if (m_enableSVO) {
			rd->clear();
			//rd->setProjectionAndCameraMatrix(activeCamera()->projection(), activeCamera()->frame());

			rd->push2D();
			const Vector2int32 guardBand(m_settings.hdrFramebuffer.depthGuardBandThickness - m_settings.hdrFramebuffer.colorGuardBandThickness);
			const Vector2int32 colorRegionExtent = Vector2int32(m_framebuffer->vector2Bounds()) - guardBand * 2;

			Args args;
			rd->setGuardBandClip2D(Vector2int16(guardBand));
			args.setRect(rd->viewport());

			Matrix4 proj;
			activeCamera()->getProjectUnitMatrix(m_framebuffer->rect2DBounds(), proj);
			float focalLength = proj[0][0];

			m_svo->setCurSvoId(0);
			args.setUniform("guardBand", guardBand);

			args.setUniform("focalLength", focalLength);
			args.setUniform("renderRes", Vector2(colorRegionExtent));
			args.setUniform("renderResI", colorRegionExtent);
			args.setUniform("screenRatio", float(colorRegionExtent.y) / float(colorRegionExtent.x));

			m_svo->connectToShader(args, Access::READ, m_svo->maxDepth(), m_svo->maxDepth());

			rd->setColorWrite(true);
			rd->setDepthWrite(false);
			
			const Matrix4& cameraToVoxelMatrix = Matrix4(m_svo->svoToWorldMatrix()).inverse() * activeCamera()->frame();

			args.setUniform("cameraToVoxelMatrix", cameraToVoxelMatrix);
			args.setUniform("voxelToWorldMatrix", m_svo->svoToWorldMatrix());
			args.setUniform("worldToVoxelMatrix", m_svo->worldToSVOMatrix());
			args.setUniform("wsCameraPos", activeCamera()->frame().translation);
			scene()->lightingEnvironment().setShaderArgs(args);
			args.setUniform("raycastingConeFactor", m_voxelConeAperture);
			

			rd->setDepthTest(RenderDevice::DEPTH_ALWAYS_PASS); // TODO: write gl_FragDepth and use a regular depth test here
			m_gbuffer->texture(GBuffer::Field::DEPTH_AND_STENCIL)->setShaderArgs(args, "depth_", Sampler::buffer());
			//rd->setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA);
			
			LAUNCH_SHADER("raycast.pix", args);
			rd->pop2D();
		}

		// Call to make the App show the output of debugDraw(...)
		rd->setProjectionAndCameraMatrix(activeCamera()->projection(), activeCamera()->frame());
		drawDebugShapes();
		const shared_ptr<Entity>& selectedEntity = (notNull(developerWindow) && notNull(developerWindow->sceneEditorWindow)) ? developerWindow->sceneEditorWindow->selectedEntity() : shared_ptr<Entity>();
        scene()->visualize(rd, selectedEntity, allSurfaces, sceneVisualizationSettings(), activeCamera());		

		rd->setPolygonOffset(-0.2f);
		if (m_debugSVONodes) {
			m_svo->visualizeNodes(rd, m_debugSVONodeLevel);
		}
		if (m_debugSVOFragments) {
			m_svo->visualizeFragments(rd);
		}
		rd->setPolygonOffset(0.0f);

        // Post-process special effects
        m_depthOfField->apply(rd, m_framebuffer->texture(0), m_framebuffer->texture(Framebuffer::DEPTH), activeCamera(), m_settings.hdrFramebuffer.depthGuardBandThickness - m_settings.hdrFramebuffer.colorGuardBandThickness);
        
        m_motionBlur->apply(rd, m_framebuffer->texture(0), m_gbuffer->texture(GBuffer::Field::SS_EXPRESSIVE_MOTION), 
                            m_framebuffer->texture(Framebuffer::DEPTH), activeCamera(), 
                            m_settings.hdrFramebuffer.depthGuardBandThickness - m_settings.hdrFramebuffer.colorGuardBandThickness);



    } rd->popState();

    if ((submitToDisplayMode() == SubmitToDisplayMode::MAXIMIZE_THROUGHPUT) && (!renderDevice->swapBuffersAutomatically())) {
        // We're about to render to the actual back buffer, so swap the buffers now.
        // This call also allows the screenshot and video recording to capture the
        // previous frame just before it is displayed.
        swapBuffers();
    }

	// Clear the entire screen (needed even though we'll render over it, since
    // AFR uses clear() to detect that the buffer is not re-used.)
    rd->clear();

    // Perform gamma correction, bloom, and SSAA, and write to the native window frame buffer
    m_film->exposeAndRender(rd, activeCamera()->filmSettings(), m_framebuffer->texture(0));
}
Exemple #12
0
Vector2int16 Vector2int16::clamp(const Vector2int16& lo, const Vector2int16& hi) {
    return Vector2int16(iClamp(x, lo.x, hi.x), iClamp(y, lo.y, hi.y));
}
Exemple #13
0
void App::onUserInput(UserInput* ui) {
    GApp::onUserInput(ui);
    bool pressed = ui->keyPressed(GKey::LEFT_MOUSE);
    bool held    = ui->keyDown(GKey::LEFT_MOUSE);
    const Ray& mouseRay = scene()->eyeRay(activeCamera(), userInput->mouseXY() + Vector2(0.5f, 0.5f), RenderDevice::current->viewport(), Vector2int16(0, 0));
    m_automata.handleMouse(pressed, held, mouseRay, userInput->mouseXY());
    
    (void)ui;
    // Add key handling here based on the keys currently held or
    // ones that changed in the last frame.
}
Exemple #14
0
void App::onGraphics3D(RenderDevice* rd, Array<shared_ptr<Surface> >& allSurfaces) {
    // This implementation is equivalent to the default GApp's. It is repeated here to make it
    // easy to modify rendering. If you don't require custom rendering, just delete this
    // method from your application and rely on the base class.

    if (! scene()) {
        return;
    }

    // Debug visualizations and post-process effects
    rd->pushState(m_framebuffer); {
        // Call to make the App show the output of debugDraw(...)
        rd->setProjectionAndCameraMatrix(activeCamera()->projection(), activeCamera()->frame());
	
	    rd->setColorClearValue(Color3::black());
	    rd->clear();
        const Ray& mouseRay = scene()->eyeRay(activeCamera(), userInput->mouseXY() + Vector2(0.5f, 0.5f), rd->viewport(), Vector2int16(0, 0));
	    m_automata.draw(rd, mouseRay, m_gridColor);
        if (m_showHelp) {
            renderGUI(rd);
        }
        

    } rd->popState();

    if ((submitToDisplayMode() == SubmitToDisplayMode::MAXIMIZE_THROUGHPUT) && (!renderDevice->swapBuffersAutomatically())) {
        // We're about to render to the actual back buffer, so swap the buffers now.
        // This call also allows the screenshot and video recording to capture the
        // previous frame just before it is displayed.
        swapBuffers();
    }

	// Clear the entire screen (needed even though we'll render over it, since
    // AFR uses clear() to detect that the buffer is not re-used.)
    rd->clear();

    // Perform gamma correction, bloom, and SSAA, and write to the native window frame buffer
    m_film->exposeAndRender(rd, activeCamera()->filmSettings(), m_framebuffer->texture(0));
}