Download

Shader in C to material blueprint

I’m currently moving my game from Unity to Unreal Engine 4.and I’m not familiar with this engine. I have shader written in C listed below. Anyone know how to move this to material brlueprint?

It script is called “Blending”. Maybe is similar function in material blueprints?

I would be very grateful if you’ll help me.

Thank you,
Patrick




        Shader "Enviro/BumpedDiffuseOverlaySM3" {
        Properties {
            _Color ("Main Color", Color) = (1,1,1,1)
            _Opacity ("Color over opacity", Range (0, 1)) = 1
            _MainTex ("Color over (RGBA)", 2D) = "white" {}
            _BumpMap ("Normalmap over", 2D) = "bump" {}
            _MainTex2 ("Color under (RGBA)", 2D) = "white" {}
            _BumpMap2 ("Normalmap under", 2D) = "bump" {}
        }
         
        SubShader {
            Tags { "RenderType"="Opaque" }
            LOD 400
           
        CGPROGRAM
        #pragma surface surf Lambert
        #pragma target 3.0
         
        sampler2D _MainTex;
        sampler2D _BumpMap;
        sampler2D _MainTex2;
        sampler2D _BumpMap2;
        fixed4 _Color;
        float _Opacity;
         
        struct Input {
            float2 uv_MainTex;
            float2 uv_BumpMap;
            float2 uv_MainTex2;
            float2 uv_BumpMap2;
        };
         
        void surf (Input IN, inout SurfaceOutput o) {
            float4 tex = tex2D(_MainTex, IN.uv_MainTex);
            float4 tex2 = tex2D(_MainTex2, IN.uv_MainTex2);
            float4 dest;
            _Opacity*=tex.a;
            dest.rgb = tex2.rgb<=0.5 ? 2*tex.rgb*tex2.rgb : 1-2*(1-tex.rgb)*(1-tex2.rgb);
            dest.rgb = lerp(tex2.rgb, dest.rgb, _Opacity);
            dest.rgb *= _Color.rgb;
            o.Albedo = dest.rgb;
            o.Alpha = tex2.a * _Color.a;
           
            float4 norm = tex2D(_BumpMap, IN.uv_BumpMap);
            float4 norm2 = tex2D(_BumpMap2, IN.uv_BumpMap2);
            dest = norm2<=0.5 ? 2*norm*norm2 : 1-2*(1-norm)*(1-norm2);
            dest = lerp(norm2, dest, _Opacity);
            o.Normal = UnpackNormal(dest);
        }
        ENDCG
         
        }
         
        FallBack "Bumped Diffuse"
        }

That’s HLSL, not C.

The shader looks easy enough to recreate, it only has one function (surf) that you can translate directly into nodes, and the only inputs are textures.

This is HLSL like Ambershee said and it’s pretty forward regarding how to set it up in mtl, However you can use that HLSL code as it is in the “Custom” expression in your material. There are also expressions that can do exactly what your HLSL code does.

I tried to recreate this shader in material blueprint and look what I’ve made. Have you any idea how to do this simply?

material.jpg