// Copyright 2014 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license agreement // provided at the time of installation or download, or which otherwise // accompanies this software in either electronic or hard copy form. // // Simple shader to output some vertex attributes to different output targets // For now will write out 2 outputs: position and normals in world space. // #include "Common.ogsfh" // Vertex input structure attribute VS_INPUT { vec3 Pm : POSITION; vec3 Nm : NORMAL; } // Vertex output structure attribute VS_TO_PS { vec3 Pw : TEXCOORD0; vec3 Nw : TEXCOORD1; } // Globals uniform mat4 WorldIT : worldinversetranspose; uniform mat4 World : world; uniform float DepthPriority : depthpriority; uniform mat4 WorldViewProj : worldviewprojection; // Vertex shader fragments GLSLShader VS_GeometryAttributes { vec3 iNw( vec3 nm, mat4 worldITC ) { return ( worldITC * vec4(nm,0) ).xyz; } vec3 iPw( vec3 pm, mat4 world ) { return ( world * vec4(pm, 1.0) ).xyz; } // vec3 iVw( vec3 Pm, vec3 Ew, mat4 world ) // { // vec4 Pw = world * vec4(Pm,1); // return Ew - Pw.xyz; // } vec4 iPcPriority( vec3 pm, float depthPriority, mat4 worldViewProjectionC ) { vec4 P = worldViewProjectionC * vec4(pm,1); P.z -= P.w * 2.0 * depthPriority; return P; } void main() { Nw = iNw( Nm, WorldIT ); Pw = iPw( Pm, World ); gl_Position= iPcPriority ( Pm, DepthPriority, WorldViewProj ); } } // Pixel shader output structure. attribute PS_OUT { vec4 colorOut[2]; } // Pixel shader. GLSLShader PS_GeometryAttributes { void main() { colorOut[0] = vec4( Pw, 1.0); colorOut[1] = vec4((normalize(Nw) + 1.0) * 0.5, 1.0); } } // Technique. technique Main { pass p0 { VertexShader (in VS_INPUT, out VS_TO_PS) = VS_GeometryAttributes; PixelShader (in VS_TO_PS, out PS_OUT) = PS_GeometryAttributes; } }