From 035c2e7de25d367934f8415fc42bae6ba31f6684 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 18 Sep 2012 19:38:49 +0200 Subject: [PATCH] Added GLSL example code. --- documentation/Lighting.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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.