Jump to content

Texture Animation


noonespecial

Recommended Posts

Thanks nli2work, that's helpful info. Might have to tap you up for some shader knowledge, along with nosing through the Unity API and working out what is possible with KSP. The layered mesh thing occurred to me as a potential solution, so I'm glad I wasn't too far off the mark with that. I assume you need to have a tiny bit of separation to stop z-fighting? Either way, if it can be achieved in code without a special mesh setup, that would be sweet. Hooking into what actually drives the blend change is less of a concern at this stage than achieving the actual effect, so that's what I'd work on first. I usually just bind experimental stuff to a UI slider for testing, it saves a lot of hassle while setting things up. Be interesting to see what Starwaster is up to, though.

Not sure exactly how it might work yet, but I'd aim for a configurable module so you can mess with bump/spec/diffuse as you please. It's going to take some research to work out what's possible, though.

Edited by lo-fi
Link to comment
Share on other sites

Thanks :) the idea I currently have is to write a module that does the actual blending stuff and exposes a control interface, then write modules that tie into different things like reentry heat, or mission time of whatever to control it. My KF wheel modules are set up like that and if works rather well.

Link to comment
Share on other sites

When dealing with textures at run time ksp adds an extra hurdle in that many textures can not be read from (or written to), ie you can't read the individual pixel values. Textures loaded from mbm and tga files behave like this, textures loaded from png files are readable, at least in win32 and 64 bit ubuntu.
Is this true?

It's what I've found working on my mod to write text to textures. It's apparently a technique to reduce memory usage - if a texture is marked as not readable or writable then unity can push the texture to gpu memory and then drop the pixels from main memory and only keep the simple information about a texture like it's width and height.

You can get around the issue by using file formats that don't get marked as unreadable / unwritable by ksp or by loading the textures direct from file.

Edited by CmdrThyte
typo
Link to comment
Share on other sites

It's what I've found working on my mod to write text to textures. It's apparently a technique to reduce memory usage - if a texture is marked as not readable or writable then unity can push the texture to gpu memory and then drop the pixels from main memory and only keep the simple information about a texture like it's width and height.

You can get around the issue by using file formats that don't get marked as unreadable / unwritable by ksp or by loading the textures direct from file.

ActiveTextureManagement has flags to exempt textures from being marked unreadable/writable. I think this limitation affects plugins like the WriteStuff more than plugins that simply switch texture being displayed. RPM doesn't seem to be affected by converting it's textures to DDS from what I read. FStextureSwitch2 doesn't appear to have any problems switching between MBM and PNGs. The flagDecal module and JSISelectableFlags will only display PNGs however. I'm don't know much of the internal mechanics of the code unfortunately. But until PartTools is updated to handle more shaders I'm pretty sure everything would have to be done via plugins and config file settings.

A good place to start might be just to port some additional Unity shaders to KSP.

Edited by nli2work
Link to comment
Share on other sites

Someone else recently requested exactly this feature and was asking if my texture animator could be used; not really for this, sadly. However, blending textures.... That sounds promising! You can only apply one shader per object in KSP afaik, so I assume you mean blend at diffuse level within the shader, stupid_chris? I'll see what I can dig up in Unity docs.

Shader can do, but it could easily be done with a simple method at run time. Hold on let me try something...

Here: http://pastebin.com/TsE9siYM

A little on the top, but this should do the job of lerping to textures at runtime, without creating new objects every frame and overloading the memory

Edited by stupid_chris
Link to comment
Share on other sites

and now it's gone :-(

Doh, didn't think this through.

        /// <summary>
/// Blends two textures together and stores the result in an output texture
/// </summary>
/// <param name="blend">Percentage to blend through (from 0 to 1)</param>
/// <param name="from">Beginning texture</param>
/// <param name="to">Finishing texture</param>
/// <param name="output">Texture to appear blended</param>
private void BlendTextures(float blend, Texture2D from, Texture2D to, Texture2D output)
{
blend = Mathf.Clamp01(blend);
Color[] a = from.GetPixels(), b = to.GetPixels();
if (a.Length != b.Length || a.Length != output.height * output.width) { return; }
Color[] pixels = new Color[a.Length];
for (int i = 0; i < a.Length; i++)
{
pixels[i] = Color.Lerp(a[i], b[i], blend);
}
output.SetPixels(pixels);
output.Apply();
}

Gonna public domain this. Whoever wanna use it.

Link to comment
Share on other sites

Thanks Chris, that's really cool! I'm trying to wrap up my current mini-project, then I'll look at adding the other trimmings to make that little nugget of genius work a fully formed plugin and bundle up with the texture animating util - seems like they ought to belong together. Can't wait to see this in action!

Link to comment
Share on other sites

  • 3 months later...

Have any of you looked at Babcats Soyuz it has a BurnoutModule

MODULE

{

name = SoyuzDescendBurnoutModule

TemperatureThreshold = 200

BurnIntensity = 0.0001

}

it looks like it can do what you want ? or maybe it the CustomPartShader file he's using or both.
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...