Skip to content
Snippets Groups Projects
Commit c28674b2 authored by Kabourlix-PC's avatar Kabourlix-PC
Browse files

Work on linear brightness modification (via c# script)

parent f93f76c4
No related branches found
No related tags found
No related merge requests found
Showing
with 431 additions and 196 deletions
fileFormatVersion: 2
guid: b3500cb588211794b9413601d9eb4211
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 924375d6a3cfec240b918d47ab133638
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 114f47b60ffd0bf48ae54c5b63461cdd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File added
fileFormatVersion: 2
guid: 2a92ec3b24546c447ae2a5f5da6f3db8
TextureImporter:
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 1
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
fileFormatVersion: 2
guid: d225212aa1a40224598395b170a739ec
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Shader "Unlit/Bright_v2"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (255,255,0,255)
[MaterialToggle] _Choose("Texture on ?", Float) = 0
_Bright("Constrast Modifier", Range(0.0, 1.0)) = 1.0
_Lum("Luminosity Modifier", Range(-1.0,1.0)) = 0.0
[MaterialToggle] _DoContrast("Modify Contrast ?", Float) = 0
[MaterialToggle] _DoLum("Modify Luminosity ?", Float) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
ZWRITE Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Assets/ShadersTools/bright.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
fixed _Bright;
fixed _Lum;
bool _DoContrast;
bool _DoLum;
bool _Choose;
sampler2D _CameraDepthTexture;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col;
// sample the texture
if(_Choose)
{
col = tex2D(_MainTex, i.uv);
}else
{
col = _Color;
}
//Brighten it
if(_DoContrast)
{
if(_Choose)
{
col = saturate(lerp(fixed4(0.5,0.5,0.5,1),col,_Bright));
}else
{
col = BrightEnhancer::brighten_contrast_pixel(col,_Bright);
}
}
else if(_DoLum)
{
col = BrightEnhancer::brighten_luminosity_pixel(col,_Lum);
}
//Display it
return col;
}
ENDCG
}
}
}
fileFormatVersion: 2
guid: cc871df92098c4c4897531effee07556
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
...@@ -163,61 +163,13 @@ Transform: ...@@ -163,61 +163,13 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 30639717} m_GameObject: {fileID: 30639717}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 6.11} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 4 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &84385885
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 84385887}
- component: {fileID: 84385886}
m_Layer: 0
m_Name: UIManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &84385886
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 84385885}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 36203359968a4512badccd30291b21b1, type: 3}
m_Name:
m_EditorClassIdentifier:
jsonFile: {fileID: 4900000, guid: 11e2a74bf70b4f7483c5c355eaa247cb, type: 3}
startButton: {fileID: 0}
nextButton: {fileID: 0}
previousButton: {fileID: 0}
--- !u!4 &84385887
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 84385885}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1.5749823, y: 3.1694949, z: -5.2387547}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &416820087 --- !u!1 &416820087
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -308,7 +260,7 @@ Transform: ...@@ -308,7 +260,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 416820087} m_GameObject: {fileID: 416820087}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.5, z: 1.71} m_LocalPosition: {x: 0, y: 0.5, z: -3.52}
m_LocalScale: {x: 10, y: 1, z: 0.5} m_LocalScale: {x: 10, y: 1, z: 0.5}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
...@@ -722,7 +674,7 @@ Transform: ...@@ -722,7 +674,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1812766316} m_GameObject: {fileID: 1812766316}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 6.11} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
......
...@@ -4,14 +4,30 @@ ...@@ -4,14 +4,30 @@
{ {
"shaderName": "shader1", "shaderName": "shader1",
"occlusionMode": "partial", "occlusionMode": "partial",
"posA" : "(1,2,3)", "posA" : {
"posB" : "(1,2,3)" "x" : 1.0,
"y" : 2.0,
"z" : 3.0
},
"posB" :{
"x" : 1.0,
"y" : 2.0,
"z" : 3.0
}
}, },
{ {
"shaderName": "shader1", "shaderName": "shader1",
"occlusionMode": "partial", "occlusionMode": "partial",
"posA" : "(1,2,3)", "posA" : {
"posB" : "(1,1,1.5)" "x" : 1.0,
"y" : 2.0,
"z" : 3.0
},
"posB" : {
"x" : 1.0,
"y" : 5.0,
"z" : 4.0
}
} }
] ]
} }
\ No newline at end of file
...@@ -66,8 +66,6 @@ namespace SequenceLogic ...@@ -66,8 +66,6 @@ namespace SequenceLogic
#region Unity Modification functions #region Unity Modification functions
private void PlaceSpheres(Vector3 posA, Vector3 posB) private void PlaceSpheres(Vector3 posA, Vector3 posB)
{ {
spheres[_sphereAIndex].transform.position = posA; spheres[_sphereAIndex].transform.position = posA;
......
fileFormatVersion: 2
guid: 08b9d68fd1778d847ba07b11a897d320
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
namespace ShadersRelated
{
public class LinearBrightening : MonoBehaviour
{
[SerializeField] private GameObject camera;
[SerializeField] private bool applyLinearModification = false;
public const float MAXAugmentation = 0.8f;
public const float MINAugmentation = 0.2f;
[Tooltip("Put here two gameobject that represent the limit where the sphere could be placed.")]
[SerializeField] private GameObject[] extremaObjects;
private Material _material;
private static readonly int Bright = Shader.PropertyToID("_Bright");
private static readonly int Lum = Shader.PropertyToID("_Lum");
private void Awake()
{
_material = GetComponent<Renderer>().sharedMaterial;
}
/// <summary>
/// Compute the linearized distance from the camera with two extrema. These extrema are set by the experiment.
/// </summary>
/// <param name="closest"> Closest point for the camera</param>
/// <param name="furthest"> Furthest point from the camera</param>
/// <returns>Values between 0 and 1.</returns>
private float GetLinearizedDistanceFromCamera(Vector3 closest, Vector3 furthest)
{
var camPosition = camera.transform.position;
var distance = Vector3.Distance(camPosition,transform.position);
var closestD = Vector3.Distance(camPosition, closest);
var furthestD = Vector3.Distance(camPosition, furthest);
return (distance - closestD) / (furthestD - closestD); //Between 0 and 1
}
private void SetShaderSpec()
{
var spec = Mathf.Lerp(MAXAugmentation, MINAugmentation,
GetLinearizedDistanceFromCamera(extremaObjects[0].transform.position, extremaObjects[1].transform.position));
//We modify both (lum & contrast) since only one could be active at a time.
_material.SetFloat(Bright, spec);
_material.SetFloat(Lum, spec);
}
private void Update()
{
if(applyLinearModification) SetShaderSpec();
}
}
}
fileFormatVersion: 2
guid: 092ad539f8f08324e9a77a2a26ea0a2c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -8,23 +8,12 @@ using Random = UnityEngine.Random; ...@@ -8,23 +8,12 @@ using Random = UnityEngine.Random;
/// </summary> /// </summary>
public class Test : MonoBehaviour public class Test : MonoBehaviour
{ {
private IterationSavedData _export; private IterationData _data;
private int[] _order;
private void Start() private void Start()
{ {
_export = new IterationSavedData(); _data = Tools.JsonParser<IterationData>.ParseFile("/Assets/Scripts/DataImport/ExpSettings/test.json");
_order = new[] {4, 2, 1, 3, 0}; var it = _data.iteration[1];
for (var i = 0; i < 5; i++) var val = "posA : " + it.posA + " ; posB : " + it.posB;
{ print(val);
var added = new IterationSavedSettings
{
duration = UnityEngine.Random.Range(0.1f, 15f),
iterationIndex = _order[i]
};
_export.savedSettings.Add(added);
}
print("Out of the for loop.");
Tools.JsonParser<IterationSavedData>.ExportToJson(_export,"","test.json");
print("After the save file call.");
} }
} }
...@@ -6,9 +6,9 @@ namespace Tools ...@@ -6,9 +6,9 @@ namespace Tools
{ {
public static class JsonParser<T> public static class JsonParser<T>
{ {
public static T ParseFile(string file) public static T ParseFile(string filepath)
{ {
var jsonString = File.ReadAllText(GetPath() + "/" + file); var jsonString = File.ReadAllText(GetPath() + "/" + filepath);
return JsonUtility.FromJson<T>(jsonString); return JsonUtility.FromJson<T>(jsonString);
} }
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: randomTranslucid
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ValidKeywords:
- _ALPHAPREMULTIPLY_ON
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 0.7169812, g: 0.117540024, b: 0.117540024, a: 0.40392157}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
fileFormatVersion: 2
guid: f42728e252c646ae9888765a70f099d9
timeCreated: 1651675217
\ No newline at end of file
Shader "Unlit/Bright_v2"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (255,255,0,255)
[MaterialToggle] _Choose("Texture on ?", Float) = 0
_Bright("Constrast Modifier", Range(0.0, 1.0)) = 1.0
_Lum("Luminosity Modifier", Range(-1.0,1.0)) = 0.0
[MaterialToggle] _DoContrast("Modify Contrast ?", Float) = 0
[MaterialToggle] _DoLum("Modify Luminosity ?", Float) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
ZWRITE Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Assets/ShadersTools/bright.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
fixed _Bright;
fixed _Lum;
bool _DoContrast;
bool _DoLum;
bool _Choose;
sampler2D _CameraDepthTexture;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col;
// sample the texture
if(_Choose)
{
col = tex2D(_MainTex, i.uv);
}else
{
col = _Color;
}
//Brighten it
if(_DoContrast)
{
if(_Choose)
{
col = saturate(lerp(fixed4(0.5,0.5,0.5,1),col,_Bright));
}else
{
col = BrightEnhancer::brighten_contrast_pixel(col,_Bright);
}
}
else if(_DoLum)
{
col = BrightEnhancer::brighten_luminosity_pixel(col,_Lum);
}
//Display it
return col;
}
ENDCG
}
}
}
fileFormatVersion: 2
guid: 3c0cb7537b03d43dea1266e13da46014
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment