From a001f3532966285aed0fae4597e9bbab13f08add Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 25 Jul 2016 11:28:23 +0200 Subject: [PATCH] Output UVs in [0,1] from blit shader, for custom vis shaders. Refs #304 --- docs/how/how_custom_visualisation.rst | 19 ++++++++++++++++--- renderdoc/data/glsl/blit.vert | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/how/how_custom_visualisation.rst b/docs/how/how_custom_visualisation.rst index 4eb973f7c..730a033a0 100644 --- a/docs/how/how_custom_visualisation.rst +++ b/docs/how/how_custom_visualisation.rst @@ -27,18 +27,31 @@ There are several pre-defined inputs that can either be taken as parameters to t The shader editor when using the UI can be used to insert these snippets for you, with the right type and spelling. For GLSL these snippets are inserted at the top of the file just after any ``#version`` statement. -UV co-ordinates (D3D11 only) -```````````````````````````` +UV co-ordinates +``````````````` .. highlight:: c++ .. code:: c++ + /* HLSL */ float4 main(float4 pos : SV_Position, float4 uv : TEXCOORD0) : SV_Target0 { return 1; } -This input is defined as two parameters to the shader entry point. The first defines the usual SV_Position system semantic, and the first two components of the second TEXCOORD0 parameter gives UV co-ordinates from 0 to 1 in each dimension over the size of the texture (or texture slice). + /* GLSL */ + layout (location = 0) in vec2 uv; + + void main() : SV_Target0 + { + // ... + } + +This input is defined in HLSL as a second parameter to the shader entry point. The first defines the usual ``SV_Position`` system semantic, and the first two components of the second ``TEXCOORD0`` parameter gives UV co-ordinates from 0 to 1 in each dimension over the size of the texture (or texture slice). + +In GLSL it is bound as a ``vec2`` input at location ``0``. + +You can also use the auto-generated system co-ordinates - ``SV_Position`` or ``gl_FragCoord`` if you need co-ordinates in ``0`` to ``N,M`` for an ``NxM`` texture. .. note:: diff --git a/renderdoc/data/glsl/blit.vert b/renderdoc/data/glsl/blit.vert index ac6e90b39..e6b935f57 100644 --- a/renderdoc/data/glsl/blit.vert +++ b/renderdoc/data/glsl/blit.vert @@ -28,6 +28,8 @@ out gl_PerVertex float gl_PointSize; }; +layout (location = 0) out vec2 uv; + void main(void) { const vec4 verts[4] = vec4[4](vec4(-1.0, -1.0, 0.5, 1.0), @@ -36,4 +38,5 @@ void main(void) vec4( 1.0, 1.0, 0.5, 1.0)); gl_Position = verts[VERTEX_ID]; + uv = gl_Position.xy * 0.5f + 0.5f; }