Exemple #1
0
OverlayEffect::OverlayEffect(ProgramFactory& factory, int windowWidth,
    int windowHeight, int textureWidth, int textureHeight,
    SamplerState::Filter filter, SamplerState::Mode mode0,
    SamplerState::Mode mode1, bool useColorPShader)
    :
    mWindowWidth(static_cast<float>(windowWidth)),
    mWindowHeight(static_cast<float>(windowHeight))
{
    Initialize(windowWidth, windowHeight, textureWidth, textureHeight);

    int i = factory.GetAPI();
    std::string psSource =
        (useColorPShader ? *msPSColorSource[i] : *msPSGraySource[i]);

    mProgram = factory.CreateFromSources(*msVSSource[i], psSource, "");
    if (mProgram)
    {
        std::shared_ptr<SamplerState> sampler =
            std::make_shared<SamplerState>();
        sampler->filter = filter;
        sampler->mode[0] = mode0;
        sampler->mode[1] = mode1;
        mProgram->GetPShader()->Set("imageSampler", sampler);
        mEffect = std::make_shared<VisualEffect>(mProgram);
    }
}
Fluid3InitializeSource::Fluid3InitializeSource(ProgramFactory& factory,
    int xSize, int ySize, int zSize, int numXThreads, int numYThreads,
    int numZThreads, std::shared_ptr<ConstantBuffer> const& parameters)
    :
    mNumXGroups(xSize/numXThreads),
    mNumYGroups(ySize/numYThreads),
    mNumZGroups(zSize/numZThreads)
{
    // Create the resources for generating velocity from vortices.
    mVortex = std::make_shared<ConstantBuffer>(sizeof(Vortex), true);
    mVelocity0 = std::make_shared<Texture3>(DF_R32G32B32A32_FLOAT, xSize,
        ySize, zSize);
    mVelocity0->SetUsage(Resource::SHADER_OUTPUT);
    mVelocity1 = std::make_shared<Texture3>(DF_R32G32B32A32_FLOAT, xSize,
        ySize, zSize);
    mVelocity1->SetUsage(Resource::SHADER_OUTPUT);

    // Create the resources for generating velocity from wind and gravity.
    mExternal = std::make_shared<ConstantBuffer>(sizeof(External), false);
    External& e = *mExternal->Get<External>();
    e.densityProducer = { 0.5f, 0.5f, 0.5f, 0.0f };
    e.densityPData = { 0.01f, 16.0f, 0.0f, 0.0f };
    e.densityConsumer = { 0.75f, 0.75f, 0.75f, 0.0f };
    e.densityCData = { 0.01f, 0.0f, 0.0f, 0.0f };
    e.gravity = { 0.0f, 0.0f, 0.0f, 0.0f };
    e.windData = { 0.001f, 0.0f, 0.0f, 0.0f };
    mSource = std::make_shared<Texture3>(DF_R32G32B32A32_FLOAT, xSize, ySize,
        zSize);
    mSource->SetUsage(Resource::SHADER_OUTPUT);

    // Create the shader for generating velocity from vortices.
    int i = factory.GetAPI();
    factory.PushDefines();
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);
    factory.defines.Set("NUM_Z_THREADS", numZThreads);
    std::shared_ptr<ComputeShader> cshader;

    mGenerateVortex = factory.CreateFromSource(*msGenerateSource[i]);
    if (mGenerateVortex)
    {
        cshader = mGenerateVortex->GetCShader();
        cshader->Set("Parameters", parameters);
        cshader->Set("Vortex", mVortex);
        cshader->Set("inVelocity", mVelocity0);
        cshader->Set("outVelocity", mVelocity1);
    }

    // Create the shader for generating the sources to the fluid simulation.
    mInitializeSource = factory.CreateFromSource(*msInitializeSource[i]);
    if (mInitializeSource)
    {
        cshader = mInitializeSource->GetCShader();
        cshader->Set("Parameters", parameters);
        cshader->Set("External", mExternal);
        cshader->Set("source", mSource);
    }

    factory.PopDefines();
}
Fluid3ComputeDivergence::Fluid3ComputeDivergence(ProgramFactory& factory,
    int xSize, int ySize, int zSize, int numXThreads, int numYThreads,
    int numZThreads, std::shared_ptr<ConstantBuffer> const& parameters)
    :
    mNumXGroups(xSize/numXThreads),
    mNumYGroups(ySize/numYThreads),
    mNumZGroups(zSize/numZThreads)
{
    mDivergence = std::make_shared<Texture3>(DF_R32_FLOAT, xSize, ySize,
        zSize);
    mDivergence->SetUsage(Resource::SHADER_OUTPUT);

    int i = factory.GetAPI();
    factory.PushDefines();
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);
    factory.defines.Set("NUM_Z_THREADS", numZThreads);
    mComputeDivergence = factory.CreateFromSource(*msSource[i]);
    if (mComputeDivergence)
    {
        mComputeDivergence->GetCShader()->Set("Parameters", parameters);
        mComputeDivergence->GetCShader()->Set("divergence", mDivergence);
    }

    factory.PopDefines();
}
SimpleBumpMapEffect::SimpleBumpMapEffect(ProgramFactory& factory,
    Environment const& environment, bool& created)
    :
    mPVWMatrix(nullptr)
{
    created = false;

    // Load and compile the shaders.
    std::string path = environment.GetPath("SimpleBumpMap.hlsl");
#if !defined(GTE_DEV_OPENGL)
    // The flags are chosen to allow you to debug the shaders through MSVS.
    // The menu path is "Debug | Graphics | Start Diagnostics" (ALT+F5).
    factory.PushFlags();
    factory.flags =
        D3DCOMPILE_ENABLE_STRICTNESS |
        D3DCOMPILE_IEEE_STRICTNESS |
        D3DCOMPILE_DEBUG |
        D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
    mProgram = factory.CreateFromFiles(path, path, "");
#if !defined(GTE_DEV_OPENGL)
    factory.PopFlags();
#endif
    if (!mProgram)
    {
        // The program factory will generate Log* messages.
        return;
    }

    // Load the textures.
    path = environment.GetPath("Bricks.png");
    mBaseTexture.reset(WICFileIO::Load(path, true));
    mBaseTexture->AutogenerateMipmaps();

    path = environment.GetPath("BricksNormal.png");
    mNormalTexture.reset(WICFileIO::Load(path, true));
    mNormalTexture->AutogenerateMipmaps();

    // Create the shader constants.
    mPVWMatrixConstant =
        std::make_shared<ConstantBuffer>(sizeof(Matrix4x4<float>), true);
    mPVWMatrix = mPVWMatrixConstant->Get<Matrix4x4<float>>();
    *mPVWMatrix = Matrix4x4<float>::Identity();

    // Create the texture sampler for mipmapping.
    mCommonSampler = std::make_shared<SamplerState>();
    mCommonSampler->filter = SamplerState::MIN_L_MAG_L_MIP_L;
    mCommonSampler->mode[0] = SamplerState::WRAP;
    mCommonSampler->mode[1] = SamplerState::WRAP;

    // Set the resources for the shaders.
    std::shared_ptr<VertexShader> vshader = mProgram->GetVShader();
    std::shared_ptr<PixelShader> pshader = mProgram->GetPShader();
    vshader->Set("PVWMatrix", mPVWMatrixConstant);
    pshader->Set("baseTexture", mBaseTexture);
    pshader->Set("normalTexture", mNormalTexture);
    pshader->Set("commonSampler", mCommonSampler);

    created = true;
}
Exemple #5
0
void Mesh::updateVAO()
{
	ProgramFactory programFactory;

	ProgramSP shaderprogram;

	for (uint32_t materialIndex = 0; materialIndex < surfaceMaterials.size(); materialIndex++)
	{
		SurfaceMaterialSP currentSurfaceMaterial = getSurfaceMaterialAt(materialIndex);

		SubMeshSP currentSubMesh = getSubMeshAt(materialIndex);

		shaderprogram = programFactory.createPhongProgram();

		SubMeshVAOSP vao = SubMeshVAOSP(new SubMeshVAO(shaderprogram, *this));
		currentSubMesh->addVAO(vao);

		shaderprogram = programFactory.createPhongRenderToCubeMapProgram();

		vao = SubMeshVAOSP(new SubMeshVAO(shaderprogram, *this));
		currentSubMesh->addVAO(vao);

		shaderprogram = programFactory.createPhongRenderToShadowMapProgram();

		vao = SubMeshVAOSP(new SubMeshVAO(shaderprogram, *this));
		currentSubMesh->addVAO(vao);
	}
}
Exemple #6
0
Font::Font(const string& filename, float width, float height, int32_t columns, int32_t rows, float cellWidth, float cellHeight, float fontWidth, float fontHeight) :
		width(width), height(height), columns(columns), rows(rows), cellWidth(cellWidth), cellHeight(cellHeight), fontWidth(fontWidth), fontHeight(fontHeight)
{
	cellWidthNormalized = cellWidth / width;
	cellHeightNormalized = cellHeight / height;

	fontTextureName = Texture2DManager::getInstance()->createTexture(filename, false, GL_LINEAR, GL_LINEAR)->getTextureName();

	camera = CameraManager::getInstance()->getDefaultOrthographicCamera();

	ProgramFactory programFactory;
	program = programFactory.createFontProgram();

	GLUSshape rectangularPlane;
	glusCreateRectangularPlanef(&rectangularPlane, cellWidth / 2.0f, cellHeight / 2.0f);

	numberIndices = rectangularPlane.numberIndices;

	glGenBuffers(1, &vboVertices);
	glBindBuffer(GL_ARRAY_BUFFER, vboVertices);
	glBufferData(GL_ARRAY_BUFFER, rectangularPlane.numberVertices * 4 * sizeof(GLfloat), (GLfloat*) rectangularPlane.vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &vboTexCoords);
	glBindBuffer(GL_ARRAY_BUFFER, vboTexCoords);
	glBufferData(GL_ARRAY_BUFFER, rectangularPlane.numberVertices * 2 * sizeof(GLfloat), (GLfloat*) rectangularPlane.texCoords, GL_STATIC_DRAW);

	glGenBuffers(1, &vboIndices);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndices);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, rectangularPlane.numberIndices * sizeof(GLuint), (GLuint*) rectangularPlane.indices, GL_STATIC_DRAW);

	fontVAO = FontVAOSP(new FontVAO(program, *this));

	glusDestroyShapef(&rectangularPlane);
}
Exemple #7
0
Sky::Sky(const Shape& shape, float radiusX, float radiusY, float radiusZ, const string& filename) : vboVertices(0), vboIndices(0), writeBrightColor(false), brightColorLimit(1.0f)
{
	ProgramFactory programFactory;
	program = programFactory.createSkyProgram();

	numberIndices = shape.getShape().numberIndices;

	glGenBuffers(1, &vboVertices);
	glBindBuffer(GL_ARRAY_BUFFER, vboVertices);
	glBufferData(GL_ARRAY_BUFFER,
			shape.getShape().numberVertices * 4 * sizeof(GLfloat),
			(GLfloat*) shape.getShape().vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &vboIndices);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndices);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER,
			shape.getShape().numberIndices * sizeof(GLuint),
			(GLuint*) shape.getShape().indices, GL_STATIC_DRAW);

	skyVAO = SkyVAOSP(new SkyVAO(program, *this));

	//

	scaleMatrix.scale(radiusX, radiusY, radiusZ);

	//

	skyTexture = TextureCubeMapManager::getInstance()->createTexture(filename);
}
VertexColorEffect::VertexColorEffect(ProgramFactory& factory)
    :
    mPVWMatrix(nullptr)
{
    int i = factory.GetAPI();
    mProgram = factory.CreateFromSources(*msVSSource[i], *msPSSource[i], "");
    if (mProgram)
    {
        mPVWMatrixConstant = std::make_shared<ConstantBuffer>(
            sizeof(Matrix4x4<float>), true);
        mPVWMatrix = mPVWMatrixConstant->Get<Matrix4x4<float>>();
        *mPVWMatrix = Matrix4x4<float>::Identity();

        mProgram->GetVShader()->Set("PVWMatrix", mPVWMatrixConstant);
    }
}
Exemple #9
0
OverlayEffect::OverlayEffect(ProgramFactory& factory, int windowWidth,
    int windowHeight, int textureWidth, int textureHeight,
    std::string const& psSource)
    :
    mWindowWidth(static_cast<float>(windowWidth)),
    mWindowHeight(static_cast<float>(windowHeight))
{
    int i = factory.GetAPI();
    Initialize(windowWidth, windowHeight, textureWidth, textureHeight);

    mProgram = factory.CreateFromSources(*msVSSource[i], psSource, "");
    if (mProgram)
    {
        mEffect = std::make_shared<VisualEffect>(mProgram);
    }
}
Fluid2InitializeState::Fluid2InitializeState(ProgramFactory& factory,
    int xSize, int ySize, int numXThreads, int numYThreads)
    :
    mNumXGroups(xSize/numXThreads),
    mNumYGroups(ySize/numYThreads)
{
    // Use a Mersenne twister engine for random numbers.
    std::mt19937 mte;
    std::uniform_real_distribution<float> unirnd(0.0f, 1.0f);

    // Initial density values are randomly generated.
    mDensity = std::make_shared<Texture2>(DF_R32_FLOAT, xSize, ySize);
    float* data = mDensity->Get<float>();
    for (unsigned int i = 0; i < mDensity->GetNumElements(); ++i, ++data)
    {
        *data = unirnd(mte);
    }

    // Initial velocity values are zero.
    mVelocity = std::make_shared<Texture2>(DF_R32G32_FLOAT, xSize, ySize);
    memset(mVelocity->GetData(), 0, mVelocity->GetNumBytes());

    // The states at time 0 and time -dt are initialized by a compute shader.
    mStateTm1 = std::make_shared<Texture2>(DF_R32G32B32A32_FLOAT, xSize,
        ySize);
    mStateTm1->SetUsage(Resource::SHADER_OUTPUT);

    mStateT = std::make_shared<Texture2>(DF_R32G32B32A32_FLOAT, xSize, ySize);
    mStateT->SetUsage(Resource::SHADER_OUTPUT);

    // Create the shader for initializing velocity and density.
    int i = factory.GetAPI();
    factory.PushDefines();
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);
    mInitializeState = factory.CreateFromSource(*msSource[i]);
    if (mInitializeState)
    {
        std::shared_ptr<ComputeShader> cshader =
            mInitializeState->GetCShader();
        cshader->Set("density", mDensity);
        cshader->Set("velocity", mVelocity);
        cshader->Set("stateTm1", mStateTm1);
        cshader->Set("stateT", mStateT);
    }
    factory.PopDefines();
}
Exemple #11
0
Ground::Ground(const BoundingSphere& boundingSphere, const GridPlaneShape& gridPlaneShape) :
		boundingSphere(boundingSphere), numberVertices(gridPlaneShape.getShape().numberVertices), numberIndices(gridPlaneShape.getShape().numberIndices), allVAOs()
{
	glGenBuffers(1, &vboVertices);
	glBindBuffer(GL_ARRAY_BUFFER, vboVertices);
	glBufferData(GL_ARRAY_BUFFER, numberVertices * 4 * sizeof(GLfloat), (GLfloat*)gridPlaneShape.getShape().vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &vboNormals);
	glBindBuffer(GL_ARRAY_BUFFER, vboNormals);
	glBufferData(GL_ARRAY_BUFFER, numberVertices * 3 * sizeof(GLfloat), (GLfloat*)gridPlaneShape.getShape().normals, GL_STATIC_DRAW);

	glGenBuffers(1, &vboBitangents);
	glBindBuffer(GL_ARRAY_BUFFER, vboBitangents);
	glBufferData(GL_ARRAY_BUFFER, numberVertices * 3 * sizeof(GLfloat), (GLfloat*)gridPlaneShape.getShape().bitangents, GL_STATIC_DRAW);

	glGenBuffers(1, &vboTangents);
	glBindBuffer(GL_ARRAY_BUFFER, vboTangents);
	glBufferData(GL_ARRAY_BUFFER, numberVertices * 3 * sizeof(GLfloat), (GLfloat*)gridPlaneShape.getShape().tangents, GL_STATIC_DRAW);

	glGenBuffers(1, &vboTexCoords);
	glBindBuffer(GL_ARRAY_BUFFER, vboTexCoords);
	glBufferData(GL_ARRAY_BUFFER, numberVertices * 2 * sizeof(GLfloat), (GLfloat*)gridPlaneShape.getShape().texCoords, GL_STATIC_DRAW);

	glGenBuffers(1, &vboIndices);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndices);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, numberIndices * sizeof(GLuint), (GLuint*)gridPlaneShape.getShape().indices, GL_STATIC_DRAW);

	//

	ProgramFactory programFactory;

	ProgramSP shaderprogram = programFactory.createGroundProgram();

	GroundVAOSP vao = GroundVAOSP(new GroundVAO(shaderprogram, *this));
	addVAO(vao);

	shaderprogram = programFactory.createGroundRenderToCubeMapProgram();

	vao = GroundVAOSP(new GroundVAO(shaderprogram, *this));
	addVAO(vao);

	shaderprogram = programFactory.createGroundRenderToShadowMapProgram();

	vao = GroundVAOSP(new GroundVAO(shaderprogram, *this));
	addVAO(vao);
}
Fluid2AdjustVelocity::Fluid2AdjustVelocity(ProgramFactory& factory,
    int xSize, int ySize, int numXThreads, int numYThreads,
    std::shared_ptr<ConstantBuffer> const& parameters)
    :
    mNumXGroups(xSize/numXThreads),
    mNumYGroups(ySize/numYThreads)
{
    int i = factory.GetAPI();
    factory.PushDefines();
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);

    mAdjustVelocity = factory.CreateFromSource(*msSource[i]);
    if (mAdjustVelocity)
    {
        mAdjustVelocity->GetCShader()->Set("Parameters", parameters);
    }

    factory.PopDefines();
}
Fluid2SolvePoisson::Fluid2SolvePoisson(ProgramFactory& factory, int xSize,
    int ySize, int numXThreads, int numYThreads,
    std::shared_ptr<ConstantBuffer> const& parameters, int numIterations)
    :
    mNumXGroups(xSize/numXThreads),
    mNumYGroups(ySize/numYThreads),
    mNumIterations(numIterations)
{
    mPoisson0 = std::make_shared<Texture2>(DF_R32_FLOAT, xSize, ySize);
    mPoisson0->SetUsage(Resource::SHADER_OUTPUT);
    mPoisson1 = std::make_shared<Texture2>(DF_R32_FLOAT, xSize, ySize);
    mPoisson1->SetUsage(Resource::SHADER_OUTPUT);

    int i = factory.GetAPI();
    factory.PushDefines();
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);

    // For zeroing mPoisson0 on the GPU.
    mZeroPoisson = factory.CreateFromSource(*msZeroSource[i]);
    if (mZeroPoisson)
    {
        mZeroPoisson->GetCShader()->Set("poisson", mPoisson0);
    }

    // Create the shader for generating velocity from vortices.
    mSolvePoisson = factory.CreateFromSource(*msSolveSource[i]);
    if (mSolvePoisson)
    {
        mSolvePoisson->GetCShader()->Set("Parameters", parameters);
    }

    factory.defines.Clear();
    factory.defines.Set("USE_ZERO_X_EDGE", 1);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);
    mWriteXEdge = factory.CreateFromSource(*msEnforceSource[i]);

    factory.defines.Clear();
    factory.defines.Set("USE_ZERO_Y_EDGE", 1);
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    mWriteYEdge = factory.CreateFromSource(*msEnforceSource[i]);

    factory.PopDefines();
}
BlendedTerrainEffect::BlendedTerrainEffect(ProgramFactory& factory,
    Environment const& environment, bool& created)
    :
    mPVWMatrix(nullptr),
    mFlowDirection(nullptr),
    mPowerFactor(nullptr)
{
    created = false;

    // Load and compile the shaders.
    std::string path = environment.GetPath("BlendedTerrain.hlsl");
#if !defined(GTE_DEV_OPENGL)
    // The flags are chosen to allow you to debug the shaders through MSVS.
    // The menu path is "Debug | Graphics | Start Diagnostics" (ALT+F5).
    factory.PushFlags();
    factory.flags = 
        D3DCOMPILE_ENABLE_STRICTNESS |
        D3DCOMPILE_IEEE_STRICTNESS |
        D3DCOMPILE_DEBUG |
        D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
    mProgram = factory.CreateFromFiles(path, path, "");
#if !defined(GTE_DEV_OPENGL)
    factory.PopFlags();
#endif
    if (!mProgram)
    {
        // The program factory will generate Log* messages.
        return;
    }

    // Load the textures.
    path = environment.GetPath("BTGrass.png");
    mGrassTexture.reset(WICFileIO::Load(path, true));
    mGrassTexture->AutogenerateMipmaps();

    path = environment.GetPath("BTStone.png");
    mStoneTexture.reset(WICFileIO::Load(path, true));
    mStoneTexture->AutogenerateMipmaps();

    path = environment.GetPath("BTCloud.png");
    mCloudTexture.reset(WICFileIO::Load(path, true));
    mCloudTexture->AutogenerateMipmaps();

    // Create the shader constants.
    mPVWMatrixConstant = std::make_shared<ConstantBuffer>(sizeof(Matrix4x4<float>), true);
    mPVWMatrix = mPVWMatrixConstant->Get<Matrix4x4<float>>();
    *mPVWMatrix = Matrix4x4<float>::Identity();

    mFlowDirectionConstant = std::make_shared<ConstantBuffer>(sizeof(Vector2<float>), true);
    mFlowDirection = mFlowDirectionConstant->Get<Vector2<float>>();
    *mFlowDirection = { 0.0f, 0.0f };

    mPowerFactorConstant = std::make_shared<ConstantBuffer>(sizeof(float), true);
    mPowerFactor = mPowerFactorConstant->Get<float>();
    *mPowerFactor = 1.0f;

    // Create a 1-dimensional texture whose intensities are proportional to
    // height.
    unsigned int const numTexels = 256;
    mBlendTexture = std::make_shared<Texture1>(DF_R8_UNORM, numTexels);
    unsigned char* texels = mBlendTexture->Get<unsigned char>();
    for (unsigned int i = 0; i < numTexels; ++i, ++texels)
    {
        *texels = static_cast<unsigned char>(i);
    }

    // Create the texture samplers.  The common sampler uses trilinear
    // interpolation (mipmapping).  The blend sample uses bilinear
    // interpolation (no mipmapping).
    mCommonSampler = std::make_shared<SamplerState>();
    mCommonSampler->filter = SamplerState::MIN_L_MAG_L_MIP_L;
    mCommonSampler->mode[0] = SamplerState::WRAP;
    mCommonSampler->mode[1] = SamplerState::WRAP;
    mBlendSampler = std::make_shared<SamplerState>();
    mBlendSampler->filter = SamplerState::MIN_L_MAG_L_MIP_P;
    mBlendSampler->mode[0] = SamplerState::WRAP;

    // Set the resources for the shaders.
    std::shared_ptr<VertexShader> vshader = mProgram->GetVShader();
    std::shared_ptr<PixelShader> pshader = mProgram->GetPShader();
    vshader->Set("PVWMatrix", mPVWMatrixConstant);
    vshader->Set("FlowDirection", mFlowDirectionConstant);
    pshader->Set("PowerFactor", mPowerFactorConstant);
    pshader->Set("grassTexture", mGrassTexture);
    pshader->Set("stoneTexture", mStoneTexture);
    pshader->Set("blendTexture", mBlendTexture);
    pshader->Set("cloudTexture", mCloudTexture);
    pshader->Set("commonSampler", mCommonSampler);
    pshader->Set("blendSampler", mBlendSampler);

    created = true;
}
Fluid3EnforceStateBoundary::Fluid3EnforceStateBoundary(
    ProgramFactory& factory, int xSize, int ySize, int zSize, int numXThreads,
    int numYThreads, int numZThreads)
    :
    mNumXGroups(xSize/numXThreads),
    mNumYGroups(ySize/numYThreads),
    mNumZGroups(zSize/numZThreads)
{
    mXMin = std::make_shared<Texture2>(DF_R32G32_FLOAT, ySize, zSize);
    mXMin->SetUsage(Resource::SHADER_OUTPUT);
    mXMax = std::make_shared<Texture2>(DF_R32G32_FLOAT, ySize, zSize);
    mXMax->SetUsage(Resource::SHADER_OUTPUT);
    mYMin = std::make_shared<Texture2>(DF_R32G32_FLOAT, xSize, zSize);
    mYMin->SetUsage(Resource::SHADER_OUTPUT);
    mYMax = std::make_shared<Texture2>(DF_R32G32_FLOAT, xSize, zSize);
    mYMax->SetUsage(Resource::SHADER_OUTPUT);
    mZMin = std::make_shared<Texture2>(DF_R32G32_FLOAT, xSize, ySize);
    mZMin->SetUsage(Resource::SHADER_OUTPUT);
    mZMax = std::make_shared<Texture2>(DF_R32G32_FLOAT, xSize, ySize);
    mZMax->SetUsage(Resource::SHADER_OUTPUT);

    int i = factory.GetAPI();
    factory.PushDefines();
    factory.defines.Set("USE_COPY_X_FACE", 1);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);
    factory.defines.Set("NUM_Z_THREADS", numZThreads);
    mCopyXFace = factory.CreateFromSource(*msSource[i]);
    if (mCopyXFace)
    {
        mCopyXFace->GetCShader()->Set("xMin", mXMin);
        mCopyXFace->GetCShader()->Set("xMax", mXMax);
    }

    factory.defines.Clear();
    factory.defines.Set("USE_WRITE_X_FACE", 1);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);
    factory.defines.Set("NUM_Z_THREADS", numZThreads);
    mWriteXFace = factory.CreateFromSource(*msSource[i]);
    if (mWriteXFace)
    {
        mWriteXFace->GetCShader()->Set("xMin", mXMin);
        mWriteXFace->GetCShader()->Set("xMax", mXMax);
    }

    factory.defines.Clear();
    factory.defines.Set("USE_COPY_Y_FACE", 1);
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Z_THREADS", numZThreads);
    mCopyYFace = factory.CreateFromSource(*msSource[i]);
    if (mCopyYFace)
    {
        mCopyYFace->GetCShader()->Set("yMin", mYMin);
        mCopyYFace->GetCShader()->Set("yMax", mYMax);
    }

    factory.defines.Clear();
    factory.defines.Set("USE_WRITE_Y_FACE", 1);
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Z_THREADS", numZThreads);
    mWriteYFace = factory.CreateFromSource(*msSource[i]);
    if (mWriteYFace)
    {
        mWriteYFace->GetCShader()->Set("yMin", mYMin);
        mWriteYFace->GetCShader()->Set("yMax", mYMax);
    }

    factory.defines.Clear();
    factory.defines.Set("USE_COPY_Z_FACE", 1);
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);
    mCopyZFace = factory.CreateFromSource(*msSource[i]);
    if (mCopyZFace)
    {
        mCopyZFace->GetCShader()->Set("zMin", mZMin);
        mCopyZFace->GetCShader()->Set("zMax", mZMax);
    }

    factory.defines.Clear();
    factory.defines.Set("USE_WRITE_Z_FACE", 1);
    factory.defines.Set("NUM_X_THREADS", numXThreads);
    factory.defines.Set("NUM_Y_THREADS", numYThreads);
    mWriteZFace = factory.CreateFromSource(*msSource[i]);
    if (mWriteZFace)
    {
        mWriteZFace->GetCShader()->Set("zMin", mZMin);
        mWriteZFace->GetCShader()->Set("zMax", mZMax);
    }

    factory.PopDefines();
}
Exemple #16
0
		void reloadObject(LoadableObject::Pointer o, ObjectsCache& c)
			{ owner->reloadObject(o, c); }
Exemple #17
0
#include "catch.hpp"
#include "AST/Expressions/AdditionExpression.hpp"
#include "AST/Expressions/LiteralExpression.hpp"
#include "AST/Expressions/MemoryAccessExpression.hpp"

#include "ProgramFactory.hpp"

TEST_CASE("LiteralExpression", "[expression]")
{
  ProgramFactory factory;
  SECTION("Positive Literals")
  {
    auto s = factory.literal("two", 2).exprstr("two");
    auto exp = R"(BB1:
li $1, 2
)";
    REQUIRE(s == exp);

    s = factory.literal("25", 25).exprstr("25");
    exp = R"(BB1:
li $1, 25
)";
    REQUIRE(s == exp);

    s = factory.literal("a", 'a').exprstr("a");
    exp = R"(BB1:
li $1, 97
)";
    REQUIRE(s == exp);

    s = factory.literal("true", true).exprstr("true");
Exemple #18
0
GpuShortestPath::GpuShortestPath(ProgramFactory& factory,
    std::shared_ptr<Texture2> const& weights, Environment const& env,
    bool& created)
    :
    mSize(static_cast<int>(weights->GetWidth()))
{
    created = false;
    mLogSize = Log2OfPowerOfTwo(mSize);

    mDistance = std::make_shared<Texture2>(DF_R32_FLOAT, mSize, mSize);
    mDistance->SetUsage(Resource::SHADER_OUTPUT);
    memset(mDistance->GetData(), 0, mDistance->GetNumBytes());

    mPrevious = std::make_shared<Texture2>(DF_R32G32_SINT, mSize, mSize);
    mPrevious->SetUsage(Resource::SHADER_OUTPUT);
    mPrevious->SetCopyType(Resource::COPY_STAGING_TO_CPU);

    mSegment = std::make_shared<ConstantBuffer>(3 * sizeof(int), true);

    factory.PushDefines();
    factory.defines.Set("ISIZE", mSize);
    mInitializeDiagToRow = factory.CreateFromFile(
        env.GetPath("InitializeDiagToRow.hlsl"));
    if (!mInitializeDiagToRow)
    {
        return;
    }
    std::shared_ptr<ComputeShader> cshader =
        mInitializeDiagToRow->GetCShader();
    cshader->Set("weights", weights);
    cshader->Set("previous", mPrevious);
    cshader->Set("sum", mDistance);

    mInitializeDiagToCol = factory.CreateFromFile(
        env.GetPath("InitializeDiagToCol.hlsl"));
    if (!mInitializeDiagToCol)
    {
        return;
    }
    cshader = mInitializeDiagToCol->GetCShader();
    cshader->Set("weights", weights);
    cshader->Set("previous", mPrevious);
    cshader->Set("sum", mDistance);

    mPartialSumDiagToRow.resize(mLogSize);
    mPartialSumDiagToCol.resize(mLogSize);
    for (int i = 0; i < mLogSize; ++i)
    {
        factory.defines.Set("LOGN", mLogSize);
        factory.defines.Set("P", i + 1);
        mPartialSumDiagToRow[i] = factory.CreateFromFile(
            env.GetPath("PartialSumsDiagToRow.hlsl"));
        if (!mPartialSumDiagToRow[i])
        {
            return;
        }
        mPartialSumDiagToRow[i]->GetCShader()->Set("sum", mDistance);

        mPartialSumDiagToCol[i] = factory.CreateFromFile(
            env.GetPath("PartialSumsDiagToCol.hlsl"));
        if (!mPartialSumDiagToCol[i])
        {
            return;
        }
        mPartialSumDiagToCol[i]->GetCShader()->Set("sum", mDistance);
    }

    mUpdate = factory.CreateFromFile(env.GetPath("UpdateShader.hlsl"));
    if (!mUpdate)
    {
        return;
    }
    cshader = mUpdate->GetCShader();
    cshader->Set("Segment", mSegment);
    cshader->Set("weights", weights);
    cshader->Set("distance", mDistance);
    cshader->Set("previous", mPrevious);

    factory.PopDefines();
    created = true;
}
PostProcessor2DMultisample::PostProcessor2DMultisample(int32_t samples, GLenum internalFormat, bool fixedsamplelocations, int32_t blurPixel, float blurSigma, int32_t bloomPixel, float bloomSigma, int32_t maxRadiusCoC, float cocSigma, float aperture, float focal, float focusedObject) :
	PostProcessor(GL_TEXTURE_2D_MULTISAMPLE, blurPixel, blurSigma, bloomPixel, bloomSigma, maxRadiusCoC, cocSigma, aperture, focal, focusedObject), samples(samples), internalFormat(internalFormat), fixedsamplelocations(fixedsamplelocations)
{
	char buffer[256];
	sprintf(buffer, "%p", this);
	string uniqueID(buffer);

	dummy = Texture2DManager::getInstance()->createTexture("PostProcessor2DMultisampleDummy", GL_RGB, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, false, GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);

	// Main textures

	Texture2DMultisampleSP color0Texture2DMultisample = Texture2DMultisampleManager::getInstance()->createTexture("PostProcessor2DMultisample0" + uniqueID, samples, internalFormat, 1, 1, fixedsamplelocations);
	Texture2DMultisampleSP color1Texture2DMultisample = Texture2DMultisampleManager::getInstance()->createTexture("PostProcessor2DMultisample1" + uniqueID, samples, internalFormat, 1, 1, fixedsamplelocations);

	Texture2DMultisampleSP depthTexture2DMultisample = Texture2DMultisampleManager::getInstance()->createTexture("PostProcessor2DMultisampleDepth" + uniqueID, samples, GL_DEPTH_COMPONENT, 1, 1, fixedsamplelocations);

	FrameBuffer2DMultisampleSP frameBuffer2DMultisample = FrameBuffer2DMultisampleSP(new FrameBuffer2DMultisample(1, 1));
	frameBuffer2DMultisample->setColorAttachment0(color0Texture2DMultisample);
	frameBuffer2DMultisample->setColorAttachment1(color1Texture2DMultisample);
	frameBuffer2DMultisample->setDepthAttachment(depthTexture2DMultisample);

	FrameBuffer2DMultisampleManager::getInstance()->addFrameBuffer("PostProcessor2DMultisample" + uniqueID, frameBuffer2DMultisample, true);

	// Temporary

	Texture2DMultisampleSP tempColor0Texture2DMultisample = Texture2DMultisampleManager::getInstance()->createTexture("PostProcessor2DMultisampleTemp" + uniqueID, samples, internalFormat, 1, 1, fixedsamplelocations);

	FrameBuffer2DMultisampleSP tempFrameBuffer2DMultisample = FrameBuffer2DMultisampleSP(new FrameBuffer2DMultisample(1, 1));
	tempFrameBuffer2DMultisample->setColorAttachment0(tempColor0Texture2DMultisample);

	FrameBuffer2DMultisampleManager::getInstance()->addFrameBuffer("PostProcessor2DMultisampleTemp" + uniqueID, tempFrameBuffer2DMultisample, true);

	// Depth of Field textures ...

	Texture2DMultisampleSP depthOfFieldColor0Texture2DMultisample = Texture2DMultisampleManager::getInstance()->createTexture("PostProcessor2DMultisampleDepthOfField" + uniqueID, samples, internalFormat, 1, 1, fixedsamplelocations);

	FrameBuffer2DMultisampleSP depthOfFieldFrameBuffer2DMultisample = FrameBuffer2DMultisampleSP(new FrameBuffer2DMultisample(1, 1));
	depthOfFieldFrameBuffer2DMultisample->setColorAttachment0(depthOfFieldColor0Texture2DMultisample);

	FrameBuffer2DMultisampleManager::getInstance()->addFrameBuffer("PostProcessor2DMultisampleDepthOfField" + uniqueID, depthOfFieldFrameBuffer2DMultisample, true);

	// Bloom textures ...

	Texture2DMultisampleSP bloomColor0Texture2DMultisample = Texture2DMultisampleManager::getInstance()->createTexture("PostProcessor2DMultisampleBloom" + uniqueID, samples, internalFormat, 1, 1, fixedsamplelocations);

	FrameBuffer2DMultisampleSP bloomFrameBuffer2DMultisample = FrameBuffer2DMultisampleSP(new FrameBuffer2DMultisample(1, 1));
	bloomFrameBuffer2DMultisample->setColorAttachment0(bloomColor0Texture2DMultisample);

	FrameBuffer2DMultisampleManager::getInstance()->addFrameBuffer("PostProcessor2DMultisampleBloom" + uniqueID, bloomFrameBuffer2DMultisample, true);

	// Now pass to super class

	frameBuffer = static_cast<FrameBufferSP>(frameBuffer2DMultisample);
	tempFrameBuffer = static_cast<FrameBufferSP>(tempFrameBuffer2DMultisample);
	depthOfFieldFrameBuffer = static_cast<FrameBufferSP>(depthOfFieldFrameBuffer2DMultisample);
	bloomFrameBuffer = static_cast<FrameBufferSP>(bloomFrameBuffer2DMultisample);

	//

	screenTexture = u_screenTextureMS;
	depthTexture = u_depthTextureMS;
	bloomTexture = u_bloomTextureMS;

	//

	ProgramFactory programFactory;

	program = programFactory.createPostProcess2DProgram();

	GLUSshape rectangularPlane;
	glusShapeCreateRectangularPlanef(&rectangularPlane, 0.5f, 0.5f);

	numberIndices = rectangularPlane.numberIndices;

	glGenBuffers(1, &vboVertices);
	glBindBuffer(GL_ARRAY_BUFFER, vboVertices);
	glBufferData(GL_ARRAY_BUFFER, rectangularPlane.numberVertices * 4 * sizeof(GLfloat), (GLfloat*) rectangularPlane.vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &vboTexCoords);
	glBindBuffer(GL_ARRAY_BUFFER, vboTexCoords);
	glBufferData(GL_ARRAY_BUFFER, rectangularPlane.numberVertices * 2 * sizeof(GLfloat), (GLfloat*) rectangularPlane.texCoords, GL_STATIC_DRAW);

	glGenBuffers(1, &vboIndices);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndices);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, rectangularPlane.numberIndices * sizeof(GLuint), (GLuint*) rectangularPlane.indices, GL_STATIC_DRAW);

	postProcessorVAO = PostProcessorVAOSP(new PostProcessorVAO(program, *this));

	glusShapeDestroyf(&rectangularPlane);
}
GpuMassSpringVolume::GpuMassSpringVolume(ProgramFactory& factory,
        int numColumns, int numRows, int numSlices, float step, float viscosity,
        Environment& environment, bool& created)
    :
    mNumColumns(numColumns),
    mNumRows(numRows),
    mNumSlices(numSlices)
{
    created = false;

    // Create the shaders.
    std::string path = environment.GetPath("RungeKutta.hlsl");
    int const numThreads = 4;
    factory.PushDefines();
    factory.defines.Set("NUM_X_THREADS", numThreads);
    factory.defines.Set("NUM_Y_THREADS", numThreads);
    factory.defines.Set("NUM_Z_THREADS", numThreads);

    for (int i = 0; i < 8; ++i)
    {
        factory.csEntry = "RK4Step";
        factory.csEntry += std::to_string(1 + i/2);
        factory.csEntry += ((i & 1) == 0 ? "a" : "b");
        mRK4Shader[i] = factory.CreateFromFile(path);
        if (!mRK4Shader[i])
        {
            return;
        }
    }

    // The cbuffer is tightly packed.  Only time, halfTime, and fullTime vary.
    mParameters = std::make_shared<ConstantBuffer>(sizeof(SimulationParameters),
                  true);
    SimulationParameters& p = *mParameters->Get<SimulationParameters>();
    p.dimensions[0] = numColumns;
    p.dimensions[1] = numRows;
    p.dimensions[2] = numSlices;
    p.dimensions[3] = numColumns * numRows;
    p.viscosity = viscosity;
    p.time = 0.0f;
    p.delta = step;
    p.halfDelta = p.delta / 2.0f;
    p.sixthDelta = p.delta / 6.0f;
    p.halfTime = p.time + p.halfDelta;
    p.fullTime = p.time + p.delta;

    unsigned int const numParticles = p.dimensions[2] * p.dimensions[3];
    size_t const vecsize = sizeof(Vector3<float>);
    mMass = std::make_shared<StructuredBuffer>(numParticles, sizeof(float));
    mInvMass = std::make_shared<StructuredBuffer>(numParticles,
               sizeof(float));
    mPosition = std::make_shared<StructuredBuffer>(numParticles, vecsize);
    mPosition->SetUsage(Resource::SHADER_OUTPUT);
    mPosition->SetCopyType(Resource::COPY_STAGING_TO_CPU);
    mVelocity = std::make_shared<StructuredBuffer>(numParticles, vecsize);
    mVelocity->SetUsage(Resource::SHADER_OUTPUT);
    mConstantC = std::make_shared<StructuredBuffer>(numParticles,
                 sizeof(float));
    mLengthC = std::make_shared<StructuredBuffer>(numParticles,
               sizeof(float));
    mConstantR = std::make_shared<StructuredBuffer>(numParticles,
                 sizeof(float));
    mLengthR = std::make_shared<StructuredBuffer>(numParticles,
               sizeof(float));
    mConstantS = std::make_shared<StructuredBuffer>(numParticles,
                 sizeof(float));
    mLengthS = std::make_shared<StructuredBuffer>(numParticles,
               sizeof(float));

    mPTmp = std::make_shared<StructuredBuffer>(numParticles, vecsize, true);
    mPTmp->SetUsage(Resource::SHADER_OUTPUT);
    mPTmp->SetCopyType(Resource::COPY_STAGING_TO_CPU);
    mPAllTmp = std::make_shared<StructuredBuffer>(numParticles, 4 * vecsize,
               true);
    mPAllTmp->SetUsage(Resource::SHADER_OUTPUT);
    mPAllTmp->SetCopyType(Resource::COPY_STAGING_TO_CPU);
    mVTmp = std::make_shared<StructuredBuffer>(numParticles, vecsize, true);
    mVTmp->SetUsage(Resource::SHADER_OUTPUT);
    mVTmp->SetCopyType(Resource::COPY_STAGING_TO_CPU);
    mVAllTmp = std::make_shared<StructuredBuffer>(numParticles, 4 * vecsize,
               true);
    mVAllTmp->SetUsage(Resource::SHADER_OUTPUT);
    mVAllTmp->SetCopyType(Resource::COPY_STAGING_TO_CPU);

    mNumXGroups = p.dimensions[0] / numThreads;
    mNumYGroups = p.dimensions[1] / numThreads;
    mNumZGroups = p.dimensions[2] / numThreads;

    std::shared_ptr<ComputeShader> cshader = mRK4Shader[0]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("constantC", mConstantC);
    cshader->Set("lengthC", mLengthC);
    cshader->Set("constantR", mConstantR);
    cshader->Set("lengthR", mLengthR);
    cshader->Set("constantS", mConstantS);
    cshader->Set("lengthS", mLengthS);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);
    cshader->Set("position", mPosition);
    cshader->Set("velocity", mVelocity);

    cshader = mRK4Shader[1]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("pTmp", mPTmp);
    cshader->Set("vTmp", mVTmp);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);
    cshader->Set("position", mPosition);
    cshader->Set("velocity", mVelocity);

    cshader = mRK4Shader[2]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("constantC", mConstantC);
    cshader->Set("lengthC", mLengthC);
    cshader->Set("constantR", mConstantR);
    cshader->Set("lengthR", mLengthR);
    cshader->Set("constantS", mConstantS);
    cshader->Set("lengthS", mLengthS);
    cshader->Set("pTmp", mPTmp);
    cshader->Set("vTmp", mVTmp);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);
    cshader->Set("velocity", mVelocity);

    cshader = mRK4Shader[3]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("pTmp", mPTmp);
    cshader->Set("vTmp", mVTmp);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);
    cshader->Set("position", mPosition);
    cshader->Set("velocity", mVelocity);

    cshader = mRK4Shader[4]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("constantC", mConstantC);
    cshader->Set("lengthC", mLengthC);
    cshader->Set("constantR", mConstantR);
    cshader->Set("lengthR", mLengthR);
    cshader->Set("constantS", mConstantS);
    cshader->Set("lengthS", mLengthS);
    cshader->Set("pTmp", mPTmp);
    cshader->Set("vTmp", mVTmp);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);
    cshader->Set("velocity", mVelocity);

    cshader = mRK4Shader[5]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("pTmp", mPTmp);
    cshader->Set("vTmp", mVTmp);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);
    cshader->Set("position", mPosition);
    cshader->Set("velocity", mVelocity);

    cshader = mRK4Shader[6]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("constantC", mConstantC);
    cshader->Set("lengthC", mLengthC);
    cshader->Set("constantR", mConstantR);
    cshader->Set("lengthR", mLengthR);
    cshader->Set("constantS", mConstantS);
    cshader->Set("lengthS", mLengthS);
    cshader->Set("pTmp", mPTmp);
    cshader->Set("vTmp", mVTmp);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);
    cshader->Set("velocity", mVelocity);

    cshader = mRK4Shader[7]->GetCShader();
    cshader->Set("SimulationParameters", mParameters);
    cshader->Set("invMass", mInvMass);
    cshader->Set("position", mPosition);
    cshader->Set("velocity", mVelocity);
    cshader->Set("pAllTmp", mPAllTmp);
    cshader->Set("vAllTmp", mVAllTmp);

    factory.PopDefines();
    created = true;
}