Skip to content

Commit

Permalink
Merge pull request #109 from post-kerbin-mining-corporation/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
ChrisAdderley authored Jul 10, 2022
2 parents c2b71f2 + ff80836 commit 1815392
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
Binary file modified GameData/Waterfall/Shaders/waterfallshaders-linux.waterfall
Binary file not shown.
Binary file modified GameData/Waterfall/Shaders/waterfallshaders-macos.waterfall
Binary file not shown.
Binary file modified GameData/Waterfall/Shaders/waterfallshaders-windows.waterfall
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/Waterfall/Versioning/Waterfall.version
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"MAJOR":0,
"MINOR":8,
"PATCH":1,
"PATCH":2,
"BUILD":0
},
"KSP_VERSION":
Expand Down
26 changes: 24 additions & 2 deletions Source/ShaderLab/ProceduralParticles.shader
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ Shader "Waterfall/Procedural Particles (Additive)"
_StartTint("StartTint", Color) = (1,1,1,1)
_EndTint("EndTint", Color) = (1,1,1,1)
_Brightness("Brightness", Range(0, 5)) = 1
_PlumeDir("Exhaust Direction", Vector) = (0,1,0,0)
[Space]

_Scale("Scale", Range(1, 10)) = 1
_Scale("Scale", Range(1, 15)) = 1
_Expand("Expand", Range(0, 5)) = 0
_FadeIn("Fade In", Range(0, 1)) = 0.4
_FadeOut("Fade Out", Range(0.0, 2.5)) = 1
Expand All @@ -36,6 +37,7 @@ Shader "Waterfall/Procedural Particles (Additive)"
float4 _StartTint;
float4 _EndTint;
float _Brightness;
float4 _PlumeDir;
float _Scale;
float _Expand;
float _FadeIn;
Expand Down Expand Up @@ -131,9 +133,29 @@ Shader "Waterfall/Procedural Particles (Additive)"
float viewdot : TEXCOORD4;
};

float3 dirToViewSpace(float3 view_zero, float3 dir) {
float3 perpendicular = normalize(dir);
float3 view = UnityObjectToViewPos(perpendicular);
return view - view_zero;
}

float4 billboardTransform(in float4 vertex, in float beta) {
float3 view_zero = UnityObjectToViewPos(float3(0, 0, 0));
float3 plumeDir = normalize(_PlumeDir.xyz);

// calculate two vectors perpendicular to plumeDir
float3 notPlumeDir = normalize(plumeDir + float3(1, 1, 1));
float3 perpendicular1 = cross(plumeDir, notPlumeDir);
float3 perpendicular2 = cross(plumeDir, perpendicular1);
// transform those to view space
float3 perp1view = dirToViewSpace(view_zero, perpendicular1);
float3 perp2view = dirToViewSpace(view_zero, perpendicular2);
// combine the scaling of these vectors through the model matrix
float transformScaleTotal = sqrt(length(cross(perp1view, perp2view)));
//float transformScaleTotal = length(perp1view); <- simple version, only uses one dimension to check scaling

// only transform y with MV matrix, then add xz components, then apply projection
float scale = _Scale + beta * _Expand;
float scale = (_Scale + beta * _Expand) * transformScaleTotal;
float4 xz = float4(vertex.x, vertex.z, 0, 0);
float4 yView = float4(UnityObjectToViewPos(float4(0, vertex.y, 0, 1)), 1);

Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.8.2
------
- Fix to procedural particles shader

v0.8.1
------
- Fix compatibility with KSP < 1.12
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
===============
Waterfall 0.8.1
Waterfall 0.8.2
===============

Waterfall is a mod for Kerbal Space Program that provides a cool new way to create and drive engine effects for smooth rocket plumes. It has
Expand Down

0 comments on commit 1815392

Please sign in to comment.