Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Shaders #1

Open
RichardDastardly opened this issue Aug 5, 2016 · 10 comments
Open

Shaders #1

RichardDastardly opened this issue Aug 5, 2016 · 10 comments
Assignees

Comments

@RichardDastardly
Copy link

RichardDastardly commented Aug 5, 2016

We should have a chat about shaders sometime, I have one somewhat like Bac9s, but it doesn't require messing with vertex data & supports up to 255 different colour areas per pattern ( and three switchable patterns ) if you're sufficiently mad. Can imagine the UI issues :p

Also I kinda want to work on a proc wing with changeable profiles which means doing a much more complex mesh, so if the mesh shaping part ( and FAR aero data ) can be modular that'd save a bunch of effort down the road. The other part of that was being able to slice a wing & have two parts, which ... is a lot more complicated than it sounds.

Call it ShapeWings or something for now, I'm sure the perfect name is out there somewhere.

@Crzyrndm Crzyrndm self-assigned this Aug 5, 2016
@Crzyrndm
Copy link
Owner

Crzyrndm commented Aug 13, 2016

This sounds very interesting. Geometry stuff is quite easy to modify independently so no need to worry about that (otherwise supporting both types would be a nightmare...). Just a matter of working out the maths

Not so sure about the patterns thing, that just sounds like bottled UI pain (I'm all for more patterns, that's relatively simple, but colourisable zones to that extent just sounds like a PITA if you ask me. Obviously not the target audience :P)

@RichardDastardly
Copy link
Author

RichardDastardly commented Aug 22, 2016

The pattern selection isn't really any different to the AO layer Bac9's shader does - I'm passing a colour to the shader to pick an RGB channel as a pattern, and then some maths to decide what colour to put where based on grey levels. Writing paint colours to the shader just means sending an array ( which is a slight pain in 5.2, 5.4 you will be able to just send an array as one ), the UI... well, yes.

I actually have a partmodule (ModuleTintable in my repo, at any given moment it might be in a working state - this is my "learn C# & Unity" thing ) to test out shader stuff, I haven't managed to get round to learning more complicated UI stuff than right-click menus yet - I was looking at U5 UI stuff & wondering how much to use directly or whether there's something KSP specific on top. I'll attempt to prototype as much as possible, anyway.

https://flic.kr/p/KcAoqy demo with temporary colour pickers.

@Crzyrndm
Copy link
Owner

Crzyrndm commented Aug 25, 2016

ye, it's more the UI I'm concerned about. If you have an idea of how that could be a useable UI I can probably make it work in KSP (or atleast have an idea of where to start). Although I think I need to understand a bit more about how your shader works first and have the current functionality finished...

My current understanding:

  • Three values to select the pattern (0-255? 16581375 possible patterns)
  • Four colour inputs per pattern? (RGBA / HSBA? 0-1 floats?)

@Crzyrndm
Copy link
Owner

Crzyrndm commented Aug 26, 2016

UI Stuff:
So assuming, the above assumptions are correct, patterns can be done with a single integer parameter and a bit of bit shifting and masking internally. That would leave essentially identical to how the B9 material is selected. Doesn't matter if they aren't continuous, just need to maintain a lookup table in that case.

That leaves the colour selection. I favour just having an array of coloured buttons to select the edit colour ( Should be extendable to large numbers of colours).

That would result in one pattern select, one select array, and one colour picker (only 1 extra row over the current appearance groups)

@RichardDastardly
Copy link
Author

  • One colour to pick overlay ( write using Material.SetColor()) - predefined either R,G,B, unless you really want to blend patterns - UI for that should probably be either a drop-down list of strings or a left/right radio button selector + label. Needs the labels stored somewhere...
  • One colour to pick paint pattern, same as above. Material.SetColor() passes a unity Color object which is just a struct of floats with some utility properties.
  • 1-n colours to put into paint pattern areas. Sensible max for n is probably 16, although even 4 is enough for most people's use. The shader can go up to 255 because it uses one 8 bit channel to store paint area data, but I can't imagine any sane use of that ( transition areas would be spectacular rainbows! ). So, that would need a bunch of colour pickers or being able to flip back & forwards across UI pages depending how much fiddling with colour you want to do. The shader has a property which needs to be set to tell it how many colours it's meant to be painting, so that's a pretty important per-pattern var which needs storing somewhere ( along with the label ).

So, yep - pretty much what you were thinking. I still need to learn U5 UI though :P my own partmod has to handle blending existing textures which is a whole bunch of other sliders.

The shader demo uses 4 colours because I didn't want to write actual code to handle setting colours just to mess with it in the inspector. U5.2 writes arrays to shaders by having a single property for each array entry; thankfully 5.4 handles passing arrays properly.

@Crzyrndm
Copy link
Owner

ok, floats rather than bytes (I couldn't recall what Unity used for colours...) and a few extra colour variants but otherwise nothing extreme.

I think I need to look at modularising the appearance

@RichardDastardly
Copy link
Author

RichardDastardly commented Aug 29, 2016

Yeah, I can't actually think of any extreme things. Swapping actual textures, and possibly loading decals in ( note: I haven't written a shader which can load decals :P but it's only a couple of extra lines in the shader ) are the only future features I can think of. The latter would need some UV offset& scaling sliders, but let's worry about that some other time like when I've written support for it...

One thing from my own work I noticed is using www to load assets means you can use any name for a bundle, so if you chop the .ksp extension off you won't end up loading bundles twice. Also means you can unload unused stuff finally... modularising the appearance might not be necessary if the UI code can handle multiple UI versions, can just do a lot of them & load the one you want later.

@Crzyrndm
Copy link
Owner

Crzyrndm commented Aug 30, 2016

removing the extension is probably a very good idea (infact, I should probably write my own exporter, but that can be some other time...)
Just be very careful with unloading the bundle if it's for public work. You can do it immediately on 32 bit windows, but 64 bit requires a 25 frame wait here, and I don't know if that changes by machine or what linux/mac versions require

@RichardDastardly
Copy link
Author

Seems not to need a timeout for shaders ( I test on 64bit everything ), but I did start writing a delay into my bundle manager anyway. Should probably make a comprehensive test for everything you can put in a bundle, really.

I did steal some code from the unity forums to build bundles, but the loader doesn't seem to like 'em.

@RichardDastardly
Copy link
Author

OK, going to sit on this until 1.2 is actually out - I need to do some fiddling with PBR shaders & need a stable platform for that. We would need new assets, so I'd probably better deconstruct Bac9s at some point ( there is a bug in his control surface model I've been wanting to fix forever anyway ).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants