Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by xiaokujuju · May 31, 2014 at 09:19 PM · slider

How do i use a slider to adjust Brightness or Contrast?

I need a small line of code that I can adjust the Brightness/Contrast of my game. Make sure it uses a slider from -100 to +100, -100 would mean less brightness or Contrast and +100 would mean more brightness and contrast. Anyway I can approach this?

Comment
Add comment · Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · May 31, 2014 at 09:45 PM 1
Share

If you are using lighting in your game, you can adjust the ambient light:

http://docs.unity3d.com/ScriptReference/RenderSettings-ambientLight.html

avatar image xiaokujuju · May 31, 2014 at 09:49 PM 0
Share

couldn't I just use the camera to give an Illusion of game brightness to adjust?

avatar image meat5000 ♦ · May 31, 2014 at 11:48 PM 0
Share

http://forum.unity3d.com/threads/77779-Why-there-is-no-simple-brightness-or-gamma-slider-in-unity

Hack it out or use Pro image effects, apparently.

avatar image HuskyPanda213 · Jun 01, 2014 at 12:27 AM 0
Share

Yeah, you could just use image effects.

avatar image xiaokujuju · Jun 01, 2014 at 07:50 PM 0
Share

I actually tried the ambient light thing. Works for brightness, not so much contrast. Also it doesn't really add much to work with only grey and white makes things brighter the rest are completely different colors.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Jessespike · Sep 23, 2015 at 08:39 PM

I tried a quick crack at it. It's not perfect, but it might be a good starting point for someone who wants to pursue a similar effect... Import the ImageEffects from the StandardAsset. Put this script on the camera and hook up the shader reference.

To work with a slider, place the SetBrightness or SetContrast function in the slider's OnValueChanged list.

 using System;
 using UnityEngine;
 using UnityStandardAssets.ImageEffects;
 
 [ExecuteInEditMode]
 [AddComponentMenu("Image Effects/Custom/Brightness Effect")]
 public class BrightnessEffect : ImageEffectBase
 {
     [Range(0f, 2f)] public float _Brightness = 1f;    
     [Range(0f, 2f)] public float _Contrast = 1f;
 
     // Called by camera to apply image effect
     void OnRenderImage (RenderTexture source, RenderTexture destination)
     {   
         material.SetFloat ("_Brightness", _Brightness);
         material.SetFloat ("_Contrast", _Contrast);
         Graphics.Blit (source, destination, material);
     }
     public void SetBrightness(float value)
     {
         _Brightness = value;
     }
     public void SetContrast(float value)
     {
         _Contrast = value;
     }
 }


//

 Shader "Custom/Brightness Effect" {
 Properties {
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _Brightness ("Brightness", float) = 1
     _Contrast ("Contrast", float) = 1
 }
 
 SubShader {
     Pass {
         ZTest Always Cull Off ZWrite Off
                 
         CGPROGRAM
         #pragma vertex vert_img
         #pragma fragment frag
         #include "UnityCG.cginc"
 
         uniform sampler2D _MainTex;
         uniform float _Brightness;
         uniform float _Contrast;
 
         fixed4 frag (v2f_img i) : SV_Target
         {
             fixed4 output = tex2D(_MainTex, i.uv);
             output = output * _Brightness;
             output = (output - 0.5) * _Contrast + 0.5;
             return output;
         }
         ENDCG
     }
 }
 
 Fallback off
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image noise256 · Apr 28, 2017 at 01:37 PM 0
Share

Nice and simple. Works well.

For the uninitiated:

You can add the shader as a variable to the BrightnessEffect script and then call:

 material = CheckShaderAndCreate$$anonymous$$aterial(shader, material);

The standard asset image effects do it as follows:

 public override bool CheckResources () {
     CheckSupport(false);

     material = CheckShaderAndCreate$$anonymous$$aterial(shader, material);

     if (!isSupported)
         ReportAutoDisable ();
     return isSupported;
 }

 // Called by camera to apply image effect
 void OnRenderImage (RenderTexture source, RenderTexture destination) {   
     if (CheckResources() == false) {
         Graphics.Blit(source, destination);

         return;
     }

avatar image douglas_ciole · Nov 06, 2017 at 03:58 PM 0
Share

Thanks, it worked just fine to me!

avatar image
0

Answer by Tony_T · Sep 23, 2015 at 08:43 PM

You have to do a bit of a research. I will link you to some pages that will help but you have to write the scripts yourself. It's the best way to understand how things work and learn at the same time. Take a look at the Slider, Slider UI, RenderSettings. Good luck !

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Crazydadz · Sep 23, 2015 at 08:48 PM 0
Share

As I already said, unfortunately, playing with the ambient intensity has no effect on object that are baked.

avatar image
0

Answer by Twinklier · Sep 29, 2018 at 12:56 PM

Hey, why not use Colour Grading is Post Processing? Bump up those sliders and you'll have pretty much the same effect.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Twinklier · Sep 29, 2018 at 12:56 PM 0
Share

Well, "same effect" I mean same brightness effect you see in other games.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Write multiple GUI slider values to json file in Unity 0 Answers

How can I load post processing profile throught a script ? 0 Answers

Trying to move slider based off percentage of screen 1 Answer

UI Slider looses control in Update function 1 Answer

How to Assign FloatParameter 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges