Created
October 1, 2018 06:52
-
-
Save JSandusky/7522f22cdb30a03e52c8360ce4b8fd99 to your computer and use it in GitHub Desktop.
Render normal to texture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if OPENGL | |
#define SV_POSITION POSITION | |
#define VS_SHADERMODEL vs_3_0 | |
#define PS_SHADERMODEL ps_3_0 | |
#else | |
#define VS_SHADERMODEL vs_4_0_level_9_1 | |
#define PS_SHADERMODEL ps_4_0_level_9_1 | |
#endif | |
matrix WorldViewProjection; | |
float4 OffsetScale; | |
struct VertexShaderInput | |
{ | |
float4 Position : POSITION0; | |
float4 Normal : NORMAL0; | |
float2 UVCoord : TEXCOORD0; | |
}; | |
struct VertexShaderOutput | |
{ | |
float4 Position : SV_POSITION; | |
float4 Color : COLOR0; | |
}; | |
VertexShaderOutput MainVS(in VertexShaderInput input) | |
{ | |
VertexShaderOutput output = (VertexShaderOutput)0; | |
output.Position = mul(float4(input.UVCoord.x * OffsetScale.z + OffsetScale.x, input.UVCoord.y * OffsetScale.w + OffsetScale.y, 0, 1), WorldViewProjection); | |
output.Color = input.Normal * 0.5 + 0.5; | |
output.Color.a = 1; | |
return output; | |
} | |
float4 MainPS(VertexShaderOutput input) : COLOR | |
{ | |
return input.Color; | |
} | |
technique BakeNormal | |
{ | |
pass P0 | |
{ | |
VertexShader = compile VS_SHADERMODEL MainVS(); | |
PixelShader = compile PS_SHADERMODEL MainPS(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment