You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/files/materials/terrain.shader

128 lines
2.9 KiB
Plaintext

13 years ago
#include "core.h"
#define FOG @shGlobalSettingBool(fog)
13 years ago
#define MRT @shGlobalSettingBool(mrt_output)
13 years ago
#define COLOUR_MAP @shPropertyBool(colour_map)
13 years ago
#define NUM_LAYERS @shPropertyString(num_layers)
#define COMPONENT_0 x
#define COMPONENT_1 y
#define COMPONENT_2 z
#define COMPONENT_3 w
#define IS_FIRST_PASS 1
13 years ago
@shAllocatePassthrough(1, depth)
13 years ago
@shAllocatePassthrough(2, UV)
13 years ago
#ifdef SH_VERTEX_SHADER
SH_BEGIN_PROGRAM
shUniform(float4x4, worldMatrix) @shAutoConstant(worldMatrix, world_matrix)
shUniform(float4x4, viewProjMatrix) @shAutoConstant(viewProjMatrix, viewproj_matrix)
shInput(float2, uv0)
@shPassthroughVertexOutputs
SH_START_PROGRAM
{
float4 worldPos = shMatrixMult(worldMatrix, shInputPosition);
shOutputPosition = shMatrixMult(viewProjMatrix, worldPos);
@shPassthroughAssign(depth, shOutputPosition.z);
13 years ago
@shPassthroughAssign(UV, uv0);
13 years ago
}
#else
SH_BEGIN_PROGRAM
13 years ago
#if COLOUR_MAP
shSampler2D(colourMap)
#endif
13 years ago
shSampler2D(normalMap) // global normal map
@shForeach(@shPropertyString(num_blendmaps))
shSampler2D(blendMap@shIterator)
@shEndForeach
@shForeach(@shPropertyString(num_layers))
shSampler2D(diffuseMap@shIterator)
@shEndForeach
13 years ago
#if FOG
shUniform(float3, fogColor) @shAutoConstant(fogColor, fog_colour)
shUniform(float4, fogParams) @shAutoConstant(fogParams, fog_params)
#endif
13 years ago
@shPassthroughFragmentInputs
#if MRT
shDeclareMrtOutput(1)
13 years ago
shUniform(float, far) @shAutoConstant(far, far_clip_distance)
13 years ago
#endif
SH_START_PROGRAM
{
float depth = @shPassthroughReceive(depth);
13 years ago
float2 UV = @shPassthroughReceive(UV);
13 years ago
float3 normal = shSample(normalMap, UV).rgb * 2 - 1;
// fetch blendmaps
@shForeach(@shPropertyString(num_blendmaps))
float4 blendValues@shIterator = shSample(blendMap@shIterator, UV);
@shEndForeach
float3 albedo;
@shForeach(@shPropertyString(num_layers))
#if IS_FIRST_PASS == 1 && @shIterator == 0
// first layer of first pass doesn't need a blend map
13 years ago
albedo = shSample(diffuseMap0, UV * 10).rgb;
13 years ago
#else
13 years ago
#define BLEND_AMOUNT blendValues@shPropertyString(blendmap_index_@shIterator).@shPropertyString(blendmap_component_@shIterator)
13 years ago
13 years ago
albedo = shLerp(albedo, shSample(diffuseMap@shIterator, UV * 10).rgb, BLEND_AMOUNT);
13 years ago
#endif
@shEndForeach
shOutputColour(0) = float4(1,1,1,1);
13 years ago
#if COLOUR_MAP
shOutputColour(0).rgb *= shSample(colourMap, UV).rgb;
#endif
13 years ago
shOutputColour(0).rgb *= albedo;
13 years ago
#if FOG
float fogValue = shSaturate((depth - fogParams.y) * fogParams.w);
shOutputColour(0).xyz = shLerp (shOutputColour(0).xyz, fogColor, fogValue);
#endif
13 years ago
#if MRT
13 years ago
shOutputColour(1) = float4(depth / far,1,1,1);
13 years ago
#endif
}
#endif