Ça fait 2 jours que je me prend la tête pour faire un effet sur mon jeu...
J'essaye de créer un fog manuellement avec plusieurs couleurs.
Pour ça, j'ai déjà besoin d'accéder au depth buffer sur mon shader.
Ça marche très bien sur l'éditeur, mais pas du tout sur mon device Android (Pixel 2)
Je suis sur Unity 2019.2
Voici le script que j'ai mi sur ma caméra.
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
public class PostProcess : MonoBehaviour
{
private Material material;
// Creates a private material used to the effect
void Awake()
{
material = new Material(Shader.Find("Kcm/Depth"));
// On active le depth
GetComponent<Camera>().depthTextureMode = GetComponent<Camera>().depthTextureMode | DepthTextureMode.Depth;
}
// Postprocess the image
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(source, destination, material);
}
}
Code : Tout sélectionner
Shader "Kcm/Depth"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _CameraDepthTexture;
float4 frag(v2f_img i) : COLOR
{
float depht = tex2D(_CameraDepthTexture, i.uv).r;
return depht * 38.0;
}
ENDCG
}
}
}
Créez un nouveau projet 3D sur Unity.
Placez le script sur la Camera puis Lancez.
Vous avez une idée de ce qui cloche ?