Added follow cam

Added "Controlled" mesh classes
Added Global Lighting Class
Added Gamepad controls
Split terrain nodes into Height and Perlin classes
Fixed Splitmesh node stuff
This commit is contained in:
iDunnoDev
2022-05-09 17:50:22 +01:00
committed by iDunnoDev
parent bc906064e5
commit f6bba67897
58 changed files with 1743 additions and 351 deletions

View File

@ -11,16 +11,19 @@ cbuffer ConstantBuffer
float shininess; // The shininess factor
float opacity; // The opacity (transparency) of the material. 0 = fully transparent, 1 = fully opaque
// Vars to deal with the water, also padding because the cbuffer needs to be a multiple of 16
float waterHeight;
float waterShininess;
float4 waterColor;
// Padded with a float array, floats being 4 bytes each, the above just hits the multiple of 16 but added extra incase this was the issue, will remove later most likely
float padding[4];
}
Texture2D BlendMap : register(t0);
Texture2DArray TexturesArray : register(t1);
Texture2D WaterNormalMap : register(t2);
Texture2D rngNoiseMap : register(t3);
Texture2D snowTest : register(t3);
SamplerState ss
{
@ -42,6 +45,7 @@ struct PixelShaderInput
{
float4 Position : SV_POSITION;
float4 PositionWS: TEXCOORD2;
float4 PositionOG: TEXCOORD4;
float4 NormalWS : TEXCOORD3;
float2 TexCoord : TEXCOORD0;
float2 BlendMapTexCoord : TEXCOORD1;
@ -63,14 +67,17 @@ PixelShaderInput VShader(VertexShaderInput vin)
{
PixelShaderInput output;
float3 position = vin.Position;
output.PositionOG = output.PositionWS = mul(worldTransformation, float4(position, 1.0f));
output.TexCoord = vin.TexCoord;
// Check if the y pos is lower than the water point, and set the position to it minus a tiny offset because the textures were clipping and causing a weird effect
if (position.y < waterHeight)
{
position.y = waterHeight - 0.01f;
position.y = waterHeight;
}
output.Position = mul(completeTransformation, float4(position, 1.0f));
output.PositionWS = mul(worldTransformation, float4(position, 1.0f));
output.NormalWS = float4(mul((float3x3)worldTransformation, vin.Normal), 1.0f);
output.TexCoord = vin.TexCoord;
output.BlendMapTexCoord = vin.BlendMapTexCoord;
return output;
}
@ -87,11 +94,15 @@ float4 PShader(PixelShaderInput input) : SV_TARGET
float4 directionToLight = normalize(-lightVector);
float surfaceShininess = shininess;
float4 adjustedNormal = normalize(input.NormalWS);
if (input.PositionWS.y < waterHeight)
float currentHeightPer = (waterHeight - input.PositionOG.y) / waterHeight;
if (input.PositionOG.y < waterHeight)
{
float3 n0 = (float3)WaterNormalMap.Sample(ss, input.TexCoord);
// Sample the normal from the water normal map and calculate it with the worldtransform
float3 n0 = 2.0f * (float3)WaterNormalMap.Sample(ss, input.TexCoord) - 1.0f;
float4 n2 = float4(mul((float3x3)worldTransformation, n0), 1.0f);
adjustedNormal = n2;
adjustedNormal = normalize(n2);
surfaceShininess = waterShininess;
}
@ -110,11 +121,11 @@ float4 PShader(PixelShaderInput input) : SV_TARGET
float4 ambientLight = ambientColor * diffuseCoefficient;
float4 color;
float4 randSamp = rngNoiseMap.Sample(ss, input.BlendMapTexCoord);
// Randomly rotate the UV coordinates using the noise map
float2 scaleCenter = float2(0.5f, 0.5f);
float currentScale = randSamp.r;
float2 scaledUV = frac(UVRotate(input.TexCoord, scaleCenter, currentScale)); // (input.TexCoord - scaleCenter) * currentScale + scaleCenter;
// The noise map is greyscale so we only need to check 1 channel since they should all be the same value
float2 scaledUV = frac(UVRotate(input.TexCoord, scaleCenter, input.BlendMapTexCoord.x)); // (input.TexCoord - scaleCenter) * currentScale + scaleCenter;
float2 xChange = ddx(scaledUV);
float2 yChange = ddy(scaledUV);
@ -133,7 +144,8 @@ float4 PShader(PixelShaderInput input) : SV_TARGET
float4 c1 = TexturesArray.SampleGrad(ss, float3(scaledUV, 1.0f), xChange, yChange);
float4 c2 = TexturesArray.SampleGrad(ss, float3(scaledUV, 2.0f), xChange, yChange);
float4 c3 = TexturesArray.SampleGrad(ss, float3(scaledUV, 3.0f), xChange, yChange);
float4 c4 = TexturesArray.SampleGrad(ss, float3(scaledUV, 4.0f), xChange, yChange);
//float4 c4 = TexturesArray.SampleGrad(ss, float3(scaledUV, 4.0f), xChange, yChange);
float4 c4 = snowTest.SampleGrad(ss, float2(scaledUV), xChange, yChange);
// Sample the blend map.
float4 t = BlendMap.Sample(ss, input.BlendMapTexCoord);
@ -146,9 +158,10 @@ float4 PShader(PixelShaderInput input) : SV_TARGET
color = lerp(color, c4, t.a);
// Combine all components
if (input.PositionWS.y < waterHeight)
if (input.PositionOG.y < waterHeight)
{
color = color * waterColor;
// Tint the water
color = saturate(color) * waterColor;
}
color = (ambientLight + diffuse) * color;
color = saturate(color + specular);