1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-22 06:05:38 +01:00

Specular working

This commit is contained in:
Nick Blakely 2020-11-02 22:15:00 -08:00
parent fad39babcb
commit d0dbb056c5

View File

@ -48,13 +48,12 @@ bool bFogRange : register(b4) = true;
int iTexType = TEX_TYPE_NONE; int iTexType = TEX_TYPE_NONE;
int iTexGenType = TEXGEN_TYPE_NONE; int iTexGenType = TEXGEN_TYPE_NONE;
int g_NumLights;
float4 DirectionalLightAmbient[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightAmbient; float4 DirectionalLightAmbient[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightAmbient;
float4 DirectionalLightDiffuse[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightDiffuse; float4 DirectionalLightDiffuse[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightDiffuse;
float3 DirectionalLightDirection[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightDirection; float3 DirectionalLightDirection[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightDirection;
bool DirectionalLightEnabled[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightEnabled; bool DirectionalLightEnabled[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightEnabled;
float4 DirectionalLightSpecular[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightSpecular; float4 DirectionalLightSpecular[MAX_DIRECTIONAL_LIGHTS] : DirectionalLightSpecular;
float3 g_CameraPosition : CameraPosition;
struct Material struct Material
{ {
@ -71,6 +70,7 @@ Material g_Material : Material;
float4x4 matWorldViewProjection : WorldViewProjection; float4x4 matWorldViewProjection : WorldViewProjection;
float4x4 matWorldView : WorldView; float4x4 matWorldView : WorldView;
float4x4 matWorld : World; float4x4 matWorld : World;
float4x4 matView : View;
//function output structures //function output structures
struct VS_OUTPUT struct VS_OUTPUT
@ -99,31 +99,33 @@ float4 CalculateAmbientLight()
} }
} }
return g_Material.Ambient * ambient; return ambient;
} }
COLOR_PAIR DoDirectionalLight(float3 N, int i) COLOR_PAIR DoDirectionalLight(float3 worldPos, float3 N, int i)
{ {
COLOR_PAIR Out; COLOR_PAIR Out = (COLOR_PAIR)0;
float NdotL = dot(N, -DirectionalLightDirection[i]); float NdotL = dot(N, -DirectionalLightDirection[i]);
Out.Color = 0; // g_Material.Ambient* DirectionalLights[i].Ambient;
Out.ColorSpec = 0;
if (NdotL > 0.f) if (NdotL > 0.f)
{ {
//compute diffuse color //compute diffuse color
Out.Color += max(0, NdotL * DirectionalLightDiffuse[i]); //+ (g_Material.Ambient * DirectionalLightAmbient[i]); Out.Color += max(0, NdotL * DirectionalLightDiffuse[i]);
//add specular component if (g_Material.Power > 0)
//if(g_Material.Power > 0) {
//{ float3 toEye = g_CameraPosition.xyz - worldPos;
// float3 H = normalize(L + V); //half vector toEye = normalize(toEye);
// Out.ColorSpec = pow(max(0, dot(H, N)), g_Material.Power) * DirectionalLights[i].Specular; float3 halfway = normalize(toEye + -DirectionalLightDirection[i]);
//} float NDotH = saturate(dot(halfway, N));
float4 spec = DirectionalLightSpecular[i];
Out.ColorSpec += spec * pow(NDotH, g_Material.Power);
}
} }
return Out; return Out;
} }
COLOR_PAIR ComputeLighting(float3 N) COLOR_PAIR ComputeLighting(float3 worldPos, float3 N)
{ {
COLOR_PAIR finalResult = (COLOR_PAIR)0; COLOR_PAIR finalResult = (COLOR_PAIR)0;
@ -132,7 +134,7 @@ COLOR_PAIR ComputeLighting(float3 N)
COLOR_PAIR lightResult = (COLOR_PAIR)0; COLOR_PAIR lightResult = (COLOR_PAIR)0;
if (DirectionalLightEnabled[i]) if (DirectionalLightEnabled[i])
{ {
lightResult = DoDirectionalLight(N, i); lightResult = DoDirectionalLight(worldPos, N, i);
} }
finalResult.Color += lightResult.Color; finalResult.Color += lightResult.Color;
@ -201,8 +203,6 @@ VS_OUTPUT vs_main (float4 vPosition : POSITION0,
vNormal = normalize(vNormal); vNormal = normalize(vNormal);
Out.Pos = mul(vPosition, matWorldViewProjection); Out.Pos = mul(vPosition, matWorldViewProjection);
//float3 V = -normalize(P); //viewer
//automatic texture coordinate generation //automatic texture coordinate generation
Out.Tex0.xy = tc; Out.Tex0.xy = tc;
/*Out.Tex0 = float4((2.f * dot(V,N) * N - V) * (iTexGenType == TEXGEN_TYPE_CAMERASPACEREFLECTIONVECTOR) /*Out.Tex0 = float4((2.f * dot(V,N) * N - V) * (iTexGenType == TEXGEN_TYPE_CAMERASPACEREFLECTIONVECTOR)
@ -213,8 +213,9 @@ VS_OUTPUT vs_main (float4 vPosition : POSITION0,
//light computation //light computation
//directional lights //directional lights
float4 worldPos = mul(vPosition, matWorld); //position in view space
float3 N = mul(vNormal, (float3x3)matWorld); float3 N = mul(vNormal, (float3x3)matWorld);
COLOR_PAIR lighting = ComputeLighting(N); COLOR_PAIR lighting = ComputeLighting(worldPos, N);
////point lights ////point lights
//for(int i = 0; i < iLightPointNum; i++) //for(int i = 0; i < iLightPointNum; i++)
@ -229,7 +230,7 @@ VS_OUTPUT vs_main (float4 vPosition : POSITION0,
Out.ColorSpec = lighting.ColorSpec; Out.ColorSpec = lighting.ColorSpec;
//apply fog //apply fog
float3 P = mul(matWorldView, vPosition); //position in view space float4 P = mul(matWorldView, vPosition); //position in view space
float d; float d;
if(bFogRange) if(bFogRange)
d = length(P); d = length(P);
@ -251,9 +252,6 @@ technique basic_with_shader
{ {
pass P0 pass P0
{ {
SPECULARENABLE = (g_Material.Power > 0);
FOGENABLE = (iFogType != FOG_TYPE_NONE);
FOGCOLOR = (vFogColor);
VertexShader = compile vs_2_0 vs_main(); VertexShader = compile vs_2_0 vs_main();
} }
} }