Normals: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(new page) |
(add link) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== dFdx/dFdy == |
== dFdx/dFdy method == |
||
You can calculate normals in the fragment shader without passing any vertex normals either to or from the vertex shader. However, that these normals will not interpolate across faces. |
|||
<source lang="GLSL"> |
<source lang="GLSL"> |
||
Line 13: | Line 15: | ||
} |
} |
||
</source> |
</source> |
||
=== See also === |
|||
* https://medium.com/@bgolus/generating-perfect-normal-maps-for-unity-f929e673fc57 {{TODO|expand}} |
|||
[[Category:Graphics programming]] |
[[Category:Graphics programming]] |
Latest revision as of 13:51, 24 February 2020
dFdx/dFdy method
You can calculate normals in the fragment shader without passing any vertex normals either to or from the vertex shader. However, that these normals will not interpolate across faces.
in vec3 vertex_coord;
// https://community.khronos.org/t/getting-the-normal-with-dfdx-and-dfdy/70177
// http://web.archive.org/web/20120302100158/http://athile.net/library/blog/?tag=dfdx
vec3 normal()
{
vec3 x = dFdx(vertex_coord);
vec3 y = dFdy(vertex_coord);
return normalize(cross(x, y));
}