Starwaster

[1.0.5] Reflection Plugin Continued 2.0

Recommended Posts

This is an updated version of the Reflection Plugin created by Razchek with some additional features and fixes that provide more control over reflective materials and non-realtime updating for performance increases. The original thread is to be found here: [0.21.x] ReflectiveShader Plugin (Version 1.2)

This plugin is released as Public Domain as was the original plugin by Razchek.

Plugin and source downloads:

Latest Download! (for KSP 1.0.5)

Reflection Plugin github repository

Confirmed working with 1.0.5

Version 2.0.1 for KSP 1.1.2 in progress

Not available yet.

Version 2.0

  • Fixed long standing detached transform bug
  • Fixed rendering artifacts
  • Switched to multi-pass rendering (as done in Texture Replacer... MULTI-PAAAASSSS)
  • Compiled for KSP 1.0.5
  • Included version file

BETA

Version 1.2

See Changelog in next post

Changes from the original:

 

  • Can use ReflectionColor in place of ReflectionStrength. If ReflectionStrength is less than 0 then ReflectionColor is used instead. Default behavior retained.
  • NearClipPlane added. Set this to if unwanted portions of your Part are being reflected.
  • UpdateRate added. This is the number of seconds in GAME TIME (not real time) between environment map updates. Eliminates realtime reflection and increases performance.
  • Texture scaling bug fixed. (if textures were scaled in original material, it wasn't carried over to reflective material)

 

Known issues. The reflection camera may reflect parts of the model to which it is attached. Use NearClipPlane to eliminate unwanted reflections. (value should be set to distance in meters. If the part of your mesh that is showing up in reflections is 1 meter away from the center of geometry then set NearClipPlane to 1 or greater)

updateRate is not working properly in SW1.0. The cubemap is updated continuously. As soon as I get the update rates properly sorted I'll be releasing a new version that also restores all missing shaders.

5eR6nTMl.png

Alpha channel controls strength:

kIS3f2Ml.png

Edited by Starwaster
Updated plugin for KSP 1.0.5

Share this post


Link to post
Share on other sites

1.3.0

  • Official update for KSP 1.0.x
  • Ensure that camera transform position is updated to match vessel/parts
  • Fixed bugs with black/blue color replacing expected reflections.
  • MeshesToReplace defaults to all now

Known issues: VAB / SPH reflections not working properly. (or maybe they are......)

First version is designated SW-1.0 (to differentiate from Razchek's)

NearClipPlane = -1 //(not KSP/Unity3D default; -1 is a flag that says not to set nearClipPlane of the camera. Positive values should be in meters)

realTimeReflection = True

updateRate = 300 // Requires realTimeReflection to be set to False

ReflectionColor = 0.5, 0.5, 0.5, 0.5 // Requires ReflectionStrength to be set to -1. Default value mimic's Razchek's default setting of 0.5

SW-1.2 - Attempted fixes for reflection bugs. (blue or black replacing missing reflection or not updating when not at warp)

SW-1.1

Missing shaders restored. Uses proper shader names (Reflective/Bumped, Reflective/Bumped Specular, etc)

updateRate bug fixed. updateRate was not properly working in SW-1.0. To activate set realTimeReflections to false. This will basically turn reflections into procedural environment mapping. In addition to updating every updateRate game seconds (NOT real life seconds) the reflection will refresh whenever SOI changes. (might be of limited value since it will likely refresh long before you get close to a new body to notice)

Changelog for 1.2.0

  • Restored missing shaders (compiled versions)
  • Increased default FarClipPlane value to 1000000000f (!!!!!)
  • Mark refresh map as dirty when coming of rails.
  • Caps reflection map refresh rate when time warping. (shouldn't lag when time warping now, BUT NEED FEEDBACK SO I KNOW IT WORKS FOR PEOPLE WHO ARENT STARWASTER. THIS MEANS YOU!!!!)
  • Removed unnecessary debug messages.
  • Enhanced exception handling and shader fallback.
  • Added Starwaster/Bumped Specular shader (reflective, WIP, highly experimental, use at your own risk)
  • Fed the cats.

Edited by Starwaster

Share this post


Link to post
Share on other sites

Example usage


MODULE
{
name = ReflectiveShaderModule

// Lower values for performance, higher values for aesthetics (you shouldn't ever need to go higher than 1024).
CubeMapSize = 128

// How deep the reflection will be ("how far the reflection camera will view")
FarClipPlane = 500000000
// How far away must something be before it is reflected
//NearClipPlane = 1

// Set to false to render all 6 faces of the CubeMap at once (six times slower~)
OneFacePerFrame = true

// The shader to find. The reflective shaders are:
// Reflective/Diffuse
// Reflective/Specular
// Reflective/VertexLit
// Reflective/Bumped Diffuse
// Reflective/Bumped Specular
// Reflective/Bumped Unlit
// Reflective/Bumped VertexLit
// Reflective/Parallax Diffuse
// Reflective/Parallax Specular
ShaderName = Reflective/Bumped
realTimeReflection = False
updateRate = 300


// The height of the parallax map. Values are accepted between 0.005 and 0.08.
ParallaxHeight = 0.005

// How reflective the reflection will be (Weakest 0.0 - 1.0 Strongest).
ReflectionStrength = 1.0
//ReflectionColor = 0, 0, 0, 0

// Use this variable to specify which meshes to apply the shader to.
// Not using this variable will default to the first found mesh.
// Use the actual mesh name for the value. Or you could use:
// all - to replace the shader on all meshes in the model.
//MeshesToChange = polymsh,polymsh_detached,polymsh_detached1

// How shiny the specularity will be (if specular).
// This value will be automatically set if it already exists on the previous shader and is not defined here.
Shininess = 1.0

// These variables should be used together only.
// These values will be automatically set if they already exist on the previous shader and are not defined here
//SpecColorR = 0.5
//SpecColorG = 0.5
//SpecColorB = 0.5
//SpecColorA = 0.5
}

Alpha channel controls reflection strength!

kIS3f2Ml.png

Edited by Starwaster

Share this post


Link to post
Share on other sites

Very cool! Going to have to play with this tonight on some hatches. See if I can get a kerbal to see his reflection!

Share this post


Link to post
Share on other sites
Very cool! Going to have to play with this tonight on some hatches. See if I can get a kerbal to see his reflection!

You'll probably want to increase the resolution of the cube map. Kerbals are a little grainy. I think the default is 128x128? I forgot about that. That means I can increase resolution on my drop tank.

Share this post


Link to post
Share on other sites

this plugin is awesome,

If you have a tga with an alpha channel you can get some nice looking reflections.

PNG alpha does not work.

b9xATuF.jpg

Share this post


Link to post
Share on other sites

will this work for, say, parts from the Near Future pack?

Share this post


Link to post
Share on other sites

I love it, I want to use it! How affects performance? frame drops?

And one question I keep wondering... this reflects starfield??

Edited by Proot

Share this post


Link to post
Share on other sites
I love it, I want to use it! How affects performance? frame drops?

And one question I keep wondering... this reflects starfield??

If you use it on enough parts then it can affect performance. The original version (by Razchek) was realtime reflections. The way it works is by incorporating a camera into the part. Each frame the camera would update either all faces or a single face of the cubemap depending on how it was configured. If you're not familiar with a cube map, think of it like a skybox except that it's used for simulating reflections.

This version however allows you to set an update rate. By default it's still real time which means every single frame the camera is updating the cube map. However if you set the variables realTimeReflections to false and updateRate to a positive value then it will only update periodically. The number of seconds between updates is whatever you set updateRate to. When I say seconds I'm referring to game seconds and not real time seconds. The reason I did that is because the frequency with which the scenery changes is dependent on the passage of game time as your ship orbits around a planet. In a later update I'll think about maybe basing it on how many degrees (or would radians be better?) you've passed through your orbit as that is a truer indicator of how much your environment has changed visibly.

When testing, I find that a value of 300 seconds (5 minutes) works well. When set up that way performance is hardly impaired at all. In addition to the update rate, the camera will fully update automatically every time the scene changes. So even if you were to use hyperedit to move your ship from Kerbin to Duna, the cubemap texture will update.

Also, as far as future updates, I'm working on an update to restore the missing reflection shaders. Originally there were a variety of reflection based shaders that were actually stock Unity3D shaders that KSP does not use. Starting in 0.23 however, most of those were removed. Only VertexLit (fastest but least realistic) and Bumped Diffuse reflection shaders remain. Specular reflective shaders were missing. The next version should have those restored by incorporating the shaders directly into the plugin.

Share this post


Link to post
Share on other sites

Can we have an option for a purely static cubemap that we can define, or do you think that will not make that much of a difference?

Share this post


Link to post
Share on other sites

Could it be used in the kerbal's helmet glass in some way? Texture Replacer Mod can modify that texture, but I don't know any "part" for helmet or it glass. That would be an awesome feature...

Share this post


Link to post
Share on other sites

Would it be possible to have an adaptive refresh rate? On the surface of a planet you need a high rate to make it look right, in orbit you only need low rate.

this plugin is awesome,

If you have a tga with an alpha channel you can get some nice looking reflections.

PNG alpha does not work.

That is exactly what your already pretty parts were missing :) KSP may become beautiful yet!

Edited by Camacha

Share this post


Link to post
Share on other sites
Can we have an option for a purely static cubemap that we can define, or do you think that will not make that much of a difference?

I have not been successful in getting KSP to load cube maps.

I thought of that and actually experimented with it before implementing update rates. But the cube map texture didn't register in the log at all. I decided to put it off in favor of the current scheme. TBH it probably would not matter because you could set updateRate so high (maxInt) that it effectively only updates on scene change. The only time it would really contribute to lag is when the cameras update.

Could it be used in the kerbal's helmet glass in some way? Texture Replacer Mod can modify that texture, but I don't know any "part" for helmet or it glass. That would be an awesome feature...

It probably could but you would definitely need alpha to mask the parts you want less reflectivity on (or no reflectivity at all). Also unless Unity has a translucent shader that does reflections, you would have to choose one over the other. Or write a new shader. I have done some shader work in HLSL for Crysis but it's been while. Also after the next update when I fix the missing reflection shaders, I'm going to resume full work on Copernicus to get the first few parts out the door.

That was what actually motivated me to update RP, was the desire to have reflective shaders for the MTV fuel tanks that didn't lag me.

Share this post


Link to post
Share on other sites

Regarding my earlier question, how do parts looks with a low refresh rate near the ground?

Share this post


Link to post
Share on other sites

Excuse me if I'm bothering you, lol. But I have one more question: could be used in the stock textures in an easier way? I mean, it need modify the stock texture of a squad pod to add an alpha in the windows, for example. No?

But, is not possible add a new texture only with the alpha, to be used as a layer for the reflections? This could allow add reflections to squad parts without modify stock textures or add new complete re-textures.

Share this post


Link to post
Share on other sites
Would it be possible to have an adaptive refresh rate? On the surface of a planet you need a high rate to make it look right, in orbit you only need low rate.

missed this because I was replying when you were posting.

yes it's possible, that's one of the things I was talking about earlier. Having the option to base update rate on how much of your orbit you've covered in a given period.

Share this post


Link to post
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.