Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question No script asset for GrayScale.

Discussion in 'Image Effects' started by Aeneas13, Oct 7, 2023.

  1. Aeneas13

    Aeneas13

    Joined:
    Jan 22, 2019
    Posts:
    1
    Im trying to implement my own custom post-processing volumes in Unity for a university Project, but I cant seem to get it to work properly.
    I created the scripts as Documented by Unity on this site : https://docs.unity3d.com/Packages/c...finition@17.0/manual/Custom-Post-Process.html

    Then created a global volume with the custom override. All of the settings appear but the moment I fiddle with the available settings in the volume it throws this error code : "No script asset for GrayScale. Check that the definition is in a file of the same name and that it compiles properly."

    My scripts are the same as in the documentation but i changed the shaders name thinking he had problems finding the shader since both the C# script and the shader shared the same name.
    Just in case im going to add the code down here :

    Script:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.HighDefinition;
    4. using System;
    5.  
    6. [Serializable, VolumeComponentMenu("Post-processing/Custom/GrayScale")]
    7. public sealed class GrayScale : CustomPostProcessVolumeComponent, IPostProcessComponent
    8. {
    9.     [Tooltip("Controls the intensity of the effect.")]
    10.     public ClampedFloatParameter intensity = new ClampedFloatParameter(0f, 0f, 1f);
    11.     Material m_Material;
    12.  
    13.     public bool IsActive() => true; //m_Material != null && intensity.value > 0f;
    14.  
    15.     public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess;
    16.  
    17.     public override void Setup()
    18.     {
    19.         Debug.Log("Shader Found" + Shader.Find("Shader/GrayscaleShader"));
    20.         if (Shader.Find("Shader/GrayScaleShader") != null)
    21.             m_Material = new Material(Shader.Find("Shader/GrayScaleShader"));
    22.     }
    23.  
    24.     public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
    25.     {
    26.         if (m_Material == null)
    27.             return;
    28.  
    29.         m_Material.SetFloat("_Intensity", intensity.value);
    30.         cmd.Blit(source, destination, m_Material, 0);
    31.     }
    32.  
    33.     public override void Cleanup() => CoreUtils.Destroy(m_Material);
    34.  
    35. }
    Shader:
    Code (CSharp):
    1. Shader "Shader/GrayScaleShader"
    2. {
    3.     Properties
    4.     {
    5.         // This property is necessary to make the CommandBuffer.Blit bind the source texture to _MainTex
    6.         _MainTex("Main Texture", 2DArray) = "grey" {}
    7.     }
    8.  
    9.     HLSLINCLUDE
    10.  
    11.     #pragma target 4.5
    12.     #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
    13.  
    14.     #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
    15.     #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
    16.     #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
    17.     #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
    18.     #include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
    19.  
    20.     struct Attributes
    21.     {
    22.         uint vertexID : SV_VertexID;
    23.         UNITY_VERTEX_INPUT_INSTANCE_ID
    24.     };
    25.  
    26.     struct Varyings
    27.     {
    28.         float4 positionCS : SV_POSITION;
    29.         float2 texcoord   : TEXCOORD0;
    30.         UNITY_VERTEX_OUTPUT_STEREO
    31.  
    32.     };
    33.  
    34.     Varyings Vert(Attributes input)
    35.     {
    36.         Varyings output;
    37.  
    38.         UNITY_SETUP_INSTANCE_ID(input);
    39.         UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
    40.  
    41.         output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
    42.         output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
    43.  
    44.         return output;
    45.     }
    46.  
    47.     // List of properties to control your post process effect
    48.     float _Intensity;
    49.     TEXTURE2D_X(_MainTex);
    50.  
    51.     float4 CustomPostProcess(Varyings input) : SV_Target
    52.     {
    53.         UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
    54.  
    55.         float3 sourceColor = SAMPLE_TEXTURE2D_X(_MainTex, s_linear_clamp_sampler, input.texcoord).xyz;
    56.  
    57.         // Apply greyscale effect
    58.         //float3 color = lerp(sourceColor, Luminance(sourceColor), _Intensity);
    59.         float3 color = 1 - sourceColor;
    60.  
    61.         return float4(color, 1);
    62.     }
    63.  
    64.     ENDHLSL
    65.  
    66.     SubShader
    67.     {
    68.         Pass
    69.         {
    70.             Name "GrayScale"
    71.  
    72.             ZWrite Off
    73.             ZTest Always
    74.             Blend Off
    75.             Cull Off
    76.  
    77.             HLSLPROGRAM
    78.                 #pragma fragment CustomPostProcess
    79.                 #pragma vertex Vert
    80.             ENDHLSL
    81.         }
    82.     }
    83.  
    84.     Fallback Off
    85. }
    Thank you in advance.