Jump to content

Shader Model 4.0 and above not working in-game


Recommended Posts

Hello, I'm developing a shader that requires the use of double precision values. To do this, I must use at least Shader Model (SM) 4.6.

SM 4.6 is supported by DX11, which is what KSP uses by default now.

Moving from SM 3.0 to SM 4.x was causing the shader to appear pink in-game, so I tested this on a completely default, fresh surface shader. I also tested it on a vert-frag shader to be sure. The results were the same - It wasn't working, even when I forced DX11. The shader works fine on SM 3.0. The line I'm referring to is #pragma target 4.6.

It's worth keeping in mind that SM 4.6 works fine in the Unity editor.

The code for the very basic shader is here:

Shader "Custom/Shader"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Albedo (RGB)", 2D) = "white" {}
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" }
        LOD 200
        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows
        #pragma target 4.6
        sampler2D _MainTex;
        struct Input
        {
            float2 uv_MainTex;
        };
        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
        }
        ENDCG
    }
}

The code for the shader that I'll actually be moving over to SM 4.6 is here:

https://github.com/Gameslinx/Parallax-Occlusion/blob/master/Shaders/ParallaxOcclusion.shader

How come using SM 4.0 and above just doesn't work, even though it should be supported by KSP? Am I doing something wrong?

Link to comment
Share on other sites

Posting this here for future reference:

I managed to load a SM 4.0 shader in KSP, only I removed the #pragma target 4.0 line from the shader and used a SM 4.0 feature (in my case a geometry shader) and that gets the shader to load in KSP and force SM 4.0
For forcing SM 4.6 use a tesselation shader anf make sure there is no #pragma target defined.
Edited by blackrack
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...