Jump to content

[HOW-TO] Using custom CG shaders in KSP


Recommended Posts

Hello,

As you might know, it's possible to load your own shaders into KSP that uses fixed pipeline, but not custom CG shaders as runtime lacks CG compiler and so it's unable to compile the shader. Well, as it turned out, it is possible to do that with little trickery. Here's how:

1. put your shader into some Unity project

2. open it in Unity

3. find the shader in the asset explorer, right click it and select "Reimport"

4. navigate into your Unity project's Temp folder.

There will be a file named "CgBatchOutput.shader". Open it up and it will contain your compiled shader. Now you can load up it's contents however you want (hardcode it into the code, embed it as a resource in dll, put it as a stand-alone file), and the pass this text into constructor of Material object. Bingo! Now you can leverage however complex and cool shaders you want!

A word of caution though - if you opt to use some advanced shader features (like Geometry shaders for example), be aware that there might be users with hardware that doesn't support them. In this case you can either provide a fallback solution, or provide some other sensible reaction to the user.

Link to comment
Share on other sites

  • 11 months later...
It works fine. It's used in MJ and I do it in SmokeScreen too.

You are quite right, I tried the same instructions today and they worked. Now to find out how I get the shader working with a kerbtown model.

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