Commit e5afc8e4 authored by BRUNEAU Julien's avatar BRUNEAU Julien
Browse files

+ Fix non spawn agent being visible again...

+ remove texture variation from share code
+ Fix camera feature with rockect box
parent 8550b1f1
......@@ -33,7 +33,7 @@ public class ObjectInterface
}
public virtual void Show()
{
if(_MeshRenderer.Length>1)
if(_MeshRenderer.Length>0)
{
foreach(SkinnedMeshRenderer mesh in _MeshRenderer)
mesh.enabled = true;
......@@ -41,7 +41,7 @@ public class ObjectInterface
}
public virtual void Hide()
{
if (_MeshRenderer.Length > 1)
if (_MeshRenderer.Length > 0)
{
foreach (SkinnedMeshRenderer mesh in _MeshRenderer)
mesh.enabled = false;
......
......@@ -139,7 +139,7 @@ public class LoadEnv : MonoBehaviour
// ---------------------
// SET NAME, TAG, AND ID
character.name += i.ToString("D4");
character.name = i.ToString("D4");
character.tag = "Player";
character.GetComponent<GetMemberPosition>().ID = i;
......@@ -251,25 +251,6 @@ public class LoadEnv : MonoBehaviour
foreach (SkinnedMeshRenderer renderer in rendererList)
renderer.materials = mats;
}
// --------------------------------------
// ELSE ADD SOME VARIATION IN THE TEXTURE
else
{
TextureVariation[] tvList = rb.GetComponentsInChildren<TextureVariation>();
int variation = 0;
if (tvList.Length>0)
{
variation = (int)(((int)(id / 2)) / 20);
variation = (variation % (tvList[0].getNumberOfVariationsMax()-1)) + 1;
}
foreach (TextureVariation tv in tvList)
{
tv.SetVariationId(variation);
}
}
return rb;
}
......
fileFormatVersion: 2
guid: 2bb24139a86198b4a9ac013f37790283
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 71e4a6c39397f71419f039b0e6390c12
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
// Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax.
Shader "Custom/HSVTextureVariation" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Glossiness ("Smoothness", Range(0,1)) = 0.0
_Metallic ("Metallic", Range(0,1)) = 0.0
_BumpScale("Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_EmissionColor("Color", Color) = (0,0,0)
_AlphaMask("Alpha Mask", 2D) = "white" {}
//_HSVoffset("HSV Offset", Color) = (0.5,0.5,0.5)
_HSVoffsetMap("HSV Offset", 2D) = "gray" {}
_DoVariation("Do Variation", Range(0.0, 1.0)) = 1.0
// Blending state
[HideInInspector] _Mode ("__mode", Float) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _AlphaMask;
sampler2D _HSVoffsetMap;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
float _DoVariation;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
float3 rgb2hsv(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = c.g < c.b ? float4(c.bg, K.wz) : float4(c.gb, K.xy);
float4 q = c.r < p.x ? float4(p.xyw, c.r) : float4(c.r, p.yzx);
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
float3 hsv2rgb(float3 c)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
}
void surf(Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
if (_DoVariation > 0.0)
{
float channelVariationID = tex2D(_AlphaMask, IN.uv_MainTex).x;
float2 variationTexCoord = float2(channelVariationID, 0.0);
fixed3 _HSVoffset = tex2D(_HSVoffsetMap, variationTexCoord);
_HSVoffset = (_HSVoffset * 2.0 - 1.0);
_HSVoffset.x = _HSVoffset.x * 0.5;
fixed3 hsv = rgb2hsv(c.rgb) +_HSVoffset;
if (hsv.r > 1.0)
hsv.r -= 1.0;
if (hsv.r < 0)
hsv.r += 1.0;
hsv.g = clamp(hsv.g, 0.0, 1.0);
hsv.b = clamp(hsv.b, 0.0, 1.0);
c.rgb = hsv2rgb(hsv);
}
o.Albedo = c * _Color;
// Metallic and smoothness come from slider variables
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "HSVTextureVariationGUI"
}
fileFormatVersion: 2
guid: ec5d30d21a4c2044dad1c40d9d2cb52d
timeCreated: 1520433258
licenseType: Free
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
// Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax.
Shader "Custom/HSVTextureVariationFade" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Glossiness ("Smoothness", Range(0,1)) = 0.0
_Metallic ("Metallic", Range(0,1)) = 0.0
_BumpScale("Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_EmissionColor("Color", Color) = (0,0,0)
_AlphaMask("Alpha Mask", 2D) = "white" {}
//_HSVoffset("HSV Offset", Color) = (0.5,0.5,0.5)
_HSVoffsetMap("HSV Offset", 2D) = "gray" {}
_DoVariation("Do Variation", Range(0.0, 1.0)) = 1.0
// Blending state
[HideInInspector] _Mode ("__mode", Float) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard alpha:fade fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _AlphaMask;
sampler2D _HSVoffsetMap;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
float _DoVariation;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
float3 rgb2hsv(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = c.g < c.b ? float4(c.bg, K.wz) : float4(c.gb, K.xy);
float4 q = c.r < p.x ? float4(p.xyw, c.r) : float4(c.r, p.yzx);
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
float3 hsv2rgb(float3 c)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, saturate(p - K.xxx), c.y);
}
void surf(Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
if (_DoVariation > 0.0)
{
//float channelVariationID = tex2D(_AlphaMask, IN.uv_MainTex).x;
float channelVariationID = 176.0 / 255.0; // Fix for Hair with opacity -> Single texture = no mask
float2 variationTexCoord = float2(channelVariationID, 0.0);
fixed3 _HSVoffset = tex2D(_HSVoffsetMap, variationTexCoord);
_HSVoffset = (_HSVoffset * 2.0 - 1.0);
_HSVoffset.x = _HSVoffset.x * 0.5;
fixed3 hsv = rgb2hsv(c.rgb) +_HSVoffset;
if (hsv.r > 1.0)
hsv.r -= 1.0;
if (hsv.r < 0)
hsv.r += 1.0;
hsv.g = clamp(hsv.g, 0.0, 1.0);
hsv.b = clamp(hsv.b, 0.0, 1.0);
c.rgb = hsv2rgb(hsv);
}
o.Albedo = c * _Color;
// Metallic and smoothness come from slider variables
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "HSVTextureVariationGUI"
}
fileFormatVersion: 2
guid: 7087c273dd283074db61e9e618646464
timeCreated: 1520433257
licenseType: Free
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 41ce65fba6f3ede418f7e887e7fcb95a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
namespace UnityEditor
{
internal class HSVTextureVariationGUI : ShaderGUI
{
private enum WorkflowMode
{
Specular,
Metallic,
Dielectric
}
public enum BlendMode
{
Opaque,
Cutout,
Fade, // Old school alpha-blending mode, fresnel does not affect amount of transparency
Transparent // Physically plausible transparency mode, implemented as alpha pre-multiply
}
public enum SmoothnessMapChannel
{
SpecularMetallicAlpha,
AlbedoAlpha,
}
private static class Styles
{
public static GUIContent albedoText = new GUIContent("Albedo", "Albedo (RGB) and Transparency (A)");
public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff");
//public static GUIContent specularMapText = new GUIContent("Specular", "Specular (RGB) and Smoothness (A)");
//public static GUIContent metallicMapText = new GUIContent("Metallic", "Metallic (R) and Smoothness (A)");
//public static GUIContent smoothnessText = new GUIContent("Smoothness", "Smoothness value");
//public static GUIContent smoothnessScaleText = new GUIContent("Smoothness", "Smoothness scale factor");
public static GUIContent highlightsText = new GUIContent("Specular Highlights", "Specular Highlights");
public static GUIContent reflectionsText = new GUIContent("Reflections", "Glossy Reflections");
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map");
public static GUIContent heightMapText = new GUIContent("Height Map", "Height Map (G)");
public static GUIContent emissionText = new GUIContent("Color", "Emission (RGB)");
public static GUIContent alphaMaskText = new GUIContent("Alpha Mask", "Mask for body parts");
public static GUIContent variationMapText = new GUIContent("HSV Variation Map", "Map for HSV texture variations");
public static string primaryMapsText = "Main Maps";
public static string forwardText = "Forward Rendering Options";
public static string renderingMode = "Rendering Mode";
public static readonly string[] blendNames = Enum.GetNames(typeof(BlendMode));
}
MaterialProperty blendMode = null;
MaterialProperty albedoMap = null;
MaterialProperty albedoColor = null;
MaterialProperty alphaCutoff = null;
MaterialProperty metallic = null;
MaterialProperty smoothness = null;
MaterialProperty smoothnessScale = null;
MaterialProperty bumpScale = null;
MaterialProperty bumpMap = null;
MaterialProperty alphaMask = null;
//MaterialProperty hsvOffset = null;
MaterialProperty hsvOffsetMap = null;
MaterialProperty doVariation = null;
MaterialProperty highlights = null;
MaterialProperty reflections = null;
MaterialProperty emissionColorForRendering = null;
MaterialEditor m_MaterialEditor;
WorkflowMode m_WorkflowMode = WorkflowMode.Specular;
private const float kMaxfp16 = 65536f; // Clamp to a value that fits into fp16.
ColorPickerHDRConfig m_ColorPickerHDRConfig = new ColorPickerHDRConfig(0f, kMaxfp16, 1 / kMaxfp16, 3f);
bool m_FirstTimeApply = true;
public void FindProperties(MaterialProperty[] props)
{
blendMode = FindProperty("_Mode", props);
albedoMap = FindProperty("_MainTex", props);
albedoColor = FindProperty("_Color", props);
alphaCutoff = FindProperty("_Cutoff", props);
metallic = FindProperty("_Metallic", props, false);
m_WorkflowMode = WorkflowMode.Metallic;
smoothness = FindProperty("_Glossiness", props);
smoothnessScale = FindProperty("_GlossMapScale", props, false);
bumpScale = FindProperty("_BumpScale", props);
bumpMap = FindProperty("_BumpMap", props);
emissionColorForRendering = FindProperty("_EmissionColor", props);
alphaMask = FindProperty("_AlphaMask", props);
//hsvOffset = FindProperty("_HSVoffset", props);
hsvOffsetMap = FindProperty("_HSVoffsetMap", props);
doVariation = FindProperty("_DoVariation", props);
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
{
FindProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
// Make sure that needed setup (ie keywords/renderqueue) are set up if we're switching some existing
// material to a standard shader.
// Do this before any GUI code has been issued to prevent layout issues in subsequent GUILayout statements (case 780071)
if (m_FirstTimeApply)
{
MaterialChanged(material, m_WorkflowMode);
m_FirstTimeApply = false;
}
ShaderPropertiesGUI(material);
}
public void ShaderPropertiesGUI(Material material)
{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{
BlendModePopup();
// Primary properties
GUILayout.Label(Styles.primaryMapsText, EditorStyles.boldLabel);
DoAlbedoArea(material);
DoSpecularMetallicArea();
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap, bumpMap != null ? bumpScale : null);
m_MaterialEditor.TexturePropertySingleLine(Styles.alphaMaskText, alphaMask != null ? alphaMask : null);
m_MaterialEditor.TexturePropertySingleLine(Styles.variationMapText, hsvOffsetMap != null ? hsvOffsetMap : null, doVariation);
DoEmissionArea(material);
EditorGUI.BeginChangeCheck();
// Third properties
GUILayout.Label(Styles.forwardText, EditorStyles.boldLabel);
if (highlights != null)
m_MaterialEditor.ShaderProperty(highlights, Styles.highlightsText);
if (reflections != null)
m_MaterialEditor.ShaderProperty(reflections, Styles.reflectionsText);
}
if (EditorGUI.EndChangeCheck())
{
foreach (var obj in blendMode.targets)
MaterialChanged((Material)obj, m_WorkflowMode);
}
}
internal void DetermineWorkflow(MaterialProperty[] props)
{
if (FindProperty("_SpecGlossMap", props, false) != null && FindProperty("_SpecColor", props, false) != null)
m_WorkflowMode = WorkflowMode.Specular;
else if (FindProperty("_MetallicGlossMap", props, false) != null && FindProperty("_Metallic", props, false) != null)
m_WorkflowMode = WorkflowMode.Metallic;
else
m_WorkflowMode = WorkflowMode.Dielectric;
}
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
{
// _Emission property is lost after assigning Standard shader to the material
// thus transfer it before assigning the new shader
if (material.HasProperty("_Emission"))
{
material.SetColor("_EmissionColor", material.GetColor("_Emission"));
}
base.AssignNewShaderToMaterial(material, oldShader, newShader);
if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
{
SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode"));
return;
}
BlendMode blendMode = BlendMode.Opaque;
if (oldShader.name.Contains("/Transparent/Cutout/"))
{
blendMode = BlendMode.Cutout;
}
else if (oldShader.name.Contains("/Transparent/"))
{
// NOTE: legacy shaders did not provide physically based transparency
// therefore Fade mode
blendMode = BlendMode.Fade;
}
material.SetFloat("_Mode", (float)blendMode);
DetermineWorkflow(MaterialEditor.GetMaterialProperties(new Material[] { material }));
MaterialChanged(material, m_WorkflowMode);
}
void BlendModePopup()
{
EditorGUI.showMixedValue = blendMode.hasMixedValue;
var mode = (BlendMode)blendMode.floatValue;
EditorGUI.BeginChangeCheck();
mode = (BlendMode)EditorGUILayout.Popup(Styles.renderingMode, (int)mode, Styles.blendNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Rendering Mode");
blendMode.floatValue = (float)mode;
}
EditorGUI.showMixedValue = false;
}
void DoAlbedoArea(Material material)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoText, albedoMap, albedoColor);
if (((BlendMode)material.GetFloat("_Mode") == BlendMode.Cutout))
{
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text, MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1);
}
}
void DoEmissionArea(Material material)
{
// Emission for GI?
if (m_MaterialEditor.EmissionEnabledProperty())
{
bool hadEmissionTexture = false;
// Texture and HDR color controls
//m_MaterialEditor.TexturePropertyWithHDRColor(Styles.emissionText, emissionMap, emissionColorForRendering, m_ColorPickerHDRConfig, false);
// If texture was assigned and color was black set color to white
float brightness = emissionColorForRendering.colorValue.maxColorComponent;
/*if (emissionMap.textureValue != null && !hadEmissionTexture && brightness <= 0f)
emissionColorForRendering.colorValue = Color.white;*/
// change the GI flag and fix it up with emissive as black if necessary
m_MaterialEditor.LightmapEmissionFlagsProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel, true);
}
}