Jump to content

KSP/ScreenSpaceMask Shader Source? (used on Part icons in editor)


Recommended Posts

Hi all,

While working through using custom shaders on parts in KSP I ran into a bit of a hitch related to the editor part icons.  Apparently all models used for Part Icons are stripped of their original shader/materials, and a custom material/shader combination is applied to them using the 'KSP/ScreenSpaceMask' shader.  I cannot locate this shader in any of the PartTools distributions (0.20, 0.23, 1.1, 1.2-porkjet parts).

I would like to override whatever shader is forced onto the Part Icon models back to the custom shaders that the actual parts have assigned to them.  However before I do such a hacky/heavy handed move, I would like to take a look at the source of the shader currently in use on the icons to see if there is anything special required of that shader (I would assume so, else why use a custom shader for part-icons?).  As stated above though, I cannot locate the source for that shader anywhere.

 

Basically I've created custom shaders with RGB specular maps and AO as a separate texture slot, but all of these features get stripped on the part-icons, resulting in dull and washed-out (and in some cases, just wrong) looking parts for the icons (missing their specular map entirely, lacking AO and detail maps).  Not really a showstopper, and far from game-breaking, but none the less a problem I would like to solve.

The first step would be to look at the existing shader source for what features are used specifically for part-icons.  The next step would be to create new plugin code that updates the shaders on the part icons after all of the parts have been compiled (either through a hook in one of my custom PartModules, or a more generic KSPAddon solution hooking into the database events).  Might be necessary to write my own customized version of the KSP/ScreenSpaceMask shader with support for the custom texture slots, but cannot know without looking at the existing shader.

 

Does anyone have any information on that shader -- what it does, why it exists, and where to find the source?

Thanks in advance,

Shadowmage

Link to comment
Share on other sites

  • 8 months later...

Ehh... since nobody else bothered to post with info, I managed to kludge my way through a re-implementation of said shader.

What it does:  Clips the rendering bounds into a specific area based on screen-space.  E.g. only render within a specific sub-window.  Analogous to openGL scissor function

Why it exists:  As a very hacky workaround to only rendering editor-part-list part-icons within the bounds of the editor-part-list scroll area.  Probably could have been handled more properly by a separate camera and render-texture.

How it does it:  Uses a couple of shader properties to setup the clip bounds.  In the shader, checks if the output coordinate is within the desired bounds, else discards the fragment without rendering it.


Links to working implementation -- note the explicit handling of directX vs. openGL screen-space coordinates in the shader.  Without this the clip space will have inverted Y coordinates between the two rendering systems.

https://github.com/shadowmage45/SSTULabs/blob/master/CustomShaders/SSTUMaskedIcon.shader

 

Mods -- if reading, you can probably close this thread.  It has served its purpose, and the information sought has been figured out.

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