- Home /
Can you specify both Surface and Vertex/Fragment shaders?
So I am working on a super basic shader. Is it possible to use both surface and vert+frag? From surface -> vert -> frag.
Basically, I want the shader to be physically based, support most features of unity lighting for my artist. All I need is to add a few things on top of a "traditional" unity shader.
Thx
Answer by Socapex · Jul 27, 2016 at 12:22 AM
Yes you can, I found the answer here (thank you Farfarer)
Shader "Blee" {
Properties {
}
SubShader{
Pass
{
CGPROGRAM
// Vertex and fragment shader here.
ENDCG
}
Pass
{
CGPROGRAM
// More if you want, you can use Blend and all.
ENDCG
}
CGPROGRAM
// Surface shader here.
ENDCG
}
Fallback "Blou"
}
You can also control when the passes are applied by writing your surface shader before (I haven't tried in between though).
Using this method, you can use the nice Standard Shader with all the fancy physically based stuff, and add/blend specialized things your artist demands.
Answer by Bunny83 · Jul 26, 2016 at 04:09 PM
Surface shaders are a highlevel method of writing shaders. The compiler actually creates a vertex and a fragment shader out of your surface shader since that's the only thing the GPU understands / supports. However a surface shader can result even in several passes with different vert/frag shaders.
You might want to take a look at Writing SurfaceShaders.
It's hard to answer your question without anything more concrete. Unity's lighting models are quite complex. Depending on the renderpath lighting might be done in seperate shader passes. "Traditional" shader code might not be compatible with that.
Also see Aras answer over here.
I wanted to mix a surface shader for the base pass, then mix fragment additions. I found the answer I was looking for (adding it here).
Answer by RJ45 · Jul 31, 2016 at 06:51 PM
You can in multiple passes but one pass will write on top of the other obviously. What you probably want. what your question actually is, is how to write to some frag pass which the surface shader takes in as albedo texture (mainTex). That I don't know how to do off the top of my head but would be interested in knowing how. Should be able to do it somehow now that you said it this way.
Your answer
Follow this Question
Related Questions
Is it possible to read light value per vertex with a shader? 0 Answers
Issue with the merging of a surface shader and vert/frag shader using UNITY_MATRIX_MVP 0 Answers
viewDir changes with o.Normal 1 Answer
Can I have a surface shader and a fragment shader on the same mesh? 0 Answers
How to convert surface shader to Vertex/Fragment code? 0 Answers