Need help converting this shader to amplify shader nodes

Node-based Shader Editor

Need help converting this shader to amplify shader nodes

Postby qw_zzz » Mon Oct 15, 2018 3:10 am

Hi all,

im not a shader artist myself but im looking ways to convert this piece of code into nodes so that i could also add other stuff into the shader..
i got the shader off this unity forum link: https://forum.unity.com/threads/interio ... st-2751518

thanks, & it would be great if someone help me create the shader nodes & share it with the rest of the world

ther refs: https://simonschreibt.de/gat/windows-ac-row-ininite/

Code: Select all
Shader "Custom/InteriorMapping - Cubemap"
{
    Properties
    {
        _RoomCube ("Room Cube Map", Cube) = "white" {}
        [Toggle(_USEOBJECTSPACE)] _UseObjectSpace ("Use Object Space", Float) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
 
            #pragma shader_feature _USEOBJECTSPACE
         
            #include "UnityCG.cginc"
 
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float3 normal : NORMAL;
                float4 tangent : TANGENT;
            };
 
            struct v2f
            {
                float4 pos : SV_POSITION;
            #ifdef _USEOBJECTSPACE
                float3 uvw : TEXCOORD0;
            #else
                float2 uv : TEXCOORD0;
            #endif
                float3 viewDir : TEXCOORD1;
            };
 
            samplerCUBE _RoomCube;
            float4 _RoomCube_ST;
 
            // psuedo random
            float3 rand3(float co){
                return frac(sin(co * float3(12.9898,78.233,43.2316)) * 43758.5453);
            }
         
            v2f vert (appdata v)
            {
                v2f o;
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
 
            #ifdef _USEOBJECTSPACE
                // slight scaling adjustment to work around "noisy wall" when frac() returns a 0 on surface
                o.uvw = v.vertex * _RoomCube_ST.xyx * 0.999 + _RoomCube_ST.zwz;
 
                // get object space camera vector
                float4 objCam = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0));
                o.viewDir = v.vertex.xyz - objCam.xyz;
 
                // adjust for tiling
                o.viewDir *= _RoomCube_ST.xyx;
            #else
                // uvs
                o.uv = TRANSFORM_TEX(v.uv, _RoomCube);
 
                // get tangent space camera vector
                float4 objCam = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0));
                float3 viewDir = v.vertex.xyz - objCam.xyz;
                float tangentSign = v.tangent.w * unity_WorldTransformParams.w;
                float3 bitangent = cross(v.normal.xyz, v.tangent.xyz) * tangentSign;
                o.viewDir = float3(
                    dot(viewDir, v.tangent.xyz),
                    dot(viewDir, bitangent),
                    dot(viewDir, v.normal)
                    );
 
                // adjust for tiling
                o.viewDir *= _RoomCube_ST.xyx;
            #endif
                return o;
            }
         
            fixed4 frag (v2f i) : SV_Target
            {
            #ifdef _USEOBJECTSPACE
                // room uvws
                float3 roomUVW = frac(i.uvw);
 
                // raytrace box from object view dir
                float3 pos = roomUVW * 2.0 - 1.0;
                float3 id = 1.0 / i.viewDir;
                float3 k = abs(id) - pos * id;
                float kMin = min(min(k.x, k.y), k.z);
                pos += kMin * i.viewDir;
 
                // randomly flip & rotate cube map for some variety
                float3 flooredUV = floor(i.uvw);
                float3 r = rand3(flooredUV.x + flooredUV.y + flooredUV.z);
                float2 cubeflip = floor(r.xy * 2.0) * 2.0 - 1.0;
                pos.xz *= cubeflip;
                pos.xz = r.z > 0.5 ? pos.xz : pos.zx;
            #else
                // room uvs
                float2 roomUV = frac(i.uv);
 
                // raytrace box from tangent view dir
                float3 pos = float3(roomUV * 2.0 - 1.0, 1.0);
                float3 id = 1.0 / i.viewDir;
                float3 k = abs(id) - pos * id;
                float kMin = min(min(k.x, k.y), k.z);
                pos += kMin * i.viewDir;
 
                // randomly flip & rotate cube map for some variety
                float2 flooredUV = floor(i.uv);
                float3 r = rand3(flooredUV.x + 1.0 + flooredUV.y * (flooredUV.x + 1));
                float2 cubeflip = floor(r.xy * 2.0) * 2.0 - 1.0;
                pos.xz *= cubeflip;
                pos.xz = r.z > 0.5 ? pos.xz : pos.zx;
            #endif
 
                // sample room cube map
                fixed4 room = texCUBE(_RoomCube, pos.xyz);
                return fixed4(room.rgb, 1.0);
            }
            ENDCG
        }
    }
}
qw_zzz
 
Posts: 3
Joined: Tue Jun 20, 2017 9:20 am

Re: Need help converting this shader to amplify shader nodes

Postby Amplify_Borba » Mon Oct 15, 2018 11:30 am

Hello, thank you for getting in touch!

Unfortunately, shader conversion is beyond the scope of our support as we don't have the resources to be able to provide this type of assistance due to our limited team size.

That being said, I'd recommend that you look into our FREE Fake Interiors Asset, as it's fully compatible and editable through the Amplify Shader Editor.

I hope that you find this information useful, and please rest assured we're entirely at your disposal to assist with any ASE related issues.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Need help converting this shader to amplify shader nodes

Postby qw_zzz » Tue Oct 16, 2018 3:50 am

Hello Amplify_Borba!

thanks for replying

well 1st of all would like to avoid using the fake free interior is because, the shader doesnt even work in VR, it looks stretchy & unrefined
qw_zzz
 
Posts: 3
Joined: Tue Jun 20, 2017 9:20 am

Re: Need help converting this shader to amplify shader nodes

Postby Amplify_Borba » Tue Oct 16, 2018 1:53 pm

No problem, we have received a few requests for improving the Free Fake Interiors package with VR in mind, so it's definitely a possibility for us to consider at a later stage.

Please let us know if you have any further questions, thanks!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Need help converting this shader to amplify shader nodes

Postby qw_zzz » Thu Oct 18, 2018 9:18 am

nope... im just hoping if someone else could help me with the conversion?
qw_zzz
 
Posts: 3
Joined: Tue Jun 20, 2017 9:20 am

Re: Need help converting this shader to amplify shader nodes

Postby Ricardo Teixeira » Fri Oct 19, 2018 10:33 am

qw_zzz wrote:nope... im just hoping if someone else could help me with the conversion?


Apologies but this forum is aimed mostly at technical support, I don't think you'll get many answers here from other users.

I recommend posting on the official shader section of the unity forum.
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests

cron