/*---------------------------------------------------------------------------* Copyright (C) Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ /////////////////////////////////////////////////////////////////////////////////////////////////////// // G-Buffer Pass ////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// float4x4 u_modelMtx : WORLD : register(c0); float4x4 u_viewprojMtx : VIEWPROJ : register(c4); float4 u_color : COLOR : register(c8); struct VS_INPUT_SETUP { float4 position : POSITION0; float3 normal : NORMAL0; }; struct PS_INPUT_SETUP { float4 vPos : POSITION0; float4 vWorldPos : TEXCOORD1; float4 vWorldNrm : TEXCOORD2; }; struct PS_OUTPUT_SETUP { float4 vMaterial : COLOR0; float4 vWorldNrm : COLOR1; float4 vWorldPosXYZ : COLOR2; }; PS_INPUT_SETUP vertexSetup(VS_INPUT_SETUP input) { PS_INPUT_SETUP output; output.vWorldPos = mul(input.position, u_modelMtx); output.vPos = mul(output.vWorldPos, u_viewprojMtx); output.vWorldNrm = normalize(mul(float4(input.normal, 0.0), u_modelMtx)); return output; } PS_OUTPUT_SETUP pixelSetup(PS_INPUT_SETUP input) { PS_OUTPUT_SETUP output; output.vMaterial = u_color; output.vWorldNrm = float4(input.vWorldNrm.xyz, 1.0); output.vWorldPosXYZ = input.vWorldPos; return output; } technique setup { pass p0 { VertexShader = compile vs_1_1 vertexSetup(); PixelShader = compile ps_2_0 pixelSetup(); CullMode = cw; Zenable = true; ZWriteEnable = true; ZFunc = less; StencilEnable = false; AlphaBlendEnable = false; AlphaTestEnable = false; } } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Lighting Pass ////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// float3 u_lightPosition : LIGHTPOS : register(c0); float3 u_ambientColor : AMBIENTCOLOR : register(c1); float4 u_lightColor : LIGHTCOLOR : register(c2); float3 u_cameraPosition : CAMERAPOS : register(c3); texture2D t_diffuse; sampler s_diffuse : register(s0) = sampler_state { Texture = ; MagFilter = Point; MinFilter = Point; }; texture2D t_normal; sampler s_normal : register(s1) = sampler_state { Texture = ; MagFilter = Point; MinFilter = Point; }; texture2D t_position; sampler s_position : register(s2) = sampler_state { Texture = ; MagFilter = Point; MinFilter = Point; }; struct VS_INPUT_LIGHTING { float4 position : POSITION0; float2 texCoord : TEXCOORD0; }; struct PS_INPUT_LIGHTING { float4 vPos : POSITION0; float2 vTex0 : TEXCOORD0; }; PS_INPUT_LIGHTING vertexLighting(VS_INPUT_LIGHTING input) { PS_INPUT_LIGHTING output; output.vPos = input.position; output.vTex0 = input.texCoord; return output; } float4 pixelLighting(PS_INPUT_LIGHTING input) : COLOR0 { float4 diffuse = tex2D(s_diffuse, input.vTex0); float4 norm = tex2D(s_normal, input.vTex0); float3 pos = tex2D(s_position, input.vTex0).xyz; if(norm.w == 0.0) { discard; } float3 normal = normalize(norm.xyz); float3 lightDir = normalize(u_lightPosition - pos); float3 ambientCol = u_ambientColor * diffuse.rgb; float strength = u_lightColor.a * 255.0 / distance(pos, u_lightPosition); float3 diffuseCol = u_lightColor.rgb * strength * diffuse.rgb; float3 specularCol = diffuse.a * u_lightColor.rgb; float3 refl = reflect(lightDir, normal); float3 toViewer = normalize(pos - u_cameraPosition); float shininess = diffuse.a * 255.0; return float4(ambientCol + diffuseCol * max(0.0, dot(normal, lightDir)) + specularCol * pow(max(0.0, dot(refl, toViewer)), shininess), 1.0); } technique lighting { pass p0 { VertexShader = compile vs_1_1 vertexLighting(); PixelShader = compile ps_2_0 pixelLighting(); CullMode = none; Zenable = false; StencilEnable = false; AlphaBlendEnable = false; Srcblend = One; Destblend = One; AlphaTestEnable = false; } }