Jump to content

Is there a way to change stock shader for the celestials in map view?


Recommended Posts

Basically the title says it all. I'm thinking about embarking on resources implementation since it's unlikely that we'll see it done by devs for at least several months (my guesstimate), and in order to implement resource maps that would overlay planets, I figured the best way to do that is to modify pixel shader for the planet rendering so it would read my resource map mask and color areas where resources are. Does anyone have anything in this regard? Thank you!

Link to comment
Share on other sites

Awesome!, are you planning on making this into something? like Kethane?

I'm planning something much more complex - multiple resources, mining bases with ground structures, etc. I'm still thinking it through and doing some proof-of-concept things, like the one above. Once I have this more of less finalized and all technical implementation concepts nailed down, I'll create a topic here so everyone will have a chance to provide input.

Link to comment
Share on other sites

I'm planning something much more complex - multiple resources, mining bases with ground structures, etc. I'm still thinking it through and doing some proof-of-concept things, like the one above. Once I have this more of less finalized and all technical implementation concepts nailed down, I'll create a topic here so everyone will have a chance to provide input.

Wish you the best, I hope to one day see this idea turn into reality, a great mod in the making, I can already see in the shader map you made, nobody has made one of these yet!

Link to comment
Share on other sites

Would you mind telling me how you did the overlay in the above picture?

Sure, once I reach home I'll post code sample. It actually uses current (VERY rudimentary but still) support of resources in stock game. Basically you need to provide a texture that will be alpha-blended with terrain texture during rendering (it's classic alpha-blending mechanism result_color = resource_texture.rgb * resource_texture.a + main_texture.rgb * (1 - resource_texture.a)). So you can start working on building this texture, and this evening I'll show you how to "connect" it to renderer.

Edited by asmi
Link to comment
Share on other sites

As promised, here is the code:

public static class ResourceTextureSetter

{

private static FieldInfo textureField = typeof(CelestialBody).GetField("\u000A\u0006", BindingFlags.NonPublic | BindingFlags.Instance);

public static void SetResourceTexture(CelestialBody body, Texture2D resourceTexture)

{

textureField.SetValue(body, resourceTexture);

}

}

Just call this method and pass celestial and texture to display it, or pass null instead of texture to hide resource.

Link to comment
Share on other sites

Ermmm... what???

No offense, but that doesn't look "healthy".

Do you want the code that works, or one that looks "healthy" (btw what is it?), but doesn't work? You've asked me how did I do that - I've told you, if you don't like it feel free to find the other way. I've spent almost a full day in dotPeek + debugger trying to find the way, I've found it, it works, so it's good enough for me.

Link to comment
Share on other sites

I'm not sure either what healthy looking code means.

But I'm not one to talk, most of my code could best be described as italian pasta product. Hey, it works.

Thanks for the code, I'm unlikely to do anything with it but it's nice to think I could.

Link to comment
Share on other sites

I'm not sure either what healthy looking code means.

But I'm not one to talk, most of my code could best be described as italian pasta product. Hey, it works.

Thanks for the code, I'm unlikely to do anything with it but it's nice to think I could.

You've got to keep in mind, that in absence of documentation we're bound to use such ways - I don't like it either to be honest, but we've gotta deal with what we have. I've isolated this code into separate class for that exact reason - if it would become broken in future versions (BTW it's confirmed to work in 0.20.2), it could be fixed in one place, and not scattered across the codebase making such a fix a nightmare.

Link to comment
Share on other sites

Don't take this the wrong way please:

Your code accesses a private field. This might work in this case, but it is not a good idea in general. Besides that: The field has a weird name. Obfuscators?

Link to comment
Share on other sites

Don't take this the wrong way please:

Your code accesses a private field. This might work in this case, but it is not a good idea in general. Besides that: The field has a weird name. Obfuscators?

Field name most likely is obfuscator's work. Yea, in general I agree, but this feature itself is incomplete, so for now it's acceptable. As I've said above, I've isolated this inside a class so if/when this part is changed, the codebase can easily be fixed.

Link to comment
Share on other sites

Field name most likely is obfuscator's work. Yea, in general I agree, but this feature itself is incomplete, so for now it's acceptable. As I've said above, I've isolated this inside a class so if/when this part is changed, the codebase can easily be fixed.

I agree. A good KSP API documentation would be so helpful. But it is hard to maintain, so I don't blame Squad for not doing it...

Thanks for sharing :-). I might need it in my new plugin to mark a specific spot (latitude and longitude are known) on a planet.

Link to comment
Share on other sites

That's all well and good, but how (if at all) did you modify the shader? Or are you replacing an existing texture? I'm curious...

Re being healthy - everything is C# - we have already thrown healthy out the window when we made that decision. :)

I'd like to add some better shaders - the silly half-angle specular makes my eyes bleed everytime it pokes through something, and every other shader looks stock and boring... i'm betting there is room for optimisation and visual improvement at the same time. :P

Also, IMO, a good API documents itself. e.g. by not having one class called Part and one called PartModule and an obvious legacy of indecisive early work still being present because its an alpha release... when its finished we might not need any documentation. Most code I've ever had to work with is completely undocumented - the best you get is maybe the guy who wrote it did so in the last 3 months and is still employed. :P

Edited by jheriko
adding based on further posts
Link to comment
Share on other sites

That's all well and good, but how (if at all) did you modify the shader? Or are you replacing an existing texture? I'm curious...

No, I use existing (VERY preliminary) support for resources, or some part of it that allows one to specify second texture that will then be alpha-blended with terrain during rendering pass.

Re being healthy - everything is C# - we have already thrown healthy out the window when we made that decision. :)

What?

I'd like to add some better shaders - the silly half-angle specular makes my eyes bleed everytime it pokes through something, and every other shader looks stock and boring... i'm betting there is room for optimisation and visual improvement at the same time. :P

Theoretically Unity allows you to set whatever shader you want to anything, but there is one caveat - since OpenGL doesn't support Cg for shaders directly (unlike Direct3D that supports HLSL), you can't create Cg shaders dynamically. I didn't pursue this way since I've found easier way to solve my problem :)

Also, IMO, a good API documents itself. e.g. by not having one class called Part and one called PartModule and an obvious legacy of indecisive early work still being present because its an alpha release... when its finished we might not need any documentation. Most code I've ever had to work with is completely undocumented - the best you get is maybe the guy who wrote it did so in the last 3 months and is still employed. :P

Yea I'm used to using decompilers at work as it's the best way to figure out how exactly some third-party component works.

Edited by asmi
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...