Hi,
I try to port some of the code from the Cg tutorial in Unity.
The Cg tutorial is here , it is a tutorial about writing shaders.
I post the results in the wiki, you can find it here.
If you have any suggestions - corrections - whatever, please post them here.
Right now I have ported up to Chapter 2 ( included ).
If you find it useful, please consider a donation ( at my blog in the signature ).
Thanks ![]()
Oh…wow…this is what i’ve been looking for all this time…O.o… thank you soo much…
Btw…will you port the lighting tutorial too? (just curious )… thank you sir ![]()
I try to port all the code, chapter by chapter, slowly.
A great resource for lighting is lihgting.cginc
Ref : Unity - Manual: Custom lighting models in Surface Shaders
This is a very good idea. I think a lot of people are scared off by the Cg Tutorial because they don’t know enough about ShaderLab to put the Cg in the right context.
True…Because it’s so confusing since there’s no example about porting CG to Shaderlab ( Well i haven’t fine any ) ![]()
Shaderlab uses Cg, so it’s not really a matter of porting. Hooking up your shader properties is easy–just read the manual.
Getting it to work with Unity’s lighting environment is hard, as it would be with any engine.
rea:
Lighting is covered in Chapter 5. I hope that I will be able to get there ![]()
Daniel :
As I slowly port the code, I find a few more caveats.
For example, the way Unity handles offset - tiling. It uses the texcoord.zw.
I managed to make it work in the end but it is not so straightforward.
Or the fact that all the members of a a2v ( application to vertex shader structure ) may only have specific names, e.g. only float4 vertex : POSITION works in this context.
Perhaps there are more. They are documented but not so easy to find.
I stared at a pink cube many times trying to port the examples !
I think that if you try to use the code from the Cg tutorial in Unity you have to
-embed it in a shader ( ShaderLab shader ).
-modify it so it integrates with unity.
I figured it is called porting. If you have another suggestion, I am interested in calling it properly.
Thanks for your interest, I will post again here when next chapter is finished
The Lighting Part is confuse me the most…![]()