Search Unity

How to Write a shader with custom lighting?

Discussion in 'Shaders' started by Epic-Username, Nov 3, 2017.

  1. Epic-Username

    Epic-Username

    Joined:
    May 24, 2015
    Posts:
    339
    I'm currently developing a procedural generated game which uses chunks made up of one mesh and a texture atlas to define each block on the mesh. I've always thought that i would never have to write my own shader and the default built in ones would be everything i need, but i have found that this is no longer true as i have no other choice but to write a shader for what my game needs.
    I've never written a shader before and have been putting this back further and further developing other features instead but now i have come to the time where i should just get it over with and write the shader. I would like to get it done quickly so would it be possible to develop and learn the following within 24 hrs?

    What i need in the shader:
    • It needs to support both transparent and opaque textures for a texture atlas.
    • It needs to not use unity's lighting i'm writing my own lighting system instead (I'm creating a lighting system similar to Minecraft's (https://minecraft.gamepedia.com/Light)).
    • Related to the above point: it needs each face (2 triangles) to have a "lighting level" which defines how dark or light a face is.
    • Each "lighting level" on the faces needs to be set by a script.
    I've never written a shader before so i don't know if the above is possible, but could anyone suggest any tips or links to tutorials for writing a shader containing these features.

    -Thanks for your time and help
     
  2. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    360
    first your script should store the "lighting level" to mesh's color data. And then your shader use the color data to multiply with texture color.