public void SetShader(Type shaderType, ShaderProperties properties) { ShaderProperties p = new ShaderProperties(properties); p.SetProperty("DEFAULT", true); SetShader(ShaderManager.GetShader(shaderType, p)); }
public override void OnInspectorGUI() { serializedObject.Update(); SerializedProperty properties = serializedObject.FindProperty(nameof(_properties)); EditorGUILayout.PropertyField(properties); ShaderProperties shaderProperties = properties.objectReferenceValue as ShaderProperties; if (shaderProperties) { SerializedProperty targetTexture = serializedObject.FindProperty(nameof(_targetTexture)); targetTexture.stringValue = shaderProperties.DrawPropertyMenu(ShaderProperties.PropertyTypes.Texture, targetTexture.stringValue, "Target Texture"); } EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(_targetObject))); EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(_saveFile))); serializedObject.ApplyModifiedProperties(); if (GUILayout.Button("Save")) { foreach (SaveTextureFromShader stfs in targets) { stfs.Save(); } } }
private Color CalculateColorSync(ShaderProperties sp) { sp._Color.r = sp._Color.r * (sp._Offset + KeyframeListener.frequencyBands[sp._Frequency] * sp._Strength); sp._Color.b = sp._Color.b * (sp._Offset + KeyframeListener.frequencyBands[sp._Frequency] * sp._Strength); sp._Color.g = sp._Color.g * (sp._Offset + KeyframeListener.frequencyBands[sp._Frequency] * sp._Strength); return(sp._Color); }
private void DrawShaderProperties(ShaderProperties props) { this.m_ScrollViewShaderProps = GUILayout.BeginScrollView(this.m_ScrollViewShaderProps); Rect nameRect; Rect flagsRect; Rect valueRect; if (((IEnumerable <ShaderTextureInfo>)props.textures).Count <ShaderTextureInfo>() > 0) { GUILayout.Label("Textures", EditorStyles.boldLabel, new GUILayoutOption[0]); this.GetPropertyFieldRects(((IEnumerable <ShaderTextureInfo>)props.textures).Count <ShaderTextureInfo>(), 16f, out nameRect, out flagsRect, out valueRect); foreach (ShaderTextureInfo texture in props.textures) { this.OnGUIShaderPropTexture(nameRect, flagsRect, valueRect, texture); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } if (((IEnumerable <ShaderFloatInfo>)props.floats).Count <ShaderFloatInfo>() > 0) { GUILayout.Label("Floats", EditorStyles.boldLabel, new GUILayoutOption[0]); this.GetPropertyFieldRects(((IEnumerable <ShaderFloatInfo>)props.floats).Count <ShaderFloatInfo>(), 16f, out nameRect, out flagsRect, out valueRect); foreach (ShaderFloatInfo t in props.floats) { this.OnGUIShaderPropFloat(nameRect, flagsRect, valueRect, t); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } if (((IEnumerable <ShaderVectorInfo>)props.vectors).Count <ShaderVectorInfo>() > 0) { GUILayout.Label("Vectors", EditorStyles.boldLabel, new GUILayoutOption[0]); this.GetPropertyFieldRects(((IEnumerable <ShaderVectorInfo>)props.vectors).Count <ShaderVectorInfo>(), 16f, out nameRect, out flagsRect, out valueRect); foreach (ShaderVectorInfo vector in props.vectors) { this.OnGUIShaderPropVector4(nameRect, flagsRect, valueRect, vector); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } if (((IEnumerable <ShaderMatrixInfo>)props.matrices).Count <ShaderMatrixInfo>() > 0) { GUILayout.Label("Matrices", EditorStyles.boldLabel, new GUILayoutOption[0]); this.GetPropertyFieldRects(((IEnumerable <ShaderMatrixInfo>)props.matrices).Count <ShaderMatrixInfo>(), 48f, out nameRect, out flagsRect, out valueRect); foreach (ShaderMatrixInfo matrix in props.matrices) { this.OnGUIShaderPropMatrix(nameRect, flagsRect, valueRect, matrix); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } GUILayout.EndScrollView(); }
public override void Create() { ShaderProperties.Init(32); //hack for now blurAlgorithm = new ScalableBlur(); pass = new TranslucentImageBlurRenderPass(); tisCache.Clear(); }
void Awake() { ShaderName = "RockCompany/DiffuseRockShader"; DisplayName = "Custom Rocks"; ShaderProperties.Add(new VegetationItemShaderProperty() { PropertyName = "_SnowAmount", DisplayName = "Snow Amount", FloatValue = 0.5f, ShaderPropertyType = VegetationItemShaderPropertyType.Float }); }
//Dynamically create a shaderproperty for each shader property in the actual shader target public void AddProperties() { List <ShaderProperties> p = new List <ShaderProperties>(); //Check each of the properties in the actual shader target and create out ShaderProperties structure accordingly for (int i = 0; i < ShaderUtil.GetPropertyCount(skf.shader); i++) { //Check for the type of the shader property index since there are some types we never want to change (ie vectors) ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(skf.shader, i); //the true variable inside the shader target (ie _ZoomValue) string trueName = ShaderUtil.GetPropertyName(skf.shader, i); string displayName = string.Empty; //Create a "clean" string of the shader property name (ie _ZoomValue to Zoom Value) that we'll use as the display name for (int k = 0; k < trueName.Length; k++) { if (char.IsUpper(trueName[k]) && k != 1) { displayName += $" {trueName[k]}"; } else { displayName += trueName[k]; } } ShaderProperties prop = new ShaderProperties(); //since we dont want to modify textures we'll skip all of these if (type != ShaderUtil.ShaderPropertyType.TexEnv) { //Create our properties structure and add it to our list prop = new ShaderProperties { _TrueName = trueName, _Name = $"{displayName.Replace("_", "")} ({type.ToString()})", _Strength = 0, _Offset = 0, _UseForKeyframing = false, _LogValue = false, _Frequency = 0, _PropertyType = type, _FilterRange = 0 }; p.Add(prop); } } //Update the ShaderKeyFramers shaderproperties list with the list of structures we created in this method skf.properties = p; serializedObject.ApplyModifiedProperties(); }
public Kn5Material Clone() { return(new Kn5Material { Name = Name, ShaderName = ShaderName, BlendMode = BlendMode, AlphaTested = AlphaTested, DepthMode = DepthMode, ShaderProperties = ShaderProperties.Select(x => x.Clone()).ToArray(), TextureMappings = TextureMappings.Select(x => x.Clone()).ToArray() }); }
private bool ShouldKeyFrame(ShaderProperties sp) { bool result = true; //if we want to keyframe between a specific time frame (ie from 3 seconds to 6 seconds) if (sp._SpecificTime) { //return true if current time is more than or equal to start time and less than or equal to end time, else we should not keyframe it result = Time.time >= sp._StartTime && Time.time <= sp._EndTime; } return(result); }
/// <summary> /// Lerp materials on all child renderers between material A and material B. /// </summary> /// <param name="t">Value between 0 and 1.</param> public void Lerp(float t, bool trackValue = true) { if (!MaterialA) { return; } if (!MaterialB) { return; } if (!ShaderProperties) { return; } //set shared material on all renderers if necessary Material targetMaterial = Mathf.Approximately(t, 0) ? MaterialA : MaterialB; //should make a smarter check... if (CurrentMaterial != targetMaterial) { SetMaterial(targetMaterial); } //lerp renderers for (int i = 0; i < Renderers.Length; i++) { //for each renderer: Renderer r = Renderers[i]; //just skip null renderers for now if (!r) { continue; } //initialize property block with r's current properties //without this step, lerped values won't be set correctly ShaderProperties.SetProperties(MPB, r.sharedMaterial); //set lerped properties on property block ShaderProperties.LerpProperties(MPB, MaterialA, MaterialB, t); //apply properties to r r.SetPropertyBlock(MPB); } //store value for later if (trackValue) { CurrentValue = t; } }
private float CalculateShaderSync(ShaderProperties sp) { float result; if (sp._FilterRange > 0 && KeyframeListener.frequencyBands[sp._Frequency] < sp._FilterRange) { result = 0; } else { result = sp._Offset + KeyframeListener.frequencyBands[sp._Frequency] * sp._Strength; } return(result); }
private ShadowFactory() { cmd = new CommandBuffer { name = "Shadow Commands" }; materialProps = new MaterialPropertyBlock(); materialProps.SetVector(ShaderId.CLIP_RECT, new Vector4(float.NegativeInfinity, float.NegativeInfinity, float.PositiveInfinity, float.PositiveInfinity)); materialProps.SetInt(ShaderId.COLOR_MASK, (int)ColorWriteMask.All); // Render shadow even if mask hide graphic ShaderProperties.Init(8); blurConfig = ScriptableObject.CreateInstance <ScalableBlurConfig>(); blurConfig.hideFlags = HideFlags.HideAndDontSave; blurProcessor = new ScalableBlur(); blurProcessor.Configure(blurConfig); }
private void UpdateShaderKeywords() { if (m_ShaderKeywords == null || m_ShaderKeywords.Length != 12) { m_ShaderKeywords = new string[12]; } m_ShaderKeywords[0] = ShaderProperties.GetOrthographicProjectionKeyword(cameraData.camera.orthographic); m_ShaderKeywords[1] = ShaderProperties.GetDirectionsKeyword(hbao.quality.value); m_ShaderKeywords[2] = ShaderProperties.GetStepsKeyword(hbao.quality.value); m_ShaderKeywords[3] = ShaderProperties.GetNoiseKeyword(hbao.noiseType.value); m_ShaderKeywords[4] = ShaderProperties.GetDeinterleavingKeyword(hbao.deinterleaving.value); m_ShaderKeywords[5] = ShaderProperties.GetDebugKeyword(hbao.debugMode.value); m_ShaderKeywords[6] = ShaderProperties.GetMultibounceKeyword(hbao.useMultiBounce.value); m_ShaderKeywords[7] = ShaderProperties.GetOffscreenSamplesContributionKeyword(hbao.offscreenSamplesContribution.value); m_ShaderKeywords[8] = ShaderProperties.GetPerPixelNormalsKeyword(hbao.perPixelNormals.value); m_ShaderKeywords[9] = ShaderProperties.GetBlurRadiusKeyword(hbao.blurType.value); m_ShaderKeywords[10] = ShaderProperties.GetVarianceClippingKeyword(hbao.varianceClipping.value); m_ShaderKeywords[11] = ShaderProperties.GetColorBleedingKeyword(hbao.colorBleedingEnabled.value); material.shaderKeywords = m_ShaderKeywords; }
public static string FormatShaderProperties(string origCode, ShaderProperties properties) { string res = ""; string[] lines = origCode.Split('\n'); bool inIfStatement = false; String ifStatementText = ""; bool removing = false; List <string> ifdefs = new List <string>(); List <string> ifndefs = new List <string>(); string currentIfDef = ""; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (line.Trim().StartsWith("#ifdef")) { inIfStatement = true; ifStatementText = lines[i].Trim().Substring(7); ifdefs.Add("!" + ifStatementText); currentIfDef = "!" + ifStatementText; bool remove = !(properties.GetBool(ifStatementText)); int num_ifdefs = 0; int num_endifs = 0; for (int j = i; j < lines.Length; j++) { if (lines[j].Trim().StartsWith("#ifdef") || lines[j].Trim().StartsWith("#ifndef")) { num_ifdefs++; } else if (lines[j].Trim().StartsWith("#endif")) { num_endifs++; if (num_endifs >= num_ifdefs) { break; } } else { if (remove) { lines[j] = ""; } } } lines[i] = ""; } else if (lines[i].Trim().StartsWith("#ifndef")) { inIfStatement = true; ifStatementText = lines[i].Trim().Substring(8); ifdefs.Add("!" + ifStatementText); currentIfDef = "!" + ifStatementText; bool remove = (properties.GetBool(ifStatementText)); int num_ifdefs = 0; int num_endifs = 0; for (int j = i; j < lines.Length; j++) { if (lines[j].Trim().StartsWith("#ifdef") || lines[j].Trim().StartsWith("#ifndef")) { num_ifdefs++; } else if (lines[j].Trim().StartsWith("#endif")) { num_endifs++; if (num_endifs >= num_ifdefs) { break; } } else { if (remove) { lines[j] = ""; } } } lines[i] = ""; } else if (lines[i].Trim().StartsWith("#endif")) { lines[i] = ""; } if (lines[i] != "") { res += lines[i] + "\n"; } } foreach (var val in properties.values) { res = res.Replace("$" + val.Key, GetValueString(val.Key, val.Value)); } // Console.WriteLine(res); return(res); }
public DepthShader(ShaderProperties properties) : base(properties, (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\depth.vert"), (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\depth.frag")) { }
public AnimatedShader(ShaderProperties properties, string vs_code, string fs_code, string gs_code) : base(properties, vs_code, fs_code, gs_code) { }
public static string FormatShaderProperties_old(string origCode, ShaderProperties properties) { string res = ""; string[] lines = origCode.Split('\n'); bool inIfStatement = false; String ifStatementText = ""; bool removing = false; List <string> ifdefs = new List <string>(); List <string> ifndefs = new List <string>(); string currentIfDef = ""; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (line.Trim().StartsWith("#ifdef")) { inIfStatement = true; ifStatementText = lines[i].Trim().Substring(7); ifdefs.Add(ifStatementText); currentIfDef = ifStatementText; if (properties.GetBool(ifStatementText) == true) { removing = false; } else { removing = true; } lines[i] = ""; } else if (lines[i].Trim().StartsWith("#ifndef")) { inIfStatement = true; ifStatementText = lines[i].Trim().Substring(8); if (properties.GetBool(ifStatementText) == false) { removing = false; } else { removing = true; } ifdefs.Add("!" + ifStatementText); currentIfDef = "!" + ifStatementText; lines[i] = ""; } else if (lines[i].Trim().StartsWith("#endif")) { if (inIfStatement) { inIfStatement = false; removing = false; } lines[i] = ""; } if (inIfStatement && removing) { lines[i] = ""; } if (lines[i] != "") { res += lines[i] + "\n"; } } foreach (var val in properties.values) { res = res.Replace("$" + val.Key, GetValueString(val.Key, val.Value)); } return(res); }
public BarkShader(ShaderProperties properties) : base(properties, (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\vegetation\\tree.vert"), (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\vegetation\\tree.frag")) { }
public static bool CompareShader(ShaderProperties a, ShaderProperties b) { if (a.values.Count != b.values.Count) return false; string[] keys_a = a.values.Keys.ToArray(); string[] keys_b = b.values.Keys.ToArray(); object[] vals_a = a.values.Values.ToArray(); object[] vals_b = b.values.Values.ToArray(); for (int i = 0; i < keys_a.Length; i++) { if (!keys_a[i].Equals(keys_b[i])) { return false; } else { if (!vals_a[i].Equals(vals_b[i])) { return false; } } } /*foreach (var pair in a.values) { object value; if (b.values.TryGetValue(pair.Key, out value)) { if (value is bool) { if (pair.Value is bool) return ((bool)value) == ((bool)pair.Value); else return false; } else if (value is int) { if (pair.Value is int) return ((int)value) == ((int)pair.Value); else return false; } else if (value is float) { if (pair.Value is float) return ((float)value) == ((float)pair.Value); else return false; } else if (value is string) { if (pair.Value is string) return ((string)value) == ((string)pair.Value); else return false; } } else { return false; } }*/ return true; }
void OnGUI() { m_scrollPosition = EditorGUILayout.BeginScrollView(m_scrollPosition); Rect verticalLayoutRect = EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Select the parent object that is to be combined."); EditorGUI.BeginChangeCheck(); m_parentObject = (GameObject)EditorGUILayout.ObjectField("Parent Object Of Meshes To Be Combined", m_parentObject, typeof(GameObject), true); if (EditorGUI.EndChangeCheck()) { m_textureAtlasInfo = new TextureAtlasInfo(); m_texPropArraySize = m_textureAtlasInfo.shaderPropertiesToLookFor.Length; m_shaderFoldoutBools = new bool[m_texPropArraySize]; } if (m_parentObject != null) { m_textureAtlasInfo.compressTexturesInMemory = false; //EditorGUILayout.Toggle("Compress Texture", m_textureAtlasInfo.compressTexturesInMemory); EditorGUI.BeginChangeCheck(); m_texPropArraySize = EditorGUILayout.IntSlider("# Of Shader Properties", m_texPropArraySize, 0, 20); if (EditorGUI.EndChangeCheck()) { if (m_texPropArraySize > m_textureAtlasInfo.shaderPropertiesToLookFor.Length) { ShaderProperties[] temp = new ShaderProperties[m_texPropArraySize]; for (int i = 0; i < m_texPropArraySize; i++) { if (i < m_textureAtlasInfo.shaderPropertiesToLookFor.Length) { temp[i] = m_textureAtlasInfo.shaderPropertiesToLookFor[i]; } else { temp[i] = new ShaderProperties(false, ""); } } m_textureAtlasInfo.shaderPropertiesToLookFor = temp; } else if (m_texPropArraySize < m_textureAtlasInfo.shaderPropertiesToLookFor.Length) { ShaderProperties[] temp = new ShaderProperties[m_texPropArraySize]; for (int i = 0; i < m_texPropArraySize; i++) { temp[i] = m_textureAtlasInfo.shaderPropertiesToLookFor[i]; } m_textureAtlasInfo.shaderPropertiesToLookFor = temp; } m_shaderFoldoutBools = new bool[m_texPropArraySize]; } m_showShaderProperties = EditorGUILayout.Foldout(m_showShaderProperties, "Shader Properties To Watch For"); if (m_showShaderProperties) { for (int i = 0; i < m_texPropArraySize; i++) { m_shaderFoldoutBools[i] = EditorGUILayout.Foldout(m_shaderFoldoutBools[i], "Shader Properties Element " + i); if (m_shaderFoldoutBools[i] == true) { m_textureAtlasInfo.shaderPropertiesToLookFor[i].markAsNormal = EditorGUILayout.Toggle("Mark As Normal Map", m_textureAtlasInfo.shaderPropertiesToLookFor[i].markAsNormal); m_textureAtlasInfo.shaderPropertiesToLookFor[i].propertyName = EditorGUILayout.TextField("Shader Property Name", m_textureAtlasInfo.shaderPropertiesToLookFor[i].propertyName); } } } GUILayout.Space(m_window.position.height * 0.05f); EditorGUI.BeginChangeCheck(); m_folderPath = EditorGUILayout.TextField("Combined Asset Path", m_folderPath); if (EditorGUI.EndChangeCheck()) { m_pathToAssets = Application.dataPath + "/" + m_folderPath + "/"; } GUILayout.Space(m_window.position.height * 0.05f); m_showModelSettings = EditorGUILayout.Foldout(m_showModelSettings, "Model Settings"); if (m_showModelSettings == true) { GUILayout.Label("Meshes", "BoldLabel"); EditorGUILayout.LabelField("Meshes"); m_modelImportSettings.globalScale = EditorGUILayout.FloatField("Global Scale", m_modelImportSettings.globalScale); m_modelImportSettings.meshCompression = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup("Mesh Compression", m_modelImportSettings.meshCompression); m_modelImportSettings.optimizeMesh = EditorGUILayout.Toggle("Optimize Mesh", m_modelImportSettings.optimizeMesh); m_modelImportSettings.addCollider = EditorGUILayout.Toggle("Generate Colliders", m_modelImportSettings.addCollider); m_modelImportSettings.swapUVChannels = EditorGUILayout.Toggle("Swap UVs", m_modelImportSettings.swapUVChannels); m_modelImportSettings.generateSecondaryUV = EditorGUILayout.Toggle("Generate Lightmap UVs", m_modelImportSettings.generateSecondaryUV); GUILayout.Label("Normals & Tangents", "BoldLabel"); m_modelImportSettings.normalImportMode = (ModelImporterTangentSpaceMode)EditorGUILayout.EnumPopup("Normals", m_modelImportSettings.normalImportMode); m_modelImportSettings.tangentImportMode = (ModelImporterTangentSpaceMode)EditorGUILayout.EnumPopup("Tangents", m_modelImportSettings.tangentImportMode); if ((m_modelImportSettings.normalImportMode == ModelImporterTangentSpaceMode.Calculate) && !(m_modelImportSettings.tangentImportMode == ModelImporterTangentSpaceMode.None)) { m_modelImportSettings.tangentImportMode = ModelImporterTangentSpaceMode.Calculate; } EditorGUI.BeginDisabledGroup(!(m_modelImportSettings.normalImportMode == ModelImporterTangentSpaceMode.Calculate)); m_modelImportSettings.normalSmoothingAngle = EditorGUILayout.IntSlider("Normal Smoothing Angle", (int)m_modelImportSettings.normalSmoothingAngle, 0, 180); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!(m_modelImportSettings.tangentImportMode == ModelImporterTangentSpaceMode.Calculate)); m_modelImportSettings.splitTangentsAcrossSeams = EditorGUILayout.Toggle("Split Tangents", m_modelImportSettings.splitTangentsAcrossSeams); EditorGUI.EndDisabledGroup(); } m_showTextureSettings = EditorGUILayout.Foldout(m_showTextureSettings, "Texture Settings"); if (m_showTextureSettings == true) { m_textureImportSettings.textureType = (TextureImporterType)EditorGUILayout.EnumPopup("", m_textureImportSettings.textureType); switch (m_textureImportSettings.textureType) { case TextureImporterType.Bump: //m_textureImportSettings.convertToNormalmap = EditorGUILayout.Toggle("", m_textureImportSettings.convertToNormalmap); m_textureImportSettings.heightmapScale = EditorGUILayout.Slider(m_textureImportSettings.heightmapScale, 0.0f, 0.3f); m_textureImportSettings.normalmapFilter = (TextureImporterNormalFilter)EditorGUILayout.EnumPopup("Normal Map Filter", m_textureImportSettings.normalmapFilter); m_textureImportSettings.wrapMode = (TextureWrapMode)EditorGUILayout.EnumPopup("Texture Wrap Mode", m_textureImportSettings.wrapMode); m_textureImportSettings.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Texture Filter Mode", m_textureImportSettings.filterMode); m_textureImportSettings.anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_textureImportSettings.anisoLevel, 0, 10); break; case TextureImporterType.Lightmap: m_textureImportSettings.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Texture Filter Mode", m_textureImportSettings.filterMode); m_textureImportSettings.anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_textureImportSettings.anisoLevel, 0, 10); break; case TextureImporterType.Reflection: m_textureImportSettings.grayscaleToAlpha = EditorGUILayout.Toggle("Alpha From Grayscale", m_textureImportSettings.grayscaleToAlpha); m_textureImportSettings.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Texture Filter Mode", m_textureImportSettings.filterMode); m_textureImportSettings.anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_textureImportSettings.anisoLevel, 0, 10); break; case TextureImporterType.Image: default: m_textureImportSettings.textureType = TextureImporterType.Image; m_textureImportSettings.grayscaleToAlpha = EditorGUILayout.Toggle("Alpha From Grayscale", m_textureImportSettings.grayscaleToAlpha); m_textureImportSettings.wrapMode = (TextureWrapMode)EditorGUILayout.EnumPopup("Texture Wrap Mode", m_textureImportSettings.wrapMode); m_textureImportSettings.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Texture Filter Mode", m_textureImportSettings.filterMode); m_textureImportSettings.anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_textureImportSettings.anisoLevel, 0, 10); break; } m_textureImportSettings.maxTextureSize = (int)(object)EditorGUILayout.EnumPopup((TextureSize)m_textureImportSettings.maxTextureSize); m_textureImportSettings.textureFormat = (TextureImporterFormat)EditorGUILayout.EnumPopup(m_textureImportSettings.textureFormat); /*mip map stuff*/ } EditorGUILayout.Toggle("Export Assets ", exportAssets); GUILayout.Space(m_window.position.height * 0.05f); EditorGUILayout.EndVertical(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Combine Mesh", GUILayout.Height(m_window.position.height * 0.1f))) { combineMesh(exportAssets); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); }
public void SetShader(Type shaderType, ShaderProperties properties) { properties.SetProperty("DEFAULT", true); SetShader(ShaderManager.GetShader(shaderType, properties)); properties.SetProperty("DEFAULT", false); }
public DefaultPostShader(ShaderProperties props) : base(props, FRAGMENT_CODE) { }
private void DrawShaderProperties(ShaderProperties props) { this.m_ScrollViewShaderProps = GUILayout.BeginScrollView(this.m_ScrollViewShaderProps, new GUILayoutOption[0]); if (props.textures.Count <ShaderTextureInfo>() > 0) { GUILayout.Label("Textures", EditorStyles.boldLabel, new GUILayoutOption[0]); Rect nameRect; Rect flagsRect; Rect valueRect; this.GetPropertyFieldRects(props.textures.Count <ShaderTextureInfo>(), 16f, out nameRect, out flagsRect, out valueRect); ShaderTextureInfo[] textures = props.textures; for (int i = 0; i < textures.Length; i++) { ShaderTextureInfo t = textures[i]; this.OnGUIShaderPropTexture(nameRect, flagsRect, valueRect, t); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } if (props.floats.Count <ShaderFloatInfo>() > 0) { GUILayout.Label("Floats", EditorStyles.boldLabel, new GUILayoutOption[0]); Rect nameRect; Rect flagsRect; Rect valueRect; this.GetPropertyFieldRects(props.floats.Count <ShaderFloatInfo>(), 16f, out nameRect, out flagsRect, out valueRect); ShaderFloatInfo[] floats = props.floats; for (int j = 0; j < floats.Length; j++) { ShaderFloatInfo t2 = floats[j]; this.OnGUIShaderPropFloat(nameRect, flagsRect, valueRect, t2); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } if (props.vectors.Count <ShaderVectorInfo>() > 0) { GUILayout.Label("Vectors", EditorStyles.boldLabel, new GUILayoutOption[0]); Rect nameRect; Rect flagsRect; Rect valueRect; this.GetPropertyFieldRects(props.vectors.Count <ShaderVectorInfo>(), 16f, out nameRect, out flagsRect, out valueRect); ShaderVectorInfo[] vectors = props.vectors; for (int k = 0; k < vectors.Length; k++) { ShaderVectorInfo t3 = vectors[k]; this.OnGUIShaderPropVector4(nameRect, flagsRect, valueRect, t3); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } if (props.matrices.Count <ShaderMatrixInfo>() > 0) { GUILayout.Label("Matrices", EditorStyles.boldLabel, new GUILayoutOption[0]); Rect nameRect; Rect flagsRect; Rect valueRect; this.GetPropertyFieldRects(props.matrices.Count <ShaderMatrixInfo>(), 48f, out nameRect, out flagsRect, out valueRect); ShaderMatrixInfo[] matrices = props.matrices; for (int l = 0; l < matrices.Length; l++) { ShaderMatrixInfo t4 = matrices[l]; this.OnGUIShaderPropMatrix(nameRect, flagsRect, valueRect, t4); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } if (props.buffers.Count <ShaderBufferInfo>() > 0) { GUILayout.Label("Buffers", EditorStyles.boldLabel, new GUILayoutOption[0]); Rect nameRect; Rect flagsRect; Rect valueRect; this.GetPropertyFieldRects(props.buffers.Count <ShaderBufferInfo>(), 16f, out nameRect, out flagsRect, out valueRect); ShaderBufferInfo[] buffers = props.buffers; for (int m = 0; m < buffers.Length; m++) { ShaderBufferInfo t5 = buffers[m]; this.OnGUIShaderPropBuffer(nameRect, flagsRect, valueRect, t5); nameRect.y += nameRect.height; flagsRect.y += flagsRect.height; valueRect.y += valueRect.height; } } GUILayout.EndScrollView(); }
public void SetAlpha(float alpha, bool trackValue = true) { if (!ShaderProperties) { return; } if (FadeMode == Modes.SeparateMaterials) { if (!OpaqueMaterial || !TransparentMaterial) { return; } //set opaque or transparent material Material m = Mathf.Approximately(alpha, 1) ? OpaqueMaterial : TransparentMaterial; if (CurrentMaterial != m) { SetMaterial(m); CurrentMaterial = m; } } for (int i = 0; i < Renderers.Length; i++) { //for each renderer: Renderer r = Renderers[i]; //just skip null/missing renderers for now - not sure how to keep the list up to date in every situation yet if (!r) { continue; } //turn renderer on or off if (Mathf.Approximately(alpha, 0f)) { if (r.enabled) { r.enabled = false; } } else if (!r.enabled) { r.enabled = true; } //initialize property block with default material values ShaderProperties.SetProperties(MPB, r.sharedMaterial, clear: true); //add per-renderer colors back in PerRendererColor prc = r.GetComponent <PerRendererColor>(); if (prc && prc.enabled) { MPB.SetColor(prc.ColorName, prc.Color); } //scale alpha based on min/max alpha float scaledAlpha = Mathf.Lerp(MinAlpha, MaxAlpha, alpha); //set alpha value of all colors ShaderProperties.SetAlpha(MPB, scaledAlpha); //apply property block r.SetPropertyBlock(MPB); } if (trackValue) { CurrentValue = alpha; } }
public PostShader(ShaderProperties properties, string fs_code) : base(properties, VERTEX_CODE, fs_code) { }
public SkyboxShader(ShaderProperties properties) : base(properties, (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\skybox.vert"), (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\skybox.frag")) { }
void OnGUI() { m_scrollPosition = EditorGUILayout.BeginScrollView(m_scrollPosition); Rect verticalLayoutRect = EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Select the parent object that is to be combined."); EditorGUI.BeginChangeCheck(); m_parentObject = (GameObject)EditorGUILayout.ObjectField("Parent Object Of Meshes To Be Combined", m_parentObject, typeof(GameObject), true); if(EditorGUI.EndChangeCheck()) { m_textureAtlasInfo = new TextureAtlasInfo(); m_texPropArraySize = m_textureAtlasInfo.shaderPropertiesToLookFor.Length; m_shaderFoldoutBools = new bool[m_texPropArraySize]; } if(m_parentObject != null) { m_textureAtlasInfo.compressTexturesInMemory = false;//EditorGUILayout.Toggle("Compress Texture", m_textureAtlasInfo.compressTexturesInMemory); EditorGUI.BeginChangeCheck(); m_texPropArraySize = EditorGUILayout.IntSlider("# Of Shader Properties", m_texPropArraySize, 0, 20); if(EditorGUI.EndChangeCheck()) { if(m_texPropArraySize > m_textureAtlasInfo.shaderPropertiesToLookFor.Length) { ShaderProperties[] temp = new ShaderProperties[m_texPropArraySize]; for(int i = 0; i < m_texPropArraySize; i++) { if(i < m_textureAtlasInfo.shaderPropertiesToLookFor.Length) { temp[i] = m_textureAtlasInfo.shaderPropertiesToLookFor[i]; } else { temp[i] = new ShaderProperties(false, ""); } } m_textureAtlasInfo.shaderPropertiesToLookFor = temp; } else if(m_texPropArraySize < m_textureAtlasInfo.shaderPropertiesToLookFor.Length) { ShaderProperties[] temp = new ShaderProperties[m_texPropArraySize]; for(int i = 0; i < m_texPropArraySize; i++) { temp[i] = m_textureAtlasInfo.shaderPropertiesToLookFor[i]; } m_textureAtlasInfo.shaderPropertiesToLookFor = temp; } m_shaderFoldoutBools = new bool[m_texPropArraySize]; } m_showShaderProperties = EditorGUILayout.Foldout(m_showShaderProperties, "Shader Properties To Watch For"); if(m_showShaderProperties) { for(int i = 0; i < m_texPropArraySize; i++) { m_shaderFoldoutBools[i] = EditorGUILayout.Foldout(m_shaderFoldoutBools[i], "Shader Properties Element " + i); if(m_shaderFoldoutBools[i] == true) { m_textureAtlasInfo.shaderPropertiesToLookFor[i].markAsNormal = EditorGUILayout.Toggle("Mark As Normal Map", m_textureAtlasInfo.shaderPropertiesToLookFor[i].markAsNormal); m_textureAtlasInfo.shaderPropertiesToLookFor[i].propertyName = EditorGUILayout.TextField("Shader Property Name", m_textureAtlasInfo.shaderPropertiesToLookFor[i].propertyName); } } } GUILayout.Space(m_window.position.height * 0.05f); EditorGUI.BeginChangeCheck(); m_folderPath = EditorGUILayout.TextField("Combined Asset Path", m_folderPath); if(EditorGUI.EndChangeCheck()) { m_pathToAssets = Application.dataPath + "/" + m_folderPath + "/"; } GUILayout.Space(m_window.position.height * 0.05f); m_showModelSettings = EditorGUILayout.Foldout(m_showModelSettings, "Model Settings"); if(m_showModelSettings == true) { GUILayout.Label("Meshes", "BoldLabel"); EditorGUILayout.LabelField("Meshes"); m_modelImportSettings.globalScale = EditorGUILayout.FloatField("Global Scale", m_modelImportSettings.globalScale); m_modelImportSettings.meshCompression = (ModelImporterMeshCompression)EditorGUILayout.EnumPopup("Mesh Compression", m_modelImportSettings.meshCompression); m_modelImportSettings.optimizeMesh = EditorGUILayout.Toggle("Optimize Mesh", m_modelImportSettings.optimizeMesh); m_modelImportSettings.addCollider = EditorGUILayout.Toggle("Generate Colliders", m_modelImportSettings.addCollider); m_modelImportSettings.swapUVChannels = EditorGUILayout.Toggle("Swap UVs", m_modelImportSettings.swapUVChannels); m_modelImportSettings.generateSecondaryUV = EditorGUILayout.Toggle("Generate Lightmap UVs", m_modelImportSettings.generateSecondaryUV); GUILayout.Label("Normals & Tangents", "BoldLabel"); m_modelImportSettings.normalImportMode = (ModelImporterTangentSpaceMode)EditorGUILayout.EnumPopup("Normals", m_modelImportSettings.normalImportMode); m_modelImportSettings.tangentImportMode = (ModelImporterTangentSpaceMode)EditorGUILayout.EnumPopup("Tangents", m_modelImportSettings.tangentImportMode); if((m_modelImportSettings.normalImportMode == ModelImporterTangentSpaceMode.Calculate) && !(m_modelImportSettings.tangentImportMode == ModelImporterTangentSpaceMode.None)) { m_modelImportSettings.tangentImportMode = ModelImporterTangentSpaceMode.Calculate; } EditorGUI.BeginDisabledGroup(!(m_modelImportSettings.normalImportMode == ModelImporterTangentSpaceMode.Calculate)); m_modelImportSettings.normalSmoothingAngle = EditorGUILayout.IntSlider("Normal Smoothing Angle", (int)m_modelImportSettings.normalSmoothingAngle, 0, 180); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!(m_modelImportSettings.tangentImportMode == ModelImporterTangentSpaceMode.Calculate)); m_modelImportSettings.splitTangentsAcrossSeams = EditorGUILayout.Toggle("Split Tangents", m_modelImportSettings.splitTangentsAcrossSeams); EditorGUI.EndDisabledGroup(); } m_showTextureSettings = EditorGUILayout.Foldout(m_showTextureSettings, "Texture Settings"); if(m_showTextureSettings == true) { m_textureImportSettings.textureType = (TextureImporterType)EditorGUILayout.EnumPopup("", m_textureImportSettings.textureType); switch(m_textureImportSettings.textureType) { case TextureImporterType.Bump: //m_textureImportSettings.convertToNormalmap = EditorGUILayout.Toggle("", m_textureImportSettings.convertToNormalmap); m_textureImportSettings.heightmapScale = EditorGUILayout.Slider(m_textureImportSettings.heightmapScale, 0.0f, 0.3f); m_textureImportSettings.normalmapFilter = (TextureImporterNormalFilter)EditorGUILayout.EnumPopup("Normal Map Filter", m_textureImportSettings.normalmapFilter); m_textureImportSettings.wrapMode = (TextureWrapMode)EditorGUILayout.EnumPopup("Texture Wrap Mode", m_textureImportSettings.wrapMode); m_textureImportSettings.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Texture Filter Mode", m_textureImportSettings.filterMode); m_textureImportSettings.anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_textureImportSettings.anisoLevel, 0, 10); break; case TextureImporterType.Lightmap: m_textureImportSettings.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Texture Filter Mode", m_textureImportSettings.filterMode); m_textureImportSettings.anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_textureImportSettings.anisoLevel, 0, 10); break; case TextureImporterType.Reflection: m_textureImportSettings.grayscaleToAlpha = EditorGUILayout.Toggle("Alpha From Grayscale", m_textureImportSettings.grayscaleToAlpha); m_textureImportSettings.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Texture Filter Mode", m_textureImportSettings.filterMode); m_textureImportSettings.anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_textureImportSettings.anisoLevel, 0, 10); break; case TextureImporterType.Image: default: m_textureImportSettings.textureType = TextureImporterType.Image; m_textureImportSettings.grayscaleToAlpha = EditorGUILayout.Toggle("Alpha From Grayscale", m_textureImportSettings.grayscaleToAlpha); m_textureImportSettings.wrapMode = (TextureWrapMode)EditorGUILayout.EnumPopup("Texture Wrap Mode", m_textureImportSettings.wrapMode); m_textureImportSettings.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Texture Filter Mode", m_textureImportSettings.filterMode); m_textureImportSettings.anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_textureImportSettings.anisoLevel, 0, 10); break; } m_textureImportSettings.maxTextureSize = (int)(object)EditorGUILayout.EnumPopup((TextureSize)m_textureImportSettings.maxTextureSize); m_textureImportSettings.textureFormat = (TextureImporterFormat)EditorGUILayout.EnumPopup(m_textureImportSettings.textureFormat); /*mip map stuff*/ } EditorGUILayout.Toggle("Export Assets ", exportAssets); GUILayout.Space(m_window.position.height * 0.05f); EditorGUILayout.EndVertical(); EditorGUILayout.BeginHorizontal(); if(GUILayout.Button("Combine Mesh", GUILayout.Height(m_window.position.height * 0.1f))) { combineMesh(exportAssets); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); }
public static string FormatShaderProperties(string origCode, ShaderProperties properties) { string res = ""; string[] lines = origCode.Split('\n'); bool inIfStatement = false; String ifStatementText = ""; bool removing = false; List<string> ifdefs = new List<string>(); List<string> ifndefs = new List<string>(); string currentIfDef = ""; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (line.Trim().StartsWith("#ifdef")) { inIfStatement = true; ifStatementText = lines[i].Trim().Substring(7); ifdefs.Add("!" + ifStatementText); currentIfDef = "!" + ifStatementText; bool remove = !(properties.GetBool(ifStatementText)); int num_ifdefs = 0; int num_endifs = 0; for (int j = i; j < lines.Length; j++) { if (lines[j].Trim().StartsWith("#ifdef") || lines[j].Trim().StartsWith("#ifndef")) { num_ifdefs++; } else if (lines[j].Trim().StartsWith("#endif")) { num_endifs++; if (num_endifs >= num_ifdefs) { break; } } else { if (remove) { lines[j] = ""; } } } lines[i] = ""; } else if (lines[i].Trim().StartsWith("#ifndef")) { inIfStatement = true; ifStatementText = lines[i].Trim().Substring(8); ifdefs.Add("!" + ifStatementText); currentIfDef = "!" + ifStatementText; bool remove = (properties.GetBool(ifStatementText)); int num_ifdefs = 0; int num_endifs = 0; for (int j = i; j < lines.Length; j++) { if (lines[j].Trim().StartsWith("#ifdef") || lines[j].Trim().StartsWith("#ifndef")) { num_ifdefs++; } else if (lines[j].Trim().StartsWith("#endif")) { num_endifs++; if (num_endifs >= num_ifdefs) { break; } } else { if (remove) { lines[j] = ""; } } } lines[i] = ""; } else if (lines[i].Trim().StartsWith("#endif")) { lines[i] = ""; } if (lines[i] != "") res += lines[i] + "\n"; } foreach (var val in properties.values) { res = res.Replace("$" + val.Key, GetValueString(val.Key, val.Value)); } // Console.WriteLine(res); return res; }
public static bool CompareShader(ShaderProperties a, ShaderProperties b) { if (a.values.Count != b.values.Count) { return(false); } string[] keys_a = a.values.Keys.ToArray(); string[] keys_b = b.values.Keys.ToArray(); object[] vals_a = a.values.Values.ToArray(); object[] vals_b = b.values.Values.ToArray(); for (int i = 0; i < keys_a.Length; i++) { if (!keys_a[i].Equals(keys_b[i])) { return(false); } else { if (!vals_a[i].Equals(vals_b[i])) { return(false); } } } /*foreach (var pair in a.values) * { * object value; * if (b.values.TryGetValue(pair.Key, out value)) * { * if (value is bool) * { * if (pair.Value is bool) * return ((bool)value) == ((bool)pair.Value); * else * return false; * } * else if (value is int) * { * if (pair.Value is int) * return ((int)value) == ((int)pair.Value); * else * return false; * } * else if (value is float) * { * if (pair.Value is float) * return ((float)value) == ((float)pair.Value); * else * return false; * } * else if (value is string) * { * if (pair.Value is string) * return ((string)value) == ((string)pair.Value); * else * return false; * } * } * else * { * return false; * } * }*/ return(true); }
public static string FormatShaderProperties_old(string origCode, ShaderProperties properties) { string res = ""; string[] lines = origCode.Split('\n'); bool inIfStatement = false; String ifStatementText = ""; bool removing = false; List<string> ifdefs = new List<string>(); List<string> ifndefs = new List<string>(); string currentIfDef = ""; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (line.Trim().StartsWith("#ifdef")) { inIfStatement = true; ifStatementText = lines[i].Trim().Substring(7); ifdefs.Add(ifStatementText); currentIfDef = ifStatementText; if (properties.GetBool(ifStatementText) == true) removing = false; else removing = true; lines[i] = ""; } else if (lines[i].Trim().StartsWith("#ifndef")) { inIfStatement = true; ifStatementText = lines[i].Trim().Substring(8); if (properties.GetBool(ifStatementText) == false) removing = false; else removing = true; ifdefs.Add("!" + ifStatementText); currentIfDef = "!" + ifStatementText; lines[i] = ""; } else if (lines[i].Trim().StartsWith("#endif")) { if (inIfStatement) { inIfStatement = false; removing = false; } lines[i] = ""; } if (inIfStatement && removing) { lines[i] = ""; } if (lines[i] != "") res += lines[i] + "\n"; } foreach (var val in properties.values) { res = res.Replace("$" + val.Key, GetValueString(val.Key, val.Value)); } return res; }
public NormalMapShader(ShaderProperties properties) : base(properties, (string)AssetManager.Load(AssetManager.GetAppPath() + "\\shaders\\normal_map_generator\\nm.vert"), (string)AssetManager.Load(AssetManager.GetAppPath() + "\\shaders\\normal_map_generator\\nm.frag")) { }
public PostFilter(ShaderProperties properties, string fs_code) : this(new PostShader(properties, fs_code)) { }
public void RegisterShaderProperty(IShaderProperty property) { ShaderProperties.Add(property); }
public SkyShader(ShaderProperties properties) : base(properties, (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\sky.vert"), (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\sky.frag")) { DefaultValues(); }