コード例 #1
0
bool NzDeferredDOFPass::Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const
{
	NazaraUnused(scene);

	NzRenderer::SetTextureSampler(0, m_pointSampler);
	NzRenderer::SetTextureSampler(1, m_bilinearSampler);
	NzRenderer::SetTextureSampler(2, m_pointSampler);

	NzRenderer::SetTarget(&m_dofRTT);
	NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x/4, m_dimensions.y/4));

	NzRenderer::SetShader(m_gaussianBlurShader);

	const unsigned int dofBlurPass = 2;
	for (unsigned int i = 0; i < dofBlurPass; ++i)
	{
		m_dofRTT.SetColorTarget(0); // dofTextureA

		m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, NzVector2f(1.f, 0.f));

		NzRenderer::SetTexture(0, (i == 0) ? m_workTextures[secondWorkTexture] : static_cast<const NzTexture*>(m_dofTextures[1]));
		NzRenderer::DrawFullscreenQuad();

		m_dofRTT.SetColorTarget(1); // dofTextureB

		m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, NzVector2f(0.f, 1.f));

		NzRenderer::SetTexture(0, m_dofTextures[0]);
		NzRenderer::DrawFullscreenQuad();
	}

	m_workRTT->SetColorTarget(firstWorkTexture);
	NzRenderer::SetTarget(m_workRTT);
	NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));

	NzRenderer::SetShader(m_dofShader);
	NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
	NzRenderer::SetTexture(1, m_dofTextures[1]);
	NzRenderer::SetTexture(2, m_GBuffer[1]);
	NzRenderer::DrawFullscreenQuad();

	return true;
}
コード例 #2
0
ファイル: Algorithm.cpp プロジェクト: BigFax/NazaraEngine
void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
{
	unsigned int xIndexCount, yIndexCount, zIndexCount;
	unsigned int xVertexCount, yVertexCount, zVertexCount;

	NzComputePlaneIndexVertexCount(NzVector2ui(subdivision.y, subdivision.z), &xIndexCount, &xVertexCount);
	NzComputePlaneIndexVertexCount(NzVector2ui(subdivision.x, subdivision.z), &yIndexCount, &yVertexCount);
	NzComputePlaneIndexVertexCount(NzVector2ui(subdivision.x, subdivision.y), &zIndexCount, &zVertexCount);

	NzMatrix4f transform;
	NzVector3f halfLengths = lengths/2.f;

	// Face +X
	transform.MakeTransform(NzVector3f::UnitX() * halfLengths.x, NzEulerAnglesf(-90.f, 0.f, -90.f));
	NzGeneratePlane(NzVector2ui(subdivision.z, subdivision.y), NzVector2f(lengths.z, lengths.y), NzMatrix4f::ConcatenateAffine(matrix, transform), textureCoords, vertices, indices, nullptr, indexOffset);
	indexOffset += xVertexCount;
	indices += xIndexCount;
	vertices += xVertexCount;

	// Face +Y
	transform.MakeTransform(NzVector3f::UnitY() * halfLengths.y, NzEulerAnglesf(0.f, 0.f, 0.f));
	NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), NzVector2f(lengths.x, lengths.z), NzMatrix4f::ConcatenateAffine(matrix, transform), textureCoords, vertices, indices, nullptr, indexOffset);
	indexOffset += yVertexCount;
	indices += yIndexCount;
	vertices += yVertexCount;

	// Face +Z
	transform.MakeTransform(NzVector3f::UnitZ() * halfLengths.z, NzEulerAnglesf(-90.f, 90.f, 90.f));
	NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), NzVector2f(lengths.x, lengths.y), NzMatrix4f::ConcatenateAffine(matrix, transform), textureCoords, vertices, indices, nullptr, indexOffset);
	indexOffset += zVertexCount;
	indices += zIndexCount;
	vertices += zVertexCount;

	// Face -X
	transform.MakeTransform(-NzVector3f::UnitX() * halfLengths.x, NzEulerAnglesf(-90.f, 0.f, 90.f));
	NzGeneratePlane(NzVector2ui(subdivision.z, subdivision.y), NzVector2f(lengths.z, lengths.y), NzMatrix4f::ConcatenateAffine(matrix, transform), textureCoords, vertices, indices, nullptr, indexOffset);
	indexOffset += xVertexCount;
	indices += xIndexCount;
	vertices += xVertexCount;

	// Face -Y
	transform.MakeTransform(-NzVector3f::UnitY() * halfLengths.y, NzEulerAnglesf(0.f, 0.f, 180.f));
	NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), NzVector2f(lengths.x, lengths.z), NzMatrix4f::ConcatenateAffine(matrix, transform), textureCoords, vertices, indices, nullptr, indexOffset);
	indexOffset += yVertexCount;
	indices += yIndexCount;
	vertices += yVertexCount;

	// Face -Z
	transform.MakeTransform(-NzVector3f::UnitZ() * halfLengths.z, NzEulerAnglesf(-90.f, -90.f, 90.f));
	NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), NzVector2f(lengths.x, lengths.y), NzMatrix4f::ConcatenateAffine(matrix, transform), textureCoords, vertices, indices, nullptr, indexOffset);
	indexOffset += zVertexCount;
	indices += zIndexCount;
	vertices += zVertexCount;

	if (aabb)
	{
		aabb->Set(-halfLengths, halfLengths);
		aabb->Transform(matrix, false);
	}
}
コード例 #3
0
ファイル: Worley2D.cpp プロジェクト: Overdrivr/NazaraEngine
void NzWorley2D::SquareTest(int xi, int yi, float x, float y)
{
    ii = xi & 255;
    jj = yi & 255;

    seed = perm[ii +     perm[jj]];

    //On initialise notre rng avec seed
    randomNumberGenerator.seed(seed);

    //On prend un nombre de points à déterminer dans le cube, compris entre 1 et 8
    unsigned int m = (seed & 7) + 1;

    //On calcule les emplacements des différents points
    for(unsigned int i(0) ; i < m ; ++i)
    {
        NzVector2f featurePoint;
        featurePoint.x = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(xi);
        featurePoint.y = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(yi);

        //Insertion dans la liste triée
        featurePoints[featurePoint.Distance(NzVector2f(x,y))] = featurePoint;
    }
}
コード例 #4
0
ファイル: Worley2D.cpp プロジェクト: Overdrivr/NazaraEngine
float NzWorley2D::Get()
{
    xc = x * m_scale;
    yc = y * m_scale;

    x0 = fastfloor(xc);
    y0 = fastfloor(yc);

    fractx = xc - static_cast<float>(x0);
    fracty = yc - static_cast<float>(y0);

    featurePoints.clear();
    //Dummy points : FIX ME : Remove them
    featurePoints[100.f] = NzVector2f(0.f,0.f);
    featurePoints[101.f] = NzVector2f(0.f,0.f);
    featurePoints[102.f] = NzVector2f(0.f,0.f);
    featurePoints[103.f] = NzVector2f(0.f,0.f);

    SquareTest(x0,y0,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(fractx < it->first)
        SquareTest(x0 - 1,y0,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(1.f - fractx < it->first)
        SquareTest(x0 + 1,y0,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(fracty < it->first)
        SquareTest(x0,y0 - 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(1.f - fracty < it->first)
        SquareTest(x0,y0 + 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(fractx < it->first &&
       fracty < it->first)
       SquareTest(x0 - 1, y0 - 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(1.f - fractx < it->first &&
       fracty < it->first)
       SquareTest(x0 + 1, y0 - 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(fractx < it->first &&
       1.f - fracty < it->first)
       SquareTest(x0 - 1, y0 + 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(1.f - fractx < it->first &&
       1.f - fracty < it->first)
       SquareTest(x0 + 1, y0 + 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    //Remove dummy points
    featurePoints.erase(--(featurePoints.end()));
    featurePoints.erase(--(featurePoints.end()));
    featurePoints.erase(--(featurePoints.end()));
    featurePoints.erase(--(featurePoints.end()));

    return it->first * scale[m_function];
}
コード例 #5
0
ファイル: Light.cpp プロジェクト: Moumou38/NazaraEngine
void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) const
{
	/*
	struct Light
	{
		int type;
		vec4 color;
		vec2 factors;

		vec4 parameters1;
		vec4 parameters2;
		vec2 parameters3;
	};

	Directional
	-P1: vec3 direction

	Point
	-P1: vec3 position + float attenuation
	-P2: vec3 NON-USED + float invRadius

	Spot
	-P1: vec3 position + float attenuation
	-P2: vec3 direction + float invRadius
	-P3: float cosInnerAngle + float cosOuterAngle
	*/

	///TODO: Optimiser
	int typeLocation = program->GetUniformLocation("Lights[0].type");
	int colorLocation = program->GetUniformLocation("Lights[0].color");
	int factorsLocation = program->GetUniformLocation("Lights[0].factors");
	int parameters1Location = program->GetUniformLocation("Lights[0].parameters1");
	int parameters2Location = program->GetUniformLocation("Lights[0].parameters2");
	int parameters3Location = program->GetUniformLocation("Lights[0].parameters3");

	if (lightUnit > 0)
	{
		int type2Location = program->GetUniformLocation("Lights[1].type");
		int offset = lightUnit * (type2Location - typeLocation); // type2Location - typeLocation donne la taille de la structure

		// On applique cet offset
		typeLocation += offset;
		colorLocation += offset;
		factorsLocation += offset;
		parameters1Location += offset;
		parameters2Location += offset;
		parameters3Location += offset;
	}

	program->SendInteger(typeLocation, m_type);
	program->SendColor(colorLocation, m_color);
	program->SendVector(factorsLocation, NzVector2f(m_ambientFactor, m_diffuseFactor));

	if (!m_derivedUpdated)
		UpdateDerived();

	switch (m_type)
	{
		case nzLightType_Directional:
			program->SendVector(parameters1Location, NzVector4f(m_derivedRotation * NzVector3f::Forward()));
			break;

		case nzLightType_Point:
			program->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation));
			program->SendVector(parameters2Location, NzVector4f(0.f, 0.f, 0.f, 1.f/m_radius));
			break;

		case nzLightType_Spot:
			program->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation));
			program->SendVector(parameters2Location, NzVector4f(m_derivedRotation * NzVector3f::Forward(), 1.f/m_radius));
			program->SendVector(parameters3Location, NzVector2f(std::cos(NzDegreeToRadian(m_innerAngle)), std::cos(NzDegreeToRadian(m_outerAngle))));
			break;
	}
}