Git Product home page Git Product logo

unityurptoonlitshaderexample's People

Contributors

colinleung-nilocat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unityurptoonlitshaderexample's Issues

compilation error on iOS build

Hello there,

I wanted to use this as a toon shader base for my game, but when I build for iOS the materials with the shader appear in magenta color when game is run on the device. This is the log for the compilation error:

Compilation failed: 
program_source:104:29: error: as_type cast from 'half' to 'int' is not allowed
    u_xlati18 = u_xlatb18 ? as_type<int>(u_xlat16_1.x) : int(0);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~

I'm total noob when it comes to shaders, and I couldn't figure out what part of code exactly compiles to the one above. Can you please help me with it?

Here is the rest of the dump:


#include <metal_stdlib>
#include <metal_texture>
using namespace metal;
#if !(__HAVE_FMA__)
#define fma(a,b,c) ((a) * (b) + (c))
#endif
#ifndef XLT_REMAP_O
	#define XLT_REMAP_O {0, 1, 2, 3, 4, 5, 6, 7}
#endif
constexpr constant uint xlt_remap_o[] = XLT_REMAP_O;
struct FGlobals_Type
{
    float4 _MainLightPosition;
    half4 _MainLightColor;
    half4 _MainLightShadowParams;
};
struct UnityPerDraw_Type
{
    float4 hlslcc_mtx4x4unity_ObjectToWorld[4];
    float4 hlslcc_mtx4x4unity_WorldToObject[4];
    float4 unity_LODFade;
    half4 unity_WorldTransformParams;
    half4 unity_LightData;
    half4 unity_LightIndices[2];
    float4 unity_ProbesOcclusion;
    half4 unity_SpecCube0_HDR;
    float4 unity_LightmapST;
    float4 unity_DynamicLightmapST;
    half4 unity_SHAr;
    half4 unity_SHAg;
    half4 unity_SHAb;
    half4 unity_SHBr;
    half4 unity_SHBg;
    half4 unity_SHBb;
    half4 unity_SHC;
};
struct UnityPerMaterial_Type
{
    float4 _BaseMap_ST;
    half4 _BaseColor;
    float _UseAlphaClipping;
    half _Cutoff;
    half3 _IndirectLightConstColor;
    half _IndirectLightMultiplier;
    half _DirectLightMultiplier;
    half _CelShadeMidPoint;
    half _CelShadeSoftness;
    half _ReceiveShadowMappingAmount;
    float _UseEmission;
    half3 _EmissionColor;
    half3 _EmissionMapChannelMask;
    float _OutlineWidth;
    half3 _OutlineColor;
};
struct Mtl_FragmentIn
{
    float2 TEXCOORD0 [[ user(TEXCOORD0) ]] ;
    half3 TEXCOORD3 [[ user(TEXCOORD3) ]] ;
    float4 TEXCOORD6 [[ user(TEXCOORD6) ]] ;
};
struct Mtl_FragmentOut
{
    half4 SV_TARGET0 [[ color(xlt_remap_o[0]) ]];
};
constexpr sampler _mtl_xl_shadow_sampler(address::clamp_to_edge, filter::linear, compare_func::greater_equal);
fragment Mtl_FragmentOut xlatMtlMain(
    constant FGlobals_Type& FGlobals [[ buffer(0) ]],
    constant UnityPerDraw_Type& UnityPerDraw [[ buffer(1) ]],
    constant UnityPerMaterial_Type& UnityPerMaterial [[ buffer(2) ]],
    sampler sampler_MainLightShadowmapTexture [[ sampler (0) ]],
    sampler sampler_BaseMap [[ sampler (1) ]],
    sampler sampler_EmissionMap [[ sampler (2) ]],
    texture2d<half, access::sample > _BaseMap [[ texture(0) ]] ,
    texture2d<half, access::sample > _EmissionMap [[ texture(1) ]] ,
    depth2d<float, access::sample > _MainLightShadowmapTexture [[ texture(2) ]] ,
    Mtl_FragmentIn input [[ stage_in ]])
{
    Mtl_FragmentOut output;
    half4 u_xlat16_0;
    half3 u_xlat16_1;
    half3 u_xlat16_2;
    half3 u_xlat16_3;
    half3 u_xlat16_4;
    float u_xlat5;
    half u_xlat16_5;
    bool u_xlatb5;
    half u_xlat16_9;
    half u_xlat16_18;
    int u_xlati18;
    bool u_xlatb18;
    half u_xlat16_20;
    u_xlat16_0 = _BaseMap.sample(sampler_BaseMap, input.TEXCOORD0.xy);
    u_xlat16_0.xyz = u_xlat16_0.xyz * UnityPerMaterial._BaseColor.xyz;
    u_xlat16_1.x = half((float(0.0)!=UnityPerMaterial._UseAlphaClipping) ? 0xFFFFFFFFu : uint(0));
    u_xlat16_2.x = fma(u_xlat16_0.w, UnityPerMaterial._BaseColor.w, (-UnityPerMaterial._Cutoff));
    u_xlatb18 = u_xlat16_2.x<half(0.0);
    u_xlati18 = u_xlatb18 ? as_type<int>(u_xlat16_1.x) : int(0);
    if((u_xlati18)!=0){discard_fragment();}
    u_xlatb18 = float(0.0)!=UnityPerMaterial._UseEmission;
    if(u_xlatb18){
        u_xlat16_1.xyz = _EmissionMap.sample(sampler_EmissionMap, input.TEXCOORD0.xy).xyz;
        u_xlat16_1.xyz = u_xlat16_1.xyz * UnityPerMaterial._EmissionColor.xyzx.xyz;
        u_xlat16_1.xyz = u_xlat16_1.xyz * UnityPerMaterial._EmissionMapChannelMask.xyzx.xyz;
        u_xlat16_1.xyz = u_xlat16_1.xyz;
    }
    u_xlat16_2.xyz = (bool(u_xlatb18)) ? u_xlat16_1.xyz : half3(0.0, 0.0, 0.0);
    u_xlat16_20 = dot(input.TEXCOORD3.xyz, input.TEXCOORD3.xyz);
    u_xlat16_20 = rsqrt(u_xlat16_20);
    u_xlat16_3.xyz = half3(u_xlat16_20) * input.TEXCOORD3.xyz;
    u_xlat16_4.x = max(UnityPerDraw.unity_SHAr.w, half(0.0));
    u_xlat16_4.y = max(UnityPerDraw.unity_SHAg.w, half(0.0));
    u_xlat16_4.z = max(UnityPerDraw.unity_SHAb.w, half(0.0));
    u_xlat16_4.xyz = fma(u_xlat16_4.xyz, half3(UnityPerMaterial._IndirectLightMultiplier), UnityPerMaterial._IndirectLightConstColor.xxyz.yzw);
    u_xlat16_18 = _MainLightShadowmapTexture.sample_compare(_mtl_xl_shadow_sampler, input.TEXCOORD6.xy, saturate(input.TEXCOORD6.z), level(0.0));
    u_xlat16_20 = (-FGlobals._MainLightShadowParams.x) + half(1.0);
    u_xlat16_20 = fma(u_xlat16_18, FGlobals._MainLightShadowParams.x, u_xlat16_20);
    u_xlatb18 = 0.0>=input.TEXCOORD6.z;
    u_xlatb5 = input.TEXCOORD6.z>=1.0;
    u_xlatb18 = u_xlatb18 || u_xlatb5;
    u_xlat16_3.x = dot(float3(u_xlat16_3.xyz), FGlobals._MainLightPosition.xyz);
    u_xlat16_5 = u_xlat16_20 + half(-1.0);
    u_xlat5 = fma(float(UnityPerMaterial._ReceiveShadowMappingAmount), float(u_xlat16_5), 1.0);
    u_xlat16_20 = (u_xlatb18) ? half(1.0) : half(u_xlat5);
    u_xlat16_9 = min(UnityPerDraw.unity_LightData.z, half(2.0));
    u_xlat16_20 = u_xlat16_20 * u_xlat16_9;
    u_xlat16_9 = (-UnityPerMaterial._CelShadeSoftness) + UnityPerMaterial._CelShadeMidPoint;
    u_xlat16_3.z = UnityPerMaterial._CelShadeSoftness + UnityPerMaterial._CelShadeMidPoint;
    u_xlat16_3.xz = (-half2(u_xlat16_9)) + u_xlat16_3.xz;
    u_xlat16_9 = half(1.0) / u_xlat16_3.z;
    u_xlat16_3.x = u_xlat16_9 * u_xlat16_3.x;
    u_xlat16_3.x = clamp(u_xlat16_3.x, 0.0h, 1.0h);
    u_xlat16_9 = fma(u_xlat16_3.x, half(-2.0), half(3.0));
    u_xlat16_3.x = u_xlat16_3.x * u_xlat16_3.x;
    u_xlat16_3.x = u_xlat16_3.x * u_xlat16_9;
    u_xlat16_20 = u_xlat16_20 * u_xlat16_3.x;
    u_xlat16_20 = u_xlat16_20 * UnityPerMaterial._DirectLightMultiplier;
    u_xlat16_3.xyz = u_xlat16_0.xyz * FGlobals._MainLightColor.xyz;
    u_xlat16_3.xyz = half3(u_xlat16_20) * u_xlat16_3.xyz;
    u_xlat16_3.xyz = fma(u_xlat16_0.xyz, u_xlat16_4.xyz, u_xlat16_3.xyz);
    u_xlat16_2.xyz = u_xlat16_2.xyz + u_xlat16_3.xyz;
    output.SV_TARGET0.xyz = u_xlat16_2.xyz * UnityPerMaterial._OutlineColor.xyzx.xyz;
    output.SV_TARGET0.w = half(1.0);
    return output;
}

Shader error

shader error in 'SimpleURPToonLitExample(With Outline)': undeclared identifier 'AdditionalLightShadow' at Assets/UnityURPToonLitShaderExample-master/SimpleURPToonLitOutlineExample_Shared.hlsl(354) (on d3d11)
image

Material doesn't have a texture property '_MainTex'

Hi,

I am very new to both unity and shader, and I come across your brilliant project.
I just tried to pull your code and import to a new project I loaded together with Unity-chan. I tried to change her body material to this project, but everything goes purple and the following error was thrown

Material 'body' with Shader 'SimpleURPToonLitExample(With Outline)' doesn't have a texture property '_MainTex' UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

image

I have tried to

  1. add the original picture to _BaseMap (Albedo)
  2. change the variable _BaseMap to _MainTex in SimpleURPToonLitOutlineExample.shader
    but both does not work...

If it helps, I am using Unity version 2020.1.f11.

I am very new to these tools and concepts, I am sorry if I asked a stupid question.

Bright Pink

I downloaded and unzipped the file. Then I dragged the folder into my editor. After I created a new material I changed the shader from Standard to SimpleURPToonLitExample and it turned bright pink.

Anti-Aliasing causes emulator/PC-Quality Demo to run at 1 FPS

When quality slider is set to emulator/PC, the demo runs at a maximum of 1 FPS in all situations except when I turn anti-aliasing off in the "check" scene featuring Klee and Ganyu.

Screen Recording 1
Screen Recording 2 - Less stuttering
Screen recording is done with OBS. The AA at emulator/PC quality taxes my GPU enough that it causes stuttering in my recording. I tried to optimize my encoding settings and uploaded a second screen recording that I hope is helpful. You can notice the recording stutter when my mouse jumps to a new position suddenly. My mouse was moving smoothly across the screen when I recorded this.

My specs as shown in the debug UI are:

OS: Windows 10 (10.0.19042) 64bit [WindowsPlayer]
CPU: AMD Ryzen 7 3700X 8-Core Processor [16 Cores]
GPU: NVIDIA GeForce GTX 1660 SUPER
GPU: Direct3D 11.0 [level 11.1] [Direct3D11]
GPU: SM: 5.0, VRAM: 5991 MB
RAM: 16292 MB
SCR: 3840x2160@60Hz [window size: 3840x2160, DPI: 144]
Model: System Product Name (ASUS)

GPU instancing

Hello,

Thank you for shader, it is very good work.
But i need performance. How can add GPU instancing in shader?

No answer

Hi,

I sent you an email in order to buy your full shader, but there was no response. Are you still active?

Getting some "Couldn't open include file..." errors With 2021.3.33

First of all, thank you very much for sharing these. Actually, I used these shaders before, and now when I want to use them again, I encountered these errors. I tried to research and fix them, but I couldn't manage. I checked if the relevant files were removed from the mentioned repository, but I couldn't find a solution because I'm not very knowledgeable about shaders. How can this issue be resolved?

Version : 2021.3.33f URP
Platform : Windows 10

image

Objects disappear if Depth Priming is not set to "Disabled"

In an existing project and a blank project I just created for testing, the shader does not work as intended.

Currently it is behaving like this:

┌────────────────────┬──────────────────────────┐
│ Depth Priming Mode │       Visibility         │
├────────────────────┼──────────────────────────┤
│ Disabled           │ Scene & Game Window      │
│ Auto               │ Game Window Only         │
│ Forced             │ Only shadows are visible │
└────────────────────┴──────────────────────────┘

You can see a video of this here.

Both projects/scenes have identical camera settings, post-processing, and URP Asset settings. Both projects shown have Light Layers enabled.

Unity Version: 2021.2.7f1
URP Version: 12.1.2

wow

라이트맵
Pink in the shadow area. How did you do it? this is beauti!!!
Is it a light map?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.