Example #1
0
	void ChoiceForm::AutotuneTex()
	{
		additionalAttribs.Clear();
		auto texs = choiceControl->GetPrecomputedTextures(currentShaderName);
		auto choices = choiceControl->GetChoices(currentShaderName, EnumerableDictionary<String, Spire::Compiler::ShaderChoiceValue>());

		for (auto & t : texs)
		{
			String choiceName;
			String searchKey = L"." + t.Key;
			for (auto & choice : choices)
				if (choice.ChoiceName.EndsWith(searchKey))
					choiceName = choice.ChoiceName;
			if (choiceName.Length() == 0)
				break;
			int w, h;
			t.Value.GetSize(w, h);
			List<float> data;
			data.SetSize(w*h*4);
			t.Value.GetComponents();
			for (auto & pix : data) pix = 0.0f;
			t.Value.GetData(0, DataType::Float4, data.Buffer(), w * h);
			bool isNormal = true, isColor = true;
			for (auto & pix : data)
			{
				if (!isNormal && !isColor)
					break;
				if (pix > 1.001f)
				{
					isColor = false;
					isNormal = false;
				}
				if (pix < -0.001)
				{
					isColor = false;
				}
				if (pix < -1.001)
				{
					isNormal = false;
				}
			}
			printf("PrecomputedTex %s: N=%d, C=%d\n", t.Key.ToMultiByteString(), isNormal?1:0, isColor?1:0);
				
			if (isColor)
			{
				EnumerableDictionary<String, String> attribs;
				attribs[L"Storage"] = L"RGBA8";
				additionalAttribs[choiceName] = attribs;
			}
			else if (isNormal)
			{
				EnumerableDictionary<String, String> attribs;
				attribs[L"Normal"] = L"1";
				additionalAttribs[choiceName] = attribs;
			}
		}
		Recompile();
	}
Example #2
0
	List<Vec4> ChoiceForm::ReadFrameData(GL::Texture2D tex)
	{
		List<Vec4> rs;
		int w, h;
		tex.GetSize(w, h);
		rs.SetSize(w*h);
		tex.GetData(0, DataType::Float4, rs.Buffer(), rs.Count()*sizeof(Vec4));
		return rs;
	}