Summer Work (Day 20)
Texture Automation
First off, I haven't updated this blog in a few days. That's because I was out of town for some time, and until I go back to school that will happen a few more times, mostly over the weekends. Regardless, I have managed to make at least some progress today in the realm of texturing these planets.
The one thing that I wanted to accomplish today was to automate the process of creating the curve atlases. This was to catch up to the tutorial series in which Sebastian Lague creates a texture based on the color gradient. But as mentioned in previous blog entries, this approach will work in Unity but not Unreal.
In Unreal I decided to just use the atlas directly instead of trying to create a genuine texture. This meant that I had to fill all gradient curve slots in the atlas with the gradient that I wanted to use. The problem with this is that the atlases must be square. So if you want a texture resolution of 256 so you get the most color detail, that means you also need to fill 256 gradient curves. Doing that manually would be stupid and if you wanted to change the gradient you are using, it would be incredibly time consuming to manually replace all the curves. So instead of doing that, I decided to try to automate that process.
Initially I tried this:
void ColorGenerator::UpdateColors() { ColorSettings->Atlas->TextureSize = TextureResolution; for (int i = 0; i < ColorSettings->Atlas->MaxTextureSize; i++) { ColorSettings->Atlas->UpdateGradientSlot(); } ColorSettings->Atlas->UpdateTextures(); for (int i = 0; i < ColorSettings->DynamicMaterials.Num(); i++) { ColorSettings->DynamicMaterials[i]->SetTextureParameterValue(FName("_texture"), Cast<UTexture>(ColorSettings->Atlas)); }
This code resulted in this planet:
Very weird but not what I wanted. After some tinkering, I found that the UpdateGradientSlot() was not doing what I thought. Eventually I found that what I actually wanted was to change the GradientCurves array. This is what I ended up working for me:
void ColorGenerator::UpdateColors() { ColorSettings->Atlas->TextureSize = TextureResolution; ColorSettings->Atlas->GradientCurves.SetNum(TextureResolution); TArray<UCurveLinearColor*> Curves; Curves.Init(ColorSettings->Curve, TextureResolution); ColorSettings->Atlas->GradientCurves = Curves; ColorSettings->Atlas->UpdateTextures(); for (int i = 0; i < ColorSettings->DynamicMaterials.Num(); i++) { ColorSettings->DynamicMaterials[i]->SetTextureParameterValue(FName("_texture"), Cast<UTexture>(ColorSettings->Atlas)); } }
The initialization of the array will need to change in the future as I go on to add biomes and that will require multiple sets of gradients. For now though the end result is the same, just the behind the scenes has become more streamlined.
Sidenote: The height issue from day 15 has decided to fix itself and the gradients actually read from 0 to 1 instead of 0 to 0.55. This might have happened when I updated the source engine but regardless I'm glad that it's fixed.
Comments
Post a Comment