Summer Work (Day 21)

Biomes pt.1

    This will be a small update about what I have accomplished before I go away again for a few days. I have been focusing fully on trying to get the biome system implemented.
    The main thing I am trying to do is to get the tint working. This is more of a debug tool than anything, but it will allow me to see that the system is working properly. It is supposed to color the part of the planet belonging to a specific biome a solid color. Also if I can manage to get that to work then all I have to do is replace that solid color with a gradient and the whole job is essentially done. Here's what I have so far for that:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void ColorGenerator::UpdateColors()
{
	ColorSettings->Atlas->TextureSize = TextureResolution;
	ColorSettings->Atlas->GradientCurves.SetNum(ColorSettings->BiomeColorSettings->Biomes.Num());
	TArray<UCurveLinearColor*> BaseCurves;
	for (auto& biome : ColorSettings->BiomeColorSettings->Biomes)
	{
		BaseCurves.Add(biome->Gradient);
	}
	ColorSettings->Atlas->GradientCurves = BaseCurves;
	ColorSettings->Atlas->UpdateTextures();

	ColorSettings->BiomeTintAtlas->TextureSize = ColorSettings->BiomeColorSettings->Biomes.Num();
	ColorSettings->BiomeTintAtlas->GradientCurves.SetNum(ColorSettings->BiomeColorSettings->Biomes.Num());
	TArray<UCurveLinearColor*> TintCurves;
	for (auto& biome : ColorSettings->BiomeColorSettings->Biomes)
	{
		auto Tint = NewObject<UCurveLinearColor>();
		auto Keys = TArray<FRichCurveKey>();
		Keys.Add(FRichCurveKey(0, biome->Tint.A));
		Keys.Add(FRichCurveKey(1, biome->Tint.A));
		Tint->FloatCurves->SetKeys(Keys);
		TintCurves.Add(Tint);
	}
	ColorSettings->BiomeTintAtlas->GradientCurves.Empty();
	ColorSettings->BiomeTintAtlas->GradientCurves = TintCurves;
	ColorSettings->BiomeTintAtlas->UpdateTextures();

	for (int i = 0; i < ColorSettings->DynamicMaterials.Num(); i++)
	{
		ColorSettings->DynamicMaterials[i]->SetTextureParameterValue(FName("_texture"), Cast<UTexture>(ColorSettings->Atlas));
		ColorSettings->DynamicMaterials[i]->SetTextureParameterValue(FName("_biomeTint"), Cast<UTexture>(ColorSettings->BiomeTintAtlas));
		ColorSettings->DynamicMaterials[i]->SetScalarParameterValue(FName("_tintPercent"), ColorSettings->BiomeColorSettings->Biomes[0]->TintPercent);
	}
}

It's messy as all hell right now but it kinda works. Lines 3-11 deal with the base texture; that's nothing new. Lines 13-27 are do the exact same thing but for tinting the biomes rather than coloring the terrain directly. Then 29-33 just applies all those changes to the texture.

The Problems:
    There are a few problems with this code right now. Firstly, lines 20 and 21. These are supposed to add the keys to the color curve so that the gradient is all one color. The problem is that the in value for FRichCurveKey is a float, not a vector or a color meaning I can't pass it the full tint color I intend to. Interestingly though, when I ran this it created a color curve and added the point at time 0 with the correct color, but not the point at time 1. To fix this I could either fix the problem with FRichCurveKey and find out how to pass it a color value, or I could just use the vertical component of the atlas at a constant time 0. The latter would work in the short term but the former is what I will have to figure out to get the actual biome colors to work.
    The next problem has something to do with the way that the material shows the tint on the planet. This is the material editor for the planet material:
So the theory here is that if the "_tintPercent" is 0 then the texture will be entirely the base texture and if it's 1 then the texture will be entirely the tint. This is done by the lerp. But here's the actual outcome. 
_tintPercent = 0
_tintPercent = 1
Something here is screwed up but I'll have to figure it out later. For now that's all the problems I've found. I hope to post another update by Tuesday at the latest with the whole system working.

Comments

Popular posts from this blog

Polishing the Foundation

Progress Update #13

A New Chapter