Esempio n. 1
0
    void onDrawContent(SkCanvas* canvas) override {
        fLightAngle += 0.015f;
        fColorFactor += 0.01f;
        if (fColorFactor > 1.0f) {
            fColorFactor = 0.0f;
        }

        SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLightAngle,
                                                                          fColorFactor));

        fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap,
                                               lights, SkVector::Make(1.0f, 0.0f),
                                               nullptr, nullptr));

        SkPaint paint;
        paint.setShader(fShader);
        paint.setColor(SK_ColorBLACK);

        SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(), 
                                  (SkScalar)fDiffuseBitmap.height());
        canvas->drawRect(r, paint);

        // so we're constantly updating
        this->inval(NULL);
    }
Esempio n. 2
0
    void onDrawContent(SkCanvas* canvas) override {
        fLightAngle += 0.015f;
        fColorFactor += 0.01f;
        if (fColorFactor > 1.0f) {
            fColorFactor = 0.0f;
        }

        sk_sp<SkLights> lights(create_lights(fLightAngle, fColorFactor));
        SkPaint paint;
        sk_sp<SkShader> normalMap = SkShader::MakeBitmapShader(fNormalBitmap,
            SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr);
        sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(
                std::move(normalMap), SkMatrix::I());
        sk_sp<SkShader> diffuseShader = SkShader::MakeBitmapShader(fDiffuseBitmap,
                SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr);
        paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::move(normalSource),
                                               std::move(lights)));
        paint.setColor(SK_ColorBLACK);

        SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(),
                                  (SkScalar)fDiffuseBitmap.height());
        canvas->drawRect(r, paint);

        // so we're constantly updating
        this->inval(nullptr);
    }
Esempio n. 3
0
bool Demo::create()
{
    renderer.set_auto_clear(false, false);
    renderer.set_viewport(render_size);

    create_scene();
    create_arcball();
    create_lights();

    return true;
}
Esempio n. 4
0
    void onDrawContent(SkCanvas* canvas) override {
        sk_sp<SkLights> lights(create_lights(fLightAngle, fColorFactor));

        SkPaint paint;
        paint.setShader(SkLightingShader::Make(fDiffuseShader,
                                               fNormalSource,
                                               std::move(lights)));
        paint.setColor(SK_ColorBLACK);

        canvas->drawRect(fRect, paint);
    }
Esempio n. 5
0
    LightingView() {
        SkString diffusePath = GetResourcePath("brickwork-texture.jpg");
        SkImageDecoder::DecodeFile(diffusePath.c_str(), &fDiffuseBitmap);
        SkString normalPath = GetResourcePath("brickwork_normal-map.jpg");
        SkImageDecoder::DecodeFile(normalPath.c_str(), &fNormalBitmap);

        fLightAngle = 0.0f;
        fColorFactor = 0.0f;

        SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLightAngle, 1.0f));

        fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap,
                                               lights, SkVector::Make(1.0f, 0.0f),
                                               nullptr, nullptr));
    }
Esempio n. 6
0
int main(int argc, char** argv)
{
    if (argc < 2)
    {
        std::cerr << "Use " << argv[0] << " filename" << std::endl;
        return 1;
    }

    // load image
    int width, height, nc;
    float* rgba = stbi_loadf(argv[1], &width, &height, &nc, 4);
    if (stbi_failure_reason())
    {
        std::cerr << "stbi: " << stbi_failure_reason() << std::endl;
        return 1;
    }

    // create summed area table of luminance image
    summed_area_table lum_sat;
    lum_sat.create_lum(rgba, width, height, 4);

    // apply median cut
    std::vector<sat_region> regions;
    median_cut(lum_sat, 9, regions); // max 2^n cuts

    // create 2d positions from regions
    std::vector<float2> lights;
    create_lights(regions, lights);

    // draw a marker into image for each position
    size_t i = 0;
    for (auto l = lights.begin(); l != lights.end(); ++l)
    {
        std::cout << "Light " << i++ << ": (" << l->x << ", " << l->y << ")" << std::endl;
        draw(rgba, width, height, *l);
    }

    // save image with marked samples
    std::vector<unsigned char> conv;
    conv.resize(width*height*4);

    for (size_t i = 0; i < width * height * 4; ++i)
        conv[i] = static_cast<unsigned char>(rgba[i]*255);

    stbi_write_bmp("test.bmp", width, height, 4, &conv[0]);

    return 0;
}
Esempio n. 7
0
int main(int argc, char **argv) 
{
	std::string fileName(argv[1]);
	primaryOBJ = new model(fileName, verticesPerFace);

	//setup glut window
	setupGlut(argc, argv);

	//setup the projection and view matrices
	initViewport();
	//initialize the cube map textures that will form our skybox
	initCubeMap();

	// initialize the fbo for dynamic cubemapping
	//initDynamicCubeMap();
	// standard light initialization.  Relatively unchanged from the Bunny project
	create_lights();
	//standard material initialization.  Relatively unchanged from the Bunny project
	create_material();
	teapotShader = set_shaders((char *)"phongEC");
	planeShader = set_shaders((char *)"plane");

	// This will read in the texture that will be applied to the teapot, if a texture is applied to the teapot at all
	// initTeapotTexture((char*)"textures/bubble_color.ppm");
	initCircleTexture((char*)"textures/circle.tga");
	// setting up the main shader for the teapot
	defaultShader = set_shaders((char*)"phongEC");
	// setting up the shader for the skybox / cube map
	skyboxShader = set_shaders((char*)"skybox");
	// set up the skybox geometry cube
	initSkyboxGeometry();

	// Main loop functions
	glutDisplayFunc(draw_AA);
	glutKeyboardFunc(keyBindings);
	glutSpecialFunc(translateCam);

	glutMainLoop();
	return 0;
}