Commit 3fd3a302 authored by chili's avatar chili
Browse files

rename worldPos => viewPos

parent 15e490b0
......@@ -21,10 +21,10 @@ Texture2D tex;
SamplerState splr;
float4 main(float3 worldPos : Position, float3 n : Normal, float2 tc : Texcoord) : SV_Target
float4 main(float3 viewPos : Position, float3 n : Normal, float2 tc : Texcoord) : SV_Target
{
// fragment to light vector data
const float3 vToL = lightPos - worldPos;
const float3 vToL = lightPos - viewPos;
const float distToL = length(vToL);
const float3 dirToL = vToL / distToL;
// attenuation
......@@ -35,7 +35,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float2 tc : Texcoord)
const float3 w = n * dot(vToL, n);
const float3 r = w * 2.0f - vToL;
// calculate specular intensity based on angle between viewing vector and reflection vector, narrow with power function
const float3 specular = att * (diffuseColor * diffuseIntensity) * specularIntensity * pow(max(0.0f, dot(normalize(-r), normalize(worldPos))), specularPower);
const float3 specular = att * (diffuseColor * diffuseIntensity) * specularIntensity * pow(max(0.0f, dot(normalize(-r), normalize(viewPos))), specularPower);
// final color
return float4(saturate((diffuse + ambient) * tex.Sample(splr, tc).rgb + specular), 1.0f);
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ Texture2D nmap : register(t2);
SamplerState splr;
float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent, float3 bitan : Bitangent, float2 tc : Texcoord) : SV_Target
float4 main(float3 viewPos : Position, float3 n : Normal, float3 tan : Tangent, float3 bitan : Bitangent, float2 tc : Texcoord) : SV_Target
{
// sample normal from map if normal mapping enabled
if( normalMapEnabled )
......@@ -43,7 +43,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent,
n = mul(n, tanToView);
}
// fragment to light vector data
const float3 vToL = lightPos - worldPos;
const float3 vToL = lightPos - viewPos;
const float distToL = length(vToL);
const float3 dirToL = vToL / distToL;
// attenuation
......@@ -54,7 +54,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent,
const float3 w = n * dot(vToL, n);
const float3 r = w * 2.0f - vToL;
// calculate specular intensity based on angle between viewing vector and reflection vector, narrow with power function
const float3 specular = att * (diffuseColor * diffuseIntensity) * specularIntensity * pow(max(0.0f, dot(normalize(-r), normalize(worldPos))), specularPower);
const float3 specular = att * (diffuseColor * diffuseIntensity) * specularIntensity * pow(max(0.0f, dot(normalize(-r), normalize(viewPos))), specularPower);
// final color
return float4(saturate((diffuse + ambient) * tex.Sample(splr, tc).rgb + specular), 1.0f);
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ Texture2D nmap;
SamplerState splr;
float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent, float3 bitan : Bitangent, float2 tc : Texcoord) : SV_Target
float4 main(float3 viewPos : Position, float3 n : Normal, float3 tan : Tangent, float3 bitan : Bitangent, float2 tc : Texcoord) : SV_Target
{
// sample normal from map if normal mapping enabled
if (normalMapEnabled)
......@@ -42,7 +42,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent,
n = mul(n, tanToView);
}
// fragment to light vector data
const float3 vToL = lightPos - worldPos;
const float3 vToL = lightPos - viewPos;
const float distToL = length(vToL);
const float3 dirToL = vToL / distToL;
// attenuation
......@@ -56,7 +56,7 @@ float4 main(float3 worldPos : Position, float3 n : Normal, float3 tan : Tangent,
const float4 specularSample = spec.Sample(splr, tc);
const float3 specularReflectionColor = specularSample.rgb;
const float specularPower = pow(2.0f, specularSample.a * 13.0f);
const float3 specular = att * (diffuseColor * diffuseIntensity) * pow(max(0.0f, dot(normalize(-r), normalize(worldPos))), specularPower);
const float3 specular = att * (diffuseColor * diffuseIntensity) * pow(max(0.0f, dot(normalize(-r), normalize(viewPos))), specularPower);
// final color
return float4(saturate((diffuse + ambient) * tex.Sample(splr, tc).rgb + specular * specularReflectionColor), 1.0f);
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ cbuffer CBuf
struct VSOut
{
float3 worldPos : Position;
float3 viewPos : Position;
float3 normal : Normal;
float2 tc : Texcoord;
float4 pos : SV_Position;
......@@ -15,7 +15,7 @@ struct VSOut
VSOut main(float3 pos : Position, float3 n : Normal, float2 tc : Texcoord)
{
VSOut vso;
vso.worldPos = (float3) mul(float4(pos, 1.0f), modelView);
vso.viewPos = (float3) mul(float4(pos, 1.0f), modelView);
vso.normal = mul(n, (float3x3) modelView);
vso.pos = mul(float4(pos, 1.0f), modelViewProj);
vso.tc = tc;
......
......@@ -6,7 +6,7 @@ cbuffer CBuf
struct VSOut
{
float3 worldPos : Position;
float3 viewPos : Position;
float3 normal : Normal;
float3 tan : Tangent;
float3 bitan : Bitangent;
......@@ -17,7 +17,7 @@ struct VSOut
VSOut main(float3 pos : Position, float3 n : Normal, float3 tan : Tangent, float3 bitan : Bitangent, float2 tc : Texcoord)
{
VSOut vso;
vso.worldPos = (float3) mul(float4(pos, 1.0f), modelView);
vso.viewPos = (float3) mul(float4(pos, 1.0f), modelView);
vso.normal = mul(n, (float3x3) modelView);
vso.tan = mul(tan, (float3x3) modelView);
vso.bitan = mul(bitan, (float3x3) modelView);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment