示例#1
0
int main(int argc, char **argv)
{
    int bufferMenu;
    int stenSize;

    glutInit(&argc, argv);
    glutInitWindowSize(winWidth = 256, winHeight = 256);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_STENCIL|GLUT_DEPTH|GLUT_ALPHA);
    (void)glutCreateWindow("torus depth");
    glutDisplayFunc(redraw);
    glutKeyboardFunc(keyboard);
    glutMotionFunc(motion);
    glutMouseFunc(button);
    glutReshapeFunc(reshape);

    resizeBuffers();
    glGetIntegerv(GL_STENCIL_BITS, &stenSize);
    fprintf(stderr, "(%d bits of stencil available in this visual)\n", stenSize);

    fprintf(stderr, "Hit 'h' for help message\n");

    bufferMenu = glutCreateMenu(changeData);
    glutAddMenuEntry("Color data", COLOR);
    glutAddMenuEntry("Stencil data", STENCIL);
    glutAddMenuEntry("Depth data", DEPTH);

    mainMenu = glutCreateMenu(mainMenuFunc);
    glutAddSubMenu("Visible buffer", bufferMenu);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    init();
    glutMainLoop();

    return 0;
}
示例#2
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);
}
示例#3
0
void reshape(int width, int height)
{
    glViewport(0, 0, width, height);
    winWidth = width;
    winHeight = height;
    resizeBuffers();
    glutPostRedisplay();
}
示例#4
0
文件: display.cpp 项目: w00key/Stage
void Display::resize(const int width, const int height)
{
	Memory::releaseDynamic(mainRTV_);
	Memory::releaseDynamic(depthStencilView_);
	resizeBuffers(width,height);

	const int viewportWidth = Core::getViewport().width;
	const int viewportHeight = Core::getViewport().height;

	DX::createRenderTargetView(device_, swapchain_, &mainRTV_);
	DX::createDepthStencilView(device_, &depthStencilView_, &sceneDepthSRV_, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT, viewportWidth, viewportHeight);
	DX::createRenderTargetView(device_,&sceneColourRTV_, &sceneColourSRV_, DXGI_FORMAT_R8G8B8A8_UNORM,  viewportWidth, viewportHeight);
	DX::createRenderTargetView(device_,&sceneNormalsRTV_, &sceneNormalsSRV_, DXGI_FORMAT_R16G16_FLOAT,  viewportWidth, viewportHeight);
	DX::createRenderTargetView(device_,&sceneSpecularRTV_, &sceneSpecularSRV_, DXGI_FORMAT_R8G8B8A8_UNORM,  viewportWidth, viewportHeight);
	DX::createRenderTargetView(device_,&nextStateRTV_, &nextStateSRV_, DXGI_FORMAT_R11G11B10_FLOAT,  viewportWidth, viewportHeight);
}
示例#5
0
int main(int argc, char **argv)
{
    int bufferMenu;
    int finishMenu;
    int stenSize;

    glutInitWindowSize(winWidth = 512, winHeight = 512);
    glutInit(&argc, argv);
    glutInitDisplayString("samples stencil>=3 rgb double depth");
    /* glutInitDisplayMode(GLUT_DOUBLE|GLUT_STENCIL|GLUT_DEPTH|GLUT_ALPHA); */
    (void)glutCreateWindow("decaling using stencil");
    glutDisplayFunc(redraw);
    glutKeyboardFunc(keyboard);
    glutMotionFunc(motion);
    glutMouseFunc(button);
    glutReshapeFunc(reshape);

    resizeBuffers();
    glGetIntegerv(GL_STENCIL_BITS, &stenSize);
    fprintf(stderr, "(%d bits of stencil available in this visual)\n", stenSize);

    fprintf(stderr, "Hit 'h' for help message\n");

    finishMenu = glutCreateMenu(changeStage);
    glutAddMenuEntry("Clearing screen", 1);
    glutAddMenuEntry("Drawing airplane", 2);
    glutAddMenuEntry("Drawing ground ", 3);
    glutAddMenuEntry("Drawing asphalt", 4);
    glutAddMenuEntry("Drawing paint", 5);
    glutAddMenuEntry("Drawing shadow", 6);

    bufferMenu = glutCreateMenu(changeData);
    glutAddMenuEntry("Color data", COLOR);
    glutAddMenuEntry("Stencil data", STENCIL);
    glutAddMenuEntry("Depth data", DEPTH);

    mainMenu = glutCreateMenu(stencilDecalEnable);
    glutAddMenuEntry("Turn on stencil decal", 1);
    glutAddSubMenu("Visible buffer", bufferMenu);
    glutAddSubMenu("Finish frame after...", finishMenu);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    init();
    glutMainLoop();

    return 0;
}
示例#6
0
void Buddha::set( double re, double im, double s, uint lr, uint lg, uint lb, uint hr, uint hg, uint hb, QSize wsize, bool pause ) {
	qDebug() << "Buddha::set()";
	bool haveToClear = (wsize.width() != (int) w) || (wsize.height() != (int) h) ||(re != cre) || (im != cim) || (s != scale);
	
	if ( pause ) pauseGenerators( );
	
	w = wsize.width();
	h = wsize.height();
	// I reallocate only if the dimensions are changed otherwise I simply clean the memory
	if ( size != w * h ) {
		size = w * h;
		resizeBuffers( );
	}
	
	cre = re;
	cim = im;
	scale = s;	
	rangere = w / scale;
	rangeim = h / scale;
	minre = cre - rangere * 0.5;
	maxre = cre + rangere * 0.5;
	minim = cim - rangeim * 0.5;
	maxim = cim + rangeim * 0.5;
    lowr = lr;
    lowg = lg;
    lowb = lb;
    highr = hr;
    highg = hg;
    highb = hb;
	high = max( max( highr, highg ), highb );
    low = min( min(lowr, lowg), lowb);
	resizeSequences( );
	//status = RUN;
	
	if ( pause ) {
		if ( haveToClear ) clearBuffers( );
		resumeGenerators( );
	}
	
	emit settedValues( );
}
void ChorusAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
    // In case we have more outputs than inputs, this code clears any output
    // channels that didn't contain input data, (because these aren't
    // guaranteed to be empty - they may contain garbage).
    // I've added this to avoid people getting screaming feedback
    // when they first compile the plugin, but obviously you don't need to
    // this code if your algorithm already fills all the output channels.
    for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
        buffer.clear (i, 0, buffer.getNumSamples());

	// If the sample rate has changed resize the buffers
	if (FS != getSampleRate())resizeBuffers(depthOSC, delayOSC, delayBufferL, delayBufferR);

	// If the modulation rate or the depth have been changed recreate LFO
	if (freq != modRate || Amp != depth)LFOBuffer();

	// get current write pointers
	depthOSCwp = depthOSC.getWritePointer(0);
	delayOSCwp = delayOSC.getWritePointer(0);
	delayBufferLwp = delayBufferL.getWritePointer(0);
	delayBufferRwp = delayBufferR.getWritePointer(0);

	// get current read pointers
	depthOSCrp = depthOSC.getReadPointer(0);
	delayOSCrp = delayOSC.getReadPointer(0);
	delayBufferLrp = delayBufferL.getReadPointer(0);
	delayBufferRrp = delayBufferR.getReadPointer(0);
		
	// Calculate delay in samples
	int delay = (int)(delayTime*FS);


	// create input and output channels to read from and write to
	const float *inL = buffer.getReadPointer(0);
	const float *inR = buffer.getReadPointer(1);
	float *outL = {};
	outL = buffer.getWritePointer(0);
	float *outR = {};
	outR = buffer.getWritePointer(1);

	// Step through each sample in the current buffer
	for (int i = 0; i < buffer.getNumSamples(); i++)
	{

		// Calculate the delay point, and write to delay buffer
		double dSamp = i + bidx - delay;

		// Current sample for the delay buffer
		int ridx = i + bidx;
		
		// Wrap ridx if it is larger than the size of the delay buffer (equal to the sample rate)
		if (ridx >= FS)ridx -= FS;

		// Calculate delay after modulation has been applied
		double modDelay = (delay * 0.3 * depthOSCrp[ridx]); 
		double dSampMod = dSamp - modDelay;

		// If the delay time exceeds or is under the buffer length wrap around
		if ((int)dSampMod < 0)dSampMod += FS;
		if ((int)dSampMod >= FS)dSampMod -= FS;

		double delaySampleL = 0;
		double delaySampleR = 0;

		// write current input data to delayBuffer
		delayBufferRwp[ridx] = inR[i];
		delayBufferLwp[ridx] = inL[i];

		// Check whether the delay is fractional
		double dSampModround = round(dSampMod);
		double check = dSampMod - dSampModround;
		int inc = 0;

		// If the fractional content of the delay is > 0 then interpolate against the next sample
		// If the fractional ocntent of the delay is < 0 then interpolate against the previous sample
		// Else take the current sample without interpolation
		if (check > 0)
		{
			inc = (int)dSampModround+1;
			
			if (inc >= FS)
			{
				delaySampleL = interpolateLinear(delayBufferLrp[int(dSampMod)], delayBufferLrp[inc-FS], dSampMod, round(dSampMod));
				delaySampleR = interpolateLinear(delayBufferRrp[int(dSampMod)], delayBufferRrp[inc - FS], dSampMod, round(dSampMod));
			}
			else
			{
				delaySampleL = interpolateLinear(delayBufferLrp[int(dSampMod)], delayBufferLrp[inc], dSampMod, round(dSampMod));
				delaySampleR = interpolateLinear(delayBufferRrp[int(dSampMod)], delayBufferRrp[inc], dSampMod, round(dSampMod));
			}
		}
		else if (check < 0)
		{
			inc = (int)dSampModround-1;
			
			if (inc < 0)
			{
				delaySampleL = interpolateLinear(delayBufferLrp[inc + FS], delayBufferLrp[int(dSampMod)], dSampMod, inc);
				delaySampleR = interpolateLinear(delayBufferRrp[inc + FS], delayBufferRrp[int(dSampMod)], dSampMod, inc);
			}
			else
			{
				delaySampleL = interpolateLinear(delayBufferLrp[inc], delayBufferLrp[int(dSampMod)], dSampMod, inc);
				delaySampleR = interpolateLinear(delayBufferRrp[inc], delayBufferRrp[int(dSampMod)], dSampMod, inc);
			}
		}
		else
		{
			delaySampleL = delayBufferLrp[int(dSampMod)];
			delaySampleR = delayBufferRrp[int(dSampMod)];
		}

		// Add the delayed sample to the current sample
		// Weight each sample against how much of the wet/dry mix has been select
		outL[i] = ((1 - wetDry)*inL[i] + wetDry*delaySampleL)*0.5;
		outR[i] = ((1 - wetDry)*inR[i] + wetDry*delaySampleR)*0.5;

	}

	// Increment index in relation to where the current buffer will be placed within the delay buffer
	// wrap bidx if greater than sample rate
	bidx += buffer.getNumSamples();
	if (bidx >= FS)bidx -= FS;

	// store current freqency and modulation rates
	freq = modRate;
	Amp = depth;
}
void SoXipCPUMprRender::GLRender(SoGLRenderAction * action)
{
	SoState *state = action->getState();
	SbViewportRegion vpRegion = SoViewportRegionElement::get(state);
	SbVec2s vpSize = vpRegion.getViewportSizePixels();

	// Don't do anything if 0 size
	if (!vpSize[0] || !vpSize[1])
		return;

	// Bind texture to available texture stage
	if (!mMPRTexId)
		glGenTextures(1, &mMPRTexId);

	int texUnit = SoXipMultiTextureElement::getFreeUnit(state);
	SoXipMultiTextureElement::setUnit(state, texUnit);
	SoXipMultiTextureElement::bindTexture(state, GL_TEXTURE_2D, mMPRTexId);

	// Check the size against min/max
	SbVec2s minmax = minMaxSize.getValue();
	int which = (vpSize[0] > vpSize[1]) ? 0 : 1;
	float ratio = (float) vpSize[which] / (float) vpSize[1 - which];
	// If smallest dim is < min
	if (vpSize[1 - which] < minmax[0])
	{
		// Clamp to min and change biggest dim according to aspect ratio
		vpSize[1 - which] = minmax[0];
		vpSize[which] = (short) (ratio * vpSize[1 - which]);
	}
	// If biggest dim is > max
	if (vpSize[which] > minmax[1])
	{
		// Clamp to max and change smallest dim according to aspect ratio
		vpSize[which] = minmax[1];
		vpSize[1 - which] = (short) (vpSize[which] / ratio);
	}

	// Ready the buffers
	readyBuffers(state);

	if (vpSize[0] == 0 || vpSize[1] == 0)
		return;

	// Check if mpr texture must be resized
	if (mMPRSize != vpSize)
	{
		resizeBuffers(vpSize);
		mUpdateFlag |= UPDATE_MPRCACHE;
    }
    
    // Exit if unsupported image type
    if (mTexInternalFormat == 0 ||
        mTexType == 0)
        return;

	// Check if orientation has changed
	SbVec3f	corners[4];
	SbViewVolume viewVolume = SoViewVolumeElement::get(state);
	float dist = viewVolume.getNearDist() + viewVolume.getDepth() * 0.5f;
	corners[0] = viewVolume.getPlanePoint(dist, SbVec2f(0, 1));
	corners[1] = viewVolume.getPlanePoint(dist, SbVec2f(1, 1));
	corners[2] = viewVolume.getPlanePoint(dist, SbVec2f(1, 0));
	corners[3] = viewVolume.getPlanePoint(dist, SbVec2f(0, 0));
	if (corners[0] != mCorners[0] ||
		corners[1] != mCorners[1] ||
		corners[2] != mCorners[2] ||
		corners[3] != mCorners[3])
	{
		mCorners[0] = corners[0];
		mCorners[1] = corners[1];
		mCorners[2] = corners[2];
		mCorners[3] = corners[3];
		mUpdateFlag |= UPDATE_MPRCACHE;
	}

	
	//
	if (mUpdateFlag & UPDATE_MPRCACHE)
	{
		// Compute new cache table and mpr
		switch (mVolDataType)
		{
		case SbXipImage::UNSIGNED_BYTE:
			mLutBuf ? computeMPRCacheLUT(this, (unsigned char*)mVolBuf, state) : computeMPRCache(this, (unsigned char*)mVolBuf, state);
			break;
		case SbXipImage::BYTE:
			mLutBuf ? computeMPRCacheLUT(this, (char*)mVolBuf, state) : computeMPRCache(this, (char*)mVolBuf, state);
			break;
		case SbXipImage::UNSIGNED_SHORT:
			mLutBuf ? computeMPRCacheLUT(this, (unsigned short*)mVolBuf, state) : computeMPRCache(this, (unsigned short*)mVolBuf, state);
			break;
		case SbXipImage::SHORT:
			mLutBuf ? computeMPRCacheLUT(this, (short*)mVolBuf, state) : computeMPRCache(this, (short*)mVolBuf, state);
			break;
		case SbXipImage::UNSIGNED_INT:
			mLutBuf ? computeMPRCacheLUT(this, (unsigned int*)mVolBuf, state) : computeMPRCache(this, (unsigned int*)mVolBuf, state);
			break;
		case SbXipImage::INT:
			mLutBuf ? computeMPRCacheLUT(this, (int*)mVolBuf, state) : computeMPRCache(this, (int*)mVolBuf, state);
			break;
		case SbXipImage::FLOAT:
			mLutBuf ? computeMPRCacheLUT(this, (float*)mVolBuf, state) : computeMPRCache(this, (float*)mVolBuf, state);
			break;
		case SbXipImage::DOUBLE:
			mLutBuf ? computeMPRCacheLUT(this, (double*)mVolBuf, state) : computeMPRCache(this, (double*)mVolBuf, state);
			break;
		default:
            // will never come here cause we already checked for it in resize
			break;	
		}
		// Update mpr texture
		updateTexture();
	}
	else if (mUpdateFlag & UPDATE_MPR)
	{
		// Compute new mpr
		switch (mVolDataType)
		{
		case SbXipImage::UNSIGNED_BYTE:
			mLutBuf ? computeMPRLUT(this, (unsigned char*)mVolBuf) : computeMPR(this, (unsigned char*)mVolBuf);
			break;
		case SbXipImage::BYTE:
			mLutBuf ? computeMPRLUT(this, (char*)mVolBuf) : computeMPR(this, (char*)mVolBuf);
			break;
		case SbXipImage::UNSIGNED_SHORT:
			mLutBuf ? computeMPRLUT(this, (unsigned short*)mVolBuf) : computeMPR(this, (unsigned short*)mVolBuf);
			break;
		case SbXipImage::SHORT:
			mLutBuf ? computeMPRLUT(this, (short*)mVolBuf) : computeMPR(this, (short*)mVolBuf);
			break;
		case SbXipImage::UNSIGNED_INT:
			mLutBuf ? computeMPRLUT(this, (unsigned int*)mVolBuf) : computeMPR(this, (unsigned int*)mVolBuf);
			break;
		case SbXipImage::INT:
			mLutBuf ? computeMPRLUT(this, (int*)mVolBuf) : computeMPR(this, (int*)mVolBuf);
			break;
		case SbXipImage::FLOAT:
			mLutBuf ? computeMPRLUT(this, (float*)mVolBuf) : computeMPR(this, (float*)mVolBuf);
			break;
		case SbXipImage::DOUBLE:
			mLutBuf ? computeMPRLUT(this, (double*)mVolBuf) : computeMPR(this, (double*)mVolBuf);
			break;
		default:
            // will never come here cause we already checked for it in resize
			break;	
		}
		// Update mpr texture
		updateTexture();
	}

	// Render mpr to a quad
	renderMPR(texUnit);

	// Reset update flag
	mUpdateFlag = 0;
}
示例#9
0
void AmbientOcclusion::compute
   (RenderDevice*                   rd,
    const AmbientOcclusionSettings& settings,
    const shared_ptr<Texture>&      depthBuffer, 
    const Vector3&                  clipConstant,
    const Vector4&                  projConstant,
    float                           projScale,
    const CFrame&                   currentCameraFrame,
    const CFrame&                   prevCameraFrame,
    const shared_ptr<Texture>&      peeledDepthBuffer,
    const shared_ptr<Texture>&      normalBuffer,
    const shared_ptr<Texture>&      ssVelocityBuffer) {

    BEGIN_PROFILER_EVENT("AmbientOcclusion");

    alwaysAssertM(depthBuffer, "Depth buffer is required.");
    
    int depthBufferCount = 1;

    if (notNull(peeledDepthBuffer)) {
        ++depthBufferCount;
    }

    initializePerViewBuffers(depthBufferCount);
    resizeBuffers(depthBuffer);
#   if COMBINE_CSZ_INTO_ONE_TEXTURE == 1
        m_perViewBuffers[0]->resizeBuffers(depthBuffer, peeledDepthBuffer);
        computeCSZ(rd, m_perViewBuffers[0]->cszFramebuffers, m_perViewBuffers[0]->cszBuffer, settings, depthBuffer, clipConstant, peeledDepthBuffer);
#   else
        shared_ptr<Texture> depthTexture = depthBuffer;
        for (int i = 0; i < m_perViewBuffers.size(); ++i) {
            m_perViewBuffers[i]->resizeBuffers(depthTexture, shared_ptr<Texture>());
            computeCSZ(rd, m_perViewBuffers[i]->cszFramebuffers, m_perViewBuffers[i]->cszBuffer, settings, depthTexture, clipConstant, shared_ptr<Texture>());
            depthTexture = peeledDepthBuffer;
        }
#   endif

#   if COMBINE_CSZ_INTO_ONE_TEXTURE == 1
       shared_ptr<Texture> depthPeelCSZ = m_perViewBuffers[0]->cszBuffer;
#   else
       shared_ptr<Texture> depthPeelCSZ = notNull(peeledDepthBuffer) ? m_perViewBuffers[1]->cszBuffer : shared_ptr<Texture>();
#   endif

    computeRawAO(rd, settings, depthBuffer, clipConstant, projConstant, projScale, m_perViewBuffers[0]->cszBuffer, depthPeelCSZ, normalBuffer);
    if (notNull(ssVelocityBuffer)) {
        m_temporallyFilteredBuffer = m_temporalFilter.apply(rd, clipConstant, projConstant, currentCameraFrame, prevCameraFrame, m_rawAOBuffer, 
        depthBuffer, ssVelocityBuffer, Vector2((float)m_guardBandSize, (float)m_guardBandSize), 1, settings.temporalFilterSettings);
    } else {
        m_temporallyFilteredBuffer = m_rawAOBuffer;
    }
    

    if (settings.blurRadius != 0) {
        BEGIN_PROFILER_EVENT("Blur");
        alwaysAssertM(settings.blurRadius >= 0 && settings.blurRadius <= 6, "The AO blur radius must be a nonnegative number, 6 or less");
        alwaysAssertM(settings.blurStepSize > 0, "Must use a positive blur step size");
        blurHorizontal(rd, settings, depthBuffer, projConstant, normalBuffer);
        blurVertical(rd, settings, depthBuffer, projConstant, normalBuffer);
        END_PROFILER_EVENT();
    } // else the result is still in the m_temporallyFilteredBuffer 

    END_PROFILER_EVENT();
}