diff --git a/extern/shiny b/extern/shiny index 8af2cce2db..ccaaefa59c 160000 --- a/extern/shiny +++ b/extern/shiny @@ -1 +1 @@ -Subproject commit 8af2cce2db40aa67edcba78c534a268e595696c8 +Subproject commit ccaaefa59c0500cf790a1f3114c8b5593489afeb diff --git a/files/materials/objects.shader b/files/materials/objects.shader index 3697e33e5a..6dd05442ce 100644 --- a/files/materials/objects.shader +++ b/files/materials/objects.shader @@ -9,6 +9,8 @@ #define NEED_DEPTH #endif +#define NUM_LIGHTS 8 + #define HAS_VERTEXCOLOR @shPropertyBool(has_vertex_colour) #ifdef SH_VERTEX_SHADER @@ -18,10 +20,15 @@ shInput(float2, uv0) shOutput(float2, UV) shNormalInput(float4) - shOutput(float4, normalPassthrough) #ifdef NEED_DEPTH shOutput(float, depthPassthrough) #endif + +#if LIGHTING + shOutput(float3, normalPassthrough) + shOutput(float3, objSpacePositionPassthrough) +#endif + #if HAS_VERTEXCOLOR shColourInput(float4) shOutput(float4, colorPassthrough) @@ -30,11 +37,15 @@ { shOutputPosition = shMatrixMult(wvp, shInputPosition); UV = uv0; - normalPassthrough = normal; + normalPassthrough = normal.xyz; #ifdef NEED_DEPTH depthPassthrough = shOutputPosition.z; #endif +#if LIGHTING + objSpacePositionPassthrough = shInputPosition.xyz; +#endif + #if HAS_VERTEXCOLOR colorPassthrough = colour; #endif @@ -48,13 +59,27 @@ #if MRT shDeclareMrtOutput(1) #endif - shInput(float4, normalPassthrough) #ifdef NEED_DEPTH shInput(float, depthPassthrough) #endif - + shUniform(float far) @shAutoConstant(far, far_clip_distance) + +#if LIGHTING + shInput(float3, normalPassthrough) + shInput(float3, objSpacePositionPassthrough) + shUniform(float4 lightAmbient) @shAutoConstant(lightAmbient, ambient_light_colour) + shUniform(float passIteration) @shAutoConstant(passIteration, pass_iteration_number) + shUniform(float4 materialAmbient) @shAutoConstant(materialAmbient, surface_ambient_colour) + shUniform(float4 materialDiffuse) @shAutoConstant(materialDiffuse, surface_diffuse_colour) + shUniform(float4 materialEmissive) @shAutoConstant(materialEmissive, surface_emissive_colour) + @shForeach(NUM_LIGHTS) + shUniform(float4 lightPosObjSpace@shIterator) @shAutoConstant(lightPosObjSpace@shIterator, light_position_object_space, @shIterator) + shUniform(float4 lightAttenuation@shIterator) @shAutoConstant(lightAttenuation@shIterator, light_attenuation, @shIterator) + shUniform(float4 lightDiffuse@shIterator) @shAutoConstant(lightDiffuse@shIterator, light_diffuse_colour, @shIterator) + @shEndForeach +#endif #if FOG shUniform(float3 fogColor) @shAutoConstant(fogColor, fog_colour) @@ -66,9 +91,29 @@ #endif SH_START_PROGRAM { - //shOutputColor(0) = float4((normalize(normalPassthrough.xyz)+float3(1.0,1.0,1.0)) / 2.f, 1.0); shOutputColor(0) = shSample(diffuseMap, UV); +#if LIGHTING + float3 normal = normalize(normalPassthrough); + float3 lightDir, diffuse; + float d; + float3 ambient = materialAmbient.xyz * lightAmbient.xyz; + + @shForeach(NUM_LIGHTS) + + lightDir = lightPosObjSpace@shIterator.xyz - (objSpacePositionPassthrough.xyz * lightPosObjSpace@shIterator.w); + d = length(lightDir); + + lightDir = normalize(lightDir); + + diffuse += materialDiffuse.xyz * lightDiffuse@shIterator.xyz * (1.0 / ((lightAttenuation@shIterator.y) + (lightAttenuation@shIterator.z * d) + (lightAttenuation@shIterator.w * d * d))) * max(dot(normal, lightDir), 0); + + @shEndForeach + + shOutputColor(0).xyz *= (ambient + diffuse + materialEmissive.xyz); +#endif + + #if HAS_VERTEXCOLOR shOutputColor(0).xyz *= colorPassthrough.xyz; #endif diff --git a/files/materials/openmw.configuration b/files/materials/openmw.configuration new file mode 100644 index 0000000000..6122cd8cb0 --- /dev/null +++ b/files/materials/openmw.configuration @@ -0,0 +1,15 @@ +configuration water_reflection +{ + fog false + receives_shadows false + mrt_output false +} + +configuration local_map +{ + fog false + receives_shadows false + simple_water true + mrt_output false + lighting false +}