top of page
รูปภาพนักเขียนสรรเพชญ สมจิตย์

Fake BRDF Samlple code for Unity3D

  1. Shader "Custom/TestShader" {

  2. Properties {

  3. _MainTex ("Base (RGB)", 2D) = "white" {}

  4. _BRDFTex ("BRDF (RGB)", 2D) = ""{}

  5. }

  6. SubShader {

  7. Tags { "RenderType"="Opaque" }

  8. LOD 200

  9. CGPROGRAM

  10. #pragma surface surf NoLighting


  11. sampler2D _MainTex;

  12. sampler2D _BRDFTex;


  13. struct Input {

  14. float2 uv_MainTex;

  15. float2 uv_BRDFTex;

  16. };


  17. void surf (Input IN, inout SurfaceOutput o) {

  18. half4 c = tex2D (_MainTex, IN.uv_MainTex);

  19. o.Albedo = c.rgb;

  20. o.Alpha = c.a;

  21. }

  22. fixed4 LightingNoLighting (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten){

  23. half NdotL = dot(s.Normal, lightDir);

  24. half NdotV = dot(s.Normal, viewDir);

  25. half HalfNdotL = (NdotL*0.5f)+0.5f;

  26. half4 c;

  27. fixed4 ramp = tex2D (_BRDFTex,float2(NdotV,HalfNdotL));

  28. c.rgb = s.Albedo * _LightColor0.rgb * ramp.rgb *( atten *2);

  29. c.a = s.Alpha;

  30. return c;

  31. }

  32. ENDCG

  33. }

  34. FallBack "Diffuse"

  35. }



ดู 1 ครั้ง0 ความคิดเห็น

Comentarios


bottom of page