<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: m2048</title>
    <description>The latest articles on DEV Community by m2048 (@m2048).</description>
    <link>https://dev.to/m2048</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F668963%2F78e831f4-1a84-4f01-a239-c4e09fb7ac9c.png</url>
      <title>DEV Community: m2048</title>
      <link>https://dev.to/m2048</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/m2048"/>
    <language>en</language>
    <item>
      <title>[Unity] Access to the PostProcess from script</title>
      <dc:creator>m2048</dc:creator>
      <pubDate>Mon, 28 Oct 2024 13:57:02 +0000</pubDate>
      <link>https://dev.to/m2048/unity-access-to-the-postprocess-from-script-35g9</link>
      <guid>https://dev.to/m2048/unity-access-to-the-postprocess-from-script-35g9</guid>
      <description>&lt;h2&gt;
  
  
  [Built-in render pipeline]
&lt;/h2&gt;

&lt;p&gt;1st of all, import &lt;a href="https://docs.unity3d.com/Packages/com.unity.postprocessing@2.1/api/UnityEngine.Rendering.PostProcessing.html" rel="noopener noreferrer"&gt;UnityEngine.Rendering.PostProcessing&lt;/a&gt;,&lt;br&gt;
and get the &lt;a href="https://docs.unity3d.com/Packages/com.unity.postprocessing@2.1/api/UnityEngine.Rendering.PostProcessing.PostProcessVolume.html" rel="noopener noreferrer"&gt;PostProcessVolume&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;UnityEngine.Rendering.PostProcessing&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;PostProcessVolume&lt;/span&gt; &lt;span class="n"&gt;m_vol&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2nd of all, get the &lt;a href="https://docs.unity3d.com/Packages/com.unity.postprocessing@2.0/api/UnityEngine.Rendering.PostProcessing.PostProcessProfile.html" rel="noopener noreferrer"&gt;PostProcessProfile&lt;/a&gt; and get the effect you want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="n"&gt;PostProcessProfile&lt;/span&gt; &lt;span class="n"&gt;profile&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m_vol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;m_colorGrading&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetSetting&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ColorGrading&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;br&gt;
and edit parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using UnityEngine;
using UnityEngine.Rendering.PostProcessing;

namespace PostProcessBuiltinChangerDemo
{
    public class PostProcessBuiltinChanger : MonoBehaviour
    {
        [SerializeField] PostProcessVolume m_vol;
        ColorGrading m_colorGrading;

        // Start is called once before the first execution of Update after the MonoBehaviour is created
        void Start()
        {
            PostProcessProfile profile = m_vol.profile;
            m_colorGrading = profile.GetSetting&amp;lt;ColorGrading&amp;gt;();
        }

        // Update is called once per frame
        void Update()
        {
        }

        public void OnSetGamma(float _value)
        {
            Vector4Parameter gamma = m_colorGrading.gamma;
            gamma.value = new Vector4(1f, 1f, 1f, _value);
            m_colorGrading.gamma = gamma;
            Debug.Log("gamma: " + gamma.value);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2km31gf26strifet1q30.png" alt="image.png" width="712" height="397"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftsz66efii02n2xqz49z0.png" alt="image.png" width="719" height="414"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  [Universal render pipeline(URP)]
&lt;/h2&gt;

&lt;p&gt;1st of all, import &lt;a href="https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@7.0/api/UnityEngine.Rendering.Universal.html" rel="noopener noreferrer"&gt;UnityEngine.Rendering.Universal&lt;/a&gt;,&lt;br&gt;
and get the &lt;a href="https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@5.9/api/UnityEngine.Rendering.Volume.html" rel="noopener noreferrer"&gt;UnityEngine.Rendering.Volume&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;UnityEngine.Rendering.Universal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;UnityEngine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Rendering&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Volume&lt;/span&gt; &lt;span class="n"&gt;m_vol&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2nd of all, TryGet() the effect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="n"&gt;LiftGammaGain&lt;/span&gt; &lt;span class="n"&gt;m_liftGammaGain&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        m_liftGammaGain = null;
        m_vol.profile.TryGet(out m_liftGammaGain);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;br&gt;
and edit parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using UnityEngine;
using UnityEngine.Rendering.Universal;

namespace PostProcessURPChangerDemo
{
    public class PostProcessURPChanger : MonoBehaviour
    {
        [SerializeField] UnityEngine.Rendering.Volume m_vol;
        LiftGammaGain m_liftGammaGain;

        // Start is called once before the first execution of Update after the MonoBehaviour is created
        void Start()
        {
            m_liftGammaGain = null;
            m_vol.profile.TryGet(out m_liftGammaGain);
        }

        // Update is called once per frame
        void Update()
        {
        }

        public void OnSetGamma(float _value)
        {
            m_liftGammaGain.gamma.value = new Vector4(1f, 1f, 1f, _value);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5yftmua18wvaow6u16e.png" alt="image.png" width="715" height="400"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1gi9p9xbwemha99rzykc.png" alt="image.png" width="709" height="398"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
    </item>
    <item>
      <title>[Unity] Make a loop sound from non-loop one</title>
      <dc:creator>m2048</dc:creator>
      <pubDate>Fri, 24 Sep 2021 06:33:56 +0000</pubDate>
      <link>https://dev.to/m2048/unity-make-a-loop-sound-from-non-loop-one-3o42</link>
      <guid>https://dev.to/m2048/unity-make-a-loop-sound-from-non-loop-one-3o42</guid>
      <description>&lt;p&gt;We released &lt;a href="https://assetstore.unity.com/packages/tools/audio/ambientlooper-203078" rel="noopener noreferrer"&gt;AmbientLooper&lt;/a&gt; on Unity Asset store.&lt;br&gt;
This asset will generate a loop .wav file or clip from non-loop one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassetstorev1-prd-cdn.unity3d.com%2Fkey-image%2F16e84419-1ee4-4ca4-be87-6040d5058698.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassetstorev1-prd-cdn.unity3d.com%2Fkey-image%2F16e84419-1ee4-4ca4-be87-6040d5058698.webp" alt="AmbLooper" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following script is a part of this asset.&lt;br&gt;
attach this script in a object that contains AudioSource,&lt;br&gt;
a clip in the AudioSource becomes loop clip.&lt;br&gt;
&lt;a href="https://youtu.be/VyvispRoKKY" rel="noopener noreferrer"&gt;Movie&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class CrossFadeLoop : MonoBehaviour
{
    [Tooltip("cross fade dulation[sec]"), Range(0.1f, 5f)] public float m_crossFadeTime = 1f;

    void Start()
    {
        AudioSource audioSrc = gameObject.GetComponent&amp;lt;AudioSource&amp;gt;();
        AudioClip ac = audioSrc.clip;
        float[] data = new float[ac.samples * ac.channels];
        ac.GetData(data, 0);
        int span = Mathf.FloorToInt(m_crossFadeTime * (float)(ac.frequency * ac.channels));
        span -= (span % ac.channels);
        float[] newData = CrossFade(data, span);
        AudioClip newAc = AudioClip.Create("_loop_" + ac.name, newData.Length / ac.channels, ac.channels, ac.frequency, false);
        newAc.SetData(newData, 0);
        audioSrc.clip = newAc;
        if (audioSrc.playOnAwake)
            audioSrc.Play();
    }

    static public float[] CrossFade(float[] data, int span)
    {
        if (data.Length &amp;lt; span * 2)
            return data;

        float[] retData = new float[data.Length - span];
        for (int i = 0; i &amp;lt; span; ++i)
        {
            float rate = (float)(i + 1) / (float)(span + 1);
            retData[i] = data[i] * rate + data[data.Length - span + i] * (1f - rate);
        }
        for (int i = span; i &amp;lt; data.Length - span; ++i)
            retData[i] = data[i];

        return retData;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>unity3d</category>
    </item>
  </channel>
</rss>
