コード例 #1
0
HRESULT FXAAPostProcess::Render(ID3D11DeviceContext* pd3dImmediateContext, ID3D11ShaderResourceView* src,
                                ID3D11RenderTargetView* dstRTV, Camera* camera, GBuffer* gBuffer, ParticleBuffer* pBuffer, LightBuffer* lightBuffer)
{
    BEGIN_EVENT_D3D(L"FXAA");

    HRESULT hr;
    D3D11_MAPPED_SUBRESOURCE mappedResource;

    // Map the properties and set them
    V_RETURN(pd3dImmediateContext->Map(_propertiesBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource));
    CB_FXAA_PROPERTIES* properties = (CB_FXAA_PROPERTIES*)mappedResource.pData;

    properties->InverseSceneSize = _invSceneSize;
    properties->Subpixel = _subpixel;
    properties->EdgeThreshold = _edgeThreshold;
    properties->EdgeThresholdMin = _edgeThresholdMin;

    pd3dImmediateContext->Unmap(_propertiesBuffer, 0);

    pd3dImmediateContext->PSSetConstantBuffers(0, 1, &_propertiesBuffer);

    // Set the sampler
    ID3D11SamplerState* samplers[1] = { GetSamplerStates()->GetLinearClamp() };

    pd3dImmediateContext->PSSetSamplers(0, 1, samplers);

    // Set the other states
    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetDepthDisabled(), 0);

    float blendFactor[4] = {1, 1, 1, 1};
    pd3dImmediateContext->OMSetBlendState(GetBlendStates()->GetBlendDisabled(), blendFactor, 0xFFFFFFFF);

    // Set the render target
    pd3dImmediateContext->OMSetRenderTargets(1, &dstRTV, NULL);

    // Set the resources
    pd3dImmediateContext->PSSetShaderResources(0, 1, &src);

    // Render the quad
    Quad* fsQuad = GetFullScreenQuad();

    V_RETURN(fsQuad->Render(pd3dImmediateContext, _fxaaPSs[_qualityIndex]->PixelShader));

    // Unset the resources
    ID3D11ShaderResourceView* ppSRVNULL[1] = { NULL };
    pd3dImmediateContext->PSSetShaderResources(0, 1, ppSRVNULL);

    END_EVENT_D3D(L"");
    return S_OK;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: emrakul/Torus
int main(void)
{
	GLFWwindow* window;
	camera = new Camera();
	

	fov = 67;
	con = 0.0;
	int width, height;

	glfwSetErrorCallback(error_callback);

	if (!glfwInit())
		exit(EXIT_FAILURE);

	window = glfwCreateWindow(1600, 900, "Simple example", glfwGetPrimaryMonitor(), NULL);

	if (!window)
	{
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	glfwMakeContextCurrent(window);
	glfwSwapInterval(1);
	glewInit();

	glfwSetKeyCallback(window, key_callback);


	glfwGetFramebufferSize(window, &width, &height);

	glViewport(0, 0, width, height);	
	glEnable(GL_DEPTH_TEST);	
	glDepthFunc(GL_LEQUAL);	
	glDisable(GL_CULL_FACE);
	
	

	Quad* quad = new Quad;
	Shader * geom = new Shader("geometry.vert", "geometry.frag");

	geom->setAttribute(0, "point");
	geom->linkProgram();
	geom->bind();	
	geom->unbind();
	
	
	float deltaTime = float(0.005);

	while (!glfwWindowShouldClose(window))
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glDepthMask(GL_TRUE);
		camera->Update();

		geom->bind();			
			geom->passUniform(camera->position, "position");			
			geom->passUniform(camera->direction, "direction");
			geom->passUniform(camera->upVector, "upVector");
			geom->passUniform(camera->viewMatrix, "viewMatrix");
			geom->passUniform(camera->projectionMatrix, "projectionMatrix");
			geom->passUniform(con, "con");
			quad->Render();
		geom->unbind();
		glDepthMask(GL_TRUE);
		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LESS);
		

		for (int i = 0; i < wave.size(); ++i) {
			mat3 tangentSpace(wave[i].bitangent, wave[i].normal, wave[i].tangent);
			float previousDistance = wave[i].distance;
			wave[i].position += tangentSpace * wave[i].direction  * deltaTime;

			
			wave[i].distance = sdTorus(wave[i].position);
			wave[i].position += wave[i].normal * wave[i].distance;

			wave[i].normal = getNormal(wave[i].position);

			vec3 tangent, bitangent, normal;
			vec3 position = wave[i].position;
			normal = wave[i].normal;
			mat4 rotation = glm::rotate(0.05f, vec3(0, 1.0, 0));
			vec3 delta = vec3( rotation*vec4(position, 1.0) );
			
			tangent = delta - wave[i].position; 
			
			
			tangent = normalize(tangent);			

			bitangent = cross(tangent, normal);
			wave[i].bitangent = bitangent;
			wave[i].tangent = tangent;
		}		

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(67.3801, (GLfloat)1600.0 / (GLfloat)900.0, 0.5, 50.0);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(
			camera->position.x, camera->position.y, camera->position.z,

			camera->position.x + camera->direction.x,
			camera->position.y + camera->direction.y,
			camera->position.z + camera->direction.z,

			
			camera->upVector.x, camera->upVector.y, camera->upVector.z);


		if (wave.size() > 0) {
			vec3 arr[800];
			glBegin(GL_LINE_LOOP);
			for (int i = 0; i < 800; ++i){
				arr[i] = wave[i].position;
				glColor3f(1.0, 1.0, 1.0);
				glVertex3f(arr[i].x, arr[i].y, arr[i].z);

				
				/*
				glBegin(GL_LINE_LOOP);
				glColor3f(1.0, 0.0, 0.0);
				
				arr[i] = wave[i].position;
				vec3 nrm = wave[i].normal * float(0.1);
				glVertex3f(arr[i].x, arr[i].y, arr[i].z);
				glVertex3f(arr[i].x+nrm.x, arr[i].y +nrm.y, arr[i].z+nrm.z);
				glEnd();
				

				glBegin(GL_LINE_LOOP);
				glColor3f(0.0, 1.0, 0.0);

				arr[i] = wave[i].position;
				nrm = wave[i].tangent * float(0.1);
				glVertex3f(arr[i].x, arr[i].y, arr[i].z);
				glVertex3f(arr[i].x + nrm.x, arr[i].y + nrm.y, arr[i].z + nrm.z);
				glEnd();

				

				glBegin(GL_LINE_LOOP);
				glColor3f(0.0, 0.0, 1.0);

				arr[i] = wave[i].position;
				nrm = wave[i].bitangent * float(0.1);
				glVertex3f(arr[i].x, arr[i].y, arr[i].z);
				glVertex3f(arr[i].x + nrm.x, arr[i].y + nrm.y, arr[i].z + nrm.z);
				glEnd();
				
				
				*/
				


			}
			glEnd();

		}

		glfwSwapBuffers(window);
		glfwPollEvents();


	}

	glfwDestroyWindow(window);

	glfwTerminate();
	exit(EXIT_SUCCESS);
}
コード例 #3
0
HRESULT MLAAPostProcess::Render(ID3D11DeviceContext* pd3dImmediateContext, ID3D11ShaderResourceView* src,
                                ID3D11RenderTargetView* dstRTV, Camera* camera, GBuffer* gBuffer, ParticleBuffer* pBuffer,LightBuffer* lightBuffer)
{
    BEGIN_EVENT_D3D(L"MLAA");

    HRESULT hr;
    D3D11_MAPPED_SUBRESOURCE mappedResource;

    // Prepare all the settings and map them
    V_RETURN(pd3dImmediateContext->Map(_mlaaPropertiesBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource));
    CB_MLAA_PROPERTIES* properties = (CB_MLAA_PROPERTIES*)mappedResource.pData;

    properties->InverseSceneSize = XMFLOAT2(1.0f / _textureWidth, 1.0f / _textureHeight);
    properties->DepthThreshold = _depthThreshold;
    properties->NormalThreshold = _normalThreshold;
    properties->LuminanceThreshold = _luminanceThreshold;
    properties->CameraNearClip = camera->GetNearClip();
    properties->CameraFarClip = camera->GetFarClip();
    properties->MaxSearchSteps = _maxSearchSteps;

    pd3dImmediateContext->Unmap(_mlaaPropertiesBuffer, 0);

    // Set all the device states
    ID3D11SamplerState* samplers[2] =
    {
        GetSamplerStates()->GetPointClamp(),
        GetSamplerStates()->GetLinearClamp(),
    };

    pd3dImmediateContext->PSSetSamplers(0, 2, samplers);

    float blendFactor[4] = {0, 0, 0, 0};
    pd3dImmediateContext->OMSetBlendState(GetBlendStates()->GetBlendDisabled(), blendFactor, 0xFFFFFFFF);

    Quad* fsQuad = GetFullScreenQuad();

    // Render the edge detection
    BEGIN_EVENT_D3D(L"Edge Detection");

    pd3dImmediateContext->OMSetRenderTargets(1, &_edgeDetectRTV, _dsv);

    // Clear the RT since the edge detection makes use of discard
    const float clearColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
    pd3dImmediateContext->ClearRenderTargetView(_edgeDetectRTV, clearColor);
    pd3dImmediateContext->ClearDepthStencilView(_dsv, D3D11_CLEAR_STENCIL, 0.0f, 0x00);

    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetStencilReplace(), 0xFFFFFFFF);

    ID3D11ShaderResourceView* ppSRVEdgeDetect[3] =
    {
        _depthDetect ? gBuffer->GetDepthSRV() : NULL,
        _normalDetect ?  gBuffer->GetNormalSRV() : NULL,
        _luminanceDetect ? gBuffer->GetDiffuseSRV() : NULL,
    };
    pd3dImmediateContext->PSSetShaderResources(0, 3, ppSRVEdgeDetect);

    pd3dImmediateContext->PSSetConstantBuffers(0, 1, &_mlaaPropertiesBuffer);

    ID3D11PixelShader* _curEdgePS = _edgeDetectPSs[_depthDetect ? 1 : 0][_normalDetect ? 1 : 0][_luminanceDetect ? 1 : 0]->PixelShader;
    V_RETURN(fsQuad->Render(pd3dImmediateContext, _curEdgePS));
    END_EVENT_D3D(L"");

    // Render blend weights
    BEGIN_EVENT_D3D(L"Calculate Blend Weights");

    // Determine which pixel shader and weight texture to use, max search steps must be <= than
    // (max_distance - 1) / 2
    UINT weightTexIdx = 0;
    for (UINT i = 0; i < NUM_WEIGHT_TEXTURES; i++)
    {
        if (_maxSearchSteps >= (WEIGHT_TEXTURE_SIZES[i] - 1) / 2)
        {
            weightTexIdx = i;
        }
    }

    pd3dImmediateContext->OMSetRenderTargets(1, &_blendWeightRTV, _dsv);
    pd3dImmediateContext->ClearRenderTargetView(_blendWeightRTV, clearColor);

    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetStencilEqual(), 0xFFFFFFFF);

    ID3D11ShaderResourceView* ppSRVBlendWeight[3] =
    {
        _edgeDetectSRV,
        _weightSRVs[weightTexIdx]->ShaderResourceView,
        NULL
    };
    pd3dImmediateContext->PSSetShaderResources(0, 3, ppSRVBlendWeight);

    V_RETURN(fsQuad->Render(pd3dImmediateContext, _blendWeightPSs[weightTexIdx]->PixelShader));

    END_EVENT_D3D(L"");

    // Copy src into dst
    BEGIN_EVENT_D3D(L"Background Copy");

    pd3dImmediateContext->OMSetRenderTargets(1, &dstRTV, _dsv);

    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetDepthDisabled(), 0);

    ID3D11ShaderResourceView* ppSRVCopyAndNeighborhood[2] =
    {
        src,
        _blendWeightSRV,
    };

    pd3dImmediateContext->PSSetShaderResources(0, 2, ppSRVCopyAndNeighborhood);

    V_RETURN(fsQuad->Render(pd3dImmediateContext, _copyBackgroundPS->PixelShader));

    END_EVENT_D3D(L"");

    // Neighborhood blend
    BEGIN_EVENT_D3D(L"Neighborhood Blend");

    pd3dImmediateContext->OMSetDepthStencilState(GetDepthStencilStates()->GetStencilEqual(), 0xFFFFFFFF);

    V_RETURN(fsQuad->Render(pd3dImmediateContext, _neighborhoodBlendPS->PixelShader));

    END_EVENT_D3D(L"");

    // Clean up
    ID3D11ShaderResourceView* ppSRVNULL[2] = { NULL, NULL };
    pd3dImmediateContext->PSSetShaderResources(0, 2, ppSRVNULL);

    END_EVENT_D3D(L"");
    return S_OK;
}