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,

    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
    #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;
        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);
    FallBack "Bumped Diffuse"

You can find Custom block in Custom->Custom , let you create put custom shader code, there few problems thru:

  • Code language depends on renderer, DX
    one will use HLSL, GL will use GLSL
    and consoles might use something
    else, so you would need to create
    material for each, or else your game
    will be exclusive to one
  • There no functions, you will need to
    recrete it somehow in sperate block
    if that even possible. In UDK (and
    most likely in UE4 ) each block is a
    function which you could call from
    other custom blocks if you know the
    name (UDK has code preview), but it
    really hacky unreliable workaround.

You can also try to play in engine source code to implement your shader, but myself i don’t know here to start with that you will need to figure out yourself.

In general it is recommended to recrate function of your shader with pre-existing blocks.

After eyeballing the code, I think it should be possible to create this network simply using pre-existing nodes in the material editor. There’s no need to write any H/GLSL.

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

Post a comment instead of making answer :stuck_out_tongue:

If this works as it suppose to then it’s ok even thru it looks complex :slight_smile: i seen big material graphs like that in UDK. There no other way then what i explained in my answer