void InstantRadiosityRenderer::processPixel(uint32_t threadID, uint32_t tileID, const Vec2u& pixel) const {
    PixelSensor pixelSensor(getSensor(), pixel, getFramebufferSize());
    RaySample raySample;
    float positionPdf, directionPdf;
    auto We = pixelSensor.sampleExitantRay(getScene(), getFloat2(threadID), getFloat2(threadID), raySample, positionPdf, directionPdf);

    auto L = zero<Vec3f>();

    if(We != zero<Vec3f>() && raySample.pdf) {
        auto I = getScene().intersect(raySample.value);
        BSDF bsdf(-raySample.value.dir, I, getScene());
        if(I) {
            // Direct illumination
            for(auto& vpl: m_EmissionVPLBuffer) {
                RaySample shadowRay;
                auto Le = vpl.pLight->sampleDirectIllumination(getScene(), vpl.emissionVertexSample, I, shadowRay);

                if(shadowRay.pdf) {
                    auto contrib = We * Le * bsdf.eval(shadowRay.value.dir) * abs(dot(I.Ns, shadowRay.value.dir)) /
                            (vpl.lightPdf * shadowRay.pdf * m_nLightPathCount * raySample.pdf);

                    if(contrib != zero<Vec3f>()) {
                        if(!getScene().occluded(shadowRay.value)) {
                            L += contrib;
                        }
                    }
                }
            }

            // Indirect illumination
            for(auto& vpl: m_SurfaceVPLBuffer) {
                auto dirToVPL = vpl.intersection.P - I.P;
                auto dist = length(dirToVPL);

                if(dist > 0.f) {
                    dirToVPL /= dist;

                    auto fs1 = bsdf.eval(dirToVPL);
                    auto fs2 = vpl.bsdf.eval(-dirToVPL);
                    auto geometricFactor = abs(dot(I.Ns, dirToVPL)) * abs(dot(vpl.intersection.Ns, -dirToVPL)) / sqr(dist);

                    auto contrib = We * vpl.power * fs1 * fs2 * geometricFactor / raySample.pdf;
                    if(contrib != zero<Vec3f>()) {
                        Ray shadowRay(I, vpl.intersection, dirToVPL, dist);
                        if(!getScene().occluded(shadowRay)) {
                            L += contrib;
                        }
                    }
                }
            }
        }
    }

    accumulate(0, getPixelIndex(pixel.x, pixel.y), Vec4f(L, 1.f));
}
Exemplo n.º 2
0
ofColor_<PixelType> ofPixels_<PixelType>::getColor(int x, int y) const {
	ofColor_<PixelType> c;
	int index = getPixelIndex(x, y);

	if( channels == 1 ){
		c.set( pixels[index] );
	}else if( channels == 3 ){
		c.set( pixels[index], pixels[index+1], pixels[index+2] );
	}else if( channels == 4 ){
		c.set( pixels[index], pixels[index+1], pixels[index+2], pixels[index+3] );
	}

	return c;
}
Exemplo n.º 3
0
ofColor ofPixels::getPixel(int x, int y){
	ofColor c;
	int index = getPixelIndex(x, y);

	if( bytesPerPixel == 1 ){
		c.set( pixels[index] );
	}else if( bytesPerPixel == 3 ){
		c.set( pixels[index], pixels[index+1], pixels[index+2] );
	}else if( bytesPerPixel == 4 ){
		c.set( pixels[index], pixels[index+1], pixels[index+2], pixels[index+3] );
	}

	return c;
}
Exemplo n.º 4
0
void ofPixels_<PixelType>::setColor(int x, int y, ofColor_<PixelType> color) {
	int index = getPixelIndex(x, y);

	if( channels == 1 ){
		pixels[index] = color.getBrightness();
	}else if( channels == 3 ){
		pixels[index] = color.r;
		pixels[index+1] = color.g;
		pixels[index+2] = color.b;
	}else if( channels == 4 ){
		pixels[index] = color.r;
		pixels[index+1] = color.g;
		pixels[index+2] = color.b;
		pixels[index+3] = color.a;
	}
}
Exemplo n.º 5
0
void ofPixels::setColor(int x, int y, ofColor color) {
	int index = getPixelIndex(x, y);

	if( bytesPerPixel == 1 ){
		pixels[index] = color.getBrightness();
	}else if( bytesPerPixel == 3 ){
		pixels[index] = color.r;
		pixels[index+1] = color.g;
		pixels[index+2] = color.b;
	}else if( bytesPerPixel == 4 ){
		pixels[index] = color.r;
		pixels[index+1] = color.g;
		pixels[index+2] = color.b;
		pixels[index+3] = color.a;
	}
}
Exemplo n.º 6
0
ofColor_<PixelType> ofPixels_<PixelType>::getColor(int x, int y) const {
	ofColor_<PixelType> c;
	int index = getPixelIndex(x, y);

	switch(pixelFormat){
		case OF_PIXELS_RGB:
			c.set( pixels[index], pixels[index+1], pixels[index+2] );
			break;
		case OF_PIXELS_BGR:
			c.set( pixels[index+2], pixels[index+1], pixels[index] );
			break;
		case OF_PIXELS_RGBA:
			c.set( pixels[index], pixels[index+1], pixels[index+2], pixels[index+3] );
			break;
		case OF_PIXELS_BGRA:
			c.set( pixels[index+2], pixels[index+1], pixels[index], pixels[index+3] );
			break;
		case OF_PIXELS_GRAY:
			c.set( pixels[index] );
			break;
		case OF_PIXELS_GRAY_ALPHA:
			c.set( pixels[index], pixels[index], pixels[index], pixels[index+1] );
			break;
		case OF_PIXELS_RGB565:
		case OF_PIXELS_NV12:
		case OF_PIXELS_NV21:
		case OF_PIXELS_YV12:
		case OF_PIXELS_I420:
		case OF_PIXELS_YUY2:
		case OF_PIXELS_UYVY:
		case OF_PIXELS_Y:
		case OF_PIXELS_U:
		case OF_PIXELS_V:
		case OF_PIXELS_UV:
		case OF_PIXELS_VU:
		case OF_PIXELS_UNKNOWN:
		default:
			ofLogWarning() << "returning color not supported yet for " << ofToString(pixelFormat) << " format";
			return 0;
			break;
	}

	return c;
}
void UniformResamplingRecursiveMISBPTRenderer::processTile(uint32_t threadID, uint32_t tileID, const Vec4u& viewport) const {
    auto spp = getSppCount();

    TileProcessingRenderer::processTilePixels(viewport, [&](uint32_t x, uint32_t y) {
        auto pixelID = getPixelIndex(x, y);

        // Add a new sample to the pixel
        for(auto i = 0u; i <= getFramebuffer().getChannelCount(); ++i) {
            accumulate(i, pixelID, Vec4f(0, 0, 0, 1));
        }

        // Process each sample
        for(auto sampleID = 0u; sampleID < spp; ++sampleID) {
            processSample(threadID, tileID, pixelID, sampleID, x, y);
        }
    });

    // Compute contributions for 1-length eye paths (connection to sensor)
    connectLightVerticesToSensor(threadID, tileID, viewport);
}
Exemplo n.º 8
0
void ofPixels_<PixelType>::setColor(int x, int y, const ofColor_<PixelType>& color) {
	setColor(getPixelIndex(x, y), color);
}
Exemplo n.º 9
0
ofColor_<PixelType> ofPixels_<PixelType>::getColor(int x, int y) const {
	return getColor(getPixelIndex(x, y));
}
Exemplo n.º 10
0
 bool isDebugPixel(uint32_t x, uint32_t y) const {
     return isDebugPixel(getPixelIndex(x, y));
 }
Exemplo n.º 11
0
 bool isDebugPixel(uint32_t pixelIdx) const {
     return pixelIdx == getPixelIndex(m_nDebugPixelX, m_nDebugPixelY);
 }
Exemplo n.º 12
0
ofColor_<PixelType> ofPixels_<PixelType>::getColor(size_t x, size_t y) const {
	return getColor(getPixelIndex(x, y));
}
Exemplo n.º 13
0
    bool isPixelSetInMask(unsigned int maskId, unsigned int x, unsigned int y) {
        auto coordinateBitIndex = getPixelIndex(x, y);

        return isBitSet(coordinateBitIndex, maskId);
    }