Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix in-game camera preview #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Camera2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
</ItemGroup>
<ItemGroup>
<None Remove="Shaders\camera2utils" />
<None Remove="Shaders\camera2utilsvr" />
<None Remove="UI\Views\camPreview.bsml" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -194,7 +193,6 @@
<ItemGroup>
<EmbeddedResource Include="manifest.json" />
<EmbeddedResource Include="Shaders\camera2utils" />
<EmbeddedResource Include="Shaders\camera2utilsvr" />
<EmbeddedResource Include="UI\Views\camList.bsml" />
<EmbeddedResource Include="UI\Views\camPreview.bsml" />
<EmbeddedResource Include="UI\Views\camSettings.bsml" />
Expand Down
12 changes: 1 addition & 11 deletions Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BeatSaberMarkupLanguage.Util;
using Camera2.HarmonyPatches;
using Camera2.Managers;
using Camera2.Middlewares;
using Camera2.Utils;
Expand Down Expand Up @@ -40,25 +39,16 @@ public void Init(IPALogger logger) {
internal static void LoadShaders() {
void LoadNormalShaders(AssetBundle bundle) {
ShaderMat_LuminanceKey = new Material(bundle.LoadAsset<Shader>("luminancekey.shader"));
// Why does this one need the full path and others dont? I have no fing idea!
ShaderMat_Outline = new Material(bundle.LoadAsset<Shader>("assets/bundledassets/cam2/texouline.shader"));
bundle.Unload(false);
}

void LoadVRShaders(AssetBundle bundle) {
ShaderMat_Outline = new Material(bundle.LoadAsset<Shader>("texouline.shader"));
Shader_VolumetricBlit = bundle.LoadAsset<Shader>("volumetricblit.shader");
bundle.Unload(false);
}

#if !DEV
using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Camera2.Shaders.camera2utils"))
LoadNormalShaders(AssetBundle.LoadFromStream(stream));

using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Camera2.Shaders.camera2utilsvr"))
LoadVRShaders(AssetBundle.LoadFromStream(stream));
#else
LoadNormalShaders(AssetBundle.LoadFromFile(@"D:\Unity Shit\Projects\AssetBundlePacker\Assets\StreamingAssets\camera2utils"));
LoadVRShaders(AssetBundle.LoadFromFile(@"D:\Unity Shit\Projects\AssetBundlePacker\Assets\StreamingAssets\camera2utilsvr"));
#endif
}

Expand Down
19 changes: 8 additions & 11 deletions Shaders/VolumetricBlit.shader
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Shader "Custom/VolumetricBlit" {
Properties {
_MainTex ("Texture", any) = "white" {}
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
ColorMask RGB
Expand All @@ -14,7 +14,7 @@ Shader "Custom/VolumetricBlit" {

#include "UnityCG.cginc"

UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
sampler2D _MainTex;
half4 _MainTex_ST;

struct v2f {
Expand All @@ -31,15 +31,13 @@ Shader "Custom/VolumetricBlit" {
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);

o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

return o;
}

fixed4 frag(v2f i) : SV_Target {
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); //Insert

return UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.uv);
return tex2D(_MainTex, i.uv);
}
ENDCG
}
Expand All @@ -54,7 +52,7 @@ Shader "Custom/VolumetricBlit" {

#include "UnityCG.cginc"

UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
sampler2D _MainTex;
half4 _MainTex_ST;

struct v2f {
Expand All @@ -71,17 +69,16 @@ Shader "Custom/VolumetricBlit" {
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);

o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

// For back face, we mirror the texture so that it appears right way around from both sides
o.uv.x = 1 - o.uv.x;

return o;
}

fixed4 frag(v2f i) : SV_Target {
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);

return UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.uv);
return tex2D(_MainTex, i.uv);
}
ENDCG
}
Expand Down
Binary file modified Shaders/camera2utils
Binary file not shown.
Binary file removed Shaders/camera2utilsvr
Binary file not shown.