From c963a3064b703d79ecd66af554916b338a9f5f61 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 16 May 2021 23:46:43 +0200 Subject: [PATCH] Add missing resources and update .gitignore --- .gitignore | 2 + bin/resources/deferred_frag.nzsl | 73 +++++++++++++++++++++++++++ bin/resources/deferred_vert.nzsl | 62 +++++++++++++++++++++++ bin/resources/fullscreen.frag.shader | Bin 0 -> 382 bytes bin/resources/fullscreen.vert.shader | Bin 0 -> 474 bytes bin/resources/lighting.nzsl | 35 +++++++++++++ 6 files changed, 172 insertions(+) create mode 100644 bin/resources/deferred_frag.nzsl create mode 100644 bin/resources/deferred_vert.nzsl create mode 100644 bin/resources/fullscreen.frag.shader create mode 100644 bin/resources/fullscreen.vert.shader create mode 100644 bin/resources/lighting.nzsl diff --git a/.gitignore b/.gitignore index 387acfa4c..cc3e70c52 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # xmake-related files .xmake/* +.vs/* .vscode/* CMakeLists.txt Makefile @@ -8,6 +9,7 @@ vsxmake*/* # Nazara binaries bin/* +!bin/resources/* # Build files build/* diff --git a/bin/resources/deferred_frag.nzsl b/bin/resources/deferred_frag.nzsl new file mode 100644 index 000000000..c1ae6959e --- /dev/null +++ b/bin/resources/deferred_frag.nzsl @@ -0,0 +1,73 @@ +option HAS_DIFFUSE_TEXTURE: bool; +option HAS_ALPHA_TEXTURE: bool; +option ALPHA_TEST: bool; + +[layout(std140)] +struct BasicSettings +{ + AlphaThreshold: f32, + DiffuseColor: vec4 +} + +[layout(std140)] +struct InstanceData +{ + worldMatrix: mat4, + invWorldMatrix: mat4 +} + +[layout(std140)] +struct ViewerData +{ + projectionMatrix: mat4, + invProjectionMatrix: mat4, + viewMatrix: mat4, + invViewMatrix: mat4, + viewProjMatrix: mat4, + invViewProjMatrix: mat4, + renderTargetSize: vec2, + invRenderTargetSize: vec2, + eyePosition: vec3 +} + +external +{ + [binding(5)] viewerData: uniform, + [binding(4)] instanceData: uniform, + [binding(3)] settings: uniform, + [binding(0)] MaterialAlphaMap: sampler2D, + [binding(1)] MaterialDiffuseMap: sampler2D, + [binding(2)] TextureOverlay: sampler2D +} + +struct InputData +{ + [location(0)] vertNormal: vec3, + [location(1)] vertUV: vec2, + [location(2)] vertPos: vec3 +} + +struct OutputData +{ + [location(0)] diffuseMap: vec4, + [location(1)] normalMap: vec4, + [location(2)] positionMap: vec4 +} + +[entry(frag)] +fn main(input: InputData) -> OutputData +{ + let output: OutputData; + + let textureColor = select_opt(HAS_DIFFUSE_TEXTURE, MaterialDiffuseMap.Sample(input.vertUV) * settings.DiffuseColor, settings.DiffuseColor); + let alpha = select_opt(HAS_ALPHA_TEXTURE, MaterialAlphaMap.Sample(input.vertUV).x * textureColor.w, 1.0); + /*if ((select_opt(ALPHA_TEST, var0.w < settings.AlphaThreshold, false)) == (true)) + { + discard; + }*/ + + output.diffuseMap = textureColor; + output.normalMap = vec4((vec3(1.0, 1.0, 1.0) + input.vertNormal) * 0.5, 1.0); + output.positionMap = vec4(input.vertPos, 1.0); + return output; +} diff --git a/bin/resources/deferred_vert.nzsl b/bin/resources/deferred_vert.nzsl new file mode 100644 index 000000000..b4ac86099 --- /dev/null +++ b/bin/resources/deferred_vert.nzsl @@ -0,0 +1,62 @@ +[layout(std140)] +struct BasicSettings +{ + AlphaThreshold: f32, + DiffuseColor: vec4 +} + +[layout(std140)] +struct InstanceData +{ + worldMatrix: mat4, + invWorldMatrix: mat4 +} + +[layout(std140)] +struct ViewerData +{ + projectionMatrix: mat4, + invProjectionMatrix: mat4, + viewMatrix: mat4, + invViewMatrix: mat4, + viewProjMatrix: mat4, + invViewProjMatrix: mat4, + renderTargetSize: vec2, + invRenderTargetSize: vec2, + eyePosition: vec3 +} + +external +{ + [binding(5)] viewerData: uniform, + [binding(4)] instanceData: uniform, + [binding(3)] settings: uniform +} + +struct InputData +{ + [location(0)] inPos: vec3, + [location(1)] inNormals: vec3, + [location(2)] inTexCoord: vec2 +} + +struct OutputData +{ + [location(0)] vertNormal: vec3, + [location(1)] vertUV: vec2, + [location(2)] vertPos: vec3, + [builtin(position)] position: vec4 +} + +[entry(vert)] +fn main(input: InputData) -> OutputData +{ + let worldPos = instanceData.worldMatrix * vec4(input.inPos, 1.0); + + let output: OutputData; + output.vertUV = input.inTexCoord; + output.vertNormal = input.inNormals; + output.vertPos = worldPos.xyz; + output.position = viewerData.projectionMatrix * viewerData.viewMatrix * instanceData.worldMatrix * vec4(input.inPos, 1.0); + return output; +} diff --git a/bin/resources/fullscreen.frag.shader b/bin/resources/fullscreen.frag.shader new file mode 100644 index 0000000000000000000000000000000000000000..8124d2919ddf4550cb8ec57163fd3b38d81e5269 GIT binary patch literal 382 zcmZ8d%L>9U5KMivDyS%mzu`xC(2GK?-U9~d!6;!P{=Lq`1llf4*qxo-9dbPHOQlo> ztbqYA0|HT0<|E!2l09-%F&2Er2mA7})1q0imA{RX%e6onPWBC~KMOgIEG8e}>zgJzoTxD$DrE8c0BL{mX|!E literal 0 HcmV?d00001 diff --git a/bin/resources/fullscreen.vert.shader b/bin/resources/fullscreen.vert.shader new file mode 100644 index 0000000000000000000000000000000000000000..38298e2377a65d48508c428ac833e1dd5854c7b2 GIT binary patch literal 474 zcmah_yAFat5L^^dX^ckW=U8Z=jT&D)i4<3ON8m7){<+Q^Cjl*-WXL||W|!R_*9Q>^ zz!}&D$Dj;1IxFoeu?e#d*i(9MiasKW0+xta=~Mbx8k1kyW7+lS=$ztRX}_$Zdz#zx zrKN{l2AL_8RYtQDf&pC|M)-!eL}?CaSW-}nT!cL_j#6k6rh{JkMBn0znJ_4$%qalb`SUg2Ih(P{-m_HP>#E*O9_Gr(&#P9nCO?XYE literal 0 HcmV?d00001 diff --git a/bin/resources/lighting.nzsl b/bin/resources/lighting.nzsl new file mode 100644 index 000000000..5516c6213 --- /dev/null +++ b/bin/resources/lighting.nzsl @@ -0,0 +1,35 @@ +[layout(std140)] +struct PointLight +{ + color: vec3, + position: vec3, + + constant: f32, + linear: f32, + quadratic: f32, +} + +external +{ + [binding(0)] colorTexture: sampler2D, + [binding(1)] normalTexture: sampler2D, + [binding(2)] positionTexture: sampler2D, + [binding(3)] lightParameters: uniform +} + +[entry(frag)] +fn main(input: VertOut) -> FragOut +{ + let normal = normalTexture.Sample(input.uv).xyz * 2.0 - vec3(1.0, 1.0, 1.0); + let position = positionTexture.Sample(input.uv).xyz; + + let distance = length(lightParameters.position - position); + let lightDir = (lightParameters.position - position) / distance; + let lightFactor = dot(normal, lightDir); + let attenuation = 1.0 / (lightParameters.constant + lightParameters.linear * distance + lightParameters.quadratic * (distance * distance)); + + let output: FragOut; + output.color = vec4(lightParameters.color, 1.0) * lightFactor * attenuation * colorTexture.Sample(input.uv); + + return output; +} \ No newline at end of file