Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect Glasses effect problem. #367

Open
Sol1vaN opened this issue Apr 10, 2021 · 4 comments · May be fixed by #646
Open

Reflect Glasses effect problem. #367

Sol1vaN opened this issue Apr 10, 2021 · 4 comments · May be fixed by #646
Labels
Feature Request Feature Requests

Comments

@Sol1vaN
Copy link

Sol1vaN commented Apr 10, 2021

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 Sol1vaN changed the title Doom 3 | Reflect Glasses effect problem. Reflect Glasses effect problem. Apr 10, 2021
@DanielGibson DanielGibson added the Feature Request Feature Requests label Jan 18, 2025
@DanielGibson
Copy link
Member

DanielGibson commented Jan 22, 2025

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

d3-mirrors.mp4

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
Copy link
Member

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 added a commit to DanielGibson/dhewm3 that referenced this issue Jan 23, 2025
It used to crash because after recursing into R_MirrorPoint(), which
calls tr.CropRenderSize(), about MAX_RENDER_CROPS times,
CropRenderSize() wrote behind the end of tr.renderCrops[] and damaged
a pointer.
Even if it didn't crash because of that, endlessly recursing is a bad
idea, so it's limited now. The limit can be configued with the new
r_maxMirrorRecursion CVar, but the hard limit is MAX_RENDER_CROPS-3 = 5

Another problem was that mirrors and other subviews render into
a texture, specifically globalImages->scratchImage ("_scratch"), so
it could happen that it got written to several times before being used.
Now there are 8 scratch images (+ the original "_scratch" which is also
used by gamecode) that the subview code cycles through to minimize the
chance of overwriting something that's still in use.
@DanielGibson DanielGibson linked a pull request Jan 23, 2025 that will close this issue
@DanielGibson
Copy link
Member

DanielGibson commented Jan 23, 2025

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
Copy link
Member

Updated video now that it's less broken:

d3-mirrors-fixed.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Feature Requests
Development

Successfully merging a pull request may close this issue.

2 participants