TA159

Notas, resueltos y trabajos practicos de la materia Sistemas Gráficos
Index Commits Files Refs Submodules README LICENSE
commit 109082b49769570678b514c913dd39a943444053
parent 9c5a012df9e5cac7572d79cd729bfda801393f85
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Mon,  8 Jul 2024 18:24:59 -0300

Merge branch `main` into branch `shadows`

Diffstat:
Dtp/src/assets/elevation_map.png | 0
Dtp/src/assets/elevation_map2.png | 0
Dtp/src/assets/elevation_map3.png | 0
Rtp/src/assets/pared-de-ladrillos.jpg -> tp/src/assets/pared_de_ladrillo.jpg | 0
Rtp/src/assets/tierraSeca.jpg -> tp/src/assets/tierra_seca.jpg | 0
Dtp/src/assets/tree_forbidden_zone_map.png | 0
Mtp/src/bridge.js | 4++--
Mtp/src/scene.js | 1-
Dtp/src/shaders.js | 109-------------------------------------------------------------------------------
Mtp/src/standalone/bridge.js | 4++--
Mtp/src/standalone/terrain.js | 2+-
Mtp/src/standalone/track-map.js | 6++----
Mtp/src/terrain.js | 3+--
Mtp/src/trees.js | 4++--
14 files changed, 10 insertions(+), 123 deletions(-)
diff --git a/tp/src/assets/elevation_map.png b/tp/src/assets/elevation_map.png
Binary files differ.
diff --git a/tp/src/assets/elevation_map2.png b/tp/src/assets/elevation_map2.png
Binary files differ.
diff --git a/tp/src/assets/elevation_map3.png b/tp/src/assets/elevation_map3.png
Binary files differ.
diff --git a/tp/src/assets/pared-de-ladrillos.jpg b/tp/src/assets/pared_de_ladrillo.jpg
Binary files differ.
diff --git a/tp/src/assets/tierraSeca.jpg b/tp/src/assets/tierra_seca.jpg
Binary files differ.
diff --git a/tp/src/assets/tree_forbidden_zone_map.png b/tp/src/assets/tree_forbidden_zone_map.png
Binary files differ.
diff --git a/tp/src/bridge.js b/tp/src/bridge.js
@@ -1,8 +1,8 @@
 import * as THREE from 'three';
 import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
 
-import tierraSecaUrl from './assets/tierraSeca.jpg'
-import ladrillosUrl  from './assets/pared-de-ladrillos.jpg'
+import tierraSecaUrl from './assets/tierra_seca.jpg'
+import ladrillosUrl  from './assets/pared_de_ladrillo.jpg'
 
 const textures = {
     tierra:     { url: tierraSecaUrl, object: null },
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -3,7 +3,6 @@ import * as dat from 'dat.gui';
 import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
 import { FirstPersonControls } from 'three/addons/controls/FirstPersonControls.js';
 import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';
-import { vertexShader, fragmentShader } from '/src/shaders.js';
 
 import Stats from 'three/examples/jsm/libs/stats.module.js';
 
diff --git a/tp/src/shaders.js b/tp/src/shaders.js
@@ -1,109 +0,0 @@
-export const vertexShader = `
-    precision highp float;
-
-    // Atributos de los vértices
-    attribute vec3 position; // Posición del vértice
-    attribute vec3 normal;   // Normal del vértice
-    attribute vec2 uv;       // Coordenadas de textura
-
-    // Uniforms
-    uniform mat4 modelMatrix;       // Matriz de transformación del objeto
-    uniform mat4 viewMatrix;        // Matriz de transformación de la cámara
-    uniform mat4 projectionMatrix;  // Matriz de proyección de la cámara
-    uniform mat4 worldNormalMatrix; // Matriz de normales
-
-    // Varying
-    varying vec2  vUv;       // Coordenadas de textura que se pasan al fragment shader
-    varying vec3  vNormal;   // Normal del vértice que se pasa al fragment shader
-    varying vec3  vWorldPos; // Posición del vértice en el espacio  de mundo
-
-    void main() {
-        // Lee la posición del vértice desde los atributos
-        vec3 pos = position;
-
-        // Se calcula la posición final del vértice
-        // Se aplica la transformación del objeto, la de la cámara y la de proyección
-        gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(pos, 1.0);
-
-        // Se pasan las coordenadas de textura al fragment shader
-        vUv = uv;
-        vNormal = normalize(vec3(worldNormalMatrix * vec4(normal, 0.0)));
-        vWorldPos = (modelMatrix * vec4(pos, 1.0)).xyz;
-    }
-`;
-
-export const fragmentShader = `
-    precision mediump float;
-    varying vec2 vUv;
-    varying vec3 vNormal;
-    varying vec3 vWorldPos;
-
-    uniform float scale;
-    uniform float terrainAmplitude;
-    uniform float terrainAmplitudeBottom;
-    uniform float dirtStepWidth;
-    uniform float rockStepWidth;
-
-    uniform sampler2D dirtSampler;
-    uniform sampler2D rockSampler;
-    uniform sampler2D grassSampler;
-
-    float normalize(float inputValue, float minValue, float maxValue) {
-        return (inputValue - minValue) / (maxValue - minValue);
-    }
-
-    void main(void) {
-        vec2 uv = vUv*8.0;
-        vec2 uv2 = vUv*scale;
-
-        float heightFactor = vWorldPos.y - terrainAmplitudeBottom;
-        float heightFactorNormalized = normalize(heightFactor, 0.0, terrainAmplitude);
-
-        vec3 grass = texture2D(grassSampler, uv).xyz;
-        vec3 dirt  = texture2D(dirtSampler, uv*4.0).xyz;
-        vec3 rock  = texture2D(rockSampler, uv).xyz;
-
-        // muestreo de pasto a diferentes escalas, luego se combina con \`mix()\`
-        vec3 grass1 = texture2D(grassSampler, uv2*1.00).xyz;
-        vec3 grass2 = texture2D(grassSampler, uv2*3.13).xyz;
-        vec3 grass3 = texture2D(grassSampler, uv2*2.37).xyz;
-        vec3 colorGrass = mix(mix(grass1,grass2,0.5),grass3,0.3);
-
-        // lo mismo para la textura de tierra
-        vec3 dirt1 = texture2D(dirtSampler, uv2*3.77).xyz;
-        vec3 dirt2 = texture2D(dirtSampler, uv2*1.58).xyz;
-        vec3 dirt3 = texture2D(dirtSampler, uv2*1.00).xyz;
-        vec3 colorDirt = mix(mix(dirt1, dirt2, 0.5), dirt3, 0.3);
-
-        // lo mismo para la textura de roca
-        vec3 rock1 = texture2D(rockSampler,uv2*0.40).xyz;
-        vec3 rock2 = texture2D(rockSampler,uv2*2.38).xyz;
-        vec3 rock3 = texture2D(rockSampler,uv2*3.08).xyz;
-        vec3 colorRock = mix(mix(rock1, rock2, 0.5), rock3,0.5);
-
-        float u = heightFactorNormalized;
-
-        // float pi = 3.141592654;
-        // float grassFactor = sin(pi*u);
-        // float dirtFactor  = abs(sin(2.0*pi));
-        // float rockFactor  = clamp(cos(2.0*pi*u), 0.0, 1.0);
-
-        float width2 = rockStepWidth;
-        float rockFactor = 2.00 - smoothstep(0.0, width2, u)
-                                - smoothstep(1.0, 1.00 - width2, u);
-
-        float width = dirtStepWidth;
-        float s1 = smoothstep(0.00, width, u);
-        float s2 = smoothstep(width, width*2.0, u);
-        float s3 = smoothstep(0.50, 0.50 + width, u);
-        float s4 = smoothstep(0.50 + width, 0.50 + width*2.0, u);
-        float dirtFactor = (s1 - s2) + (s3 - s4);
-
-        float grassFactor = smoothstep(0.0, 0.35, u) - smoothstep(0.35, 1.00, u);
-
-        vec3 colorDirtGrass = mix(colorDirt, colorGrass, grassFactor);
-        vec3 colorDirtGrassDirt = mix(colorDirtGrass, colorDirt, dirtFactor);
-        vec3 color = mix(colorDirtGrassDirt, colorRock, rockFactor);
-
-        gl_FragColor = vec4(color, 1.0);
-    }`;
diff --git a/tp/src/standalone/bridge.js b/tp/src/standalone/bridge.js
@@ -3,8 +3,8 @@ import * as dat from 'dat.gui';
 import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
 import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
 
-import tierraSecaUrl from '../assets/tierraSeca.jpg'
-import ladrillosUrl  from '../assets/pared-de-ladrillos.jpg'
+import tierraSecaUrl from '../assets/tierra_seca.jpg'
+import ladrillosUrl  from '../assets/pared_de_ladrillos.jpg'
 
 const textures = {
     tierra:     { url: tierraSecaUrl, object: null },
diff --git a/tp/src/standalone/terrain.js b/tp/src/standalone/terrain.js
@@ -13,7 +13,7 @@ const amplitudeBottom = -1.00;
 import tierraUrl       from '../assets/tierra.jpg'
 import rocaUrl         from '../assets/roca.jpg'
 import pastoUrl        from '../assets/pasto.jpg'
-import elevationMapUrl from '../assets/elevation_map2.png'
+import elevationMapUrl from '../assets/elevation_map_wider_river.png'
 
 const textures = {
     tierra:       { url: tierraUrl,       object: null },
diff --git a/tp/src/standalone/track-map.js b/tp/src/standalone/track-map.js
@@ -14,8 +14,8 @@ const amplitudeBottom = -1.00;
 import tierraUrl           from '../assets/tierra.jpg'
 import rocaUrl             from '../assets/roca.jpg'
 import pastoUrl            from '../assets/pasto.jpg'
-import elevationMapUrl     from '../assets/elevation_map2.png'
-import treeForbiddenMapUrl from '../assets/tree_forbidden_zone_map.png'
+import elevationMapUrl     from '../assets/elevation_map_wider_river.png'
+import treeForbiddenMapUrl from '../assets/tree_forbidden_zone_map_wider_path.png'
 
 const textures = {
     tierra:           { url: tierraUrl,           object: null },
@@ -92,12 +92,10 @@ function isForbbidenPosition(position) {
     const y = position.y;
     const z = Math.floor(position.z);
 
-    /*
     if((y > 5.0) || (y < 2.65)){
         console.log("(" + position.x + ", " + position.y + ", " + position.z + ") is not valid ");
         return true;
     }
-    */
     
     let pixelArray = getPixelXY(treesForbiddenMap, x, z);
     const R = pixelArray[0]; // Red
diff --git a/tp/src/terrain.js b/tp/src/terrain.js
@@ -1,5 +1,4 @@
 import * as THREE from 'three';
-import { vertexShader, fragmentShader } from '/src/shaders.js';
 
 const widthSegments   = 100;
 const heightSegments  = 100;
@@ -9,7 +8,7 @@ const amplitudeBottom = -1.00;
 import rocaUrl             from './assets/roca.jpg'
 import pastoUrl            from './assets/pasto.jpg'
 import tierraUrl           from './assets/tierra.jpg'
-import elevationMapUrl     from './assets/elevation_map2.png'
+import elevationMapUrl     from './assets/elevation_map_wider_river.png'
 
 const textures = {
     tierra:       { url: tierraUrl,       object: null },
diff --git a/tp/src/trees.js b/tp/src/trees.js
@@ -2,8 +2,8 @@ import * as THREE from 'three';
 
 let treesForbiddenMapData, treesForbiddenMap, elevationMap, elevationMapData;
 
-import elevationMapUrl     from './assets/elevation_map2.png'
-import treeForbiddenMapUrl from './assets/tree_forbidden_zone_map.png'
+import elevationMapUrl     from './assets/elevation_map_wider_river.png'
+import treeForbiddenMapUrl from './assets/tree_forbidden_zone_map_wider_path.png'
 
 const textures = {
     elevationMap:     { url: elevationMapUrl, object: null },