Jump to content

[0.21.x] ReflectiveShader Plugin (Version 1.2)


Razchek

Recommended Posts

ReflectiveShader Plugin

by Hubs' Electrical

(Version 1.2)

Screenshots & Video

eZZ7WmKl.jpg uDIT7HJl.jpg

About

This simple plugin will alter the active shader on any part to a real-time reflective shader.

The plugin shader is
VERY
expensive to render!
Meaning that if you use a lot of parts with a reflective shader then you will get a low frame-rate.

Some lower-spec computers may have trouble using this plugin.
Scroll down for some performance tips
.

How to use

For the default settings you just need to add the module to the part config you want to become reflective.

MODULE

{

name = ReflectiveShaderModule

}

To use with
(all variables below are supported of course):

MODULE

{

namespace = ReflectionPlugin

name = StaticReflectiveShaderModule

}

The module has several supported options should you wish to change the default settings. See below.

I recommend going into unity, creating a material that uses the KSP/Specular shader and after specifying your desired settings to use this on any custom models you wish to have reflection.

Below are all the variables which you can alter.

You do
not
need to place each variable into the module scope, only the ones which you would like to change (with the exception of the SpecColor values, if one is used all should be specified).

To the right of each variable name are their respective default values.

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 = 100


// 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/Specular


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

ParallaxHeight = 0.02


// How reflective the reflection will be (Weakest 0.0 - 1.0 Strongest).

ReflectionStrength = 0.5


// 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 = meshName


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

}

Example Part Config (using a stock part):

PART

{

// Kerbal Space Program - Part Config

// FL-T500 Fuel Tank

//


// --- general parameters ---

name = fuelTank

module = Part

author = NovaSilisko


// --- asset parameters ---

mesh = model.mu

scale = 0.1



// --- node definitions ---

node_stack_top = 0.0, 7.72552, 0.0, 0.0, 1.0, 0.0

node_stack_bottom = 0.0, -7.3, 0.0, 0.0, 1.0, 0.0

node_attach = 5.01, 0.0, 0.0, 1.0, 0.0, 0.0, 1



// --- editor parameters ---

cost = 850

category = Propulsion

subcategory = 0

title = FL-T400 Fuel Tank

manufacturer = Jebediah Kerman's Junkyard and Spaceship Parts Co.

description = The FL series was received as a substantial upgrade over previous fuel containers used in the Space Program, generally due to its ability to keep the fuel unexploded more often than not. Fuel tanks are useless if there isn't a Liquid Engine attached under it. They can also be stacked with other fuel tanks to increase the amount of fuel for the engine below.


// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision

attachRules = 1,1,1,1,0


// --- standard part parameters ---

mass = 0.25

dragModelType = default

maximum_drag = 0.2

minimum_drag = 0.3

angularDrag = 2

crashTolerance = 6

breakingForce = 50

breakingTorque = 50

maxTemp = 2900


MODULE

{

name = ReflectiveShaderModule

}


RESOURCE

{

name = LiquidFuel

amount = 180

maxAmount = 180

}


RESOURCE

{

name = Oxidizer

amount = 220

maxAmount = 220

}


}

Advanced Usage

To support Parallax and Bumped shaders, I chose to use existing shaders supported by KSP (to carry the textures).

Reflective/Bumped* = KSP/Bumped Specular

Reflective/Parallax* = KSP/Emissive/Bumped Specular

For example, if you wanted to create a nice Reflective/Bumped Diffuse effect you should use the KSP/Bumped Specular shader and construct it as per normal.

This is the same for the other Reflective/Bumped* shaders.

If you wanted to use a Reflective/Parallax Specular shader you should construct your shader using the KSP/Emissive/Bumped Specular shader and use the emissive texture as your parallax height map.

Reflection Maps can be achieved two ways.

1. Use a Reflective Specular shader. The Alpha channel will map reflectiveness. "Black areas of the alpha will be zero specular reflection, while white areas will be full specular reflection." (zero alpha = black, max alpha = white)

2. Create your model with multiple meshes, one of those meshes can have their shader replaced later by using the MeshesToChange variable.

Download Instructions

1.
v1.2 (source code available
)

2. Decompress the downloaded archive inside the root of your KSP directory.

3. Modify any part configs which you would like to add the shaders to.

4. Reflectiveness!

The assembly and source code is now public domain (all rights & liabilities waived).

I would appreciate attribution, but it is not necessary. :)

Performance Tips

To increase performance consider doing the following:

1. The first thing you should do to increase performance by a considerable amount is to set "OneFacePerFrame = true" - this will force the shader to render only one face of the cubemap per frame as opposed to 6 per frame.

2. VertexLit, Diffuse and Unlit shaders are the least expensive to render, consider using them if they can provide the appearance you are after (
e.g. ShaderName = Reflective/VertexLit
) this will bump up the frame-rate slightly if you were using Reflective/Specular.

3. Drop the CubeMapSize. This is my least favourite to affect, as it effects the quality of the reflection, but lowering the value will increase the frame-rate.

For a nice metallic effect with a moderate rendering expense my favored settings would be (
):


MODULE

{

name = ReflectiveShaderModule

CubeMapSize = 1024

OneFacePerFrame = true

ShaderName = Reflective/VertexLit

}

Known Bugs

- Some GUI elements get rendered in the reflection lol. If it doesn't hinder performance any further I'll attempt to remove it from the reflected view in a future update.

Changes

V1.2B

|_ Added support for
.

V1.1b

|- Increased performance from bug fixes and code optimization.

|- Added support for Bumped and Parallax shader textures.

|_ Added multi-mesh support.

Final Words

If there are any problems or you have any suggestions, please feel free to let me know.
:)

If someone would like blur (or any other effects) added, please let me know.

Edited by Razchek
Link to comment
Share on other sites

You sir are awesome. Trying this now. Thanks!

You're welcome! Enjoy. ;)

Nice, this would be cool for EVA kerbals who would see their reflections on capsule windows.

I expect people will be using this plugin when I add the additional support for the Reflective Bumped and Parallax shaders as they let you set only certain areas to be reflective. :) Which would go great for windows and the such lol.

Link to comment
Share on other sites

Thank you greatly. Now I just have to separate my parts so that this works. I will post results up here when I am done.

You're welcome, hopefully this works out good for you!

I immediately thought: whoever made those masks and glasses for Kerbals in EVA using KAS, could they make a reflective mask for the front of the Kerbal's helmets?!

You definitely could. I would advise to wait for the next update before attempting that though.

Link to comment
Share on other sites

Impressive work, not sure is it will have real purpose but interesting. Gold foil things, some people did it, can look better with it, especially with reflective bump, I think.

How about add to it some fresnell falloff factor? For most things it's looks better. Bluring? Global switch with parametres(render all Reflective/Diffuse this way).

I barely understand how it's work but can there be switch for rendering only sky\ground or skybox\planets if it will help with perfomance, for most things it will be enough, I think.

4t9Tfd6.jpg

Edited by zzz
Link to comment
Share on other sites

Impressive work, not sure is it will have real purpose but interesting. Gold foil things, some people did it, can look better with it, especially with reflective bump, I think.

How about add to it some fresnell falloff factor? For most things it's looks better. Bluring? Global switch with parametres(render all Reflective/Diffuse this way).

I barely understand how it's work but can there be switch for rendering only sky\ground or skybox\planets if it will help with perfomance, for most things it will be enough, I think.

-http://i.imgur.com/4t9Tfd6.jpg-

Bumped and Parallax will be added in the next update. :) I'll continue to look at performance enhancements and added effects.

That picture looks nice. :D

--

I'd love to see chrome wheels! haha

I made this because BlazingAngel665 had the idea! Hats off to him as well for the concept, I never really thought about doing it until after seeing his thread. :)

Edited by Razchek
Link to comment
Share on other sites

Uh, question?

You said

"will alter the active shader on any part to a real-time reflective shader"

and I was wondering, does this automatically apply to every part, or does it need a config in every part config?

Link to comment
Share on other sites

Uh, question?

You said "will alter the active shader on any part to a real-time reflective shader" and I was wondering, does this automatically apply to every part, or does it need a config in every part config?

You need to add it to the part config of each file you want to become reflective. I'll update the post to clarify that. :)

Hey, great work here !

How about reflection maps ? That way we can define some areas that reflects and not the others. Visors and cockpit glass gonna be beautiful !

Use the alpha channel of your textures to map reflection for now, you can also map reflectiveness with the normalmap of any reflective bumped/parallax shader (I'll be adding support for those shortly).

http://docs.unity3d.com/Documentation/Components/shader-ReflectiveSpecular.html (note: in Unity, still use the KSP/Specular shader on your material when making a part, the module will take the values from the original material)

Very good mod!

Thank you! :D

-snip-

Looks cool( at pictures shader is not everywere, miss some things). I predict it will be hungry(realtime reflection usually hungry) so used 16x16 maps but, well, maybe it's just me but feels too much to regular use.

Try setting 'OneFacePerFrame = true' this will help marginally with the performance. Remember you can reload the part cfg's in-game (space-center) with the debug menu.

The downfall to the OneFacePerFrame is that the reflections look to update once every other second.

I will add a switch to the config parameters that will allow you to select which meshes will have the shader changed by providing their names.

Edited by Razchek
Link to comment
Share on other sites

Huh, I'm trying to get the structural panels and other things from the B9 pack working with shaders, however I can't get the shaders to apply.

This is my config, at least the important part of it.

// --- editor parameters ---

cost = 500

category = Structural

subcategory = 0

title = 8x8m Structural Panel

manufacturer = Tetragon Projects

description = Lightweight and sturdy composite plate for your construction needs. Be it oversized orbital docks, moon base hangars, landing pads, or hulls of ships that shouldn't realistically fly, these pieces will help you build those.

// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision

attachRules = 1,1,1,1,1

// --- standard part parameters ---

mass = 0.2

dragModelType = default

maximum_drag = 0.20

minimum_drag = 0.15

angularDrag = 1

crashTolerance = 400

maxTemp = 3400

fuelCrossFeed = True

}

MODULE

{

name = ReflectiveShaderModule

}

(yes the module part is indented)

Edited by Cooly568
Link to comment
Share on other sites

Huh, I'm trying to get the structural panels and other things from the B9 pack working with shaders, however I can't get the shaders to apply.

This is my config, at least the important part of it.


// --- editor parameters ---
cost = 500
category = Structural
subcategory = 0
title = 8x8m Structural Panel
manufacturer = Tetragon Projects
description = Lightweight and sturdy composite plate for your construction needs. Be it oversized orbital docks, moon base hangars, landing pads, or hulls of ships that shouldn't realistically fly, these pieces will help you build those.


// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
attachRules = 1,1,1,1,1


// --- standard part parameters ---
mass = 0.2
dragModelType = default
maximum_drag = 0.20
minimum_drag = 0.15
angularDrag = 1
crashTolerance = 400
maxTemp = 3400
fuelCrossFeed = True
}


MODULE
{
name = ReflectiveShaderModule
}

(yes the module part is indented)

I downloaded & installed the B9 pack. Found the part config for the part you mentioned and added (indent doesn't matter):

MODULE
{
name = ReflectiveShaderModule
}

It worked perfectly fine.

I added a couple of extra params to make the reflection nicer and it still works good. :)

liPvjUas.jpg

The above picture used the following config:

PART
{
// --- general parameters ---
name = B9_Structure_P8_Surface
module = Part
author = bac9

// --- asset parameters ---
MODEL
{
model = B9_Aerospace/Parts/Structure_P_Standard-Frame/P8_Surface
}
scale = 1
rescaleFactor = 1

// --- node definitions ---
// definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z
node_attach = 0, 4, 0, 0.0, 1.0, 0.0

node_stack_top01 = 1.875, 1.875, -0.125, 0, 0, 1
node_stack_bottom01 = 1.875, 1.875, 0.125, 0,0, -1
node_stack_top02 = 1.875, -1.875, -0.125, 0, 0, 1
node_stack_bottom02 = 1.875, -1.875, 0.125, 0,0, -1
node_stack_top03 = -1.875, 1.875, -0.125, 0, 0, 1
node_stack_bottom03 = -1.875, 1.875, 0.125, 0,0, -1
node_stack_top04 = -1.875, -1.875, -0.125, 0, 0, 1
node_stack_bottom04 = -1.875, -1.875, 0.125, 0,0, -1
node_attach = 0, 4, 0, 0.0, 1.0, 0.0

// --- FX definitions ---

// --- editor parameters ---
cost = 500
category = Structural
subcategory = 0
title = 8x8m Structural Panel
manufacturer = Tetragon Projects
description = Lightweight and sturdy composite plate for your construction needs. Be it oversized orbital docks, moon

base hangars, landing pads, or hulls of ships that shouldn't realistically fly, these pieces will help you build those.

// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
attachRules = 1,1,1,1,1

// --- standard part parameters ---
mass = 0.2
dragModelType = default
maximum_drag = 0.20
minimum_drag = 0.15
angularDrag = 1
crashTolerance = 400
maxTemp = 3400
fuelCrossFeed = True

MODULE
{
name = ReflectiveShaderModule
CubeMapSize = 1024
ShaderName = Reflective/Specular
OneFacePerFrame= true
}
}

When you select the part in the VAB have a look in the Debug Menu and see if any exceptions or errors have occurred? :)

Edited by Razchek
Link to comment
Share on other sites

I downloaded & installed the B9 pack. Found the part config for the part you mentioned and added (indent doesn't matter):

-snipidy-

When you select the part in the VAB have a look in the Debug Menu and see if any exceptions or errors have occurred? :)

I'll see if there is a error, I think its because of some other mod I have installed, for now I'll make a second install of KSP for this mod, and videos.

And such. :)

Link to comment
Share on other sites

I'll see if there is a error, I think its because of some other mod I have installed, for now I'll make a second install of KSP for this mod, and videos.

And such. :)

Let me know how it goes. :)

Any parts that use the KSP/Specular shader normally will look outstanding with this mod. For example the Cupola CommandPod looks fantastic because the reflection mapping already done on it! :D

Link to comment
Share on other sites

I'm trying to get it working with my 762 part boat...

I'm guessing I'll be lucky to get at most 0.5 FPS :P

Edit: I found my problem, I had a } in between the end of the config and the reflection module, whoops.

Edit 2: Another quick question, does the shader use the CPU or the GPU more?

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