From f8e3213996fc91583c6c1e935441709cdab43ec6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 4 Jul 2012 16:57:14 +0200 Subject: [PATCH] fog, mrt depth --- extern/shiny | 2 +- files/materials/core.h | 13 +++++++--- files/materials/objects.mat | 5 ++++ files/materials/objects.shader | 45 ++++++++++++++++++++++++++++++++-- 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/extern/shiny b/extern/shiny index 3928949316..8d95f53464 160000 --- a/extern/shiny +++ b/extern/shiny @@ -1 +1 @@ -Subproject commit 3928949316713d0c8aaf1ad564734d24ad773be9 +Subproject commit 8d95f53464a779c7da643228ace02ae28ec6a503 diff --git a/files/materials/core.h b/files/materials/core.h index 2f51925a0e..20127d3dec 100644 --- a/files/materials/core.h +++ b/files/materials/core.h @@ -14,6 +14,8 @@ #define shInput(type, name) , in type name : TEXCOORD@shCounter(1) #define shOutput(type, name) , out type name : TEXCOORD@shCounter(2) + #define shNormalInput(type) , in type normal : NORMAL + #ifdef SH_VERTEX_SHADER #define shOutputPosition oPosition @@ -32,7 +34,9 @@ #ifdef SH_FRAGMENT_SHADER - #define shOutputColor oColor + #define shOutputColor(num) oColor##num + + #define shDeclareMrtOutput(num) , out float4 oColor##num : COLOR##num #define SH_BEGIN_PROGRAM \ void main( \ @@ -67,13 +71,14 @@ #define shInputPosition vertex #define shOutputPosition gl_Position - #define shOutputColor oColor + #define shOutputColor(num) oColor##num #define float4x4 mat4 #define shInput(type, name) in type name; #define shOutput(type, name) out type name; + #define shNormalInput(type) in type normal; #ifdef SH_VERTEX_SHADER @@ -86,8 +91,10 @@ #ifdef SH_FRAGMENT_SHADER + #define shDeclareMrtOutput(num) out vec4 oColor##num; + #define SH_BEGIN_PROGRAM \ - out float4 oColor; + out float4 oColor0; #define SH_START_PROGRAM \ void main(void) diff --git a/files/materials/objects.mat b/files/materials/objects.mat index 564018724b..69b89a7e51 100644 --- a/files/materials/objects.mat +++ b/files/materials/objects.mat @@ -6,6 +6,8 @@ material openmw_objects_base emissive 0.0 0.0 0.0 has_vertex_colour false diffuseMap black.png + fog true + is_transparent false // real transparency, alpha rejection doesn't count here pass { @@ -16,9 +18,12 @@ material openmw_objects_base specular $specular ambient $ambient emissive $emissive + fog $fog ffp_vertex_colour_ambient $has_vertex_colour has_vertex_colour $has_vertex_colour + + is_transparent $is_transparent texture_unit diffuseMap { diff --git a/files/materials/objects.shader b/files/materials/objects.shader index 7bd91e526a..08e9913d98 100644 --- a/files/materials/objects.shader +++ b/files/materials/objects.shader @@ -1,15 +1,36 @@ #include "core.h" + +#define FOG @shPropertyBool(fog) +#define MRT @shPropertyNotBool(is_transparent) + +#if MRT +#define NEED_DEPTH +#endif + +#if FOG +#define NEED_DEPTH +#endif + #ifdef SH_VERTEX_SHADER SH_BEGIN_PROGRAM shUniform(float4x4 wvp) @shAutoConstant(wvp, worldviewproj_matrix) shInput(float2, uv0) shOutput(float2, UV) + shNormalInput(float4) + shOutput(float4, normalPassthrough) + #ifdef NEED_DEPTH + shOutput(float, depthPassthrough) + #endif SH_START_PROGRAM { shOutputPosition = shMatrixMult(wvp, shInputPosition); UV = uv0; + normalPassthrough = normal; + #ifdef NEED_DEPTH + depthPassthrough = shOutputPosition.z; + #endif } #else @@ -17,11 +38,31 @@ SH_BEGIN_PROGRAM shSampler2D(diffuseMap) shInput(float2, UV) + shDeclareMrtOutput(1) + shInput(float4, normalPassthrough) + #ifdef NEED_DEPTH + shInput(float, depthPassthrough) + #endif + + shUniform(float far) @shAutoConstant(far, far_clip_distance) + +#if FOG + shUniform(float3 fogColor) @shAutoConstant(fogColor, fog_colour) + shUniform(float4 fogParams) @shAutoConstant(fogParams, fog_params) + +#endif SH_START_PROGRAM { - // shOutputColor = float4(1.0, 0.0, 0.0, 1.0); - shOutputColor = shSample(diffuseMap, UV); + //shOutputColor(0) = float4((normalize(normalPassthrough.xyz)+float3(1.0,1.0,1.0)) / 2.f, 1.0); + shOutputColor(0) = shSample(diffuseMap, UV); + +#if FOG + float fogValue = shSaturate((depthPassthrough - fogParams.y) * fogParams.w); + shOutputColor(0).xyz = shLerp (shOutputColor(0).xyz, fogColor, fogValue); +#endif + + shOutputColor(1) = float4(depthPassthrough / far,1,1,1); } #endif