Skip to content

Commit

Permalink
Reorganize assets folder and tweak shaders
Browse files Browse the repository at this point in the history
Moved rim shading and underwater fog to the common cginc
  • Loading branch information
drewcassidy committed Jul 26, 2024
1 parent 14640c1 commit 7286202
Show file tree
Hide file tree
Showing 42 changed files with 23 additions and 196 deletions.
15 changes: 7 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# Unity Project Directories
Assets/*
!Assets/Shaders/
!Assets/Textures/
!Assets/Scripts/
!Assets/UI/
!Assets/ConformalDecals/
!Assets/ConformalDecals
Assets/ConformalDecals/Fonts
Assets/ConformalDecals/Parts
KSP/
Library/
Logs/
Packages/
ProjectSettings/
Temp/

# Autogenerated shaders
Assets/ConformalDecals/Shaders/Generated/*.shader

# Unity Assetbundle Manifest Files
GameData/ConformalDecals/Resources/Resources
GameData/ConformalDecals/Resources/*.manifest
Expand Down Expand Up @@ -41,9 +42,6 @@ ExportedObj/
*.opendb
*.VC.db

# Autogenerated shaders
Assets/Shaders/Generated/*.shader

# Binaries and support files
Source/ConformalDecals/dlls
Source/ConformalDecals/bin
Expand All @@ -58,3 +56,4 @@ Source/ConformalDecals/bin
obj
*.swp
@thumbs

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef DECALS_COMMON_INCLUDED
// Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members screenUV)
#pragma exclude_renderers d3d11
#define DECALS_COMMON_INCLUDED

#include "AutoLight.cginc"
Expand Down Expand Up @@ -117,10 +115,6 @@ struct v2f
#ifdef UNITY_PASS_FORWARDADD
UNITY_LIGHTING_COORDS(5,6)
#endif //UNITY_PASS_FORWARDADD

#ifdef UNITY_PASS_DEFERRED
float3 screenUV : TEXCOORD5;
#endif
};


Expand All @@ -138,6 +132,8 @@ inline float CalcMipLevel(float2 texture_coord) {
return 0.5 * log2(delta_max_sqr);
}

// Decal bounds distance function
// takes in a world position, world normal, and projector normal and outputs a unitless signed distance from the
inline float BoundsDist(float3 p, float3 normal, float3 projNormal) {
float3 q = abs(p - 0.5) - 0.5; // 1x1 square/cube centered at (0.5,0.5)
//float dist = length(max(q,0)) + min(max(q.x,max(q.y,q.z)),0.0); // true SDF
Expand Down Expand Up @@ -212,14 +208,6 @@ v2f vert(appdata_decal v)

// pass shadow and, possibly, light cookie coordinates to pixel shader
UNITY_TRANSFER_LIGHTING(o, 0.0);

#ifdef UNITY_PASS_DEFERRED
o.screenUV = o.pos.xyw;

// Correct flip when rendering with a flipped projection matrix.
// (I've observed this differing between the Unity scene & game views)
o.screenUV.y *= _ProjectionParams.x;
#endif
return o;
}

Expand Down Expand Up @@ -279,14 +267,21 @@ SurfaceOutput frag_common(v2f IN, out float3 viewDir, out UnityGI gi) {
// initialize surface output
o.Albedo = 0.0;
o.Emission = 0.0;
o.Specular = 0.0;
o.Alpha = 0.0;
o.Specular = 0.4;
o.Alpha = _DecalOpacity;
o.Gloss = 0.0;
o.Normal = fixed3(0,0,1);

// call surface function
surf(i, o);

// apply KSP fog. In the deferred pass this is a no-op
o.Albedo = UnderwaterFog(i.worldPosition, o.Albedo).rgb;

// apply KSP rim lighting
half rim = 1.0 - saturate(dot(normalize(i.viewDir), o.Normal));
o.Emission += o.Emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;

// compute world normal
float3 worldN;
worldN.x = dot(_unity_tbn_0, o.Normal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
float4 color = tex2D(_Decal, IN.uv_decal);
o.Albedo = color.rgb;
o.Specular = 0.4;
o.Gloss = _Shininess;
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Alpha = _DecalOpacity;

#ifdef DECAL_BASE_NORMAL
float3 normal = IN.normal;
float wearFactor = 1 - normal.z;
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
o.Alpha *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
#endif

Expand All @@ -24,10 +22,6 @@ void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
o.Specular = specular;
#endif


half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
o.Emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;

#ifdef DECAL_EMISSIVE
o.Emission += tex2D(_Emissive, IN.uv_emissive).rgb * _Emissive_Color.rgb * _Emissive_Color.a;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
#pragma multi_compile_local __ DECAL_BASE_NORMAL
//{{ self.pragmas() }}

//{% block prepass_skip_variants %}
#pragma skip_variants DECAL_SPECMAP DECAL_EMISSIVE
//{% endblock %}

#define DECAL_PREPASS

//{{ self.body() }}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
Binary file added Assets/ConformalDecals/Textures/Decal-Spec.tif
Binary file not shown.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 0 additions & 46 deletions Assets/Scripts/DecalProjectorTest.cs

This file was deleted.

119 changes: 0 additions & 119 deletions Assets/Scripts/TextRenderTest.cs

This file was deleted.

0 comments on commit 7286202

Please sign in to comment.