mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-11-04 09:02:14 +00:00 
			
		
		
		
	Improve static noise by using pregenerated image instead of the shader we used before.
This commit is contained in:
		@@ -46,6 +46,7 @@ Item{
 | 
				
			|||||||
    property real _maxBlurCoefficient: 0.90
 | 
					    property real _maxBlurCoefficient: 0.90
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    property size terminalSize: kterminal.terminalSize
 | 
					    property size terminalSize: kterminal.terminalSize
 | 
				
			||||||
 | 
					    property size fontMetrics: kterminal.fontMetrics
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Manage copy and paste
 | 
					    // Manage copy and paste
 | 
				
			||||||
    Connections{
 | 
					    Connections{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,53 +54,18 @@ ShaderTerminal{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    bloomSource: bloomSourceLoader.item
 | 
					    bloomSource: bloomSourceLoader.item
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ShaderEffect {
 | 
					    Image {
 | 
				
			||||||
        id: staticNoiseEffect
 | 
					        id: staticNoiseImage
 | 
				
			||||||
        anchors.fill: parent
 | 
					        source: "images/noise512.png"
 | 
				
			||||||
        property real element_size: appSettings.rasterization == appSettings.no_rasterization ? 2 : 1
 | 
					        anchors.centerIn: parent
 | 
				
			||||||
        property alias __terminalHeight: terminal.virtualResolution.height
 | 
					        width: parent.width / (appSettings.window_scaling * appSettings.fontScaling)
 | 
				
			||||||
        property alias __terminalWidth: terminal.virtualResolution.width
 | 
					        height: parent.height / (appSettings.window_scaling * appSettings.fontScaling)
 | 
				
			||||||
        property size virtual_resolution: Qt.size(__terminalWidth / element_size, __terminalHeight / element_size)
 | 
					        fillMode: Image.Tile
 | 
				
			||||||
 | 
					 | 
				
			||||||
        blending: false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        fragmentShader:
 | 
					 | 
				
			||||||
            "uniform lowp float qt_Opacity;
 | 
					 | 
				
			||||||
             varying highp vec2 qt_TexCoord0;
 | 
					 | 
				
			||||||
             uniform highp vec2 virtual_resolution;" +
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            "highp float noise(vec2 co)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                highp float a = 12.9898;
 | 
					 | 
				
			||||||
                highp float b = 78.233;
 | 
					 | 
				
			||||||
                highp float c = 43758.5453;
 | 
					 | 
				
			||||||
                highp float dt= dot(co.xy ,vec2(a,b));
 | 
					 | 
				
			||||||
                highp float sn= mod(dt,3.14);
 | 
					 | 
				
			||||||
                return fract(sin(sn) * c);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            vec2 sw(vec2 p) {return vec2( floor(p.x) , floor(p.y) );}
 | 
					 | 
				
			||||||
            vec2 se(vec2 p) {return vec2( ceil(p.x)  , floor(p.y) );}
 | 
					 | 
				
			||||||
            vec2 nw(vec2 p) {return vec2( floor(p.x) , ceil(p.y)  );}
 | 
					 | 
				
			||||||
            vec2 ne(vec2 p) {return vec2( ceil(p.x)  , ceil(p.y)  );}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            float smoothNoise(vec2 p) {
 | 
					 | 
				
			||||||
                vec2 inter = smoothstep(0., 1., fract(p));
 | 
					 | 
				
			||||||
                float s = mix(noise(sw(p)), noise(se(p)), inter.x);
 | 
					 | 
				
			||||||
                float n = mix(noise(nw(p)), noise(ne(p)), inter.x);
 | 
					 | 
				
			||||||
                return mix(s, n, inter.y);
 | 
					 | 
				
			||||||
            }" +
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            "void main() {" +
 | 
					 | 
				
			||||||
                "gl_FragColor.a = smoothNoise(qt_TexCoord0 * virtual_resolution);" +
 | 
					 | 
				
			||||||
            "}"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        onStatusChanged: if (log) console.log(log) //Print warning messages
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    noiseSource: ShaderEffectSource{
 | 
					    noiseSource: ShaderEffectSource{
 | 
				
			||||||
        id: staticNoiseSource
 | 
					        id: staticNoiseSource
 | 
				
			||||||
        sourceItem: staticNoiseEffect
 | 
					        sourceItem: staticNoiseImage
 | 
				
			||||||
        textureSize: Qt.size(mainShader.width, mainShader.height)
 | 
					 | 
				
			||||||
        wrapMode: ShaderEffectSource.Repeat
 | 
					        wrapMode: ShaderEffectSource.Repeat
 | 
				
			||||||
        smooth: true
 | 
					        smooth: true
 | 
				
			||||||
        hideSource: true
 | 
					        hideSource: true
 | 
				
			||||||
@@ -113,7 +78,7 @@ ShaderTerminal{
 | 
				
			|||||||
        height: parent.height
 | 
					        height: parent.height
 | 
				
			||||||
        property real outColor: 0.0
 | 
					        property real outColor: 0.0
 | 
				
			||||||
        property real dispX: (5 / width) * appSettings.window_scaling
 | 
					        property real dispX: (5 / width) * appSettings.window_scaling
 | 
				
			||||||
        property real dispY: 5 / height * appSettings.window_scaling
 | 
					        property real dispY: (5 / height) * appSettings.window_scaling
 | 
				
			||||||
        property size virtual_resolution: terminal.virtualResolution
 | 
					        property size virtual_resolution: terminal.virtualResolution
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        blending: false
 | 
					        blending: false
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								app/qml/images/noise512.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								app/qml/images/noise512.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 278 KiB  | 
@@ -67,5 +67,6 @@
 | 
				
			|||||||
        <file>TerminalContainer.qml</file>
 | 
					        <file>TerminalContainer.qml</file>
 | 
				
			||||||
        <file>images/crt256.png</file>
 | 
					        <file>images/crt256.png</file>
 | 
				
			||||||
        <file>utils.js</file>
 | 
					        <file>utils.js</file>
 | 
				
			||||||
 | 
					        <file>images/noise512.png</file>
 | 
				
			||||||
    </qresource>
 | 
					    </qresource>
 | 
				
			||||||
</RCC>
 | 
					</RCC>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user