Jump to content

Custom shaders


/not/pol/

Recommended Posts

12 hours ago, /not/pol/ said:

Is it possible to use self-written shaders with KSP and if so are there any limitations?

Yes.

Limitations:  Giant PITA to get them loaded and actually use them (need to compile as an asset bundle, and manually load them; stock code will not load them properly as far as I'm aware), also need to compile one version for each operating system used by KSP (Win/64, Linux, OSX, so at least three packages) and load the proper one at runtime.  You can't use them in PartTools/export, so they have to be applied at run-time through custom plugin code.  You cannot access/find them through Shader.Find(), so the stock code/other mods' code will never be able to load them/use them.  You also need to accommodate for the various rendering systems for some shader functions (openGL vs directX).

Once you get them placed onto a model/mesh/renderer... they work just like the built-in/KSP shaders, and render just fine.


Source:  I have written and am using custom shaders in SSTU to facilitate back-lit solar panels and user-recolorable parts.   ( https://github.com/shadowmage45/SSTULabs/tree/master/CustomShaders )

Link to comment
Share on other sites

3 hours ago, Shadowmage said:

Yes.

Limitations:  Giant PITA to get them loaded and actually use them (need to compile as an asset bundle, and manually load them; stock code will not load them properly as far as I'm aware), also need to compile one version for each operating system used by KSP (Win/64, Linux, OSX, so at least three packages) and load the proper one at runtime.  You can't use them in PartTools/export, so they have to be applied at run-time through custom plugin code.  You cannot access/find them through Shader.Find(), so the stock code/other mods' code will never be able to load them/use them.  You also need to accommodate for the various rendering systems for some shader functions (openGL vs directX).

Once you get them placed onto a model/mesh/renderer... they work just like the built-in/KSP shaders, and render just fine.


Source:  I have written and am using custom shaders in SSTU to facilitate back-lit solar panels and user-recolorable parts.   ( https://github.com/shadowmage45/SSTULabs/tree/master/CustomShaders )

So. a metric ton of C# and HLSL Shaderblocks for every different type of hardware and OS..... all i wanted was cockpit mirrors jesus KSP...

Link to comment
Share on other sites

9 minutes ago, /not/pol/ said:

So. a metric ton of C# and HLSL Shaderblocks for every different type of hardware and OS..... all i wanted was cockpit mirrors jesus KSP...

LoL...indeed.  That about sums it up :)

I didn't even start on the difficulty of using reflective shaders.  Those come with a whole extra load of mess to deal with; you either need to render and use your own reflection cube-maps, or try and 'fix' the problems that KSP has with Unity's standard reflection probes (or possibly even other reflection hacks that I'm unaware of).  Neither of which are trivial problems to solve, both would require additional shader and C# plugin code.

You might look at / look into how EVE and other mods' load their shaders.  They might have a simpler or more refined method figured out by now, which might reduce the difficulty of getting them compiled/loaded into KSP.

Link to comment
Share on other sites

Just now, Shadowmage said:

LoL...indeed.  That about sums it up :)

I didn't even start on the difficulty of using reflective shaders.  Those come with a whole extra load of mess to deal with; you either need to render and use your own reflection cube-maps, or try and 'fix' the problems that KSP has with Unity's standard reflection probes (or possibly even other reflection hacks that I'm unaware of).  Neither of which are trivial problems to solve, both would require additional shader and C# plugin code.

You might look at / look into how EVE and other mods' load their shaders.  They might have a simpler or more refined method figured out by now, which might reduce the difficulty of getting them compiled/loaded into KSP.

the most code i know is Lua is even thats a far stretch. does not really seem worth the time just for cockpit mirrors when i can just look behind me :|

Link to comment
Share on other sites

Well, specifically for cockpit mirrors, you might not even need custom shaders (though you would need a fair load of C# code to make it work).

Setup a camera in the position of the mirror (with appropriate frustum/culling), render to a texture, and use that texture in a mesh/material on the mirror.  Probably not as performant as a reflective-shader-based solution.... but is essentially what the docking-port-camera/external camera mods do, and they don't seem to have too big of a performance hit.  Might even be able to ask one of those mods' authors for assistance; as they already have most of the code-base in place, they should be able to (can't say as they would be willing... but probably worth it to ask) put something together for you without too much difficulty (and get a 'neat new feature'/part for their own mod in the process).

Link to comment
Share on other sites

Just now, Shadowmage said:

Well, specifically for cockpit mirrors, you might not even need custom shaders (though you would need a fair load of C# code to make it work).

Setup a camera in the position of the mirror (with appropriate frustum/culling), render to a texture, and use that texture in a mesh/material on the mirror.  Probably not as performant as a reflective-shader-based solution.... but is essentially what the docking-port-camera/external camera mods do, and they don't seem to have too big of a performance hit.  Might even be able to ask one of those mods' authors for assistance; as they already have most of the code-base in place, they should be able to (can't say as they would be willing... but probably worth it to ask) put something together for you without too much difficulty (and get a 'neat new feature'/part for their own mod in the process).

still involves C#(a coding language i am in no ways familiar with) although it sounds like a good idea

Link to comment
Share on other sites

  • 1 month later...

I would love to have standard material from Unity 5 as a shader in KSP, with support for custom substance painter sliders, so that way i could have a substance slider to control the edges wear on parts, that could be triggered by the time of use for that part, or had burn marks after reentering. Things like that.

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