Question by
Reid_Taylor · Feb 19, 2021 at 01:39 AM ·
errorshaderrenderingshadersshader writing
Custom Urp shader weird problem
Hello, I'm making a toon shader in urp and I ran into a problem when I built it on iPhone... The left side is in unity and the right is wrong on the iPhone. The ambient light is what is weird. It turns black on the iPhone... Heres the shader
Shader "Toon"
{
Properties
{
_Color("Color", Color) = (0.5, 0.65, 1, 1)
_MainTex("Main Texture", 2D) = "white" {}
[Space]
[HDR]
_AmbientColor("Ambient Color", Color) = (0.4, 0.4, 0.4, 1)
[Space]
[HDR]
_SpecularColor("Specular Color", Color) = (0.9, 0.9, 0.9, 1)
_Glossiness("Glossiness", Float) = 32
[Space]
[HDR]
_RimColor("Rim Color", Color) = (1, 1, 1, 1)
_RimAmount("Rim Amount", Range(0, 1)) = 0.716
_RimThreshold("Rim Threshold", Range(0, 1)) = 0.1
}
SubShader
{
Tags {"RenderPipeline" = "UniversalRenderPipeline"}
Pass
{
Tags {
"LightMode" = "UniversalForward"
"PassFlags" = "OnlyDirectional"
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
struct appdata
{
float3 normal : NORMAL;
float4 vertex : POSITION;
float4 uv : TEXCOORD0;
};
struct v2f
{
float3 worldNormal : NORMAL;
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float3 viewDir : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.worldNormal = UnityObjectToWorldNormal(v.normal);
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.viewDir = WorldSpaceViewDir(v.vertex);
return o;
}
float4 _Color;
float4 _AmbientColor;
float4 _SpecularColor;
float _Glossiness;
float4 _RimColor;
float _RimAmount;
float _RimThreshold;
float4 frag (v2f i) : SV_Target
{
float3 normal = normalize(i.worldNormal);
float NdotL = dot(_WorldSpaceLightPos0, normal);
float lightIntensity = smoothstep(0, 0.01, NdotL);
float4 light = lightIntensity * _LightColor0;
float3 viewDir = normalize(i.viewDir);
float3 halfVector = normalize(_WorldSpaceLightPos0 + viewDir);
// CLAMPED THIS
float NdotH = clamp(dot(normal, halfVector), 0, 1);
// CLAMPED THIS
float specularIntensity = pow(NdotH * lightIntensity, _Glossiness * _Glossiness);
float specularIntensitySmooth = smoothstep(0.005, 0.01, specularIntensity);
float4 specular = specularIntensitySmooth * _SpecularColor;
float4 rimDot = 1 - dot(viewDir, normal);
float rimIntensity = rimDot * pow(NdotL, _RimThreshold);
rimIntensity = smoothstep(_RimAmount - 0.01, _RimAmount + 0.01, rimIntensity);
float4 rim = rimIntensity * _RimColor;
float4 sample = tex2D(_MainTex, i.uv);
return _Color * sample * (_AmbientColor + light + specular + rim);
}
ENDHLSL
}
Pass
{
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On
ZTest LEqual
Cull[_Cull]
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma target 2.0
// -------------------------------------
// Material Keywords
#pragma shader_feature _ALPHATEST_ON
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
ENDHLSL
}
}
}
Even though It renders fine and doesn't go pink it gives all these errors:
Please any help appreciated! Thanks
display.png
(194.5 kB)
screen-shot-2021-02-18-at-53800-pm.png
(53.8 kB)
Comment
Your answer
Follow this Question
Related Questions
Hair and eye shader? 0 Answers
Shader error in 'libS/Lit': redefinition of 'SurfaceData' at 0 Answers
Apply inner stroke with fragment shader 0 Answers
Help with Base Color + Outline shader! 0 Answers