GI Cache를 지우고 해봅니다.

이게 빌드 속도를 높이려고 만든것인데, 간혹 제대로 조명이 제대로 안나온다면 이걸 리셋해주면 해결이 됩니다.

라이트맵이 제대로 반영이 안되거나 할때도 한번씩 눌러줍니다.

그외에 빌드 옵션이 잘못된 경우도 있으니 잘 확인해야합니다.

'Unity > ETC' 카테고리의 다른 글

플렛폼별 대표 이미지 압축율 테스트  (0) 2021.05.13
Galaxy S21, S7, fire HD 10 스펙  (0) 2021.05.12
Post Process 실시간 값 변경  (0) 2020.12.22
Post process 간략 설명  (0) 2020.12.18
Terrain Bake시 주의할점  (0) 2020.12.16
{

	int[] array = new int[7];    
	public int[] GrobA;
	public int[] GrobB;

	int tru = 0;
    
    // Start is called before the first frame update
    void Start()
    {
	    AAA();
	    BBB();
	    CCC();
    }

	void AAA()
	{
		print("-------------start--------------");
		print("-------------45개랜덤--------------");
		for (int i = 1; i < array.Length ; )
        	{
			//array[i] = i;
				int result = Random.Range(1, 45);
				if(tru != result)
				{
					print(result);
					i =i+1;
				}

	        tru = result;
        }

	}
	
	void BBB()
	{
		print("-------------GrobA 랜덤--------------");
        
		for (int i = 1; i < array.Length ;)
		{
			//array[i] = i;

            
			int result = Random.Range(1, GrobA.Length);

			if(tru != result)
			{
				print(GrobA[result]);
				i =i+1;
			}
               
			tru = result;

		}
		
	}

    
	void CCC()
	{
		print("-------------GrobB 랜덤--------------");
        
        
		for (int i = 1; i < array.Length ; )
		{
			//array[i] = i;

            
			int result = Random.Range(1, GrobB.Length);

			if(tru != result)
			{
				print(GrobB[result]);
				i =i+1;
			}
               
			tru = result;

		}  
		
	}

}

 

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class TEST_Num : MonoBehaviour
{
    private int[] numbers = Enumerable.Range(1, 45).ToArray();
    private List<int> selectedNumbers = new List<int>();

    public int SetNumber = 1;

    [SerializeField]
    private int[] desiredNumbers = new int[] { };

    private void Start()
    {
        SelectNumbers();
        DisplaySelectedNumbers();
    }

    private void SelectNumbers()
    {
        System.Random random = new System.Random();

        while (selectedNumbers.Contains(0) || selectedNumbers.Count < 6)
        {
            selectedNumbers.Clear();

            for (int i = 0; i < Math.Min(desiredNumbers.Length, SetNumber); i++)
            {
                int requiredNumberIndex = Array.IndexOf(numbers, desiredNumbers[i]);

                if (random.NextDouble() < 0.7)
                {
                    selectedNumbers.Add(desiredNumbers[i]);
                    numbers[requiredNumberIndex] = numbers[numbers.Length - i - 1];
                }
            }

            for (int i = Math.Min(desiredNumbers.Length, 3); i < 6 && selectedNumbers.Count < 6;)
            {
                int index = random.Next(0, numbers.Length - i);
                int selectedNumber = numbers[index];

                if (selectedNumber == 0)
                {
                    continue;
                }

                selectedNumbers.Add(selectedNumber);
                numbers[index] = numbers[numbers.Length - i - 1];
                i++;
            }
        }
    }

    private void DisplaySelectedNumbers()
    {
        string result = string.Join(", ", selectedNumbers.OrderBy(x => x));
        Debug.Log(result);
    }
}

'Unity > C#' 카테고리의 다른 글

물체의 랜덤 스케일  (0) 2021.01.04
캐릭터 랜덤 애니메이션  (0) 2021.01.02
유리가 깨지는 연출  (0) 2020.12.15
Sin, Cos, Tan  (0) 2020.12.15
물체를 회전하고 상하 반복움직임.  (0) 2020.12.11
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class PostProcessingTest : MonoBehaviour
{
    public Volume Volume;
    public Bloom Bloom;
    public ChromaticAberration ChromaticAberration;

    // Start is called before the first frame update
    void Awake()
    {
        Volume.profile.TryGet(out Bloom);
        Volume.profile.TryGet(out ChromaticAberration);
    }

    // Update is called once per frame
    float Value;
    void Update()
    {
        Value += Time.deltaTime;

        Bloom.intensity.value = (Mathf.Sin(Value) * 0.5f + 0.5f) * 100;
        ChromaticAberration.intensity.value = (Mathf.Sin(Value) * 0.5f + 0.5f);
    }
}

원본:    cafe.naver.com/unityhub/104284 

'Unity > ETC' 카테고리의 다른 글

Galaxy S21, S7, fire HD 10 스펙  (0) 2021.05.12
빌드후에 라이트문제가 발생했을때  (0) 2020.12.30
Post process 간략 설명  (0) 2020.12.18
Terrain Bake시 주의할점  (0) 2020.12.16
Reflection Probe의 반사..  (0) 2020.12.14
Shader "ryoo/RyooSpecularShaderForwardAddooo" 

{ 

	Properties 
	{
	
		_DiffuseTex ("Texture", 2D) = "white" {} 
		_Color ("Color", Color) = (1,0,0,1) 
		_Ambient ("Ambient", Range (0, 1)) = 0.25 
		_SpecColor ("Specular Material Color", Color) = (1,1,1,1) // 스페큘러 컬러
		_Shininess ( "Shininess", Float) = 10 // 스페큘러 강도
	}


	SubShader
	{

		Tags { "LightMode" = "ForwardBase" } 
		LOD 100

		Pass
		{

			CGPROGRAM 
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc" 
			#pragma multi_compile_fwdbase
			#include "UnityLightingCommon.cginc" 

			struct appdata 
			{
				float4 vertex : POSITION; 
				float3 normal : NORMAL;
				float2 uv : TEXCOORD0; 
			}; 

			struct v2f // v2f struct(구조체)에 변수를 추가하고, v2f를 통해 프레그먼트 셰이더에 전달
			{
				float2 uv : TEXCOORD0; 
				float4 vertexClip : SV_POSITION; 
				float4 vertexWorld : TEXCOORD2; // 프레그먼트 셰이더에서 광원 방향 벡터 계산
				float3 worldNormal : TEXCOORD1; 
			}; 

			sampler2D _DiffuseTex; 
			float4 _DiffuseTex_ST; 
			float4 _Color; 
			float _Ambient; 
			float _Shininess; 
			
			v2f vert (appdata v) //정점 셰이더 부분
			{
				v2f o;
				o.vertexClip = UnityObjectToClipPos(v.vertex); 
				//o.vertexWorld = mul(unity_ObjectToWorld, v.vertex);
				o.vertexWorld = UnityObjectToClipPos(v.vertex);
				o.uv = TRANSFORM_TEX(v.uv, _DiffuseTex); //텍스쳐 영역
				float3 worldNormal = UnityObjectToWorldNormal(v.normal); 
				o.worldNormal = worldNormal;
				return o; 
			} 

			float4 frag (v2f i) : SV_Target //프레그먼트 셰이더 부분
			{
				//정규화된 월드 공간의 노멀 벡터
				float3 normalDirection = normalize( i.worldNormal); 
				
				// 정규화된 뷰 방향 벡터
				float3 viewDirection = normalize(UnityWorldSpaceViewDir(i. vertexWorld)); 
				
				// 정규화된 광원 방향 벡터
				float3 lightDirection = normalize(UnityWorldSpaceLightDir(i. vertexWorld));
				//텍스쳐 영역
				float4 tex =tex2D(_DiffuseTex, i.uv); 
				
				// 디퓨즈(람버트) 구현
				float nl = max(_Ambient, dot(normalDirection, lightDirection));
				float4 diffuseTerm = nl * _Color * tex * _LightColor0; 
	
				//스페큘러(퐁) 구현
				float3 reflectionDirection = reflect(-lightDirection, normalDirection); 
				float3 specularDot = max(0.0, dot(viewDirection, reflectionDirection)); 
				float3 specular = pow(specularDot, _Shininess);
				float4 specularTerm = float4( specular, 1) * _SpecColor * _LightColor0; 
				
	
				float4 finalColor = diffuseTerm + specularTerm;
				return finalColor; 
			} 
			ENDCG
		}

		Pass // 추가 광원을 지원하기 위해서 같은걸 복사하고 몇가지만 수정
		{

			Tags { "LightMode" = "ForwardAdd" } // 추가 광원을 지원하기 위함.
			Blend One One
			CGPROGRAM 
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_fwdadd 
			#include "UnityCG.cginc" 
			#include "UnityLightingCommon.cginc" 
			
			struct appdata 
			{
				float4 vertex : POSITION; 
				float3 normal : NORMAL;
				float2 uv : TEXCOORD0; 
			}; 

			struct v2f 
			{
			float2 uv : TEXCOORD0; 
			float4 vertexClip : SV_POSITION; 
			float4 vertexWorld : TEXCOORD2;
			float3 worldNormal : TEXCOORD1; 
			}; 
			
			sampler2D _DiffuseTex; 
			float4 _DiffuseTex_ST; 
			float4 _Color; 
			float _Ambient;
			float _Shininess; 
			
			v2f vert (appdata v) 
			{
				v2f o;
				o.vertexClip = UnityObjectToClipPos(v.vertex); 
				o.vertexWorld = mul(unity_ObjectToWorld, v.vertex); 
				o.uv = TRANSFORM_TEX(v.uv, _DiffuseTex); 
				
				float3 worldNormal = UnityObjectToWorldNormal(v.normal); 
				o.worldNormal = worldNormal;
				return o;
			} 
			
			float4 frag (v2f i) : SV_Target 
			{
			float3 normalDirection = normalize( i.worldNormal); 
			
			// 정규화된 뷰 방향 벡터
			float3 viewDirection = normalize( UnityWorldSpaceViewDir(i.vertexWorld)); 
			
			// 정규화된 광원 방향 벡터
			float3 lightDirection = normalize(UnityWorldSpaceLightDir(i.vertexWorld));
			
			//텍스쳐 영역
			float4 tex = tex2D(_DiffuseTex, i.uv); 
			
			// 디퓨즈(람버트) 구현
			float nl = max(0.0, dot(normalDirection, lightDirection)); // Ambient를 제외시킨다. 포함시키면 빛이 더해져서 너무 밝게 나오기 때문에 0으로 셋팅한다.
			float4 diffuseTerm = nl * _Color * tex * _LightColor0; 
			
			//스페큘러(퐁) 구현
			float3 reflectionDirection = reflect(-lightDirection, normalDirection); 
			float3 specularDot = max(0.0, dot(viewDirection, reflectionDirection)); 
			float3 specular = pow( specularDot, _Shininess); 
			//여기까지 퐁
			float4 specularTerm = float4( specular, 1) *_SpecColor * _LightColor0; 
			float4 finalColor = diffuseTerm + specularTerm;
			return finalColor; 
			}
			ENDCG
		}

	}

}

참고서적: 유니티 물리 기반 셰이더 개발 

'Unity > Code base Shader' 카테고리의 다른 글

Z-Buffer, Render Queue, Tag, Blending  (0) 2021.01.01
Unity Shader에 대한 이해  (0) 2021.01.01
SpecularShader  (0) 2020.12.19
diffuseShader  (0) 2020.12.15
좌표공간 변환  (0) 2020.12.12
Shader "ryoo/RyooSpecularzero" 

{ 

	Properties 
	{
	
		_DiffuseTex ("Texture", 2D) = "white" {} 
		_Color ("Color", Color) = (1,0,0,1) 
		_Ambient ("Ambient", Range (0, 1)) = 0.25 
		_SpecColor ("Specular Material Color", Color) = (1,1,1,1) // 스페큘러 컬러
		_Shininess ( "Shininess", Float) = 10 // 스페큘러 강도
	}

	SubShader
	{

		Tags { "LightMode" = "ForwardBase" } 
		LOD 100

		Pass
		{

			CGPROGRAM 
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc" 
			#include "UnityLightingCommon.cginc" 

			struct appdata 
			{
				float4 vertex : POSITION; 
				float3 normal : NORMAL;
				float2 uv : TEXCOORD0; 
			}; 

			struct v2f // v2f struct(구조체)에 변수를 추가하고, v2f를 통해 프레그먼트 셰이더에 전달
			{
				float2 uv : TEXCOORD0; 
				float4 vertexClip : SV_POSITION; 
				float4 vertexWorld : TEXCOORD2; // 프레그먼트 셰이더에서 광원 방향 벡터 계산
				float3 worldNormal : TEXCOORD1; 
			}; 

			sampler2D _DiffuseTex; 
			float4 _DiffuseTex_ST; 
			float4 _Color; 
			float _Ambient; 
			float _Shininess; 
			
			v2f vert (appdata v) //정점 셰이더 부분
			{
				v2f o;
				o.vertexClip = UnityObjectToClipPos(v.vertex); 
				o.vertexWorld = mul(unity_ObjectToWorld, v.vertex); 
				o.uv = TRANSFORM_TEX(v.uv, _DiffuseTex); //텍스쳐 영역
				float3 worldNormal = UnityObjectToWorldNormal(v.normal); 
				o.worldNormal = worldNormal;
				return o; 
			} 

			float4 frag (v2f i) : SV_Target //프레그먼트 셰이더 부분
			{
				//정규화된 월드 공간의 노멀 벡터
				float3 normalDirection = normalize( i.worldNormal); 
				
				// 정규화된 뷰 방향 벡터
				float3 viewDirection = normalize(UnityWorldSpaceViewDir(i. vertexWorld)); 
				
				// 정규화된 광원 방향 벡터
				float3 lightDirection = normalize(UnityWorldSpaceLightDir(i. vertexWorld));
                
				//텍스쳐 영역
				float4 tex =tex2D(_DiffuseTex, i.uv); 
				
				// 디퓨즈(람버트) 구현
				float nl = max(_Ambient, dot(normalDirection, lightDirection));
				float4 diffuseTerm = nl * _Color * tex * _LightColor0; 
	
				//스페큘러(퐁) 구현
				float3 reflectionDirection = reflect(-lightDirection, normalDirection); 
				float3 specularDot = max(0.0, dot(viewDirection, reflectionDirection)); 
				float3 specular = pow(specularDot, _Shininess);
				float4 specularTerm = float4( specular, 1) * _SpecColor * _LightColor0; 
				
	
				float4 finalColor = diffuseTerm + specularTerm;
				return finalColor; 
			} 
			ENDCG
		}


	}

}

참고서적: 유니티 물리 기반 셰이더 개발 

'Unity > Code base Shader' 카테고리의 다른 글

Unity Shader에 대한 이해  (0) 2021.01.01
Specular 다 광원지원  (0) 2020.12.21
diffuseShader  (0) 2020.12.15
좌표공간 변환  (0) 2020.12.12
내적(dot)  (0) 2020.12.12

팁들을 모아 봅니다.

 

시간의 속도를 조절하기(sine그래프를 빠르게)

 

 

UV를 이용한 연출 효과

'Unity > Shader Graph & Amplify' 카테고리의 다른 글

NormalUnpack 코드  (0) 2021.11.06
갈라짐 연출하기  (0) 2021.03.18
sign값을 이용한 포지션 이동  (0) 2020.11.18
Amplify Shader 주요 기능  (0) 2020.11.04
툰 쉐이더 Amplify shader set  (0) 2020.11.02

메인 카메라에 포스트 프로세싱 레이어를 넣습니다.
Post process Volume을 넣고 profile로 new로 만들던가 기존에 만든것이 있다면 넣습니다.
포스트 프로세스를 사용하고 싶지 않는 오브젝트를 위한 카메라를 설정합니다.
원하는 오브젝트에 포스트 프로세스를 제외합니다.

참고: www.youtube.com/watch?v=AooFfmQ_Svo

 

옵션 설명

docs.unity3d.com/Packages/com.unity.postprocessing@2.3/manual/Ambient-Occlusion.html

 

Ambient Occlusion | Post Processing | 2.3.0

Ambient Occlusion The Ambient Occlusion post-processing effect darkens creases, holes, intersections and surfaces that are close to each other. For further information on the Ambient Occlusion effect, refer to the Ambient Occlusion documentation in the Uni

docs.unity3d.com

특정 물체에 포스트 프로세싱을 안하려면

- 포스트 프로세싱이 된 카메라 하단에 카메라를 하나 넣고 다음과 같이 설정합니다.

- 하지만 문제가 있습니다. 위 설정은 카메라 순서를 무시합니다.

- 이럴때는 아래와 같이 설정하면 됩니다.

 

'Unity > ETC' 카테고리의 다른 글

빌드후에 라이트문제가 발생했을때  (0) 2020.12.30
Post Process 실시간 값 변경  (0) 2020.12.22
Terrain Bake시 주의할점  (0) 2020.12.16
Reflection Probe의 반사..  (0) 2020.12.14
플렛폼별 Texutre 설정  (0) 2020.12.11

Terrain 제작시에 라이트맵이 되질 않아서 좀 헤메었습니다.(잊지않도록 메모 해봅니다.)

다음과 같은 사항에 유의합시다.

 

- Terrain 자체를 Static으로 처리가 되었는지 확인합니다.

- 나무 Prefab이 Static으로 되어있는지 확인을 합니다.(이걸 발견못해서...)

- 나무의 경우 라이트맵을 구운후에 캐스트 쉐도우를 꺼주면 그만큼 Batches에 도움이됩니다.(너무 당연한가요..)

- mesh에 Generate Lightmap UVs가 되어있는지 확인한다.(이건 맥스에서 펴와도 됩니다.)

'Unity > ETC' 카테고리의 다른 글

Post Process 실시간 값 변경  (0) 2020.12.22
Post process 간략 설명  (0) 2020.12.18
Reflection Probe의 반사..  (0) 2020.12.14
플렛폼별 Texutre 설정  (0) 2020.12.11
Unity Mask  (0) 2020.12.11