Exemple #1
0
    /*
    ==============================
    ==============================
    */
    void TwLimb::SetColor(const vec4& color)
    {
        int c[4] = {color[0]*255, color[1]*255,  color[2]*255, color[3]*255};

        TwSetParam(bar, 0, "color", TW_PARAM_INT32, 3, c);
        TwSetParam(bar, 0, "alpha", TW_PARAM_INT32, 1, &c[3]);
    }
Exemple #2
0
void SetAxisMapping(TwBar* bar, const char* varName, Axis xAxis, Axis yAxis, Axis zAxis)
{
    static const char* AxisStrings[] = { "x", "-x", "y", "-y", "z", "-z" };
    TwCall(TwSetParam(bar, varName, "axisx", TW_PARAM_CSTRING, 1, AxisStrings[uint64(xAxis)]));
    TwCall(TwSetParam(bar, varName, "axisy", TW_PARAM_CSTRING, 1, AxisStrings[uint64(yAxis)]));
    TwCall(TwSetParam(bar, varName, "axisz", TW_PARAM_CSTRING, 1, AxisStrings[uint64(zAxis)]));
}
void TW_CALL ClearDatabase(void *clientData){
	DBDeleteAllGestures();
	Gesture_ g;
	for (int i = 0; i < next_gesture_id; i++){
		char visible[] = "false";

		std::string varname;
		varname.append(std::to_string(i+1));
		varname.append(" - Name:");
		TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

		varname.clear();
		varname.append(std::to_string(i+1));
		varname.append(" - ID:");
		TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

		varname.clear();
		varname.append(std::to_string(i+1));
		varname.append(" - Hands:");
		TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

		varname.clear();
		varname.append(std::to_string(i+1));
		varname.append(" - Fingers:");
		TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

		varname.clear();
		varname.append(std::to_string(i+1));
		varname.append(" - sep:");
		TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

		g_gestureManager.gestures[i] = g;
	}
	next_gesture_id = 0;
}
Exemple #4
0
void SetValuesWidth(TwBar* bar, int32 width, bool32 fit)
{
    if(fit)
        TwCall(TwSetParam(bar, nullptr, "valueswidth", TW_PARAM_CSTRING, 1, "fit"));
    else
        TwCall(TwSetParam(bar, nullptr, "valueswidth", TW_PARAM_INT32, 1, &width));
}
Exemple #5
0
    /*
    ==============================
    ==============================
    */
    void TwLimb::SetSize(const ivec2& size)
    {
        int valueWidth = size.x*0.66f;

        TwSetParam(bar, 0, "size", TW_PARAM_INT32, 2, &size);
        TwSetParam(bar, 0, "valueswidth", TW_PARAM_INT32, 1, &valueWidth);

    }
void Loop(){
	mat4 ModelMatrix(1.0f);
	float bgColor[] = { 0.2f, 0.4f, 0.5f };
	
	do{
		glClearColor(bgColor[0], bgColor[1], bgColor[2], 1);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		g_mutex.lock();
		drawHands();
		g_mutex.unlock();
		
		g_text.printText2D(info, 30, 30, 15, 0);
		g_text.printText2D(counter, 370, 500, 100, 0);

		if (g_leapListener.saved){
			int i = next_gesture_id - 1;
			printf("next = %d\ni = %d\n", next_gesture_id, i);
			
			char visible[] = "true";

			std::string varname;
			varname.append(std::to_string(i + 1));
			varname.append(" - Name:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

			varname.clear();
			varname.append(std::to_string(i + 1));
			varname.append(" - ID:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

			varname.clear();
			varname.append(std::to_string(i + 1));
			varname.append(" - Hands:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

			varname.clear();
			varname.append(std::to_string(i + 1));
			varname.append(" - Fingers:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);

			varname.clear();
			varname.append(std::to_string(i + 1));
			varname.append(" - sep:");
			TwSetParam(bar2, varname.c_str(), "visible", TW_PARAM_CSTRING, 1, visible);
			
			g_leapListener.saved = false;

		}

		TwDraw();

		glfwSwapBuffers();
	} while (glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS &&
		glfwGetWindowParam(GLFW_OPENED));
}
void Toolbar::init()
{
  glm::ivec2 pos(4096);
  glm::ivec2 size(200, 1);

  tweakBar = TwNewBar(toolbarTitle);
  TwSetParam(tweakBar, nullptr, "help", TW_PARAM_CSTRING, 1, "Toggles the visibilty of other tweak bars");
  TwSetParam(tweakBar, nullptr, "position", TW_PARAM_INT32, 2, &pos);
  TwSetParam(tweakBar, nullptr, "size", TW_PARAM_INT32, 2, &size);
}
Exemple #8
0
void SetUseArrowMode(TwBar* bar, const char* varName, bool32 useArrowMode, Float3 initialDirection)
{
    if(useArrowMode)
    {
        std::string dirString = "'" + ToAnsiString(initialDirection.x) + " " + ToAnsiString(initialDirection.y)
                                + " " + ToAnsiString(initialDirection.z) + "'";
        TwCall(TwSetParam(bar, varName, "arrow", TW_PARAM_CSTRING, 1, dirString.c_str()));
    }
    else
        TwCall(TwSetParam(bar, varName, "arrow", TW_PARAM_CSTRING, 1, "0"));
}
void SSAO::BuildUI() {
	TwInit(TW_DIRECT3D11, _device);
	TwWindowSize(_screenWidth, _screenHeight);
	_bar = TwNewBar("AmbientOcclusion");
	TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar into a DirectX11 application.' "); // Message added to the help bar.
	int barSize[2] = {300, 375};
	TwSetParam(_bar, NULL, "size", TW_PARAM_INT32, 2, barSize);

	TwAddVarCB(_bar, "Rad", TW_TYPE_FLOAT, SSAO::SetRad, SSAO::GetRad, this, "group=ShaderParams min=0 max=20 step=0.001 keyincr=+ keydecr=-");
	TwAddVarCB(_bar, "TotalStr", TW_TYPE_FLOAT, SSAO::SetTotStr, SSAO::GetTotStr, this, "group=ShaderParams min=0 max=50 step=0.1 keyincr=+ keydecr=-");
	TwAddVarCB(_bar, "Strength", TW_TYPE_FLOAT, SSAO::SetStrength, SSAO::GetStrength, this, "group=ShaderParams min=0.1 max=100 step=0.1 keyincr=+ keydecr=-");
	TwAddVarCB(_bar, "Offset", TW_TYPE_FLOAT, SSAO::SetOffset, SSAO::GetOffset, this, "group=ShaderParams min=0 max=100 step=0.5 keyincr=+ keydecr=-");
	TwAddVarCB(_bar, "Falloff", TW_TYPE_FLOAT, SSAO::SetFalloff, SSAO::GetFalloff, this, "group=ShaderParams min=0 max=0.01 step=0.00001 keyincr=+ keydecr=-");
	TwAddVarCB(_bar, "BlurSize", TW_TYPE_FLOAT, SSAO::SetBlur, SSAO::GetBlur, this, "group=ShaderParams min=1 max=16 step=1 keyincr=+ keydecr=-");
	TwAddButton(_bar, "Reset", SSAO::ResetButton, this, "");
	TwAddButton(_bar, "ShowDebug", SSAO::ShowDebug, this, "");

	TwEnumVal* a = new TwEnumVal[3];
	a[0].Value = 0; a[0].Label = "buddha";
	a[1].Value = 1; a[1].Label = "hairball";
	a[2].Value = 2; a[2].Label = "sib";
	_index = 0;

	TwType actMesh = TwDefineEnum("mesh", a, 3);

	TwAddVarCB(_bar, "ActiveVol", actMesh, SSAO::SetMesh, SSAO::GetMesh, this, 
		" group='Mesh' keyIncr=Backspace keyDecr=SHIFT+Backspace help='Stop or change the rotation mode.' ");

}
Exemple #10
0
void SetColor(TwBar* bar, Float3 color)
{
    int32 rgb[3] = { int32(Saturate(color.x) * 255.0f),
                     int32(Saturate(color.y) * 255.0f),
                     int32(Saturate(color.z) * 255.0f) };
    TwCall(TwSetParam(bar, nullptr, "color", TW_PARAM_INT32, 3, rgb));
}
SceneDialog::SceneDialog()
{
	// Create a tweak bar
    m_dialog = TwNewBar("Scene");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar into a DirectX11 application.' "); // Message added to the help bar.
	int barSize[2] = {200, 1060};
    TwSetParam(m_dialog, NULL, "size", TW_PARAM_INT32, 2, barSize);
	TwDefine(" Scene position='10 10' ");

	TwAddButton(m_dialog, "Load Scene", LoadAGL, this, " label='Load Scene' key=c help='Load an Agile file into the editor.' group='I/O'");
	TwAddButton(m_dialog, "Save Scene", SaveAGL, this, " label='Save Scene' key=c help='Save a scene into an Agile file.' group='I/O'");

	TwAddVarRW(m_dialog, "Rotation", TW_TYPE_QUAT4F, Scene::GetInstance()->GetQuaternionRotation(), "opened=true axisz=-z");

	TwStructMember pointMembers[] = { 
        { "X", TW_TYPE_FLOAT, offsetof(AglVector3, x), " Step=0.01 " },
        { "Y", TW_TYPE_FLOAT, offsetof(AglVector3, y), " Step=0.01 " },
		{ "Z", TW_TYPE_FLOAT, offsetof(AglVector3, z), " Step=0.01 " }};
    TwType pointType = TwDefineStruct("POINT", pointMembers, 3, sizeof(AglVector3), NULL, NULL);

	TwAddVarRW(m_dialog, "Position", pointType, Scene::GetInstance()->GetPosition(), "");

	TwAddVarRW(m_dialog, "ShowHideDiffuse", TW_TYPE_BOOLCPP, &DIFFUSEON, "group='Show/Hide'");
	TwAddVarRW(m_dialog, "ShowHideSpec", TW_TYPE_BOOLCPP, &SPECULARON, "group='Show/Hide'");
	TwAddVarRW(m_dialog, "ShowHideGlow", TW_TYPE_BOOLCPP, &GLOWON, "group='Show/Hide'");
	TwAddVarRW(m_dialog, "ShowHideNormal", TW_TYPE_BOOLCPP, &NORMALON, "group='Show/Hide'");

	m_meshDialog = new MeshDialog();
	m_materialDialog = new MaterialDialog();
	m_particleSystemDialog = new ParticleSystemDialog();
	m_mergeDialog = new MergeDialog();
}
Exemple #12
0
void SetArrowColor(TwBar* bar, const char* varName, Float3 color)
{
    int32 rgb[3] = { int32(Saturate(color.x) * 255.0f),
                     int32(Saturate(color.y) * 255.0f),
                     int32(Saturate(color.z) * 255.0f) };
    TwCall(TwSetParam(bar, varName, "arrowcolor", TW_PARAM_INT32, 3, rgb));
}
void MaterialDialog::setMaterial(int pIndex)
{
	if (m_dialog)
		TwDeleteBar(m_dialog);
	// Create a tweak bar
	m_dialog = TwNewBar("Material");
	int barSize[2] = {200, 1060};
	TwDefine(" Material position='1710 10'  ");
	TwSetParam(m_dialog, NULL, "size", TW_PARAM_INT32, 2, barSize);

	m_material = Scene::GetInstance()->GetMaterial(pIndex);

	TwAddVarCB(m_dialog, "MaterialName", TW_TYPE_CDSTRING, SetName, GetName, (void*)this, " label='Name: '");
	TwAddVarRW(m_dialog, "Ambient", TW_TYPE_COLOR3F, (void*)&m_material->ambient, " help='Light color.' group='Properties'");
	TwAddVarRW(m_dialog, "Diffuse", TW_TYPE_COLOR3F, (void*)&m_material->diffuse, " help='Light color.' group='Properties'");
	TwAddVarRW(m_dialog, "Specular", TW_TYPE_COLOR3F, (void*)&m_material->specular, " help='Light color.' group='Properties'");
	TwAddVarRW(m_dialog, "Emissive", TW_TYPE_COLOR3F, (void*)&m_material->emissive, " help='Light color.' group='Properties'");

	TwAddVarRW(m_dialog, "Opacity", TW_TYPE_FLOAT, (void*)&m_material->opacity, " help='Light color.' group='Properties' min=0.0 max=1.0 step=0.01");
	TwAddVarRW(m_dialog, "Reflectivity", TW_TYPE_FLOAT, (void*)&m_material->reflectivity, " help='Light color.' group='Properties' min=0.0 max=1.0 step=0.01");
	TwAddVarRW(m_dialog, "Shininess", TW_TYPE_FLOAT, (void*)&m_material->shininess, " help='Light color.' group='Properties' min=0.0 max=100.0 step=1.0");
	TwAddVarRW(m_dialog, "Texture Scale", TW_TYPE_FLOAT, (void*)&m_material->textureScale, " help='Light color.' group='Properties' min=0.0 max=10.0 step=0.01");

	TwAddButton(m_dialog, "Load Diffuse Texture", LoadDiffuse, this, " label='Diffuse Texture' key=c help='Load an Agile file into the editor.' group='Load'");
	TwAddButton(m_dialog, "Load Specular Texture", LoadSpecular, this, " label='Specular Texture' key=c help='Load an Agile file into the editor.' group='Load'");
	TwAddButton(m_dialog, "Load Glow Texture", LoadGlow, this, " label='Glow Texture' key=c help='Load an Agile file into the editor.' group='Load'");
	TwAddButton(m_dialog, "Load Normal Texture", LoadNormal, this, " label='Normal Texture' key=c help='Load an Agile file into the editor.' group='Load'");
	TwAddButton(m_dialog, "Load Displacement Texture", LoadDisplacement, this, " label='Displacement Texture' key=c help='Load an Agile file into the editor.' group='Load'");
	TwAddButton(m_dialog, "Load Gradient Texture", LoadGradient, this, " label='Gradient Texture' key=c help='Load an Agile file into the editor.' group='Load'");

	TwStructMember tessMembers[] = { 
		{ "Edge1", TW_TYPE_FLOAT, offsetof(AglVector4, x), " Step=0.1 min=1.0 max=64.0" },
		{ "Edge2", TW_TYPE_FLOAT, offsetof(AglVector4, y), " Step=0.1 min=1.0 max=64.0" },
		{ "Edge3", TW_TYPE_FLOAT, offsetof(AglVector4, z), " Step=0.1 min=1.0 max=64.0" },
		{ "Internal", TW_TYPE_FLOAT, offsetof(AglVector4, w), " Step=0.1 min=1.0 max=64.0" }};
	TwType tessType = TwDefineStruct("TESSELATIONFACTORS", tessMembers, 4, sizeof(AglVector4), NULL, NULL);

	TwAddVarRW(m_dialog, "Tess", tessType, &m_material->tesselationFactor, " group='Properties' ");
	TwAddVarRW(m_dialog, "Displacement", TW_TYPE_FLOAT, (void*)&m_material->displacement, " group='Properties' min=0.0 max=10.0 step=0.01");

	TwAddButton(m_dialog, "Add Layer", AddLayer, this, " label='Add Layer' key=c help='Load an Agile file into the editor.' group='Gradient Mapping'");

	TwAddButton(m_dialog, "Delete", Delete, this, "");


	if (m_material->gradientDataIndex >= 0)
	{
		AglGradient* g = Scene::GetInstance()->GetGradient(m_material->gradientDataIndex);
		vector<AglGradientMaterial*> layers = g->getLayers();
		for (unsigned int i = 0; i < layers.size(); i++)
		{
			AddLayer(g, layers[i], i);
		}
	}


	show();
}
Exemple #14
0
/*
 * @brief Displays the TwBar specified by name in data, hiding all others.
 */
void TW_CALL Ui_ShowBar(void *data) {
	const char *name = (const char *) data;
	int32_t hidden = 0, visible = 1;

	Com_Debug("%s\n", name);

	if (ui.top) {
		TwSetParam(ui.top, NULL, "visible", TW_PARAM_INT32, 1, &hidden);
	}

	ui.top = TwGetBarByName(name);

	if (ui.top) {
		TwSetParam(ui.top, NULL, "visible", TW_PARAM_INT32, 1, &visible);
	}

	// then center the visible bar
	Ui_CenterBar((void *) name);
}
void Game::Initialise(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
{
	//Initialise Input
	m_Input = new Input;
	m_Input->Initialise(hinstance,hwnd,screenWidth,screenHeight);

	//Initialise Graphics
	m_Graphics = new GameRenderer;
	m_Graphics->Initialise(screenWidth, screenHeight, hwnd);


	//Initialise AntTweakBar
	TwInit(TW_DIRECT3D11, m_Graphics->GetDevice());
	TwWindowSize(screenWidth, screenHeight);

	//Create the camera
	m_Camera = new Camera;
	m_Camera->SetPosition(0, 25, -75);

	m_Camera->SetRotation(10, 0, 0);

	//Create the skybox
	m_sky = new Skybox;
	m_sky->Initialise(m_Graphics->GetDevice(), hwnd);
	m_sky->SetPosition(XMFLOAT3(0, 0, 0));

	//Create the ant tweak bar
	m_gameTweakBar = TwNewBar("Water Wave Simulation");
	int barSize[2] = { 200, 680 };
	TwSetParam(m_gameTweakBar, NULL, "size", TW_PARAM_INT32, 2, barSize);

	//Toggle wireframe on/off
	TwAddButton(m_gameTweakBar, "comment1", Callback, m_Graphics, " label='Toggle Wireframe' ");


	//Create the wave manager
	m_waveManager = new WaveManager;
	TwAddButton(m_gameTweakBar, "comment2", NextPreset, m_waveManager, " label='Next Preset' ");
	m_waveManager->Initialise(m_Graphics->GetDevice(), m_Graphics->GetDeviceContext(), m_gameTweakBar);
	
	m_waveManager->CreateWater(XMFLOAT3(-480, 0, -480), m_Graphics->GetDevice(), m_Graphics->GetDeviceContext(), hwnd);

	m_hwnd = hwnd;

	//Create terrain 
	Mesh* terrainMesh = new Mesh;
	terrainMesh->Initialise(m_Graphics->GetDevice(), m_Graphics->GetDeviceContext(), "terrain.txt", "../WaveSim/Data/Textures/sand.tga");
	//Use same mesh for multiple instances
	CreateGameobject(new GameObject, terrainMesh, XMFLOAT3(1500, -10, 2000));
	CreateGameobject(new GameObject, terrainMesh, XMFLOAT3(10, -10, 1000));
	CreateGameobject(new GameObject, terrainMesh, XMFLOAT3(-1000, -10, 0));
	Console::Log("Terrain Initalised...");
	//Create directional light
	CreateLight();
}
void AtmosphereSample::UpdateGUI()
{
    auto bar = TwGetBarByName( "Settings" );

    {
        int32_t IsVisible = m_bEnableLightScattering ? 1 : 0;
        TwSetParam( bar, "Scattering", "visible", TW_PARAM_INT32, 1, &IsVisible );
        TwSetParam( bar, "ToneMapping", "visible", TW_PARAM_INT32, 1, &IsVisible );
    }

    bool bIsEpipolarSampling = m_PPAttribs.m_uiLightSctrTechnique == LIGHT_SCTR_TECHNIQUE_EPIPOLAR_SAMPLING;
    TwSetEnabled( bar, "NumSlices", bIsEpipolarSampling );
    TwSetEnabled( bar, "MaxSamples", bIsEpipolarSampling );
    TwSetEnabled( bar, "IntialStep", bIsEpipolarSampling );
    TwSetEnabled( bar, "EpipoleSamplingDensity", bIsEpipolarSampling );
    TwSetEnabled( bar, "RefinementThreshold", bIsEpipolarSampling );
    TwSetEnabled( bar, "1DMinMaxOptimization", bIsEpipolarSampling );
    TwSetEnabled( bar, "OptimizeSampleLocations", bIsEpipolarSampling );
    TwSetEnabled( bar, "ShowSampling", bIsEpipolarSampling );
    TwSetEnabled( bar, "CorrectScattering", bIsEpipolarSampling );
    TwSetEnabled( bar, "ShowDepthBreaks", bIsEpipolarSampling && m_PPAttribs.m_bCorrectScatteringAtDepthBreaks != 0);
    TwSetEnabled( bar, "NumIntegrationSteps", !m_PPAttribs.m_bEnableLightShafts && m_PPAttribs.m_uiSingleScatteringMode == SINGLE_SCTR_MODE_INTEGRATION );

    {
        int32_t IsVisible = m_PPAttribs.m_bUseCustomSctrCoeffs ? 1 : 0;
        TwSetParam( bar, "RayleighColor", "visible", TW_PARAM_INT32, 1, &IsVisible );
        TwSetParam( bar, "MieColor", "visible", TW_PARAM_INT32, 1, &IsVisible );
        TwSetParam( bar, "UpdateCoeffsBtn", "visible", TW_PARAM_INT32, 1, &IsVisible );
    }

    TwSetEnabled( bar, "WhitePoint", m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_MODE_REINHARD_MOD ||
                                     m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_MODE_UNCHARTED2 ||
                                     m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_LOGARITHMIC ||
                                     m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_ADAPTIVE_LOG );

    TwSetEnabled( bar, "LumSaturation", m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_MODE_EXP ||
                                        m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_MODE_REINHARD ||
                                        m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_MODE_REINHARD_MOD ||
                                        m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_LOGARITHMIC ||
                                        m_PPAttribs.m_uiToneMappingMode == TONE_MAPPING_ADAPTIVE_LOG );
    TwSetEnabled( bar, "LightAdaptation", m_PPAttribs.m_bAutoExposure ? true : false );
}
Exemple #17
0
void engine::GameManager::InitializeTweakBars()
{
	m_gameBar = TwNewBar("GameBar");
	//TwAddVarRW(m_gameBar, "currentCamera", TW_TYPE_UINT32, &m_currentCameraIndex, " label='Current camera' ");
	//TwSetParam(m_gameBar, "currentCamera", "max", TW_PARAM_INT32, 1, &m_cameraCountMinusOne);
	TwSetParam(m_gameBar, nullptr, "visible", TW_PARAM_CSTRING, 1, "true"); // Hide the bar at startup

	// TODO: Move these to PlayGameState InitializeTweakBars() method.
	//TwAddVarRO(m_gameBar, "ambientLight", TW_TYPE_COLOR4F, &m_ambientLightColor, " label='Color' group='Ambient light'");
	//TwAddVarRW(m_gameBar, "ambientLightDaytime", TW_TYPE_COLOR4F, &m_ambientDaytimeColor, " label='Daytime color' group='Ambient light'");
	//TwAddVarRW(m_gameBar, "ambientLightSunNearHorizon", TW_TYPE_COLOR4F, &m_ambientSunNearHorizonColor, " label='Sun near horizon color' group='Ambient light'");
	//TwAddVarRW(m_gameBar, "ambientLightNighttime", TW_TYPE_COLOR4F, &m_ambientNighttimeColor, " label='Nighttime color' group='Ambient light'");
}
	bool TweakBar::Initialize()
	{
		TwDefine(" GLOBAL fontscaling=2 ");
		if(!TwInit(TW_OPENGL, NULL))
		{
			Engine::Error("Initialization Failed: Tweak Bar");
			return false;
		}

		m_bar = TwNewBar("CONTROLS");
		TwWindowSize(TheGraphics::Instance()->GetWidth(), TheGraphics::Instance()->GetHeight());
		int barSize[2]	= { 1280, 160 };
		int barPos[2]	= { 0, 544 };
		TwSetParam(m_bar, NULL, "size", TW_PARAM_INT32, 2, barSize);
		TwSetParam(m_bar, NULL, "position", TW_PARAM_INT32, 2, barPos);
		TwDefine(" CONTROLS alpha=255 movable=false fontsize=3 color='100 100 100' iconifiable=false resizable=false");

		m_act = TwNewBar("GROUP");
		TwDefine(" GROUP size='256 60' position='1024 520' alwaystop=true alpha=255 movable=false fontsize=3 color='150 70 70' iconifiable=false resizable=false");
		TwSetTopBar(m_act);
		return true;
	}
void GetFilmRewindRate_main(int dummy1,int dummy2,float *pRewindRate)
{
	static float fRewindRate = 0.0f;
	//ファイル巻取り率取得
	fRewindRate = *pRewindRate * 100;

	static bool bFirstCall = true;
	if(bFirstCall){
		TwAddVarRO(TW_Global::bar,TW_Global::sRewindRate, TW_TYPE_FLOAT, &fRewindRate, 
			   " label='Strip length' help='test' ");
		bFirstCall = false;
	}

	TwSetParam(TW_Global::bar, TW_Global::sRewindRate,"label",TW_PARAM_CSTRING,1,TW_Global::sRewindRate);

}
    void InitDialogs()
    {
        settings_bar = TwNewBar("Settings");
        TwDefine("Settings color='72 115 1' alpha=32 text=light valueswidth=100 iconified=true resizable=false");
        int barSize[2] = {400, 200};
        TwSetParam(settings_bar, nullptr, "size", TW_PARAM_INT32, 2, barSize);

        TwAddVarRW(settings_bar, "Focus Distance", TW_TYPE_FLOAT, &g_focal_distance, "group='Depth of Field' min=0 max=1 step=0.0025 keydecr=o keyincr=p");
        TwAddVarRW(settings_bar, "Focus Range", TW_TYPE_FLOAT, &g_focal_range, "group='Depth of Field' min=0.0 max=0.5 step=0.0025 keydecr=k keyincr=l");
        TwAddVarRW(settings_bar, "Aperture", TW_TYPE_FLOAT, &g_focal_aperture, "group='Depth of Field' min=0.01 max=1.00 step=0.01 keydecr=n keyincr=m");

        {
            TwEnumVal enumModeTypeEV[] = {
                { VIEW_MODE_DOF, "SAT Blur" },
                { VIEW_MODE_BLUR_SIZE, "Blur Size" }
            };
            TwType enumModeType = TwDefineEnum("RenderMode", enumModeTypeEV, sizeof(enumModeTypeEV) / sizeof(enumModeTypeEV[0]));
            TwAddVarRW(settings_bar, "View Mode", enumModeType, &g_view_mode, "keyIncr=v keyDecr=V");
        }
    }
//  Callback function called when the 'AutoRotate' variable value of the tweak bar has changed
void TW_CALL SetAutoRotateCB(const void *value, void *clientData)
{
	SubWindowData *win;
	
	win = (SubWindowData *)clientData;
    win->AutoRotate = *(const int *)value; // copy value to win->AutoRotate

    if (win->AutoRotate != 0) 
    {
        // init rotation
        win->RotateTime = GetTimeMs();
        win->RotateStart[0] = win->Rotation[0];
        win->RotateStart[1] = win->Rotation[1];
        win->RotateStart[2] = win->Rotation[2];
        win->RotateStart[3] = win->Rotation[3];
    }

    // make Rotation variable read-only or read-write
    TwSetCurrentWindow(win->WinID);
    TwSetParam(win->Bar, "ObjRotation", "readonly", TW_PARAM_INT32, 1, &win->AutoRotate);
}
Exemple #22
0
/*
 * @brief Centers the TwBar by the specified name.
 */
void TW_CALL Ui_CenterBar(void *data) {
	const char *name = (const char *) data;
	TwBar *bar = TwGetBarByName(name);

	if (bar) {
		double size[2], position[2];
		TwGetParam(bar, NULL, "size", TW_PARAM_DOUBLE, 2, size);

		position[0] = (r_context.width - size[0]) / 2.0;
		position[1] = (r_context.height - size[1]) / 2.0;

		if (position[0] < (r_pixel_t) 0)
			position[0] = (r_pixel_t) 0;
		if (position[1] < (r_pixel_t) 0)
			position[1] = (r_pixel_t) 0;
		position[0] = (r_pixel_t) position[0];
		position[1] = (r_pixel_t) position[1];

		// Com_Debug("%s: %4f, %4f\n", name, position[0], position[1]);

		TwSetParam(bar, NULL, "position", TW_PARAM_DOUBLE, 2, position);
	}
}
MillerRender::MillerRender()
{
    gLookAtOther = true;
    gPosition1 = vec3(-1.5f, 0.0f, 0.0f);
   //  gOrientation1;
     // Initialise GLFW
     if( !glfwInit() )
     {
         fprintf( stderr, "Failed to initialize GLFW\n" );
         //return -1;exit
     }

     glfwWindowHint(GLFW_SAMPLES, 4);
     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

     // Open a window and create its OpenGL context
     window = glfwCreateWindow( 1024, 768, "Tutorial 17 - Rotations", NULL, NULL);
     if( window == NULL ){
         fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
         glfwTerminate();
        // return -1;exit
     }
     glfwMakeContextCurrent(window);

     // Initialize GLEW
     glewExperimental = true; // Needed for core profile
     if (glewInit() != GLEW_OK) {
         fprintf(stderr, "Failed to initialize GLEW\n");
        // return -1; exit
     }


     //initGL(window);

     // Initialize the GUI
     TwInit(TW_OPENGL_CORE, NULL);
     TwWindowSize(1024, 768);
     TwBar * EulerGUI = TwNewBar("Euler settings");
    //     TwBar * QuaternionGUI = TwNewBar("Quaternion settings");
     TwSetParam(EulerGUI, NULL, "refresh", TW_PARAM_CSTRING, 1, "0.1");
  //       TwSetParam(QuaternionGUI, NULL, "position", TW_PARAM_CSTRING, 1, "808 16");

     TwAddVarRW(EulerGUI, "Euler X", TW_TYPE_FLOAT, &gOrientation1.x, "step=0.01");
     TwAddVarRW(EulerGUI, "Euler Y", TW_TYPE_FLOAT, &gOrientation1.y, "step=0.01");
     TwAddVarRW(EulerGUI, "Euler Z", TW_TYPE_FLOAT, &gOrientation1.z, "step=0.01");
     TwAddVarRW(EulerGUI, "Pos X"  , TW_TYPE_FLOAT, &gPosition1.x, "step=0.1");
     TwAddVarRW(EulerGUI, "Pos Y"  , TW_TYPE_FLOAT, &gPosition1.y, "step=0.1");
     TwAddVarRW(EulerGUI, "Pos Z"  , TW_TYPE_FLOAT, &gPosition1.z, "step=0.1");


     //TwAddVarRW(QuaternionGUI, "Quaternion", TW_TYPE_QUAT4F, &gOrientation2, "showval=true open=true ");
     //TwAddVarRW(QuaternionGUI, "Use LookAt", TW_TYPE_BOOL8 , &gLookAtOther, "help='Look at the other monkey ?'");

     // Set GLFW event callbacks. I removed glfwSetWindowSizeCallback for conciseness
     glfwSetMouseButtonCallback(window, (GLFWmousebuttonfun)TwEventMouseButtonGLFW); // - Directly redirect GLFW mouse button events to AntTweakBar
     glfwSetCursorPosCallback(window, (GLFWcursorposfun)TwEventMousePosGLFW);          // - Directly redirect GLFW mouse position events to AntTweakBar
     glfwSetScrollCallback(window, (GLFWscrollfun)TwEventMouseWheelGLFW);    // - Directly redirect GLFW mouse wheel events to AntTweakBar
     glfwSetKeyCallback(window, (GLFWkeyfun)TwEventKeyGLFW);                         // - Directly redirect GLFW key events to AntTweakBar
     glfwSetCharCallback(window, (GLFWcharfun)TwEventCharGLFW);                      // - Directly redirect GLFW char events to AntTweakBar



     // Ensure we can capture the escape key being pressed below
     glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
     glfwSetCursorPos(window, 1024/2, 768/2);

     // Dark blue background
     glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

     // Enable depth test
     glEnable(GL_DEPTH_TEST);
     // Accept fragment if it closer to the camera than the former one
     glDepthFunc(GL_LESS);

     // Cull triangles which normal is not towards the camera
     glEnable(GL_CULL_FACE);


     // Read our .obj file
     std::vector<unsigned short> indices;
     std::vector<glm::vec3> indexed_vertices;
     std::vector<glm::vec2> indexed_uvs;
     std::vector<glm::vec3> indexed_normals;

     // load model
     //char* file = "/home/kaeon/MyProgram/src/rim.stl";
     //char* file = "/home/kaeon/MyProgram/src/box.stl";
     char* file = "/home/kaeon/MyProgram/OpenGL-33-myproject/src/cube.obj";
     //char* file = "/home/kaeon/MyProgram/OpenGL-33-myproject/src/ES4.STL";

     //char* file = "/home/kaeon/MyProgram/src/suzanne.obj";
     //char* file = "/home/kaeon/MyProgram/src/monkey.obj";
     //loadOBJ(file,outIndices,vertexArray,uvArray,normalArray);

     //bool res = loadAssImp(file, indices, indexed_vertices, indexed_uvs, indexed_normals);
     loadOBJ(file, indices,indexed_vertices,indexed_uvs,indexed_normals);

     ChangeVerticesCoord(indexed_vertices);



     GLuint VertexArrayID;   
     glGenVertexArrays(1, &VertexArrayID);
     glBindVertexArray(VertexArrayID);
     GLuint WP_VertexArrayID;
     glGenVertexArrays(1, &WP_VertexArrayID);
     glBindVertexArray(WP_VertexArrayID);

     // Create and compile our GLSL program from the shaders
     //GLuint programID = LoadShaders( "/home/kaeon/MyProgram/opengl_test_success/SimpleTransform.vertexshader", "/home/kaeon/MyProgram/opengl_test_success/SingleColor.fragmentshader" );
     programID = LoadShaders(
                 "/home/kaeon/MyProgram/OpenGL-33-myproject/src/StandardShading.vertexshader",
                 "/home/kaeon/MyProgram/OpenGL-33-myproject/src/StandardShading.fragmentshader" );


     // Get a handle for our "MVP" uniform
     MatrixID = glGetUniformLocation(programID, "MVP");
     ViewMatrixID = glGetUniformLocation(programID, "V");
     ModelMatrixID = glGetUniformLocation(programID, "M");

     // Load the texture
     Texture = loadDDS("/home/kaeon/MyProgram/OpenGL-33-myproject/src/uvmap.DDS");

     // Get a handle for our "myTextureSampler" uniform
     TextureID  = glGetUniformLocation(programID, "myTextureSampler");


     /***==================== My triangle=============================e **/
     std::vector<unsigned short> indices2;//(101*101);
     std::vector<glm::vec3> indexed_vertices2;//(101*101);
     std::vector<glm::vec2> indexed_uvs2;
     std::vector<glm::vec3> indexed_normals2;
     //
     /*
     for (int i = 0; i < 101; i++) {
         for (int j = 0; j < 101; j++) {
             double z = sin(float(i)/10.0)*sin(float(i)/10.0);
             indexed_vertices2[i] = glm::vec3( i-50, j-50, z-20.0);
         }
     }*/
     //   CalculateIndices(indices2);
     // calculate indices
     //loadOBJ("/home/kaeon/MyProgram/OpenGL-33-myproject/src/ES4.STL", indices2,indexed_vertices2,indexed_uvs2,indexed_normals2);
     loadOBJ("/home/kaeon/MyProgram/OpenGL-33-myproject/src/cube.obj", indices2,indexed_vertices2,indexed_uvs2,indexed_normals2);

     ChangeVerticesCoord(indexed_vertices2);
     /***==================================================================**/



     // Load it into a VBO

     GLuint vertexbuffer;
     glGenBuffers(1, &vertexbuffer);
     glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
//     glBufferData(GL_ARRAY_BUFFER, indexed_vertices.size() * sizeof(glm::vec3), &indexed_vertices[0], GL_STATIC_DRAW);
     glBufferData(GL_ARRAY_BUFFER, (indexed_vertices.size() + indexed_vertices2.size()) * sizeof(glm::vec3), 0, GL_STATIC_DRAW);
     glBufferSubData(GL_ARRAY_BUFFER, 0 ,indexed_vertices.size()*sizeof(glm::vec3), &indexed_vertices[0] );
     glBufferSubData(GL_ARRAY_BUFFER, indexed_vertices.size()*sizeof(glm::vec3), indexed_vertices2.size()*sizeof(glm::vec3), &indexed_vertices2[0]);


     GLuint uvbuffer;
     glGenBuffers(1, &uvbuffer);
     glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
     //glBufferData(GL_ARRAY_BUFFER, indexed_uvs.size() * sizeof(glm::vec2), &indexed_uvs[0], GL_STATIC_DRAW);
     glBufferData(GL_ARRAY_BUFFER, (indexed_uvs.size()+indexed_uvs2.size() )* sizeof(glm::vec2), 0, GL_STATIC_DRAW);
     glBufferSubData(GL_ARRAY_BUFFER, 0 ,indexed_uvs.size()*sizeof(glm::vec2), &indexed_uvs[0] );
     glBufferSubData(GL_ARRAY_BUFFER, indexed_uvs.size()*sizeof(glm::vec2), indexed_uvs2.size()*sizeof(glm::vec2), &indexed_uvs2[0]);

     GLuint normalbuffer;
     glGenBuffers(1, &normalbuffer);
     glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
     //glBufferData(GL_ARRAY_BUFFER, indexed_normals.size() * sizeof(glm::vec3), &indexed_normals[0], GL_STATIC_DRAW);
     glBufferData(GL_ARRAY_BUFFER, (indexed_normals.size()+indexed_normals2.size() )* sizeof(glm::vec3), 0, GL_STATIC_DRAW);
     glBufferSubData(GL_ARRAY_BUFFER, 0 ,indexed_normals.size()*sizeof(glm::vec3), &indexed_normals[0] );
     glBufferSubData(GL_ARRAY_BUFFER, indexed_normals.size()*sizeof(glm::vec3), indexed_normals2.size()*sizeof(glm::vec3), &indexed_normals2[0]);


     // Generate a buffer for the indices as well
     GLuint elementbuffer;
     glGenBuffers(1, &elementbuffer);
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);
     //glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned short), &indices[0] , GL_STATIC_DRAW);
     glBufferData(GL_ELEMENT_ARRAY_BUFFER, (indices.size()+indices2.size() )* sizeof(unsigned short), 0, GL_STATIC_DRAW);
     glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0 ,indices.size()*sizeof(unsigned short), &indices[0] );
     glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, indices.size()*sizeof(unsigned short), indices2.size()*sizeof(unsigned short), &indices2[0]);

     // Get a handle for our "LightPosition" uniform
     glUseProgram(programID);
     GLuint LightID = glGetUniformLocation(programID, "LightPosition_worldspace");


     // For speed computation
     double lastTime = glfwGetTime();
     double lastFrameTime = lastTime;
     int nbFrames = 0;
     std::cout<<"test0"<<std::endl;
         float tt = 0.0;
     do{

         // Measure speed
         double currentTime = glfwGetTime();

         float deltaTime = (float)(currentTime - lastFrameTime);
         lastFrameTime = currentTime;

         nbFrames++;
         if ( currentTime - lastTime >= 1.0 ){ // If last prinf() was more than 1sec ago
             // printf and reset
             printf("%f ms/frame\n", 1000.0/double(nbFrames));
             nbFrames = 0;
             lastTime += 1.0;
         }


         // Clear the screen
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

         // Use our shader
         glUseProgram(programID);

         /*
         // Compute the MVP matrix from keyboard and mouse input
      //   computeMatricesFromInputs();
         glm::mat4 ProjectionMatrix = getProjectionMatrix();
         glm::mat4 ViewMatrix = getViewMatrix();
         glm::mat4 ModelMatrix = glm::mat4(1.0);
         glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;

         // Send our transformation to the currently bound shader,
         // in the "MVP" uniform
         glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
         glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &ModelMatrix[0][0]);
         glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &ViewMatrix[0][0]);
 */
         glm::mat4 ProjectionMatrix = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 110.0f);// display range
         glm::mat4 ViewMatrix = glm::lookAt(
                     //glm::vec3( 0, 0, 70 ), // Camera is here
                     glm::vec3( 20,30, 70 ), // Camera is here
                     //glm::vec3(gOrientation1.x,0,0),// and looks here
                    glm::vec3( 0, 0, 0 ), // and looks here
                     //glm::vec3( 0, 1, 0 )  // Head is up (set to 0,-1,0 to look upside-down)
                     glm::vec3( 3, 10, 5 )  // Head is up (set to 0,-1,0 to look upside-down)
                     );


         glm::vec3 lightPos = glm::vec3(gPosition1.x,2,10);
           //glm::vec3 lightPos = glm::vec3(0,2,10);
         glUniform3f(LightID, lightPos.x, lightPos.y, lightPos.z);

         // Bind our texture in Texture Unit 0
         glActiveTexture(GL_TEXTURE0);
         glBindTexture(GL_TEXTURE_2D, Texture);
         // Set our "myTextureSampler" sampler to user Texture Unit 0
         glUniform1i(TextureID, 0);

         // 1rst attribute buffer : vertices
         glEnableVertexAttribArray(0);
         glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
         glVertexAttribPointer(
                     0,                  // attribute
                     3,                  // size
                     GL_FLOAT,           // type
                     GL_FALSE,           // normalized?
                     0,                  // stride
                     (void*)0            // array buffer offset
                     );


         // 2nd attribute buffer : UVs
         glEnableVertexAttribArray(1);
         glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
         glVertexAttribPointer(
                     1,                                // attribute
                     2,                                // size
                     GL_FLOAT,                         // type
                     GL_FALSE,                         // normalized?
                     0,                                // stride
                     (void*)0                          // array buffer offset
                     );

         // 3rd attribute buffer : normals
         glEnableVertexAttribArray(2);
         glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
         glVertexAttribPointer(
                     2,                                // attribute
                     3,                                // size
                     GL_FLOAT,                         // type
                     GL_FALSE,                         // normalized?
                     0,                                // stride
                     (void*)0                          // array buffer offset
                     );

         // Index buffer
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);


         glUniform3f(LightID, lightPos.x, lightPos.y, lightPos.z);


         { // Euler

             // As an example, rotate arount the vertical axis at 180\B0/sec
         /*    gOrientation1.z += 3.14159f/2.0f * deltaTime * 5;
             gOrientation1.x = 3.14159f/2;
             gPosition1.y = 40;

             // Build the model matrix
             glm::mat4 RotationMatrix = eulerAngleYXZ(gOrientation1.y, gOrientation1.x, gOrientation1.z);
             glm::mat4 TranslationMatrix = translate(mat4(), gPosition1); // A bit to the left
             glm::mat4 ScalingMatrix = scale(mat4(), vec3(1.0f, 1.0f, 1.0f));
             glm::mat4 ModelMatrix = TranslationMatrix * RotationMatrix * ScalingMatrix;*/
             gOrientation1.z += 3.14159f/2.0f * deltaTime;
             gOrientation1.x = 20;3.14159f/2;
             gPosition1.y = 10;
             tt = tt + 0.01f;
             gPosition1.x = 20.0*sin(tt);
             //gPosition1.z = tt;//20.0*sin(tt);

             // Build the model matrix
             glm::mat4 RotationMatrix = eulerAngleYXZ(gOrientation1.y, gOrientation1.x, gOrientation1.z);
             glm::mat4 TranslationMatrix = translate(mat4(), gPosition1); // A bit to the left
             glm::mat4 ScalingMatrix = scale(mat4(), vec3(1.0f, 1.0f, 1.0f));
            glm::mat4 ModelMatrix = TranslationMatrix * RotationMatrix * ScalingMatrix;
            //  glm::mat4 ModelMatrix = eulerAngleYXZ((float)3,(float)0,(float)0)*translate(mat4(), glm::vec3(5,0,0)) *TranslationMatrix* RotationMatrix * ScalingMatrix;



             glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;

             // Send our transformation to the currently bound shader,
             // in the "MVP" uniform
             glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
             glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &ModelMatrix[0][0]);
             glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &ViewMatrix[0][0]);



             // Draw the triangles !
             glDrawElements(
                         GL_TRIANGLES,      // mode
                         indices.size(),    // count
                         GL_UNSIGNED_SHORT,   // type
                         (void*)0           // element array buffer offset
                         );

         }
//=============================================================================//
         glEnableVertexAttribArray(0);
         glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
         glVertexAttribPointer(
                     0,                  // attribute
                     3,                  // size
                     GL_FLOAT,           // type
                     GL_FALSE,           // normalized?
                     0,                  // stride
                     (void*)(0+indexed_vertices.size()*sizeof(glm::vec3))            // array buffer offset
                     );


         // 2nd attribute buffer : UVs
         glEnableVertexAttribArray(1);
         glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
         glVertexAttribPointer(
                     1,                                // attribute
                     2,                                // size
                     GL_FLOAT,                         // type
                     GL_FALSE,                         // normalized?
                     0,                                // stride
                     (void*)(0+indexed_uvs.size()*sizeof(glm::vec2))                          // array buffer offset
                     );

         // 3rd attribute buffer : normals
         glEnableVertexAttribArray(2);
         glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
         glVertexAttribPointer(
                     2,                                // attribute
                     3,                                // size
                     GL_FLOAT,                         // type
                     GL_FALSE,                         // normalized?
                     0,                                // stride
                     (void*)(0+indexed_normals.size()*sizeof(glm::vec3))                          // array buffer offset
                     );

         // Index buffer
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);


         glUniform3f(LightID, lightPos.x, lightPos.y, lightPos.z);


         { // Euler

             // As an example, rotate arount the vertical axis at 180\B0/sec
         /*    gOrientation1.z += 3.14159f/2.0f * deltaTime * 5;
             gOrientation1.x = 3.14159f/2;
             gPosition1.y = 40;

             // Build the model matrix
             glm::mat4 RotationMatrix = eulerAngleYXZ(gOrientation1.y, gOrientation1.x, gOrientation1.z);
             glm::mat4 TranslationMatrix = translate(mat4(), gPosition1); // A bit to the left
             glm::mat4 ScalingMatrix = scale(mat4(), vec3(1.0f, 1.0f, 1.0f));
             glm::mat4 ModelMatrix = TranslationMatrix * RotationMatrix * ScalingMatrix;*/
             gOrientation1.z += 3.14159f/2.0f * deltaTime/1000.0;
             gOrientation1.x = 3.14159f/2;
             gPosition1.y = 10;40;
             tt = tt + 0.01f;
             gPosition1.x = 20.0*sin(tt/100.0);
             //gPosition1.z = tt;//20.0*sin(tt);

             // Build the model matrix
             glm::mat4 RotationMatrix = eulerAngleYXZ(gOrientation1.y, gOrientation1.x, gOrientation1.z);
             glm::mat4 TranslationMatrix = translate(mat4(), gPosition1); // A bit to the left
             glm::mat4 ScalingMatrix = scale(mat4(), vec3(1.0f, 1.0f, 1.0f));
            glm::mat4 ModelMatrix = TranslationMatrix * RotationMatrix * ScalingMatrix;
            //  glm::mat4 ModelMatrix = eulerAngleYXZ((float)3,(float)0,(float)0)*translate(mat4(), glm::vec3(5,0,0)) *TranslationMatrix* RotationMatrix * ScalingMatrix;



             glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;

             // Send our transformation to the currently bound shader,
             // in the "MVP" uniform
             glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
             glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &ModelMatrix[0][0]);
             glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &ViewMatrix[0][0]);



             // Draw the triangles !
             glDrawElements(
                         GL_TRIANGLES,      // mode
                         indices2.size(),    // count
                         GL_UNSIGNED_SHORT,   // type
                         (void*)(0 + indices.size())           // element array buffer offset
                         );

         }


         //======================================================================================//



         glDisableVertexAttribArray(0);
         glDisableVertexAttribArray(1);
         glDisableVertexAttribArray(2);

         // Draw GUI
         TwDraw();

         // Swap buffers
         glfwSwapBuffers(window);
         glfwPollEvents();

     } // Check if the ESC key was pressed or the window was closed
     while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
            glfwWindowShouldClose(window) == 0 );

     // Cleanup VBO and shader
     glDeleteBuffers(1, &vertexbuffer);
     glDeleteBuffers(1, &uvbuffer);
     glDeleteBuffers(1, &normalbuffer);
     glDeleteBuffers(1, &elementbuffer);
     glDeleteProgram(programID);
     glDeleteTextures(1, &Texture);
     glDeleteVertexArrays(1, &VertexArrayID);
     glDeleteVertexArrays(1, &WP_VertexArrayID);
}
Exemple #24
0
void InitializeBar()
{
    ///@note Bad size errors will be thrown if this is not called before bar creation.
    TwWindowSize(g_auxWindow_w, g_auxWindow_h);

    // Create a tweak bar
    g_pTweakbar = TwNewBar("TweakBar");
    g_app.m_pTweakbar = g_pTweakbar;

    TwDefine(" GLOBAL fontsize=3 ");
    TwDefine(" TweakBar size='300 700' ");

    TwAddButton(g_pTweakbar, "Disable VSync", DisableVSyncCB, NULL, " group='VSync' ");
    TwAddButton(g_pTweakbar, "Enable VSync", EnableVSyncCB, NULL, " group='VSync' ");
    TwAddButton(g_pTweakbar, "Adaptive VSync", AdaptiveVSyncCB, NULL, " group='VSync' ");

    TwAddVarCB(g_pTweakbar, "Display FPS", TW_TYPE_UINT32, NULL, GetDisplayFPS, NULL, " group='Performance' ");

    TwAddVarRW(g_pTweakbar, "Target FPS", TW_TYPE_INT32, &g_targetFPS,
               " min=45 max=200 group='Performance' ");

    TwAddVarRW(g_pTweakbar, "FBO Scale", TW_TYPE_FLOAT, g_app.GetFBOScalePointer(),
               " min=0.05 max=1.0 step=0.005 group='Performance' ");
    TwAddVarRW(g_pTweakbar, "Dynamic FBO Scale", TW_TYPE_BOOLCPP, &g_dynamicallyScaleFBO,
               "  group='Performance' ");
    TwAddVarRW(g_pTweakbar, "DynFBO Smooth", TW_TYPE_FLOAT, &g_fpsSmoothingFactor,
               " min=0.001 max=1.0 step=0.001 group='Performance' ");
    TwAddVarRW(g_pTweakbar, "FPS Delta Threshold", TW_TYPE_FLOAT, &g_fpsDeltaThreshold,
               " min=0.0 max=100.0 step=1.0 group='Performance' ");
    TwAddVarRW(g_pTweakbar, "CinemaScope", TW_TYPE_FLOAT, &g_app.m_cinemaScopeFactor,
               " min=0.0 max=0.95 step=0.005 group='Performance' ");


    TwAddButton(g_pTweakbar, "Recenter Pose", RecenterPoseCB, NULL, " group='Position' ");
    TwAddButton(g_pTweakbar, "Standing", StandingCB, NULL, " group='Position' ");
    TwAddButton(g_pTweakbar, "Sitting", SittingCB, NULL, " group='Position' ");



    TwAddButton(g_pTweakbar, "Reset Timer", ResetTimerCB, &g_app.m_shaderToyScene,
        " label='Reset Timer' group='Shader' ");

    TwAddVarRW(g_pTweakbar, "head Size", TW_TYPE_FLOAT, &g_app.m_headSize,
               " label='head Size' precision=4 min=0.0001 step=0.001 group='Shader' ");



    TwAddVarRW(g_pTweakbar, "Draw Scene", TW_TYPE_BOOLCPP, &g_app.m_scene.m_bDraw,
               "  group='Scene' ");

    TwAddVarRW(g_pTweakbar, "Draw HydraScene", TW_TYPE_BOOLCPP, &g_app.m_hydraScene.m_bDraw,
               "  group='HydraScene' ");
    TwAddVarRW(g_pTweakbar, "Hydra Location x", TW_TYPE_FLOAT, &g_app.m_fm.m_baseOffset.x,
               " min=-10 max=10 step=0.05 group='HydraScene' ");
    TwAddVarRW(g_pTweakbar, "Hydra Location y", TW_TYPE_FLOAT, &g_app.m_fm.m_baseOffset.y,
               " min=-10 max=10 step=0.05 group='HydraScene' ");
    TwAddVarRW(g_pTweakbar, "Hydra Location z", TW_TYPE_FLOAT, &g_app.m_fm.m_baseOffset.z,
               " min=-10 max=10 step=0.05 group='HydraScene' ");

    TwAddVarRW(g_pTweakbar, "Draw RaymarchScene", TW_TYPE_BOOLCPP, &g_app.m_raymarchScene.m_bDraw,
               "  group='RaymarchScene' ");

    int opened = 0;
    TwSetParam(g_pTweakbar, "Scene", "opened", TW_PARAM_INT32, 1, &opened);
    TwSetParam(g_pTweakbar, "HydraScene", "opened", TW_PARAM_INT32, 1, &opened);
    TwSetParam(g_pTweakbar, "RaymarchScene", "opened", TW_PARAM_INT32, 1, &opened);
}
void AtmosphereSample::Initialize(IRenderDevice *pDevice, IDeviceContext **ppContexts, Uint32 NumDeferredCtx, ISwapChain *pSwapChain)
{
    const auto& deviceCaps = pDevice->GetDeviceCaps();
    if(!deviceCaps.bComputeShadersSupported)
    {
        throw std::runtime_error("Compute shaders are required to run this sample");
    }

    SampleBase::Initialize(pDevice, ppContexts, NumDeferredCtx, pSwapChain);

    m_bIsDXDevice = deviceCaps.DevType == DeviceType::D3D11 ||  deviceCaps.DevType == DeviceType::D3D12;
    if( pDevice->GetDeviceCaps().DevType == DeviceType::OpenGLES )
    {
        m_uiShadowMapResolution = 512;
        m_PPAttribs.m_iFirstCascade = 2;
        m_PPAttribs.m_uiSingleScatteringMode = SINGLE_SCTR_MODE_LUT;
        m_TerrainRenderParams.m_iNumShadowCascades = 4;
        m_TerrainRenderParams.m_iNumRings = 10;
        m_TerrainRenderParams.m_TexturingMode = RenderingParams::TM_MATERIAL_MASK;
    }

    m_f4CustomRlghBeta = m_PPAttribs.m_f4CustomRlghBeta;
    m_f4CustomMieBeta = m_PPAttribs.m_f4CustomMieBeta;

	m_strRawDEMDataFile = "Terrain\\HeightMap.tif";
    m_strMtrlMaskFile = "Terrain\\Mask.png";
    m_strTileTexPaths[0] = "Terrain\\Tiles\\gravel_DM.dds";
    m_strTileTexPaths[1] = "Terrain\\Tiles\\grass_DM.dds";
    m_strTileTexPaths[2] = "Terrain\\Tiles\\cliff_DM.dds";
    m_strTileTexPaths[3] = "Terrain\\Tiles\\snow_DM.dds";
    m_strTileTexPaths[4] = "Terrain\\Tiles\\grassDark_DM.dds";
    m_strNormalMapTexPaths[0] = "Terrain\\Tiles\\gravel_NM.dds";
    m_strNormalMapTexPaths[1] = "Terrain\\Tiles\\grass_NM.dds";
    m_strNormalMapTexPaths[2] = "Terrain\\Tiles\\cliff_NM.dds";
    m_strNormalMapTexPaths[3] = "Terrain\\Tiles\\Snow_NM.jpg";
    m_strNormalMapTexPaths[4] = "Terrain\\Tiles\\grass_NM.dds";

    // Create data source
    try
    {
		m_pElevDataSource.reset( new ElevationDataSource(m_strRawDEMDataFile.c_str()) );
        m_pElevDataSource->SetOffsets(m_TerrainRenderParams.m_iColOffset, m_TerrainRenderParams.m_iRowOffset);
        m_fMinElevation = m_pElevDataSource->GetGlobalMinElevation() * m_TerrainRenderParams.m_TerrainAttribs.m_fElevationScale;
        m_fMaxElevation = m_pElevDataSource->GetGlobalMaxElevation() * m_TerrainRenderParams.m_TerrainAttribs.m_fElevationScale;
    }
    catch(const std::exception &)
    {
        LOG_ERROR("Failed to create elevation data source");
        return;
    }

	const Char *strTileTexPaths[EarthHemsiphere::NUM_TILE_TEXTURES], *strNormalMapPaths[EarthHemsiphere::NUM_TILE_TEXTURES];
	for(int iTile=0; iTile < _countof(strTileTexPaths); ++iTile )
    {
		strTileTexPaths[iTile] = m_strTileTexPaths[iTile].c_str();
        strNormalMapPaths[iTile] = m_strNormalMapTexPaths[iTile].c_str();
    }
    
    CreateUniformBuffer( pDevice, sizeof( CameraAttribs ), "Camera Attribs CB", &m_pcbCameraAttribs );
    CreateUniformBuffer( pDevice, sizeof( LightAttribs ), "Light Attribs CB", &m_pcbLightAttribs );

    const auto &SCDesc = pSwapChain->GetDesc();
    m_pLightSctrPP.reset( new LightSctrPostProcess(m_pDevice, m_pImmediateContext, SCDesc.ColorBufferFormat, SCDesc.DepthBufferFormat, TEX_FORMAT_R11G11B10_FLOAT) );
    auto *pcMediaScatteringParams = m_pLightSctrPP->GetMediaAttribsCB();

    m_EarthHemisphere.Create(m_pElevDataSource.get(), 
                             m_TerrainRenderParams, 
                             m_pDevice, 
                             m_pImmediateContext, 
                             m_strMtrlMaskFile.c_str(), 
                             strTileTexPaths, 
                             strNormalMapPaths, 
                             m_pcbCameraAttribs,
                             m_pcbLightAttribs,
                             pcMediaScatteringParams );

    CreateShadowMap();

    // Create a tweak bar
    TwBar *bar = TwNewBar("Settings");
    TwDefine(" GLOBAL fontsize=3 ");
    int barSize[2] = {300, 900};
#ifdef ANDROID
    barSize[0] = 800;
    barSize[1] = 1000;
#endif
    TwSetParam(bar, NULL, "size", TW_PARAM_INT32, 2, barSize);

    // Add variables to the tweak bar
#if 0
    float3 axis(-1, 1, 0);
    m_SpongeRotation = RotationFromAxisAngle(axis, FLOAT_PI/4);
    TwAddVarRW(bar, "Rotation", TW_TYPE_QUAT4F, &m_SpongeRotation, "opened=true axisz=-z group=Sponge");
#endif

    TwAddVarRW(bar, "FPS", TW_TYPE_FLOAT, &m_fFPS, "readonly=true");

    TwAddVarRW(bar, "Light direction", TW_TYPE_DIR3F, &m_f3LightDir, "opened=true axisz=-z showval=false");
    TwAddVarRW(bar, "Camera direction", TW_TYPE_DIR3F, &m_f3CameraDir, "opened=true axisz=-z showval=false");
    TwAddVarRW( bar, "Camera altitude", TW_TYPE_FLOAT, &m_f3CameraPos.y, "min=2000 max=100000 step=100 keyincr=PGUP keydecr=PGDOWN" );

    // Shadows
    {
        // Define a new enum type for the tweak bar
        TwEnumVal ShadowMapRes[] = // array used to describe the shadow map resolution
        {
            { 512, "512" },
            { 1024, "1024" },
            { 2048, "2048" },
            { 4096, "4096" }
        };
        TwType modeType = TwDefineEnum( "Shadow Map Resolution", ShadowMapRes, _countof( ShadowMapRes ) );  // create a new TwType associated to the enum defined by the ShadowMapRes array
        TwAddVarCB( bar, "Shadow map resolution", modeType, SetShadowMapResCB, GetShadowMapResCB, this, "group=Shadows" );

        TwAddVarRW( bar, "Show cascades", TW_TYPE_BOOLCPP, &m_bVisualizeCascades, "group=Shadows" );
        TwAddVarRW( bar, "Partitioning factor", TW_TYPE_FLOAT, &m_fCascadePartitioningFactor, "min=0 max=1 step=0.01 group=Shadows" );
        TwAddVarRW( bar, "Find best cascade", TW_TYPE_BOOLCPP, &m_TerrainRenderParams.m_bBestCascadeSearch, "group=Shadows" );
        TwAddVarRW( bar, "Smooth shadows", TW_TYPE_BOOLCPP, &m_TerrainRenderParams.m_bSmoothShadows, "group=Shadows" );
        TwAddVarCB( bar, "Num cascades", TW_TYPE_INT32, SetNumCascadesCB, GetNumCascadesCB, this, "min=1 max=8 group=Shadows" );
    }

    TwAddVarRW( bar, "Enable Light Scattering", TW_TYPE_BOOLCPP, &m_bEnableLightScattering, "" );

    // Light scattering GUI controls
    {
        TwAddVarRW( bar, "Enable light shafts", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bEnableLightShafts, "group=Scattering" );

        // Define a new enum type for the tweak bar
        TwEnumVal LightSctrTech[] = // array used to describe the shadow map resolution
        {
            { LIGHT_SCTR_TECHNIQUE_EPIPOLAR_SAMPLING, "Epipolar" },
            { LIGHT_SCTR_TECHNIQUE_BRUTE_FORCE, "Brute force" }
        };
        TwType LightSctrTechType = TwDefineEnum( "Light scattering tech", LightSctrTech, _countof( LightSctrTech ) );
        TwAddVarRW( bar, "Light scattering tech", LightSctrTechType, &m_PPAttribs.m_uiLightSctrTechnique, "group=Scattering" );

        TwEnumVal Pow2Values[] =
        {
            { 1, "1" },
            { 2, "2" },
            { 4, "4" },
            { 8, "8" },
            { 16, "16" },
            { 32, "32" },
            { 64, "64" },
            { 128, "128" },
            { 256, "256" },
            { 512, "512" },
            { 1024, "1024" },
            { 2048, "2048" }
        };
        TwType BigPow2Enum = TwDefineEnum( "Large powers of two", Pow2Values + 7, 5 );
        TwAddVarRW( bar, "NumSlices", BigPow2Enum, &m_PPAttribs.m_uiNumEpipolarSlices, "group=Scattering label=\'Num slices\'" );
        TwAddVarRW( bar, "MaxSamples", BigPow2Enum, &m_PPAttribs.m_uiMaxSamplesInSlice, "group=Scattering label=\'Max samples\'" );
        TwType SmallPow2Enum = TwDefineEnum( "Small powers of two", Pow2Values+2, 5 );
        TwAddVarRW( bar, "IntialStep", SmallPow2Enum, &m_PPAttribs.m_uiInitialSampleStepInSlice, "group=Scattering label=\'Initial step\'" );
        
        TwAddVarRW( bar, "ShowSampling", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bShowSampling, "group=Scattering label=\'Show Sampling\'" );
        TwAddVarRW( bar, "RefinementThreshold", TW_TYPE_FLOAT, &m_PPAttribs.m_fRefinementThreshold, "group=Scattering label=\'Refinement Threshold\' min=0.01 max=0.5 step=0.01" );
        TwAddVarRW( bar, "1DMinMaxOptimization", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bUse1DMinMaxTree, "group=Scattering label=\'Use 1D min/max trees\'" );
        TwAddVarRW( bar, "OptimizeSampleLocations", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bOptimizeSampleLocations, "group=Scattering label=\'Optimize Sample Locations\'" );
        TwAddVarRW( bar, "CorrectScattering", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bCorrectScatteringAtDepthBreaks, "group=Scattering label=\'Correct Scattering At Depth Breaks\'" );
        TwAddVarRW( bar, "ShowDepthBreaks", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bShowDepthBreaks, "group=Scattering label=\'Show Depth Breaks\'" );
        TwAddVarRW( bar, "LightingOnly", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bShowLightingOnly, "group=Scattering label=\'Lighting Only\'" );
        //TwAddVarRW( bar, "ScatteringScale", TW_TYPE_FLOAT, &m_fScatteringScale, "group=Scattering label=\'Scattering scale\' min=0 max=2 step=0.1" );

        TwAddVarRW( bar, "NumIntegrationSteps", TW_TYPE_UINT32, &m_PPAttribs.m_uiInstrIntegralSteps, "min=5 max=100 step=5 group=Advanced label=\'Num Integrtion Steps\'" );
        TwDefine( "Settings/Advanced group=Scattering" );

        {
            TwType EpipoleSamplingDensityEnum = TwDefineEnum( "Epipole sampling density enum", Pow2Values, 4 );
            TwAddVarRW( bar, "EpipoleSamplingDensity", EpipoleSamplingDensityEnum, &m_PPAttribs.m_uiEpipoleSamplingDensityFactor, "group=Advanced label=\'Epipole sampling density\'" );
        }
        {
            TwEnumVal SinglSctrMode[] =
            {
                { SINGLE_SCTR_MODE_NONE, "None" },
                { SINGLE_SCTR_MODE_INTEGRATION, "Integration" },
                { SINGLE_SCTR_MODE_LUT, "Look-up table" }
            };
            TwType SinglSctrModeEnum = TwDefineEnum( "Single scattering mode enum", SinglSctrMode, _countof(SinglSctrMode) );
            TwAddVarRW( bar, "SingleSctrMode", SinglSctrModeEnum, &m_PPAttribs.m_uiSingleScatteringMode, "group=Advanced label=\'Single scattering\'" );
        }
        {
            TwEnumVal MultSctrMode[] =
            {
                { MULTIPLE_SCTR_MODE_NONE, "None" },
                { MULTIPLE_SCTR_MODE_UNOCCLUDED, "Unoccluded" },
                { MULTIPLE_SCTR_MODE_OCCLUDED, "Occluded" }
            };
            TwType MultSctrModeEnum = TwDefineEnum( "Higher-order scattering mode enum", MultSctrMode, _countof( MultSctrMode ) );
            TwAddVarRW( bar, "MultipleSctrMode", MultSctrModeEnum, &m_PPAttribs.m_uiMultipleScatteringMode, "group=Advanced label=\'Higher-order scattering\'" );
        }
        {
            TwEnumVal CascadeProcessingMode[] =
            {
                { CASCADE_PROCESSING_MODE_SINGLE_PASS, "Single pass" },
                { CASCADE_PROCESSING_MODE_MULTI_PASS, "Multi-pass" },
                { CASCADE_PROCESSING_MODE_MULTI_PASS_INST, "Multi-pass inst" }
            };
            TwType CascadeProcessingModeEnum = TwDefineEnum( "Cascade processing mode enum", CascadeProcessingMode, _countof( CascadeProcessingMode ) );
            TwAddVarRW( bar, "CascadeProcessingMode", CascadeProcessingModeEnum, &m_PPAttribs.m_uiCascadeProcessingMode, "group=Advanced label=\'Cascade processing mode\'" );
        }
        TwAddVarRW( bar, "FirstCascadeToRayMarch", TW_TYPE_INT32, &m_PPAttribs.m_iFirstCascade, "min=0 max=8 step=1 group=Advanced label=\'Start cascade\'" );
        TwAddVarRW( bar, "Is32BitMinMaxShadowMap", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bIs32BitMinMaxMipMap, "group=Advanced label=\'Use 32-bit float min/max SM\'" );
        {
            TwEnumVal RefinementCriterion[] =
            {
                { REFINEMENT_CRITERION_DEPTH_DIFF, "Depth difference" },
                { REFINEMENT_CRITERION_INSCTR_DIFF, "Scattering difference" }
            };
            TwType CascadeProcessingModeEnum = TwDefineEnum( "Refinement criterion enum", RefinementCriterion, _countof( RefinementCriterion ) );
            TwAddVarRW( bar, "RefinementCriterion", CascadeProcessingModeEnum, &m_PPAttribs.m_uiRefinementCriterion, "group=Advanced label=\'Refinement criterion\'" );
        }
        {
            TwEnumVal ExtinctionEvalMode[] =
            {
                { EXTINCTION_EVAL_MODE_PER_PIXEL, "Per pixel" },
                { EXTINCTION_EVAL_MODE_EPIPOLAR, "Epipolar" }
            };
            TwType ExtinctionEvalModeEnum = TwDefineEnum( "Extinction eval mode enum", ExtinctionEvalMode, _countof( ExtinctionEvalMode ) );
            TwAddVarRW( bar, "ExtinctionEval", ExtinctionEvalModeEnum, &m_PPAttribs.m_uiExtinctionEvalMode, "group=Advanced label=\'Extinction eval mode\'" );
        }
        TwAddVarRW( bar, "AerosolDensity", TW_TYPE_FLOAT, &m_PPAttribs.m_fAerosolDensityScale, "group=Advanced label=\'Aerosol density\' min=0.1 max=5.0 step=0.1" );
        TwAddVarRW( bar, "AerosolAbsorption", TW_TYPE_FLOAT, &m_PPAttribs.m_fAerosolAbsorbtionScale, "group=Advanced label=\'Aerosol absorption\' min=0.0 max=5.0 step=0.1" );
        TwAddVarRW( bar, "UseCustomSctrCoeffs", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bUseCustomSctrCoeffs, "group=Advanced label=\'Use custom scattering coeffs\'" );

        #define RLGH_COLOR_SCALE 5e-5f
        #define MIE_COLOR_SCALE 5e-5f
        TwAddVarCB(bar, "RayleighColor", TW_TYPE_COLOR4F, 
            []( const void *value, void * clientData )
            {
                AtmosphereSample *pTheSample = reinterpret_cast<AtmosphereSample*>( clientData );
                pTheSample->m_f4CustomRlghBeta = *reinterpret_cast<const float4 *>(value) * RLGH_COLOR_SCALE;
                if( (float3&)pTheSample->m_f4CustomRlghBeta == float3( 0, 0, 0 ) )
                {
                    pTheSample->m_f4CustomRlghBeta = float4( 1, 1, 1, 1 ) * RLGH_COLOR_SCALE / 255.f;
                }
            },
            [](void *value, void * clientData)
            {
                AtmosphereSample *pTheSample = reinterpret_cast<AtmosphereSample*>( clientData );
                float4 RlghColor = pTheSample->m_f4CustomRlghBeta / RLGH_COLOR_SCALE;
                RlghColor.w = 1;
                *reinterpret_cast<float4*>(value) = RlghColor;
            },
            this, "group=Advanced label=\'Rayleigh color\' colormode=rgb");

        TwAddVarCB(bar, "MieColor", TW_TYPE_COLOR4F, 
            []( const void *value, void * clientData )
            {
                AtmosphereSample *pTheSample = reinterpret_cast<AtmosphereSample*>( clientData );
                pTheSample->m_f4CustomMieBeta = *reinterpret_cast<const float4 *>(value) * MIE_COLOR_SCALE;
                if( (float3&)pTheSample->m_f4CustomMieBeta == float3( 0, 0, 0 ) )
                {
                    pTheSample->m_f4CustomMieBeta = float4( 1, 1, 1, 1 ) * MIE_COLOR_SCALE / 255.f;
                }
            },
            [](void *value, void * clientData)
            {
                AtmosphereSample *pTheSample = reinterpret_cast<AtmosphereSample*>( clientData );
                float4 MieColor = pTheSample->m_f4CustomMieBeta / MIE_COLOR_SCALE;
                MieColor.w = 1;
                *reinterpret_cast<float4*>(value) = MieColor;
            },
            this, "group=Advanced label=\'Mie color\' colormode=rgb");
        #undef RLGH_COLOR_SCALE
        #undef MIE_COLOR_SCALE
        TwAddButton(bar, "UpdateCoeffsBtn", 
                    [](void *clientData)
                    {
                        AtmosphereSample *pTheSample = reinterpret_cast<AtmosphereSample*>( clientData );
                        pTheSample->m_PPAttribs.m_f4CustomRlghBeta = pTheSample->m_f4CustomRlghBeta;
                        pTheSample->m_PPAttribs.m_f4CustomMieBeta = pTheSample->m_f4CustomMieBeta;
                    }, 
                    this, "group=Advanced label=\'Update coefficients\'");
    }

    // Tone mapping GUI controls
    {
        {
            TwEnumVal ToneMappingMode[] =
            {
                {TONE_MAPPING_MODE_EXP,          "Exp"},
                {TONE_MAPPING_MODE_REINHARD,     "Reinhard"},
                {TONE_MAPPING_MODE_REINHARD_MOD, "Reinhard Mod"},
                {TONE_MAPPING_MODE_UNCHARTED2,   "Uncharted 2"},
                {TONE_MAPPING_FILMIC_ALU,        "Filmic ALU"},
                {TONE_MAPPING_LOGARITHMIC,       "Logarithmic"},
                {TONE_MAPPING_ADAPTIVE_LOG,      "Adaptive log"}
            };
            TwType ToneMappingModeEnum = TwDefineEnum( "Tone mapping mode enum", ToneMappingMode, _countof( ToneMappingMode ) );
            TwAddVarRW( bar, "ToneMappingMode", ToneMappingModeEnum, &m_PPAttribs.m_uiToneMappingMode, "group=ToneMapping label=\'Mode\'" );
        }
        TwAddVarRW( bar, "WhitePoint", TW_TYPE_FLOAT, &m_PPAttribs.m_fWhitePoint, "group=ToneMapping label=\'White point\' min=0.01 max=10.0 step=0.1" );
        TwAddVarRW( bar, "LumSaturation", TW_TYPE_FLOAT, &m_PPAttribs.m_fLuminanceSaturation, "group=ToneMapping label=\'Luminance saturation\' min=0.01 max=2.0 step=0.1" );
        TwAddVarRW( bar, "MiddleGray", TW_TYPE_FLOAT, &m_PPAttribs.m_fMiddleGray, "group=ToneMapping label=\'Middle Gray\' min=0.01 max=1.0 step=0.01" );
        TwAddVarRW( bar, "AutoExposure", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bAutoExposure, "group=ToneMapping label=\'Auto exposure\'" );
        TwAddVarRW( bar, "LightAdaptation", TW_TYPE_BOOLCPP, &m_PPAttribs.m_bLightAdaptation, "group=ToneMapping label=\'Light adaptation\'" );
    }

    const auto& RG16UAttribs = pDevice->GetTextureFormatInfoExt( TEX_FORMAT_RG16_UNORM );
    const auto& RG32FAttribs = pDevice->GetTextureFormatInfoExt( TEX_FORMAT_RG32_FLOAT );
    bool RG16USupported = RG16UAttribs.Supported && RG16UAttribs.ColorRenderable;
    bool RG32FSupported = RG32FAttribs.Supported && RG32FAttribs.ColorRenderable;
    if( !RG16USupported && !RG32FSupported )
    {
        int32_t IsVisible = 0;
        TwSetParam( bar, "1DMinMaxOptimization", "visible", TW_PARAM_INT32, 1, &IsVisible );
        m_PPAttribs.m_bUse1DMinMaxTree = FALSE;
    }

    if( !RG16USupported || !RG32FSupported )
    {
        int32_t IsVisible = 0;
        TwSetParam( bar, "Is32BitMinMaxShadowMap", "visible", TW_PARAM_INT32, 1, &IsVisible );

        if( RG16USupported && !RG32FSupported )
            m_PPAttribs.m_bIs32BitMinMaxMipMap = FALSE;

        if( !RG16USupported && RG32FSupported )
            m_PPAttribs.m_bIs32BitMinMaxMipMap = TRUE;
    }
}
void TwSetEnabled( TwBar* bar, const char *VarName, bool bEnabled )
{
    int32_t ReadOnly = bEnabled ? 0 : 1;
    TwSetParam( bar, VarName, "readonly", TW_PARAM_INT32, 1, &ReadOnly );
}
Exemple #27
0
void SetColorOrder(TwBar* bar, const char* varName, ColorOrder order)
{
    static const char* ColorOrderStrings[] = { "rgba", "bgra" };
    TwCall(TwSetParam(bar, varName, "colororder", TW_PARAM_CSTRING, 1, ColorOrderStrings[uint64(order)]));
}
Exemple #28
0
void SetUseAlphaChannel(TwBar* bar, const char* varName, bool32 useAlpha)
{
    TwCall(TwSetParam(bar, varName, "coloralpha", TW_PARAM_INT32, 1, &useAlpha));
}
Exemple #29
0
void SetBoolLabels(TwBar* bar, const char* varName, const char* falseLabel, const char* trueLabel)
{
    TwCall(TwSetParam(bar, varName, "false", TW_PARAM_CSTRING, 1, falseLabel));
    TwCall(TwSetParam(bar, varName, "true", TW_PARAM_CSTRING, 1, trueLabel));
}
Exemple #30
0
void SetShortcutKeyDecrement(TwBar* bar, const char* varName, const char* shortcutKey)
{
    TwCall(TwSetParam(bar, varName, "keydecr", TW_PARAM_CSTRING, 1, shortcutKey));
}