JIT
Создание шейдера стекла для HDRP
Напиши шейдер стекла HDRP
Updated files
v1
Напиши шейдер стекла HDRP
Updated files
v2
Asset import failed, "Assets/__LZC__/Scripts/Glass_HDRP.shadergraph" > ArgumentException: JSON parse error: Missing a name for object member. UnityEngine.JsonUtility.FromJsonInternal (System.String json, System.Object objectToOverwrite, System.Type type) (at <b20a45908ee74fe1885c16de2db6d172>:0) UnityEngine.JsonUtility.FromJsonOverwrite (System.String json, System.Object objectToOverwrite) (at <b20a45908ee74fe1885c16de2db6d172>:0) UnityEditor.ShaderGraph.Serialization.MultiJsonInternal.Parse (System.String str) (at ./Library/PackageCache/com.unity.shadergraph@bbf164badec6/Editor/Serialization/MultiJsonInternal.cs:527) UnityEditor.ShaderGraph.MinimalGraphData.GatherMinimalDependenciesFromFile (System.String assetPath, UnityEditor.ShaderGraph.AssetCollection assetCollection) (at ./Library/PackageCache/com.unity.shadergraph@bbf164badec6/Editor/Data/Graphs/MinimalGraphData.cs:63) UnityEditor.ShaderGraph.ShaderGraphImporter.OnImportAsset (UnityEditor.AssetImporters.AssetImportContext ctx) (at ./Library/PackageCache/com.unity.shadergraph@bbf164badec6/Editor/Importers/ShaderGraphImporter.cs:190) UnityEditor.AssetImporters.ScriptedImporter.GenerateAssetData (UnityEditor.AssetImporters.AssetImportContext ctx) (at <0a4d86c6e1e443e4b37da89bc22f5b9c>:0) UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (Filename: C:\build\output\unity\unity\Modules\AssetPipelineEditor\Public\ScriptedImporter.cpp Line: 216)

It seems there was an issue with the previous file content provided for the .shadergraph extension. Shader Graph files are complex JSON structures that define the visual graph, and providing plain HLSL code within that extension caused the import error.

Unfortunately, I cannot generate the internal JSON structure of a .shadergraph file directly as plain text that Unity can correctly import as a visual graph asset.

To create an HDRP glass shader using Shader Graph, please follow these steps within the Unity Editor:

  1. Create a new Shader Graph:

    • Right-click in your Project window.
    • Select Create > Shader > HDRP > Lit Shader Graph.
    • Name it something like Glass_HDRP.
  2. Open the Shader Graph:

    • Double-click the newly created Glass_HDRP.shadergraph asset.
  3. Configure the HDRP Lit Master Node:

    • Select the HDRP Lit Master node in the graph.
    • In the Node Settings (usually on the right):
      • Change Surface Type from Opaque to Transparent.
      • Under Transparency Inputs, check the box for Refraction.
  4. Add Properties:

    • In the Blackboard (usually on the left), click the + button to add new properties.
    • Add the following properties:
      • Color named _BaseColor (Default: White, Mode: HDR)
      • Float named _Smoothness (Default: 0.5)
      • Float named _RefractionIndex (Default: 0.05)
      • Texture2D named _NormalMap (Default: Bump)
      • Float named _NormalMapScale (Default: 1.0)
  5. Add Nodes and Connect:

    • Right-click in the graph and select Create Node.

    • Add the following nodes:

      • Color (Connect the _BaseColor property to this node)
      • Float (Connect the _Smoothness property to this node)
      • Float (Connect the _RefractionIndex property to this node)
      • Sample Texture 2D (Connect the _NormalMap property to this node)
      • Normal Map (Connect the _NormalMapScale property to the Strength input of this node. Connect the Sample Texture 2D node's RGBA output to the In input of this node).
    • Connect the output of these nodes to the HDRP Lit Master node:

      • Connect the Color node's RGBA output to the Base Color input.
      • Connect the Float node (_Smoothness) output to the Smoothness input.
      • Connect the Normal Map node's Out output to the Normal input.
      • Connect the Float node (_RefractionIndex) output to the Refraction input.
  6. Save the Asset:

    • Click the Save Asset button in the top-left corner of the Shader Graph window.

This will create a functional HDRP glass shader with basic refraction, color, smoothness, and normal map support using Shader Graph. You can then create a Material using this shader and apply it to objects in your scene.