#Toon Cel-Shaded version of URP/Terrain/Lit?

1 messages · Page 1 of 1 (latest)

unique thicket
#

Would it be possible to take the stock unity Shader "Universal Render Pipeline/Terrain/Lit" and re-write the light calculations to be stepped/toon/cel-shaded style?

The doccument is very large and I am not experienced with writing shader code, only using shadergraph.

Where exactly in "URP/Terrain/Lit" is the "light" pass that refers to actual lighting? Where would I edit it to change how lighting is done?

brittle ridge
# unique thicket Would it be possible to take the stock unity Shader "Universal Render Pipeline/T...

Should be possible. Assuming Forward/Forward+ rendering paths, shading is handled by the UniversalFragmentPBR function call in TerrainLitPasses.hlsl

So something like

  • Copy the terrain shaders & TerrainLitPasses.hlsl under the Shaders/Terrain folder.
  • In the copied shaders, update the path to that TerrainLitPasses include
  • In the copied hlsl file, replace UniversalFragmentPBR with your own toon-shading function
unique thicket
#

I was able to find the terrain lit through here, but I don't know how to dig deeper and find TerrainLitPasses.hlsl

#

oh I found it

#

TerrainLitPasses is very bloated, its hard to see when/where im supposed to edit what to get toon ramp cel shaded lighting UnityChanThink

#

trying hard to step by step what you've suggested UnityChanThink copy them first step, redirect next step, update last step

#

Redirected to the copied version

#

So far so good, it accepts the new material, and the base original Terrain seems to be working

#

now I just have to find the lines in the LitPasses and rewrite them with a basic toon implementation

#

half4 color = UniversalFragmentPBR(inputData, albedo, metallic, /* specular */ half3(0.0h, 0.0h, 0.0h), smoothness, occlusion, /* emission */ half3(0, 0, 0), alpha);

#

like you said, I should replace that line with my own function

#

Is there any way to see what UniversalFragmentPBR method looks like?

#

for toon shading I dont need most of that stuff, but like I don't even know what variable data type a "inputData" is

#

I get an underclaired identifier with just this

brittle ridge
unique thicket
#

that will help fix the arguments being passed in

brittle ridge
#

I think InputData is in Input.hlsl iirc. But functions in TerrainLitPasses should initalise that struct

#

Or maybe in TerrainLitInput.hlsl, not sure off top of my head

unique thicket
#

Okay I found it, looks like UniversalFragmentPBR is quite large, no surprise there, this gets me the right inputs however

#

okay the inputs passed in are right

#

hm why is there an undeclared identifier

#

it says the method name itself is undeclared

#

but I declared it right there

#

maybe i need to move it inside the bracket

#

Nope that didnt work

brittle ridge
#

Might need to be before the fragment function

unique thicket
#

Oh order in the file might matter?

#

It does appear to matter, moving it up fixed it

brittle ridge
#

Yeah I think in hlsl functions need to be defined before they are called

unique thicket
#

hmrgh I hit a snag that I don't think is surmountable

#

A lot of their code is hard coded to deal with exactly 4 textures

#

But weirdly the default terrain material does allow for and works with more than 4 textures

#

except in my version, its applying black to the first four textures

#

and I need it to affect all of the textures, not just four

#

those other textures must still be using the default terrain material Im guessing? but where/how do I find that to resassign it

#

I was only able to reassign the terrain material through the Debug inspector

#

it seems like the terrain material that I reassigned is just one of many

#

and that unity Terrain uses a bunch more in different contexts and zoom levels

brittle ridge
unique thicket
#

the black I expect, thats my code returning all 0's

brittle ridge
#

Those shaders get connected to the main shader using a "Dependency" - I think defined at the bottom of TerrainLit.shader

unique thicket
#

I see, Ill copy those over and update their Lit path includes as well

#

oh these files are not the same files

#

I dont think I have access to the Hidden folder

#

these files exist, but its a different path and different filename

#

Base and Add don't appear to be referenced anywhere else but the Dependency at the bottom

#

How do I redirect this Hidden path reference to my version, will it be enough to just give it the path to that new file? Even though the filenames dont match?

#

Oh when I open it, that's its name, not file path

#

I see now

#

okay making progress redirecting the dependencies

#

Hm okay, I redirected all the dependencies, but nothing has changed on the material in the scene

#

which is odd, I expect that all if it should be showing black now

#

oh

#

it wasnt using the right material

#

now its all black, thats good

#

hmm lots of errors

#

some progress

#

I have it returning its unshaded albedo

#

but if you zoom out too far, one of the terrain shader/materials is fuxed UnityChanThink

#

ill grab Input which it can't seem to find maybe and make a toon version of that too?

#

DetailLit maybe is the missing one?

#

I don't have any grass and I cloned the other ones

#

but I didnt see any reference to detail lit so far

brittle ridge
unique thicket
#

Ahh

#

ill update all the include paths on all of them to a clone

brittle ridge
#

And in the Add shader you might have changed paths for both includes when you only copied one file

unique thicket
#

Hm when I updated TerrainLitAdd to the copied file, the whole Terrain turned pink

#

It's not that big of a shader file

brittle ridge
#

Does the console have errors? Or inspector when shader is selected

unique thicket
#

Let me try reloading the scene or saving or something, I don't see any errors but maybe I cleared them

#

when I reassigned the material, it turned back from completely pink to only pink in the distance again, weird

#

Ill keep going making sure all the Input files are redirected

#

Fixed all the console errors and paths, but it sstill pink in the distance

#

this is the only console message currently

brittle ridge
#

It could be that you need to reload the scene or something to force it to regenerate that baked texture?

unique thicket
#

Oh, yeah, hitting File > Save instantly unpinked it

#

whew okay good progress, we have the full Terrain material path shader redirected, from here I just have to convert my shadergraph code for toon ramp to HLSL/CG/normal text code, which I think I can do

#

I think I will give it a break here and start again fresh on that next time because I've been at this all day and my brain is mush, thank you for the help as always Cyan 🙌

unique thicket
#

Working on this again, I have this basic setup, but I hit a wall

#

I don't have the surface normals passed in

#

and I dont know where to get them, or how to get them

#

the original universalPBR didnt pass in normals either oddly

#

so im a little unclear how they calculated light/shadow without the normals

#

oh maybe its in the inputdata

#

woo that's a start

#

gotta tweak the actual math, probably want to use smoothstep not step, and include two bands

unique thicket
unique thicket
#

I've kep't working on this and I've hit a new problem

#

I re-wrote the blending logic so that it uses a dither pattern instead of just a soft linear alpha blend

#

it works, for the first four materials

#

but then all subsequent materials, it doesn't

#

the part thats stumped me is all the different passes derive their logic from ToonTerrainLitPasses

#

which is where I rewrote the blending logic

#

each shader derivative doesn't have its own blend logic, they all reference that one file

#

so I dont understand why rewriting it in one place didn't rewrite it for all of them

#

im 100% positive they've all been rewritten to target my code, not anything still making use of stock original Terrain code

brittle ridge
#

Maybe something to do with the main pass only blending/dithering between colours while additive passes have transparency?

#

Though I guess there's red/green touching above and if those are drawn by the same additive pass I'd expect those to dither

unique thicket
#

ive been trying to fix this for days now

#

I got every material dither blending on texture layers 1-4

#

and every material dither blending on texture layers 5+ which are added from the Add pass

#

but I CANNOT get the add pass layers to dither blend with the original 1-4 layers

#

and I keep rewriting it and trying debug after debug and im looking and looking and I cannot find anything wrong I cannot find a reason why its doing this, im going insane

#

its dither blending sorta

#

but its ALSO not dither blending

#

and I dont have a @#$@^@ clue why or how its even possible that it can be doing both

#

I cant move forward on anything until I fix it

#

but I cant fix it no matter how hard I try

#

im so stuck

#

I dont know what more to do than to show others

#

ive tried and tried and tried

#

the entire fragment and color mixing methods have been rewritten to use a ton of submethods trying to make it easier to work with

#

unity's code is such a mess though

#

they tried to cram like 5 separate pipelines of shader code into this one thing and it makes it impossible to get anything done or change anything

#

i just want it to not use soft alpha falloff

#

but i can barely make heads of tails of their code to find every instance of where its happening in order to remove it

#

fffffffffffffffffffffffffffffffffffffinally

#

I just resorted to directly overwriting the alpha at the last step of the render pipeline with the dither alpha

#

of course ive only fixed Lit and LitAdd

#

LitBase and LitBasemapGen still use wrong code

#

as soon as you zoom out, it blurs again because the 'low spec' versions of the terrain shader are untouched and I have to re-write the same stupid edits over and over for every one of their dumb cascade of subsitution shaders

#

except im just NOT going to do that and leave it broken because im using an orthographic camera and Its depth means it never uses the 'low spec' shader