World Normal Node generate bad code.

Node-based Shader Editor

World Normal Node generate bad code.

Postby sunrice » Tue Jan 30, 2018 4:30 am

Hello.

I transform normal map to world space.
ASE generate bad code.

I Test Default Unlit shader type.
I make [Texture sampler] node. and It set to [World Normal] node input.
3 Texture sample is terrible result.
(test on v1.4.3 dev 01)

fixed4 frag (v2f i ) : SV_Target
{
fixed4 myColorVar;
// ase common template code
float2 uv_TextureSample0 = i.texcoord.xy * _TextureSample0_ST.xy + _TextureSample0_ST.zw;
float3 tanToWorld0 = i.ase_texcoord1.xyz;
float3 tanToWorld1 = i.ase_texcoord2.xyz;
float3 tanToWorld2 = i.ase_texcoord3.xyz;
float3 worldNormal2 = float3(dot(tanToWorld0,tex2D( _TextureSample0, uv_TextureSample0 ).rgb), dot(tanToWorld1,tex2D( _TextureSample0, uv_TextureSample0 ).rgb), dot(tanToWorld2,tex2D( _TextureSample0, uv_TextureSample0 ).rgb));


myColorVar = float4( worldNormal2 , 0.0 );
return myColorVar;
}
sunrice
 
Posts: 14
Joined: Fri Nov 24, 2017 10:27 am

Re: World Normal Node generate bad code.

Postby Amplify_Borba » Tue Jan 30, 2018 10:47 am

sunrice wrote:Hello.

I transform normal map to world space.
ASE generate bad code.

I Test Default Unlit shader type.
I make [Texture sampler] node. and It set to [World Normal] node input.
3 Texture sample is terrible result.
(test on v1.4.3 dev 01)

fixed4 frag (v2f i ) : SV_Target
{
fixed4 myColorVar;
// ase common template code
float2 uv_TextureSample0 = i.texcoord.xy * _TextureSample0_ST.xy + _TextureSample0_ST.zw;
float3 tanToWorld0 = i.ase_texcoord1.xyz;
float3 tanToWorld1 = i.ase_texcoord2.xyz;
float3 tanToWorld2 = i.ase_texcoord3.xyz;
float3 worldNormal2 = float3(dot(tanToWorld0,tex2D( _TextureSample0, uv_TextureSample0 ).rgb), dot(tanToWorld1,tex2D( _TextureSample0, uv_TextureSample0 ).rgb), dot(tanToWorld2,tex2D( _TextureSample0, uv_TextureSample0 ).rgb));


myColorVar = float4( worldNormal2 , 0.0 );
return myColorVar;
}


Hello sunrice, thank you for taking the time to report this occurrence.

Would it be possible for you to send us a sample of the shader so we can debug this on our side? It's always preferred to use the same data as the user, not to mention that it greatly speeds up the debug process while also enabling us to quickly pinpoint if there were any ASE related errors identifiable only by examining the code generated.

Thank you for your understanding, looking forward to your reply!
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: World Normal Node generate bad code.

Postby sunrice » Tue Jan 30, 2018 12:46 pm

// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "ASETemplateShaders/DefaultUnlit"
{
Properties
{
_MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_BumpMap("BumpMap", 2D) = "bump" {}
[HideInInspector] _texcoord( "", 2D ) = "white" {}
}

SubShader
{
Tags { "RenderType"="Opaque" "LightMode" = "ForwardBase" }
LOD 100
Cull Off


Pass
{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"


struct appdata
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
float4 ase_tangent : TANGENT;
float4 ase_normal : NORMAL;
};

struct v2f
{
float4 vertex : SV_POSITION;
float4 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
float4 ase_texcoord1 : TEXCOORD1;
float4 ase_texcoord2 : TEXCOORD2;
float4 ase_texcoord3 : TEXCOORD3;
};

uniform sampler2D _MainTex;
uniform fixed4 _Color;
uniform sampler2D _BumpMap;
uniform float4 _BumpMap_ST;

v2f vert ( appdata v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.texcoord.xy = v.texcoord.xy;
o.texcoord.zw = v.texcoord1.xy;

// ase common template code
float3 worldTangent = UnityObjectToWorldDir(v.ase_tangent);
float3 worldNormal = UnityObjectToWorldNormal(v.ase_normal);
float tangentSign = v.ase_tangent.w * unity_WorldTransformParams.w;
float3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
float3 tanToWorld0 = float3( worldTangent.x, worldBinormal.x, worldNormal.x );
o.ase_texcoord1.xyz = tanToWorld0;
float3 tanToWorld1 = float3( worldTangent.y, worldBinormal.y, worldNormal.y );
o.ase_texcoord2.xyz = tanToWorld1;
float3 tanToWorld2 = float3( worldTangent.z, worldBinormal.z, worldNormal.z );
o.ase_texcoord3.xyz = tanToWorld2;


//setting value to unused interpolator channels and avoid initialization warnings
o.ase_texcoord1.w = 0;
o.ase_texcoord2.w = 0;
o.ase_texcoord3.w = 0;

v.vertex.xyz += float3(0,0,0) ;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}

fixed4 frag (v2f i ) : SV_Target
{
fixed4 myColorVar;
// ase common template code
float2 uv_BumpMap = i.texcoord.xy * _BumpMap_ST.xy + _BumpMap_ST.zw;
float3 tanToWorld0 = i.ase_texcoord1.xyz;
float3 tanToWorld1 = i.ase_texcoord2.xyz;
float3 tanToWorld2 = i.ase_texcoord3.xyz;
float3 worldNormal2 = float3(dot(tanToWorld0,tex2D( _BumpMap, uv_BumpMap ).rgb), dot(tanToWorld1,tex2D( _BumpMap, uv_BumpMap ).rgb), dot(tanToWorld2,tex2D( _BumpMap, uv_BumpMap ).rgb));


myColorVar = float4( worldNormal2 , 0.0 );
return myColorVar;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"
}
/*ASEBEGIN
Version=14301
-1343;87;1319;968;878.5;309;1;True;False
Node;AmplifyShaderEditor.SamplerNode;1;-564.5,27;Float;True;Property;_BumpMap;BumpMap;0;0;Create;True;None;None;True;0;False;bump;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0.0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1.0;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.WorldNormalVector;2;-242.5,31;Float;False;False;1;0;FLOAT3;0,0,0;False;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.TemplateMasterNode;0;-39,30;Float;False;True;2;Float;ASEMaterialInspector;0;2;ASETemplateShaders/DefaultUnlit;6e114a916ca3e4b4bb51972669d463bf;ASETemplateShaders/DefaultUnlit;Off;2;0;FLOAT4;0,0,0,0;False;1;FLOAT3;0,0,0;False;0
WireConnection;2;0;1;0
WireConnection;0;0;2;0
ASEEND*/
//CHKSM=2081BFEFDF9F19EB744316F835B7B938165C958A
sunrice
 
Posts: 14
Joined: Fri Nov 24, 2017 10:27 am

Re: World Normal Node generate bad code.

Postby Amplify_Borba » Tue Jan 30, 2018 2:34 pm

Thank you for sharing your shader with us.

It seems that Unpack Normal Map was not enabled on your Texture Sample node properties, be sure to also set the Default Texture to Bump.

Can you provide additional details regarding the effect that you intend to create so that we can best help you? The World Normal input simply perturbs the surface normals of the object, and seems to be working as intended.

Looking forward to your reply!
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


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests