dhewm3 icon indicating copy to clipboard operation
dhewm3 copied to clipboard

Reflect Glasses effect problem.

Open Sol1vaN opened this issue 4 years ago • 5 comments

This effect is present in Doom 3 Alpha Leaked, from 2002. So I've found a file for materials to implement this effect into the game.

The file is implemented in: materials\glass.mtr

Here's the code:

textures/glass/outdoor_glass1
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays
	sort decal

	qer_editorimage textures/glass/glass1
	{
                Program           heatHaze.vfp
                vertexParm              0       time * 0 , time * 0 // texture scrolling
                vertexParm              1       .5        // magnitude of the distortion
                fragmentProgram			heatHaze.vfp
                fragmentMap             0       _currentRender
                fragmentMap             1       textures/sfx/vp1  // the normal map for distortion			
             
    }
	{	
		maskcolor				
	    map	makealpha(textures/glass/glass1)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect

	}
	{
     blend filter
	map textures/glass/outdoor_glass1fx
	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

textures/glass/breakyglass3
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/breakyglass3
	{
                Program           heatHazeWithMaskAndVertex.vfp
                vertexParm              0       time * 0 , time * 0 // texture scrolling
                vertexParm              1       .5        // magnitude of the distortion
                fragmentMap             0       _currentRender
                fragmentMap             1       textures/glass/breakyglass3   // the normal map for distortion		
	            fragmentMap             2       textures/glass/4x4  // the normal map for distortion		
             
    }
	{	
		maskcolor				
	    map	makealpha(textures/glass/breakyglass3)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect
		vertexColor
	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

textures/glass/breakyglass3_nvp
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/breakyglass3
	{	
		maskcolor				
	    map	makealpha(textures/glass/breakyglass3)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect
		vertexColor
	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

textures/glass/breakyglass2
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/breakyglass2
	{
                Program           heatHazeWithMaskAndVertex.vfp
                vertexParm              0       time * 0 , time * 0 // texture scrolling
                vertexParm              1       .5        // magnitude of the distortion
                fragmentMap             0       _currentRender
                fragmentMap             1       textures/glass/breakyglass2   // the normal map for distortion		
	            fragmentMap             2       textures/glass/4x4  // the normal map for distortion		
             
    }
	{	
		maskcolor				
	    map	makealpha(textures/glass/breakyglass2)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect
		vertexColor
	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

textures/glass/breakyglass2_nvp
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/breakyglass2
	{	
		maskcolor				
	    map	makealpha(textures/glass/breakyglass2)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect
		vertexColor
	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

textures/glass/breakyglass1_nvp
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/breakyglass1
	{	
		maskcolor				
	    map	makealpha(textures/glass/breakyglass1)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect
		vertexColor
	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

textures/glass/breakyglass1
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/breakyglass1
	{
                Program           heatHazeWithMaskAndVertex.vfp
                vertexParm              0       time * 0 , time * 0 // texture scrolling
                vertexParm              1       .5        // magnitude of the distortion
                fragmentMap             0       _currentRender
                fragmentMap             1       textures/glass/breakyglass1   // the normal map for distortion		
	            fragmentMap             2       textures/glass/4x4  // the normal map for distortion		
             
    }
	{	
		maskcolor				
	    map	makealpha(textures/glass/breakyglass1)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect
		vertexColor
	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}



textures/glass/mc_scannerglass
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/mc_scannerglass


	{	
		maskcolor				
	    map	makealpha(textures/glass/mc_scannerglass)
	}
	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/mc_scanner2
        texgen		reflect

	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}

		
}

textures/glass/glass1
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/glass1
	{
                Program           heatHaze.vfp
                vertexParm              0       time * 0 , time * 0 // texture scrolling
                vertexParm              1       .4         // magnitude of the distortion
                fragmentProgram			heatHaze.vfp
                fragmentMap             0       _currentRender
                fragmentMap             1       textures/sfx/vp1   // the normal map for distortion			
             
    }
	{	
		maskcolor				
	    map	makealpha(textures/glass/glass1)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect

	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

textures/glass/glass1_nvp
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/glass1
	{	
		maskcolor				
	    map	makealpha(textures/glass/glass1)
	}	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect

	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

textures/glass/glass2_nvp
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/glass2

	{	
		maskcolor				
	    map	makealpha(textures/glass/glass2)
	}
	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect

	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}

		
}



textures/glass/glass2
 {
	noSelfShadow
	noshadows
	twosided
	translucent
	glass
	forceoverlays

	qer_editorimage textures/glass/glass2

	{
                Program           heatHaze.vfp
                vertexParm              0       time * 0 , time * 0 // texture scrolling
                vertexParm              1       .4         // magnitude of the distortion
                fragmentProgram			heatHaze.vfp
                fragmentMap             0       _currentRender
                fragmentMap             1       textures/sfx/vp1   // the normal map for distortion
             
    }

	{	
		maskcolor				
	    map	makealpha(textures/glass/glass2)
	}
	
	{
	    blend gl_dst_alpha, gl_one
	    maskalpha
       	cubeMap		env/gen2
			red		Parm0
	        green   Parm1
	        blue	Parm2
        texgen		reflect

	}
//reflect stage
	{
		mirrorRenderMap 512 512		//detail of reflection, higher # = better
		blend blend
		alpha 0.3			//lower # = more transparent
		translate 0.5, 0.5
		scale 0.5, 0.5
	}
	
}

However, this have a problems causing crash when there's more 1 windows/glasses in one scene. So if anybody can suggest me a way to implement this, this will be great.

Also have a znear problem when you're close next to the windows, you can see how some part of the player model are cutting through the scene in the glass.

So, this have a lot of problems that need to be solved.

I'll make a MODDB channel to share this soon.

Take a look: https://i.imgur.com/vAEvfda.jpg https://i.imgur.com/kHRl2B7.jpg

Video: https://www.youtube.com/watch?v=YeGRvsxSWG4

reflectglass.zip

Sol1vaN avatar Apr 10 '21 19:04 Sol1vaN

I have a fix/workaround for this, but TBH it looks kinda shitty:

https://github.com/user-attachments/assets/c6ec03ef-5d3f-42dc-9bbe-d2f849f30a75

Note that "ghost" of the player to the right (well, you mostly see a big hand with a flashlight), which (I think) is the reflection of your reflection of your reflection, or something like that? Like, your reflection from the glass in front of you reflects on the glass on the other side of the room, and that reflects on the glass in front of you again, and for some reason became bigger in the process..

DanielGibson avatar Jan 22 '25 23:01 DanielGibson

Hmm could also be that it's not a reflection of a reflection but that it looks so weird because R_MirrorRender() always renders into the same image

DanielGibson avatar Jan 23 '25 01:01 DanielGibson

See #646. Not sure it's really correct now, sometimes things appear in the mirror that shouldn't.. but OTOH Doom3 is a horror game so that might be ok ¯\(ツ)

Looks better than before though and, most importantly, doesn't crash anymore.

DanielGibson avatar Jan 23 '25 02:01 DanielGibson

Updated video now that it's less broken:

https://github.com/user-attachments/assets/1e5546a0-abf4-4185-824b-5dcb82ffe5e7

DanielGibson avatar Jan 23 '25 02:01 DanielGibson

uh! great! i cant wait this can be released on the next build soon 😍 also, thinking now on this... may....

be possible to appliying selective raytraicing only to glases??? i know this is another leage, but questioning is for free no? 🤩

Sol1vaN avatar Jul 05 '25 13:07 Sol1vaN