diff --git a/documentation/Lighting.rst b/documentation/Lighting.rst index d316fe5f..daddac37 100644 --- a/documentation/Lighting.rst +++ b/documentation/Lighting.rst @@ -23,7 +23,12 @@ The description here is rather oversimplified, but the idea behind these operati Further information about the derivative operations can be found in the OpenGL/Direct3D API documentation, but the implementation in code is quite simple. Firstly you need to make sure that you have access to the fragments world space position in your shader, which means you need to pass it through from the vertex shader. Then you can use the following code in your fragment shader: -//GLSL code +.. code-block:: glsl + + vec3 worldNormal = cross(dFdy(inWorldPosition.xyz), dFdx(inWorldPosition.xyz)); + worldNormal = normalize(worldNormal); + +**TODO: Check the normal direction** Similar code can be implemented in HLSL but you may need to invert the normal due to coordinate system differences between the two APIs. Also, be aware that it may be necessary to use OpenGL ES XXX extension in order to access this derivative functionality on mobile hardware.