Jump to content

[1.0] KerbPaint - Paint layering for parts (March 30th, 2016) Community Update


Texel

Recommended Posts

  • 2 weeks later...
4 hours ago, Texel said:

Props to Selfish Meme and Manwith Noname for continuing this, I updated the topmost post to hopefully let you cleanup the download confusion and released the license. 

thanks Texel, I really appreciate the work you did on this mod.

Just to let everyone know, this won't work until ModuleManager is updated to work with 1.1, we will take a look at it then.

Link to comment
Share on other sites

8 hours ago, Texel said:

Props to Selfish Meme and Manwith Noname for continuing this, I updated the topmost post to hopefully let you cleanup the download confusion and released the license. 

Texel, you have no idea how happy you've made me! My big mods rely heavily on KerbPaint and I was very worried I'd have to resort to some kind of nasty workaround. Thank you very much!

Here's a flower for you ;-) No, not painted. Stock :-)

sJW2KK5.png

Link to comment
Share on other sites

1 hour ago, selfish_meme said:

Ok there is a new MM here, so tested KerbPaint

But now I get black parts, just like people described when using DirectX11, but I am using OpenGL

I remember reading OpenGL has issues in 1.1. What about DX 9?

Link to comment
Share on other sites

It doesn't work. I tried it as soon as I found the latest MM. As a result, I pinged Texel a PM to let them know. You can tell it almost wants to work which is quite impressive really, so it might not need much to get the "system" functioning but based on the exchange of PM's I had, the shader method likely won't work as it was removed in later versions of Unity 4 and is likely not in U5 either. At least that's how I understood it, could be wrong.

Link to comment
Share on other sites

1 hour ago, Manwith Noname said:

It doesn't work. I tried it as soon as I found the latest MM. As a result, I pinged Texel a PM to let them know. You can tell it almost wants to work which is quite impressive really, so it might not need much to get the "system" functioning but based on the exchange of PM's I had, the shader method likely won't work as it was removed in later versions of Unity 4 and is likely not in U5 either. At least that's how I understood it, could be wrong.

Hmmm ... might there be a possibility to exploit the new material based shader?

Link to comment
Share on other sites

4 hours ago, Azimech said:

Hmmm ... might there be a possibility to exploit the new material based shader?

If KSP uses Unity's 5's stock material shaders, it wouldn't be a particularly bad rewrite, do you have any info on the new shaders?

Link to comment
Share on other sites

It is in the process. I believe it is using the U5 shaders, they just have put off making full use of them until 1.2. I'll try and find the devnotes.

 

Edit: This is the one I'm thinking of...

http://kerbaldevteam.tumblr.com/post/139054693224/devnote-tuesday-wednesday-edition-ii

Quote

Good news comes our way from Germany: Chris (Porkjet) fixed an issue with specular highlights that was affecting the shaders with the old lighting model in Unity 5. This means that an issue where parts shaders would look quite bad has been fixed for the coming update. On the flip side, the new (PBR) lighting model will also have to be pushed back to beyond 1.1 over performance concerns with the real time reflections. We’ll be looking into creating a more efficient, custom solution for this problem at a later date.

Reading it again however, I'm not sure what actually got done and what didn't. My recollection was that it had switched but the fancy mapping and what not would be pushed back.

 

Later Edit: Actually, it's probably best to do this... @Porkjet . If he can find the time in all the 1.1 madness he may be able to state more clearly what is and will be the case.

Edited by Manwith Noname
Link to comment
Share on other sites

1 hour ago, Manwith Noname said:

It is in the process. I believe it is using the U5 shaders, they just have put off making full use of them until 1.2. I'll try and find the devnotes.

 

Edit: This is the one I'm thinking of...

http://kerbaldevteam.tumblr.com/post/139054693224/devnote-tuesday-wednesday-edition-ii

Reading it again however, I'm not sure what actually got done and what didn't. My recollection was that it had switched but the fancy mapping and what not would be pushed back.

 

Later Edit: Actually, it's probably best to do this... @Porkjet . If he can find the time in all the 1.1 madness he may be able to state more clearly what is and will be the case.

I'm pretty sure they pushed back the new shader, but the new engine will have updated DirectX and OpenGL capabilities anyway, which is why we probably get the effect forcing DirectX11 gave.

Maybe Chris would be up for a texture realignment on the mark 3 and 2 parts as well so we could paint the bottoms black...crosses fingers.

Edited by selfish_meme
Link to comment
Share on other sites

@selfish_meme Well, for you in OpenGL you got black textures right? I guess you loaded a craft you had saved with paint on? I loaded the stock dynawing and tried to paint it. The game clearly recognised that "P" should do something as the entire craft got highlighted in blue as you would expect to happen to a part but as I kind of expected, the menu didn't show and the highlight didn't stick.

 

Edit: I'm on Win 8.1 so DX9.

Edited by Manwith Noname
Link to comment
Share on other sites

2 minutes ago, Manwith Noname said:

@selfish_meme Well, for you in OpenGL you got black textures right? I guess you loaded a craft you had saved with paint on? I loaded the stock dynawing and tried to paint it. The game clearly recognised that "P" should do something as the entire craft got highlighted in blue as you would expect to happen to a part but as I kind of expected, the menu didn't show and the highlight didn't stick.

 

Edit: I'm on Win 8.1 so DX9.

No i loaded a new part, any part that was paintable was black, it would do the purple highlight but no UI would popup (which makes sense as it's a new ui model)

Edited by selfish_meme
Link to comment
Share on other sites

Heh, how strange. Everything looked normal as far as textures on parts in DX9. Only thing that looked really bizarre was I could see a cross mesh shape above the landing gear on the wings. I thought about taking a screenshot but realised it's not really useful beyond amusement....and now I want to share that amusement.

Link to comment
Share on other sites

On 3/21/2016 at 5:22 AM, selfish_meme said:

I have integrated @Manwith Noname's masks and configs and added a few more Download

A little video to share, STS Atlantis craft will be available on KerbalX soon and a full writeup in the Spacecraft Exchange

 

Ummm, source code, please?  I wanted to take a quick look to see if I could help you with the 1.1 stuff, but it's not in the download

 

Link to comment
Share on other sites

4 minutes ago, linuxgurugamer said:

Ummm, source code, please?  I wanted to take a quick look to see if I could help you with the 1.1 stuff, but it's not in the download

 

Texel put a link to the source on the front page https://dl.dropboxusercontent.com/u/82486/ModulePaintable.cs

7 minutes ago, linuxgurugamer said:

Ummm, source code, please?  I wanted to take a quick look to see if I could help you with the 1.1 stuff, but it's not in the download

 

We only did part masks and configs we never had the code before

Link to comment
Share on other sites

12 minutes ago, selfish_meme said:

Texel put a link to the source on the front page https://dl.dropboxusercontent.com/u/82486/ModulePaintable.cs

We only did part masks and configs we never had the code before

Ah, that explains it.  I'll compile it and get a dll to you for testing

Well, it might be a little time.  Kerbpaint is using UnityEngine.Material, wihch is obsolete.  It needs to be rewritten to use Shaders, and I don't have time for that right now.  I'll take a look at it this evening to see if I can do something.

Link to comment
Share on other sites

On 9/15/2013 at 5:12 AM, Texel said:

Source -> (source)
As of March 30th 2016, the code is now under Zlib. I've updated the source file to include that license, though updating the mod to work past 1.1 may be an issue.

Thanks for releasing the restrictions on the code.  

I assume your comment about updating past 1.1 is refering to the issue with the Unityengine.Material.Material being obsolete?

Link to comment
Share on other sites

 

18 hours ago, linuxgurugamer said:

Thanks for releasing the restrictions on the code.  

I assume your comment about updating past 1.1 is refering to the issue with the Unityengine.Material.Material being obsolete?

UnityEngine.Material *isn't* obsolete, as such; They removed UnityEngine.Material's string constructor; The section in particular that is going to cause an issue is:

				// Get the material
				var mat = GetComponentInChildren<MeshRenderer>().material; // Get the first material we find, hope it's right :D
				var shaderString = KSP.IO.File.ReadAllText<KerbPaint>(Shader, null);
				paintShader = mat.shader = new Material(shaderString).shader;/*UnityEngine.Shader.Find(Shader);*/
				mat.SetTexture("_Mask", ProcessTexture(Texture));
				ManagedMats = new[] { mat };

Unity should still be able to load the precompiled shaders, which are distributed in the zip under the KerbPaint/Shaders folder, as far as I am aware the Material Constructor was only obsoleted as it no longer compiles shaders. If that fails. Though I'd previously not released this source (as I was using these techniques for some of my work at the time), if your going to make new shaders or update to the new material system, you'll need the code for actually applying the recoloring logic:
 

Spoiler

half3 RGBtoHSV(float3 clr) {
	half3 HSV = 0; // 0,0,0 implicit
	// Component Max of RGB Color (Obtain highest component)
	HSV.z = max(clr.r, max(clr.g, clr.b)); 
	// Component Min (Possibly optmize both into component SLT?)
	float M = min(clr.r, min(clr.g, clr.b));
	float C = HSV.z - M; // Chroma
	
	if (C != 0) { // Neccassery? I think it only prevents banding on certain hardware
		HSV.y = C / HSV.z; // Chroma over Value
		float3 Delta =  (HSV.z - clr) / C; // Allot of RCP Chroma, optmize?
		Delta.rgb -= Delta.brg;
		Delta.rg += float2(2,4); // Push it into the color hexagon
		if (clr.r >= HSV.z)
			HSV.x = Delta.b; 
		else if (clr.g >= HSV.z)
			HSV.x = Delta.r;
		else 
			HSV.x = Delta.g;
		HSV.x = frac(HSV.x / 6);
	}
	
	return HSV; 
}

half3 Hue(half h) {
	half R = abs((h * 6) - 3) - 1;
	half G = 2 - abs((h * 6) - 2);
	half B = 2 - abs((h * 6) - 4);
	return saturate(float3(R,G,B));
}

half3 HSVToRGB(half3 hsv) {
	hsv = saturate(hsv);
	return ((Hue(hsv.x) - 1) * hsv.y + 1) * hsv.z;
}

half4 _AWght;
half4 _BWght;
half4 _CWght;
sampler2D _Mask;

half3 ApplyWeights(half3 clr, half3 Mask) {
	half3 HSV = RGBtoHSV(clr);
	
	half3 ASet = HSV + _AWght; ASet.x = _AWght;
	ASet.z = _AWght.z * HSV.z;
	half3 BSet = HSV + _BWght; BSet.x = _BWght;
	BSet.z = _BWght.z * HSV.z;
	half3 CSet = HSV + _CWght; CSet.x = _CWght;
	CSet.z = _CWght.z * HSV.z;
	
	clr = lerp(clr, HSVToRGB(ASet), Mask.r * _AWght.a);
	clr = lerp(clr, HSVToRGB(BSet), Mask.g * _BWght.a);
	clr = lerp(clr, HSVToRGB(CSet), Mask.b * _CWght.a);
	return clr;
}

 

Again, it shouldn't be a big deal to apply this into the newer materials, but I'd need shader sources for KSP, and the old shaders were based on PartTools which I don't believe has been updated (If it has, please point this out so I can update)

Link to comment
Share on other sites

So, licensing wise, I actually had a folder of shader sources I'd indented to distribute with the mod, but because the Part Tools shader sources are 'presumably' property of squad I shouldn't be redistributing modified copies of, I only included the precompiled shaders in the old mod. Whelp, looking at the sources now seeing how bad it would be to update them, turns out to save space (as compiled shaders can be huge) I had "#pragma only_renderers opengl d3d9"

Whoops. 

So essentially, the precompiled shaders appear fine, they are missing some of the new stuff that had been added since (Temperature Color, and Burn Color, for the reentry emissive effects).

I'm at a weird crossroads on how to update the mod though, since I can't distribute sources of Squad's shaders to others to be maintainable and I don't want to leave the community hanging dry for years again. Spending a bit of time seeing how bad it would be to make an add-on for PartTools that patches the shaders.

Link to comment
Share on other sites

9 minutes ago, Texel said:

So, licensing wise, I actually had a folder of shader sources I'd indented to distribute with the mod, but because the Part Tools shader sources are 'presumably' property of squad I shouldn't be redistributing modified copies of, I only included the precompiled shaders in the old mod. Whelp, looking at the sources now seeing how bad it would be to update them, turns out to save space (as compiled shaders can be huge) I had "#pragma only_renderers opengl d3d9"

Whoops. 

So essentially, the precompiled shaders appear fine, they are missing some of the new stuff that had been added since (Temperature Color, and Burn Color, for the reentry emissive effects).

I'm at a weird crossroads on how to update the mod though, since I can't distribute sources of Squad's shaders to others to be maintainable and I don't want to leave the community hanging dry for years again. Spending a bit of time seeing how bad it would be to make an add-on for PartTools that patches the shaders.

Yeah we realised something was wrong when DirectX 11 users got black parts in 1.05, and the parts are also black for OpenGL users in the new 1.1 but they worked fine in 1.05, DirectX 9 users seem to have all the cool stuff ;)

Link to comment
Share on other sites

25 minutes ago, Texel said:

So, licensing wise, I actually had a folder of shader sources I'd indented to distribute with the mod, but because the Part Tools shader sources are 'presumably' property of squad I shouldn't be redistributing modified copies of, I only included the precompiled shaders in the old mod. Whelp, looking at the sources now seeing how bad it would be to update them, turns out to save space (as compiled shaders can be huge) I had "#pragma only_renderers opengl d3d9"

Whoops. 

So essentially, the precompiled shaders appear fine, they are missing some of the new stuff that had been added since (Temperature Color, and Burn Color, for the reentry emissive effects).

I'm at a weird crossroads on how to update the mod though, since I can't distribute sources of Squad's shaders to others to be maintainable and I don't want to leave the community hanging dry for years again. Spending a bit of time seeing how bad it would be to make an add-on for PartTools that patches the shaders.

Distribute them to other's privately, it gets harder the more you think about it.

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...