...seems to be broken in the latest buildbot builds.
Creating point objects and assigning them a texture then rendering the resulting points via GLSL is borked- the points show up as quads, sans the texture.
Any idea what may have broken this? I can probably fix this by assigning the texture to a uniform, but I was just wondering what broke it in the first place.
Texture Binding in 0.8+
Moderator: Moderators
Texture Binding in 0.8+
Last edited by Argh on 20 Aug 2009, 01:02, edited 1 time in total.
Re: Point objects and Texture Binding
I've tested, and even when I use a uniform, it's still borked. Meh. Tested with 0.79.2, and the re-written GLSL works there, but not in current buildbot. Something definitely went awry here.
Re: Point objects and Texture Binding
The code:That original code was written by Trepan, I didn't do much but minor behavior changes.
Anybody with moderate GL-fu can see that this code is simple, the shader's not complicated, and there's nothing wrong with the blending.--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: precipitation.lua
-- brief: precipitation shader gadget
-- author: Dave Rodgers
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function gadget:GetInfo()
return {
name = "Precipitation01",
desc = "Precipitation shader gadget",
author = "trepan",
date = "May 22, 2007",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Unsynced side only
if (gadgetHandler:IsSyncedCode()) then
return false
end
-- Require shaders
if (gl.CreateShader == nil) then
return false
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local enabled = Spring.GetMapOptions("snowingeffect",true)
local shader
local shaderTimeLoc
local shaderCamPosLoc
local shaderNeedLocs = true
local snowList1
local particleList
local rainDensity = 100 * 1024
local rainScale = 3000
local rainSpeed = 100
local rainTexture = 'bitmaps/snowflake01.tga'
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function gadget:Initialize()
if (not ReloadResources()) then
gadgetHandler:RemoveGadget()
return
end
end
function gadget:Shutdown()
FreeResources()
end
function ReloadResources()
FreeResources()
if ((not CreateParticleList()) or
(not CreatesnowList1()) or
(not CreateShader())) then
gadgetHandler:RemoveGadget()
return false
end
return true
end
function FreeResources()
gl.DeleteList(snowList1)
gl.DeleteList(particleList)
if (gl.DeleteShader) then
gl.DeleteShader(shader)
end
shader = nil
snowList1 = nil
particleList = nil
end
function CreateParticleList()
particleList = gl.CreateList(function()
local tmpRand = math.random()
math.randomseed(1)
gl.BeginEnd(GL.POINTS, function()
for i = 1, rainDensity do
local x = math.random()
local y = math.random()
local z = math.random()
local w = math.random()
gl.Vertex(x, y, z, w)
end
end)
math.random(1e9 * tmpRand)
end)
if (particleList == nil) then
return false
end
return true
end
function CreatesnowList1()
snowList1 = gl.CreateList(function()
gl.Color(0, 0, 1, 1)
gl.PointSprite(true, true)
gl.PointSize(10.0)
gl.PointParameter(0, 0, .001, 0, 1e9, 1)
gl.DepthTest(true)
gl.Blending(GL.SRC_ALPHA, GL.ONE)
gl.Texture(rainTexture)
gl.CallList(particleList)
gl.Texture(false)
gl.Blending(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
gl.DepthTest(false)
gl.PointParameter(1, 0, 0, 0, 1e9, 1)
gl.PointSize(1.0)
gl.PointSprite(false, false)
end)
if (snowList1 == nil) then
return false
end
return true
end
function CreateShader()
shaderNeedLocs = true
shader = gl.CreateShader({
uniform = {
time = 0,
scale = rainScale,
speed = rainSpeed,
camPos = { 0, 0, 0 },
},
vertex = [[
uniform float time;
uniform float scale;
uniform float speed;
uniform vec3 camPos;
void main(void)
{
const vec3 scalePos = vec3(gl_Vertex) * scale;
gl_FrontColor = vec4(0.8,0.8,0.9,0.0 + 0.8 * cos(scalePos.y));
const vec3 eye = camPos;
vec3 pos = scalePos - mod(camPos, scale);
pos.y -= time * 0.5 * (speed * (2.0 + gl_Vertex.w));
pos.x += sin(time)*10;
pos.z += cos(time)*10;
pos = mod(pos, scale) - (scale * 0.5) + camPos;
if (pos.y < 0.0) {
gl_FrontColor *= 1.0 + 2.0 * (pos.y / scale);
pos.y = 0.0;
}
const vec4 eyePos = gl_ModelViewMatrix * vec4(pos, 1.0);
gl_PointSize = (1 + gl_Vertex.w) * 5000 / length(eyePos);
gl_Position = gl_ProjectionMatrix * eyePos;
}
]],
})
if (shader == nil) then
print(gl.GetShaderLog())
return false
end
return true
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local startTimer = Spring.GetTimer()
local diffTime = 0
function GetShaderLocations()
shaderTimeLoc = gl.GetUniformLocation(shader, 'time')
shaderCamPosLoc = gl.GetUniformLocation(shader, 'camPos')
end
function gadget:DrawWorld()
if (not enabled) then
return
end
diffTime = Spring.DiffTimers(Spring.GetTimer(), startTimer)
gl.UseShader(shader)
if (shaderNeedLocs) then
GetShaderLocations()
shaderNeedLocs = false
end
gl.Uniform(shaderTimeLoc, diffTime * 1)
gl.Uniform(shaderCamPosLoc, Spring.GetCameraPosition())
gl.CallList(snowList1)
gl.UseShader(0)
end
DrawWorldReflection = DrawWorld -- draw reflections too
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
I've also done a version with a uniform to store the texture and a fragment operation, and it doesn't work, either. The texture isn't being bound to the point object, pure and simple. It worked in 0.79.2, it doesn't now.
Please fix, it broke my weather FX code on every map that uses it.
Re: Point objects and Texture Binding
Yes, the snow gagdet is broken for me too on 0.80. Fog works fine.
Re: Point objects and Texture Binding
1. Points aren't broken
2. Engine isn't broken
3. the gadget uses gl.Texture in gl.CreateList w/o calling gl.Texture once before, this causes the texture to recreate each damn call! also the new used mipmap generation function doesn't compile in a DisplayList, so the final texture misses its mipmaps -> that's why don't see any texture at all
2. Engine isn't broken
3. the gadget uses gl.Texture in gl.CreateList w/o calling gl.Texture once before, this causes the texture to recreate each damn call! also the new used mipmap generation function doesn't compile in a DisplayList, so the final texture misses its mipmaps -> that's why don't see any texture at all
Re: Point objects and Texture Binding
Great... 0.8.1's even more borked than 0.8 was, graphically.
Texture binding to point objects works now... with an empty world.
However, texture binding gets broken and the entire rendering system borks when multitexturing is used (i.e., Materials and the whole UnitRendering system).
Here's a screenshot, click to enlarge:

Upon close inspection, it appears that every object (including many that should not even be touched by UnitRendering) has inherited the normalmap texture of the last Unit built (in this case, a Space Chicken) as the Tex1 and Tex2.
If you need a test environment to replicate the error, I suggest downloading this and comparing 0.79.2 with 0.8.1.
Texture binding to point objects works now... with an empty world.
However, texture binding gets broken and the entire rendering system borks when multitexturing is used (i.e., Materials and the whole UnitRendering system).
Here's a screenshot, click to enlarge:

Upon close inspection, it appears that every object (including many that should not even be touched by UnitRendering) has inherited the normalmap texture of the last Unit built (in this case, a Space Chicken) as the Tex1 and Tex2.
If you need a test environment to replicate the error, I suggest downloading this and comparing 0.79.2 with 0.8.1.
Re: Point objects and Texture Binding
At least that gives us a clue about why it's not working atm.also the new used mipmap generation function doesn't compile in a DisplayList, so the final texture misses its mipmaps -> that's why don't see any texture at all
Question: why are we ever letting Spring generate mipmaps?
Seriously! If the file format == DDS, there is no need, ever.
That covers the maps and S3O.
If the file format != DDS, then it's probably a texture where generating a mipmap is a bad idea in the first place. Like, say, the texture atlases, where it's never worked right and probably never will.
Re: Point objects and Texture Binding
not all of us use dds. Try again.
Re: Point objects and Texture Binding
If you want mipmaps and no loss of quality, use 8:8:8:8 DDS.
Same performance hit as PNG (which is to say, 2X to 4X larger texture RAM requirements vs. DXT3/5 and DXT1) plus better control over each mip, instead of letting end-users' cards mangle it.
There are no good reasons to use PNG or TGA.
That said... I'm not in favor of arbitrarily breaking other people's performance, and I can see the need to keep it as it is for now.
I just want this issue with texture binding fixed. It was working just fine as of about a week and a half ago.
Same performance hit as PNG (which is to say, 2X to 4X larger texture RAM requirements vs. DXT3/5 and DXT1) plus better control over each mip, instead of letting end-users' cards mangle it.
There are no good reasons to use PNG or TGA.
That said... I'm not in favor of arbitrarily breaking other people's performance, and I can see the need to keep it as it is for now.
I just want this issue with texture binding fixed. It was working just fine as of about a week and a half ago.
- Attachments
-
- comparision.7z
- (1.87 MiB) Downloaded 13 times
Last edited by Argh on 20 Aug 2009, 00:44, edited 1 time in total.
Re: Point objects and Texture Binding
yes there is. DDS is a pain in the ass to work with. I think the toolsets are piss poor and photoshop doesn't support it cleanly.
Re: Point objects and Texture Binding
What's giving you trouble, man? If it's just some settings stuff, I can probably help. Personally, I found the Photoshop plugin was a breeze, compared to GIMP or The Compressionator.
Here, this is my setup for the DDS Photoshop plugin. Sharpens, etc. Nothing fancy, it just plain works. I haven't arrived at a completely accurate solution for DXT5 for normalmaps yet, I think I need to weight the channels differently to avoid compression errors (although I must say that it's rarely apparent when they occur with these settings).
Here, this is my setup for the DDS Photoshop plugin. Sharpens, etc. Nothing fancy, it just plain works. I haven't arrived at a completely accurate solution for DXT5 for normalmaps yet, I think I need to weight the channels differently to avoid compression errors (although I must say that it's rarely apparent when they occur with these settings).
- Attachments
-
- Standard_DDS_Settings.7z
- (1.13 KiB) Downloaded 15 times
Re: Texture Binding in 0.8+
Testing on spring_0.80.1-15-g7a4d352.exe:
Spring seems to be fixed, the normalmap shader's working fine now! Yay!
Spring seems to be fixed, the normalmap shader's working fine now! Yay!