Background Hods

(Taiidan Republic Mod) #142

ah ok - I thought there were stars shining throught the rings, but I guess they are just pebbles between the background and the camera…

(Rufus Shinra) #143

Oh, no, they are definitely stars. They are part of the skybox (I don’t use the HWRM stars):

(Taiidan Republic Mod) #144

I see, everything is baked together. I’m making mine using separate objects and going to get stars shining through the transparent parts of the ring.

(Taiidan Republic Mod) #145

With the help of @radar3301 and @PayDay I have the rings working with transparency. This is the shader they gave me. I don’t pretend to understand this shader black magic, but it worked for me. Here ist is in case anyone else wants to use it in the future.

//hod_alias		shader	variable prefix

// Rings shader
hod_alias	res_me_rings	res_me_rings	RES_
#version 330

layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNorm;
layout (location = 6) in vec2 inUV0;

uniform mat4 inMatM;
uniform mat4 inMatV;
uniform mat4 inMatP;

smooth out float outZ;
smooth out vec2 outUV0;
smooth out vec3 outNorm_W;
smooth out vec3 outPos_W;

void main()
	vec4 posW4 = inMatM*vec4(inPos, 1.0);
	outPos_W =;
	vec4 posZ = inMatV*posW4;
	outZ = posZ.z;
	vec4 normW4 = inMatM*vec4(inNorm, 0.0);
	outNorm_W =;
	outUV0 = inUV0;
	mat4 VP = inMatP*inMatV;
	gl_Position = VP*posW4;			// Clip-space vert for geo/rasterize	
smooth in vec2 outUV0;
smooth in vec3 outNorm_W;
smooth in vec3 outPos_W;

uniform vec4 inTime;
uniform vec4 inGammaScale;
uniform sampler2D inTexDiff;
uniform vec4 inLightCore[7];

uniform vec4 inColDiff;
uniform vec4 inColEmis;

layout (location = 0) out vec4 finalCol0;

void main()
	vec4 texDiff = texture(inTexDiff, outUV0);
	vec3 worldNorm = normalize(outNorm_W);
	// Seed lighting with Ambient+Black
	vec3 diffAt = inLightCore[0].rgb;
	// Key Light
	vec3 litNorm = normalize(inLightCore[1].rgb);
	diffAt += inLightCore[2].rgb*clamp(dot(litNorm, worldNorm), 0.0, 1.0);
	// Fill Light
	litNorm = normalize(inLightCore[4].rgb);
	diffAt += inLightCore[5].rgb*clamp(dot(litNorm, worldNorm), 0.0, 1.0);
	// 'Average' Light - the diffused result of lit dust...
	vec3 diffMid = inLightCore[0].rgb;
	diffMid += (inLightCore[2].rgb+inLightCore[5].rgb)*0.5;
	vec3 diffMix = mix(diffMid, diffAt, texDiff.a);
	vec3 paint = texDiff.rgb*diffMix;
	paint = pow(paint, vec3(inGammaScale))*inGammaScale.a;
	//vec4 dustC = vec4(paint, texDiff.a)*inColDiff;
	vec4 dustC = vec4(paint, texDiff.a);
	dustC.rgb += inColEmis.rgb*inColEmis.a;
	finalCol0 = dustC;
	//finalCol0 = vec4(1, 1, 1, 0.2);
//debugReload 5

// Construct and build the program
add		vert_script		res_me_rings.vert
add		frag_text		#version 330
add		frag_script		res_me_rings.frag

// Input format
input	pos
input	norm
input	uv0

// Locals
local	tex			inTexDiff		0
local	float4		inColDiff		1	1	1	1
local	float4		inColEmis		0	0	0	0

// Globals and matrices
global	timeTable		inTime
global	gammaScale		inGammaScale
global	lightCore		inLightCore

// Matrix stack uniform mappings
matrix	modelview	inMatM
matrix	camera		inMatV
matrix	projection	inMatP

local	tex			RES_diffuse		default_white
local	float4		RES_diffTint	1	1	1	0.1
local	float4		RES_emisTint	0	0	0	0

sort alpha

	program res_me_rings
	blendOps srcAlpha srcInvAlpha
	depthWrite 1
	depthFunc lequal
	cull back
	fill poly
	alias	RES_diffuse		inTexDiff
	alias	RES_diffTint	inColDiff
	alias	RES_emisTint	inColEmis
# Rings shader (modded)
    $diffuse[DXT5] = 1 1 1 0.5
        DIFF = R G B A

The material of the ring object needs to be “res_me_rings” and the image compression should be DXT5. Result:

more shots

(ajlsunrise) #146

Is that just me, or is the ring going completely invisible in the shadow of the planet?

(Is this thing on?) #147

If you’re referring to the first of the ‘hidden’ images, that planetary shadow should be pretty much solid black (see the NASA images of Saturn for comparison). But I’m actually seeing stars through it.

(ajlsunrise) #148

Yes, that’s what I meant. I can see stars through it. Which is fine, if the stars are seen through the gap in the rings.

(Taiidan Republic Mod) #149

They are not going completely transparent. They are just a black version of the main ring (background objects will not cast shadows on each other - unless @radar3301 can make a magic shader to do that…).

This is the ring texture:

Stars should shine through the gaps like they would in Saturn’s rings. The reason you cannot see stars in the background of photographs of planets is because the camera cannot cope with the contrast. For example, in these photographs of the same scene, you can see the Moon and Venus with stars in the background. They are very bright, so the photographer either chooses to have the Moon and Venus looking sensible (but all else is too dark) or the rest of the scene visible (and the Moon and Venus are overwhelmingly bright…)

Flashing image


Your eyes would not have this problem, because they perceive light differently. You could cast a glance at this scene if you were there and observe the stars and the Moon and Venus and the trees clearly.

EDIT: so Homeworld backgrounds are not like photos taken from space probes, partly because they aim to feel immersive by creating an interesting scene and partly because the game throws out realism at several points anyway (how can you hear the explosions in space?), so why not here as well?

(Is this thing on?) #150

Just did a minor edit because that flashing image was a bit painful (delay between versions too short) and I know there are one or two folks on the forums who are on the photosensitive side.

(Chimas) #151

Nasa astronaut Reid Wiseman tweeted this photo from the International Space Station on 2 September 2014

(ajlsunrise) #152

The background objects don’t get a shadowmap render, so unfortunately, this is impossible.

(Taiidan Republic Mod) #153

Oh well, thanks for looking into it.

(Leviathans Wrath) #154

Still looks great

(HWRM Resurgence) #155

You could always try rendering them into background in 3d software if you wanna make it accurate.

(Leviathans Wrath) #156

Bring on Genesis, exploding planet

(Taiidan Republic Mod) #157

Ideally I would want to see a background object (like a moon) cast a shadow across the ships on the map area as it passes in front of the main light source. It sounds like this is impossible, unless you create a giant invisible ship to cart the shadows and time it to match the moon’s transit…

(ajlsunrise) #158

shadows only have a calculation distance of ~5000 meters (maybe up to 10,000?), and only ships that are currently in the viewport and up to a couple thousand meters behind cast shadows.

i think it might be possible to hardcode a shader to do this, but it might be very background/map specific.

…unless i can figure out a way to pass “background”/level data to the ship shader.

(Taiidan Republic Mod) #159

You can have a background object that uses the ship shader, it works fine.

(ajlsunrise) #160

Well, yes, but the background objects won’t cast shadows on the ships.

(Taiidan Republic Mod) #161

Ah ok, you mean how to pass data from an object in the background to create a shadow on a ship…