Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Basic vertex shader */
- void LimitedVS(
- float4 position : POSITION,
- float3 normal : NORMAL,
- // outputs
- out float4 oPosition : POSITION,
- out float3 oNormal : TEXCOORD0,
- out float3 oLightVec : TEXCOORD1,
- out float3 oHalfVec : TEXCOORD2,
- out float3 oViewVec : TEXCOORD3,
- // parameters
- uniform float4 lightPosition,
- uniform float3 eyePosition,
- uniform float4x4 wvpMat)
- {
- // calculate output position
- oPosition = mul(wvpMat, position);
- // pass the main uvs and normals straight through unchanged
- oNormal = mul((float3x3)wMat, normal);
- // get object space light direction
- float3 lightVec = normalize(lightPosition.xyz - (worldPosition.xyz * lightPosition.w));
- // calculate half-angle
- float3 eyeVec = normalize(eyePosition - worldPosition.xyz);
- // set output registers
- oHalfVec = eyeVec + lightVec;
- oLightVec = lightVec;
- oViewVec = eyeVec;
- }
- /* Basic fragment program */
- float4 LimitedPS(
- float3 normal : TEXCOORD0,
- float3 lightVec : TEXCOORD1,
- float3 halfVec : TEXCOORD2,
- float3 viewVec : TEXCOORD3,
- // parameters
- uniform float3 lightColour,
- uniform float3 surfaceColour,
- uniform float specularHardness,
- uniform float specularIntensity) : COLOR
- {
- // retrieve vectors and normalize
- float3 N = normalize(normal);
- float3 L = normalize(lightVec);
- float3 H = normalize(halfVec);
- float3 V = normalize(viewVec);
- // compute the diffuse factor
- float3 diffuseFactor = surfaceColour * saturate(dot(N, L)) * lightColour;
- // compute the specular factor
- float3 specFactor = pow(saturate(dot(N, H)), specularHardness) * specularIntensity;
- // simple phong shading
- float3 final = diffuseFactor + float3(specularFactor);
- // calculate and return final colour with alpha
- return float4(final, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment