Skip to content

Commit

Permalink
Merge pull request #402 from umasteeringgroup/Feature-13
Browse files Browse the repository at this point in the history
Update from production
  • Loading branch information
Jaimi authored Jun 30, 2023
2 parents 67aa67a + 8a403b4 commit cfc2b03
Show file tree
Hide file tree
Showing 1,097 changed files with 117,387 additions and 10,409 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"MonoBehaviour":{"m_Enabled":true,"m_EditorHideFlags":0,"m_Name":"","m_EditorClassIdentifier":"","entries":[],"betterShader":{"fileID":-6465566751694194690,"guid":"e03404c6cbdd84c49a7102cc33112d7e","type":3},"betterShaderPath":"","optionOverrides":{"shaderName":"","useCustomEditor":false,"customEditor":"","fallback":{"instanceID":0}}}}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: AlbedoNormalColormask_Compositer_mat
m_Shader: {fileID: -6465566751694194690, guid: 00a785c0ebde240458a088cf1a70ac00,
m_Shader: {fileID: -6465566751694194690, guid: 08d702ae7f5c47a4b9675564d0302123,
type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
Expand Down Expand Up @@ -196,3 +196,4 @@ Material:
- _Tint3_0: {r: 1, g: 1, b: 1, a: 1}
- _Tint3_1: {r: 1, g: 1, b: 1, a: 1}
- _Tint3_2: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []

This file was deleted.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Jason Booth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ShaderPackager
Shader Packager is system for combining multiple shaders, written for specific render pipelines or unity versions, and making them act as a single shader in the project. The goal is to help fix on of the #SRPLife problems, which is that users install your shaders and see nothing but pink shaders, because the versions that shipped with your asset are for the wrong pipeline. The usual workaround for this is to provide various zip files and have the user unpack the right versions for the SRP and Unity version they are using- however, this is a horrible experience for new users.

So what this system does is take a list of shaders, with requirements about SRP type and Unity version, and pack them all into a single file. At import time, it detects which SRP is installed, and imports the correct shader from the package into the project. To the user, it looks like any other shader, but just works on the first install regardless of which SRP they are installed into (Assuming you have provided support for that version).

# Using in your asset store asset
To use this in an Asset Store context, you will need to do the following:
- Copy the files into your project somewhere
- Change the namespace on the files to your own namespace, so they do not conflict with someone else using the same system
- In ShaderPackagerImporter, change the k_FileExtension to something unique to your project.
- Note that you don't need to ship the ShaderPackagerImportEditor.cs file to your users, it is only required for the packing UI.

# ShaderPackager
To pack your shaders, generate your shaders in whatever program you'd like. My asset, Better Shaders, will let you write a single shader that compiles for any SRP, and can export shaders for each pipeline for you - or you can hand write them, or use something like ASE to generate them. Then create a new Shader Package in the project from the right click menu.

Add some entries, and set the SRP Target, Min and Max Unity versions for each, and set the shader. When you are done, press the Pack button, it will copy the source code for each shader into the text block of each entry. Then press Apply, and you will notice that your object now becomes a shader for the current project.

# Current Issues
The render pipeline detection is based on installed pipeline, not installed and active pipeline. So if a user switches has multiple SRPs installed, or one installed and not active, they will get the wrong shader. I'll have to fix this at some point soon.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//////////////////////////////////////////////////////
// Shader Packager
// Copyright (c)2021 Jason Booth
//////////////////////////////////////////////////////

using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
using System.Collections.Generic;

using UnityEngine;
using UnityEditor;

using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;

#if UNITY_2019_3_OR_NEWER

// installs defines for render pipelines, so we can #if USING_HDRP and do stuff. Can't believe Unity doesn't provide this crap, they
// really go out of their way to make it hard to work across pipelines.

namespace UMA.ShaderPackager
{
public static class RenderPipelineDefine
{

private const string HDRP_PACKAGE = "com.unity.render-pipelines.high-definition";
private const string URP_PACKAGE = "com.unity.render-pipelines.universal";

private const string TAG_HDRP = "USING_HDRP";
private const string TAG_URP = "USING_URP";





private static ListRequest request;
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
request = Client.List(true);
EditorApplication.update -= ListProgress;
EditorApplication.update += ListProgress;
}

private static void ListProgress()
{
if (request.IsCompleted)
{
if (request.Status == StatusCode.Success)
{
// Find out what packages are installed
var packagesList = request.Result.ToList();

///Debug.Log("List of offline Unity packages:\n\n" + String.Join("\n", packagesList.Select(x => x.name)) + "\n\n");

bool hasHDRP = packagesList.Find(x => x.name.Contains(HDRP_PACKAGE)) != null;
bool hasURP = packagesList.Find(x => x.name.Contains(URP_PACKAGE)) != null;


DefinePreProcessors(hasHDRP, hasURP);
}
else
{
Debug.Log(request.Error.message);
}

EditorApplication.update -= ListProgress;
}
}


private static void DefinePreProcessors(bool defineHDRP, bool defineURP)
{

string originalDefineSymbols;
string newDefineSymbols;

List<string> defined;
//List<BuildTargetGroup> avaliablePlatforms = Enum.GetValues(typeof(BuildTargetGroup)).Cast<BuildTargetGroup>().ToList();
BuildTargetGroup platform = EditorUserBuildSettings.selectedBuildTargetGroup;

string log = string.Empty;

// foreach(var platform in avaliablePlatforms)
originalDefineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(platform);
defined = originalDefineSymbols.Split(';').Where(x => !String.IsNullOrWhiteSpace(x)).ToList();


Action<bool, string> AppendRemoveTag = (stat, tag) =>
{
if (stat && !defined.Contains(tag))
defined.Add(tag);
else if (!stat && defined.Contains(tag))
defined.Remove(tag);
};

AppendRemoveTag(defineHDRP, TAG_HDRP);
AppendRemoveTag(defineURP, TAG_URP);

newDefineSymbols = string.Join(";", defined);
if (originalDefineSymbols != newDefineSymbols)
{
PlayerSettings.SetScriptingDefineSymbolsForGroup(platform, newDefineSymbols);
}

}




}
}

#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cfc2b03

Please sign in to comment.