Skip to content

Commit

Permalink
Changed reflection appearance and added saving images from epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsOKayCZ committed Oct 19, 2024
1 parent b8d9fb9 commit 30dd197
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
12 changes: 12 additions & 0 deletions python_trainer/trainer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy

import cv2
import numpy as np
import torch
import torch.onnx
Expand Down Expand Up @@ -69,6 +70,17 @@ def train(self, env: UnityEnvironment, temperature: float) -> float:
if self.writer is not None:
self.writer.add_image("Sample image", sample_image)

# Turn to True, if you want to see all of the images from the epoch
if False:
index = 0
for buffer in self.memory.buffer:
for sample in buffer.observations:
gray_image = cv2.cvtColor(
np.resize(sample[0], (100, 160, 1)) * 255.0, cv2.COLOR_GRAY2RGB
)
cv2.imwrite(f"/tmp/{self.curr_epoch}-{index}.jpg", gray_image)
index += 1

# Add text
steer = ""

Expand Down
8 changes: 7 additions & 1 deletion unity_env/Assets/Materials/Deepracer - terrain.mat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Deepracer - terrain
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_Shader: {fileID: 4800000, guid: 7bd43790af56d1df988076f434fb05d3, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
Expand Down Expand Up @@ -70,14 +70,20 @@ Material:
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _NoiseScale: 0.07
- _OcclusionStrength: 1
- _Parallax: 0.02
- _ReflectionStrength: 4
- _SetTexture: 0
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _Speed: 0.6
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 0.81960785, b: 0.5294118, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _MainColor: {r: 0, g: 0.81960785, b: 0.5294118, a: 1}
- _ReflectionColor: {r: 1, g: 0.9411765, b: 0.6117647, a: 1}
m_BuildTextureStacks: []
3 changes: 3 additions & 0 deletions unity_env/Assets/Materials/Road/Amazon road.mat
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Material:
- _OcclusionStrength: 1
- _Parallax: 0.02
- _ReflectionStrength: 4
- _SetTexture: 1
- _Smoothness: 0
- _SmoothnessTextureChannel: 1
- _SpecularHighlights: 1
Expand All @@ -94,5 +95,7 @@ Material:
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _MainColor: {r: 1, g: 1, b: 0, a: 1}
- _ReflectionColor: {r: 1, g: 0.9415832, b: 0.6133826, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
21 changes: 16 additions & 5 deletions unity_env/Assets/Materials/Road/Reflection.shader
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ Shader "Custom/Reflection"
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
[Maincolor] _MainColor ("Main color", Color) = (1., 1., 0., 1.)
_SetTexture ("Texture set", Float) = 0.
_ReflectionStrength ("Reflection strength", Float) = 1.0
_NoiseScale ("Noise scale", Float) = 1.0
_NoiseScaleX ("Noise scale X", Float) = 1.0
_NoiseScaleY ("Noise scale Y", Float) = 1.0
_Speed ("Noise speed", Range(0, 1)) = 0.5
_ReflectionColor ("Reflection color", Color) = (1., 1., 1., 1.)
}
SubShader
{
Expand All @@ -20,9 +24,13 @@ Shader "Custom/Reflection"
#pragma target 3.0

sampler2D _MainTex;
float4 _MainColor;
float _ReflectionStrength;
float _NoiseScale;
float _NoiseScaleX;
float _NoiseScaleY;
float _Speed;
float4 _ReflectionColor;
float _SetTexture;

struct Input
{
Expand Down Expand Up @@ -166,12 +174,15 @@ Shader "Custom/Reflection"
void surf (Input IN, inout SurfaceOutputStandard o)
{
// float2 noiseInput = IN.uv_MainTex * _NoiseScale;
float2 noiseInput = IN.worldPos.xz * _NoiseScale;
float2 noiseInput = IN.worldPos.xz;
noiseInput.x *= _NoiseScaleX;
noiseInput.y *= _NoiseScaleY;
float noiseValue = clamp(ClassicNoise(float3(noiseInput.x, noiseInput.y, _Time.y * _Speed)), 0.0, 1.0) * _ReflectionStrength;
// float noiseValue = ClassicNoise(noiseInput);

fixed4 albedo = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = albedo + noiseValue;
fixed4 albedo = tex2D(_MainTex, IN.uv_MainTex) * _SetTexture + _MainColor * (1. - _SetTexture);

o.Albedo = albedo + noiseValue * _ReflectionColor.rgb;
}
ENDCG
}
Expand Down

0 comments on commit 30dd197

Please sign in to comment.