Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to write a simple shader code in unity3d with visual studio ?

Discussion in 'Code Editors & IDEs' started by Jhones7930710, Nov 4, 2023.

  1. Jhones7930710


    Oct 20, 2023
    I created in my project a Shader > Standrad Surface Shader named it: TestShader.

    Then double click open it and open it in visual studio. once it open ed in visual studio I'm getting some errors like on the first line:

    Error HLSL0029 Cannot resolve type: 'Shader'.

    is there any way to work with shaders in unity and visual studio?
  2. Kurt-Dekker


    Mar 16, 2013
    I'm actually not 100% sure what level of HLSL intellisense is supported, but if it is, it will be supported (probably) via the same mechanism that supports the C# intellisense, so here's my notes on that:

    This may help you with intellisense and possibly other Visual Studio integration problems:

    Sometimes the fix is as simple as doing Assets -> Open C# Project from Unity. Other times it requires more.

    Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.

    Barring all that, move on to other ideas:

    Also, try update the package inside of Unity: Window -> Package Manager -> Search for Visual Studio Editor -> Press the Update button

    Depending on flavor and version of Visual Studio, it may also have an installation step that you perform within the actual Visual Studio. This step seems finicky at best and may require multiple openings of VS before it comes up.

    Update: The VSCode extension has been deprecated and abandoned:

    Update: the VSCode integration is back... maybe!?

    There may be a community fork available that is receiving updates.

    Also, this:

    Recently (July 2023) I worked on a Windows11 system that required a Microsoft component to be installed from within Visual Studio before it would work properly with all the OTHER software installed under Unity. I have no documentation on that process as I have only seen it once and it surprised me as well.
  3. Bunny83


    Oct 18, 2010
    Shaders in Unity are written in shader lab syntax. A shader lab shader may contain an HLSL subsection, but the overall syntax is not HLSL. If you're not familiar with that, you should study the documentation. It contains many examples.
    Over here are even more examples which explain the fundamentals.

    So visual studio can't really help you here with syntax checking since you're not writing pure HLSL shaders. From a technical point of view a single HLSL shader is either a vertex, fragment or geometry shader. Unity combines them into a single one with additional metadata, property and configuration definitions.