// /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetColorFromLua(const LuaPlus::LuaObject &colorData, Vector4 &color)
    {
        if(!colorData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject rData = colorData["r"];
        LuaPlus::LuaObject gData = colorData["g"];
        LuaPlus::LuaObject bData = colorData["b"];
        LuaPlus::LuaObject aData = colorData["a"];

        if(!rData.IsNumber() || !gData.IsNumber() || !bData.IsNumber() || !aData.IsNumber()) {
            return (false);
        }

        F32 r = static_cast<F32>(rData.GetNumber());
        F32 g = static_cast<F32>(gData.GetNumber());
        F32 b = static_cast<F32>(bData.GetNumber());
        F32 a = static_cast<F32>(aData.GetNumber());
        Clamp<F32>(r, 0.0f, 1.0f);
        Clamp<F32>(g, 0.0f, 1.0f);
        Clamp<F32>(b, 0.0f, 1.0f);
        Clamp<F32>(a, 0.0f, 1.0f);
        color.Set(r, g, b, a);

        return (true);
    }
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetVector4FromLua(const LuaPlus::LuaObject &dirData, Vector4 &direction)
    {
        if(!dirData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject xData = dirData["x"];
        LuaPlus::LuaObject yData = dirData["y"];
        LuaPlus::LuaObject zData = dirData["z"];
        LuaPlus::LuaObject wData = dirData["w"];

        if(!xData.IsNumber() || !yData.IsNumber() || !zData.IsNumber() || !wData.IsNumber()) {
            return (false);
        }

        F32 x = static_cast<F32>(xData.GetNumber());
        F32 y = static_cast<F32>(yData.GetNumber());
        F32 z = static_cast<F32>(zData.GetNumber());
        F32 w = static_cast<F32>(wData.GetNumber());
        direction.Set(x, y, z, w);

        return (true);
    }
Beispiel #3
0
static void Average(void)
{
	float fTexX, fTexY;
	Vector4 vOffset;
	Vector4 vTexOffset_256x256[16];
	Vector4 vTexOffset_64x64[16];
	Vector4 vTexOffset_16x16[16];
	Vector4 vTexOffset_4x4[16];
	int index = 0;

	index=0;
	fTexX = 1.0f/256.0f;
	fTexY = 1.0f/256.0f;
	vOffset.Set(-0.5f/64.0f, -0.5f/64.0f, 0.0f, 0.0f);

	for ( int y=0; y<4; y++ )
	{
		for ( int x=0; x<4; x++ )
		{
			vTexOffset_256x256[index].Set(x*fTexX, y*fTexY, 0.0f, 0.0f);
			vTexOffset_256x256[index] += vOffset;
			index++;
		}
	}

	index=0;
	fTexX = 1.0f/64.0f;
	fTexY = 1.0f/64.0f;
	vOffset.Set(-0.5f/16.0f, -0.5f/16.0f, 0.0f, 0.0f);

	for ( int y=0; y<4; y++ )
	{
		for ( int x=0; x<4; x++ )
		{
			vTexOffset_64x64[index].Set(x*fTexX, y*fTexY, 0.0f, 0.0f);
			vTexOffset_64x64[index] += vOffset;
			index++;
		}
	}

	index=0;
	fTexX = 1.0f/16.0f;
	fTexY = 1.0f/16.0f;
	vOffset.Set(-0.5f/4.0f, -0.5f/4.0f, 0.0f, 0.0f);

	for ( int y=0; y<4; y++ )
	{
		for ( int x=0; x<4; x++ )
		{
			vTexOffset_16x16[index].Set(x*fTexX, y*fTexY, 0.0f, 0.0f);
			vTexOffset_16x16[index] += vOffset;
			index++;
		}
	}

	index=0;
	fTexX = 1.0f/4.0f;
	fTexY = 1.0f/4.0f;
	vOffset.Set(-0.5f, -0.5f, 0.0f, 0.0f);

	for ( int y=0; y<4; y++ )
	{
		for ( int x=0; x<4; x++ )
		{
			vTexOffset_4x4[index].Set(x*fTexX, y*fTexY, 0.0f, 0.0f);
			vTexOffset_4x4[index] += vOffset;
			index++;
		}
	}


	ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("Average16Samples");
	ID3D10EffectShaderResourceVariable *pImage_var = g_pExposureFX->GetVariableByName("Image0")->AsShaderResource();
	ID3D10EffectVectorVariable *pTexOffset_var = g_pExposureFX->GetVariableByName("vTexOffset")->AsVector();

	// pShader->GetPassByIndex(0)->Apply(0);

	// 256x256 -> 64x64
	{
		g_pDevice->OMSetRenderTargets(1, &g_pRTView[DOWNSAMPLED_64x64], NULL);
		SetViewport(DOWNSAMPLED_64x64);

		pImage_var->SetResource(g_pSRView[DOWNSAMPLED_256x256]);
		pTexOffset_var->SetFloatVectorArray( (float *)vTexOffset_256x256, 0, 16);

		pShader->GetPassByIndex(0)->Apply(0);
		DrawFullScreenQuad();
	}

	// 64x64 -> 16x16
	{
		g_pDevice->OMSetRenderTargets(1, &g_pRTView[DOWNSAMPLED_16x16], NULL);
		SetViewport(DOWNSAMPLED_16x16);

		pImage_var->SetResource(g_pSRView[DOWNSAMPLED_64x64]);
		pTexOffset_var->SetFloatVectorArray( (float *)vTexOffset_64x64, 0, 16);

		pShader->GetPassByIndex(0)->Apply(0);
		DrawFullScreenQuad();
	}

	// 16x16 -> 4x4
	{
		g_pDevice->OMSetRenderTargets(1, &g_pRTView[DOWNSAMPLED_4x4], NULL);
		SetViewport(DOWNSAMPLED_4x4);

		pImage_var->SetResource(g_pSRView[DOWNSAMPLED_16x16]);
		pTexOffset_var->SetFloatVectorArray( (float *)vTexOffset_16x16, 0, 16);

		pShader->GetPassByIndex(0)->Apply(0);
		DrawFullScreenQuad();
	}

	// 4x4 -> 1x1
	{
		g_pDevice->OMSetRenderTargets(1, &g_pRTView[LUMINANCE_CURRENT], NULL);
		SetViewport(LUMINANCE_CURRENT);

		pImage_var->SetResource(g_pSRView[DOWNSAMPLED_4x4]);
		pTexOffset_var->SetFloatVectorArray( (float *)vTexOffset_4x4, 0, 16);

		pShader->GetPassByIndex(0)->Apply(0);
		DrawFullScreenQuad();
	}

	static int count = 0;
	count++;
}