Oh yes, quote Argh, banned for constantly making bullshit claims about subjects beyond his understanding, making yet another bullshit claim.
Code: Select all
-- liberally c/p'ed from MapRenderer.lua.deprecated
--
local function SetShaderUniformLocations(s)
MapShaderLocs.cameraMatrixLoc = glGetUniformLocation(MapShader, "cameraMatrix")
MapShaderLocs.cameraInvMatrixLoc = glGetUniformLocation(MapShader, "cameraInvMatrix")
MapShaderLocs.shadowMatrixLoc = glGetUniformLocation(MapShader, "shadowMatrix")
--MapShaderLocs.haveShadowsLoc = glGetUniformLocation(MapShader, "haveShadows")
MapShaderLocs.shadowParamsLoc = glGetUniformLocation(MapShader, "shadowParams")
--MapShaderLocs.shadowDensityLoc = glGetUniformLocation(MapShader, "shadowDensity")
MapShaderLocs.treeMoveLoc = glGetUniformLocation(MapShader, "treeMove")
MapShaderLocs.shaderTime = glGetUniformLocation(MapShader, "shaderTime")
end
local function CreateMapShader()
local MapShader = glCreateShader({
vertex = [[
varying vec3 lvES;
varying vec3 hvES;
varying vec3 nvES;
varying mat3 tbnInvMatrix;
varying vec3 cdES;
uniform mat4 shadowMatrix;
uniform vec4 shadowParams;
uniform mat4 cameraMatrix;
uniform mat4 cameraInvMatrix;
void main(void) {
gl_TexCoord[0].st = gl_MultiTexCoord0.st;
gl_TexCoord[2].st = gl_MultiTexCoord0.st * 32.0;
vec4 vertexDis = gl_Vertex;
mat4 modelMatrix = cameraInvMatrix * gl_ModelViewMatrix;
gl_Position = gl_ProjectionMatrix * cameraMatrix * modelMatrix * vertexDis;
mat4 modelInvMatrix = gl_ModelViewMatrixInverse * cameraMatrix;
vec3 vpES = (gl_ModelViewMatrix * vertexDis).xyz;
vec3 cpES = vec3(0.0, 0.0, 1.0);
vec3 svOS = gl_MultiTexCoord5.xyz;
vec3 tvOS = gl_MultiTexCoord6.xyz;
mat3 tbnMatrix = mat3(svOS, tvOS, gl_Normal);
tbnInvMatrix[0].x = tbnMatrix[0].x;
tbnInvMatrix[0].y = tbnMatrix[1].x;
tbnInvMatrix[0].z = tbnMatrix[2].x;
tbnInvMatrix[1].x = tbnMatrix[0].y;
tbnInvMatrix[1].y = tbnMatrix[1].y;
tbnInvMatrix[1].z = tbnMatrix[2].y;
tbnInvMatrix[2].x = tbnMatrix[0].z;
tbnInvMatrix[2].y = tbnMatrix[1].z;
tbnInvMatrix[2].z = tbnMatrix[2].z;
cdES = (vpES - cpES);
nvES = normalize(gl_NormalMatrix * gl_Normal);
lvES = normalize(gl_LightSource[0].position.xyz);
hvES = normalize(gl_LightSource[0].halfVector.xyz);
vec4 worldPos = gl_ModelViewMatrix * gl_Vertex;
gl_TexCoord[3] = shadowMatrix * worldPos;
gl_TexCoord[3].st = gl_TexCoord[3].st * (inversesqrt( abs(gl_TexCoord[3].st) + shadowParams.z) + shadowParams.w) + shadowParams.xy;
}
]],
fragment = [[
varying vec3 lvES;
varying vec3 hvES;
varying vec3 nvES;
varying vec3 cdES;
uniform sampler2D splatTex1;
uniform sampler2D splatTex2;
uniform sampler2D diffuseTex01;
uniform sampler2D diffuseTex02;
uniform sampler2D diffuseTex03;
uniform sampler2D diffuseTex04;
uniform sampler2D diffuseTex05;
uniform sampler2D diffuseTex06;
uniform sampler2D normalTex01;
uniform sampler2D normalTex02;
uniform sampler2D normalTex03;
uniform sampler2D normalTex04;
uniform sampler2D normalTex05;
uniform sampler2D normalTex06;
uniform samplerCube reflectMap;
uniform sampler2DShadow shadowMap;
uniform vec3 unitAmbientLight;
uniform vec3 unitDiffuseLight;
varying mat3 tbnInvMatrix;
void main(void) {
vec2 tc = vec2(gl_TexCoord[0].s, gl_TexCoord[0].t);
vec2 dtc = vec2(gl_TexCoord[2].s, gl_TexCoord[2].t);
vec4 splatOne = texture2D(splatTex1, tc);
vec4 splatTwo = texture2D(splatTex2, tc);
vec4 Diffuse01 = texture2D(diffuseTex01, dtc);
vec4 Diffuse02 = texture2D(diffuseTex02, dtc);
vec4 Diffuse03 = texture2D(diffuseTex03, dtc);
vec4 Diffuse04 = texture2D(diffuseTex04, dtc);
vec4 Diffuse05 = texture2D(diffuseTex05, dtc);
vec4 Diffuse06 = texture2D(diffuseTex06, dtc);
vec4 Normal01 = texture2D(normalTex01, dtc);
vec4 Normal02 = texture2D(normalTex02, dtc);
vec4 Normal03 = texture2D(normalTex03, dtc);
vec4 Normal04 = texture2D(normalTex04, dtc);
vec4 Normal05 = texture2D(normalTex05, dtc);
vec4 Normal06 = texture2D(normalTex06, dtc);
vec4 basicColor;
vec4 extraColor;
basicColor = Diffuse01;//Set initial "layer" now
extraColor = Normal01;//Set initial "layer" now
basicColor = mix(basicColor, Diffuse02, splatOne.r);
basicColor = mix(basicColor, Diffuse03, splatOne.g);
basicColor = mix(basicColor, Diffuse04, splatOne.b);
basicColor = mix(basicColor, Diffuse05, splatTwo.r);
basicColor = mix(basicColor, Diffuse06, splatTwo.g);//Only using 5 channels, 3 extra... may be possible to fit in another diffuse / normal
extraColor = mix(extraColor, Normal02, splatOne.r);
extraColor = mix(extraColor, Normal03, splatOne.g);
extraColor = mix(extraColor, Normal04, splatOne.b);
extraColor = mix(extraColor, Normal05, splatTwo.r);
extraColor = mix(extraColor, Normal06, splatTwo.g);//Only using 5 channels, 3 extra... may be possible to fit in another diffuse / normal
mat3 tbnMatrix;
tbnMatrix[0].x = tbnInvMatrix[0].x;
tbnMatrix[0].y = tbnInvMatrix[1].x;
tbnMatrix[0].z = tbnInvMatrix[2].x;
tbnMatrix[1].x = tbnInvMatrix[0].y;
tbnMatrix[1].y = tbnInvMatrix[1].y;
tbnMatrix[1].z = tbnInvMatrix[2].y;
tbnMatrix[2].x = tbnInvMatrix[0].z;
tbnMatrix[2].y = tbnInvMatrix[1].z;
tbnMatrix[2].z = tbnInvMatrix[2].z;
vec3 nvTS = vec3((extraColor * 2.0) - 1.0);
float nvDOTlv = 0.0;
float nvDOThv = 0.0;
vec3 reDirES;
vec3 nv_OS = normalize(tbnMatrix * nvTS);
vec3 nv_ES = normalize(gl_NormalMatrix * nv_OS);
nvDOTlv = max(nvDOTlv, dot(nv_ES, lvES));
nvDOThv = max(nvDOThv, dot(nv_ES, hvES));
reDirES = reflect(normalize(cdES), nv_ES);
float shininess = extraColor.a * 4.0;
float specPow =
(nvDOTlv > 0.0 && nvDOThv > 0.0)?
max(0.0, pow(nvDOThv, shininess)):
0.0;
vec3 texCube = textureCube(reflectMap, reDirES).rgb;
vec3 specColor = texCube * specPow * extraColor.a;
vec3 reflColor = texCube;
vec3 diffColor = (unitDiffuseLight * nvDOTlv) + unitAmbientLight; //boost light values
reflColor = mix(diffColor, reflColor, extraColor.a);
reflColor += basicColor.a;
gl_FragColor.rgb = basicColor.rgb;
gl_FragColor.rgb = gl_FragColor.rgb * reflColor + specColor;
//if(haveShadows != 0) {
float shadow = shadow2DProj(shadowMap, gl_TexCoord[3]).r;
if (shadow == 0.0) {
gl_FragColor.rgb = gl_FragColor.rgb * unitAmbientLight;
}
//}
gl_FragColor.a = 1.0;
}
]],
uniformInt = {
splatTex1 = 0,
splatTex2 = 1,
diffuseTex01 = 2,
diffuseTex02 = 3,
diffuseTex03 = 4,
diffuseTex04 = 5,
diffuseTex05 = 6,
diffuseTex06 = 7,
normalTex01 = 8,
normalTex02 = 9,
normalTex03 = 10,
normalTex04 = 11,
normalTex05 = 12,
normalTex06 = 13,
shadowMap = 14,
reflectMap = 15,
},
uniform = {
unitAmbientLight = {glGetSun("ambient", "unit")},
unitDiffuseLight = {glGetSun("diffuse", "unit")},
shadowParams = {gl.GetShadowMapParams()},
},
uniformMatrix = {shadowMatrix = {glGetMatrixData("shadow")},}
})
return MapShader
end
function gadget:Initialize()
...
Spring.SetDrawGround(false)
MapShader = CreateMapShader()
...
end
local function GetUnitDefMaterial(unitDefID, preDL, pstDL)
...
textureNames[unitDefID] = {
[1] = "maptiles/blend1.bmp",
[2] = "maptiles/blend2.bmp",
[3] = "maptiles/base.dds",
[4] = "maptiles/tex1.dds",
[5] = "maptiles/tex2.dds",
[6] = "maptiles/tex3.dds",
[7] = "maptiles/tex4.dds",
[8] = "maptiles/tex5.dds",
[9] = "maptiles/basebump.dds",
[10] = "maptiles/tex1bump.dds",
[11] = "maptiles/tex2bump.dds",
[12] = "maptiles/tex3bump.dds",
[13] = "maptiles/tex4bump.dds",
[14] = "maptiles/tex5bump.dds",
}
local matTbl = {
texunits = {
[0] = {tex = textureNames[unitDefID][1], enable = true},
[1] = {tex = textureNames[unitDefID][2], enable = true},
[2] = {tex = textureNames[unitDefID][3], enable = true},
[3] = {tex = textureNames[unitDefID][4], enable = true},
[4] = {tex = textureNames[unitDefID][5], enable = true},
[5] = {tex = textureNames[unitDefID][6], enable = true},
[6] = {tex = textureNames[unitDefID][7], enable = true},
[7] = {tex = textureNames[unitDefID][8], enable = true},
[8] = {tex = textureNames[unitDefID][9], enable = true},
[9] = {tex = textureNames[unitDefID][10], enable = true},
[10] = {tex = textureNames[unitDefID][11], enable = true},
[11] = {tex = textureNames[unitDefID][12], enable = true},
[12] = {tex = textureNames[unitDefID][13], enable = true},
[13] = {tex = textureNames[unitDefID][14], enable = true},
[14] = {tex = '$shadow', enable = true},
[15] = {tex = '$reflection', enable = false},
},
},
shader = MapShader,
prelist = preDL,
postlist = pstDL,
...
end
local function GetPreDisplayList()
...
-- see maps/{FireAndIce.sdd,SmokeCity.sdd}/unittextures/
gl.Texture(1,"maptiles/blend1.bmp")
gl.Texture(2,"maptiles/blend2.bmp")
gl.Texture(3,"maptiles/base.dds")
gl.Texture(4,"maptiles/tex1.dds")
gl.Texture(5,"maptiles/tex2.dds")
gl.Texture(6,"maptiles/tex3.dds")
gl.Texture(7,"maptiles/tex4.dds")
gl.Texture(8,"maptiles/tex5.dds")
gl.Texture(9,"maptiles/basebump.dds")
gl.Texture(10,"maptiles/tex1bump.dds")
gl.Texture(11,"maptiles/tex2bump.dds")
gl.Texture(12,"maptiles/tex3bump.dds")
gl.Texture(13,"maptiles/tex4bump.dds")
gl.Texture(14,"maptiles/tex5bump.dds")
gl.Texture(15,"$shadow")
gl.Texture(16,"$reflection")
...
end
local function MapUnit(unitID)
...
local preDL = GetPreDisplayList(unitID)
local pstDL = GetPostDisplayList(unitID)
SUR.SetMaterial(unitID, 1, "opaque", GetUnitDefMaterial(unitDefID, preDL, pstDL))
...
end
function gadget:RecvFromSynced(fun, unitID)
if (fun == "MapUnit") then
-- see mods/WORLD_BUILDER_CONTENT/Units/grid_test.fbi and maps/{FireAndIce.sdd,SmokeCity.sdd}/objects3d/0000001_grid_test.s3o
MapUnit(unitID)
end
end
So it uses the UNIT-rendering API to draw some special (map-geometry) units with a custom shader material that does nothing but trivially combine textures (through a splatting scheme not unlike SSMF's), and this is supposed to be a viable replacement for either SMF or SM3. Sure, whatever floats your boat.