提交 082d2fed 编写于 作者: H happyfire

- folder structure

上级 15bccf0d
......@@ -36,6 +36,7 @@
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
</PropertyGroup>
<ItemGroup>
<Compile Include="Assets\URasterizer\Codes\JobRasterizer\VertexJob.cs" />
<Compile Include="Assets\URasterizer\Codes\Common\HandmakeMesh.cs" />
<Compile Include="Assets\URasterizer\Codes\Common\FPSDisplay.cs" />
<Compile Include="Assets\URasterizer\Codes\Common\ProfileManager.cs" />
......@@ -43,6 +44,7 @@
<Compile Include="Assets\URasterizer\Codes\CPURasterizer\FragmentShader.cs" />
<Compile Include="Assets\URasterizer\Codes\JobRasterizer\TriangleJob.cs" />
<Compile Include="Assets\URasterizer\Codes\Common\IRenderObjectData.cs" />
<Compile Include="Assets\URasterizer\Codes\Common\URUtils.cs" />
<Compile Include="Assets\URasterizer\Codes\JobRasterizer\JobRenderObjectData.cs" />
<Compile Include="Assets\URasterizer\Codes\Common\CommonDef.cs" />
<Compile Include="Assets\URasterizer\Codes\RenderingObject.cs" />
......@@ -57,14 +59,12 @@
<Compile Include="Assets\URasterizer\Codes\CPURasterizer\CPURasterizer.cs" />
<Compile Include="Assets\URasterizer\Codes\GPURasterizer\GPURasterizer.cs" />
<Compile Include="Assets\URasterizer\Codes\Common\TransformTool.cs" />
<Compile Include="Assets\URasterizer\Codes\Common\URUtils.cs" />
<Compile Include="Assets\URasterizer\Codes\JobRasterizer\VertexJob.cs" />
<None Include="Assets\URasterizer\Shaders\URVertexShader.hlsl" />
<None Include="Assets\URasterizer\Codes\GPURasterizer\Shaders\URVertexShader.hlsl" />
<None Include="Assets\URasterizer\DefaultAssets\DefaultShader.shader" />
<None Include="Assets\URasterizer\Shaders\URCommon.hlsl" />
<None Include="Assets\URasterizer\Shaders\URTriangleProcess.hlsl" />
<None Include="Assets\URasterizer\Shaders\URFragmentShader.hlsl" />
<None Include="Assets\URasterizer\Shaders\URComputeShader.compute" />
<None Include="Assets\URasterizer\Codes\GPURasterizer\Shaders\URCommon.hlsl" />
<None Include="Assets\URasterizer\Codes\GPURasterizer\Shaders\URTriangleProcess.hlsl" />
<None Include="Assets\URasterizer\Codes\GPURasterizer\Shaders\URFragmentShader.hlsl" />
<None Include="Assets\URasterizer\Codes\GPURasterizer\Shaders\URComputeShader.compute" />
<Reference Include="UnityEngine">
<HintPath>C:\Program Files\Unity\Hub\Editor\Unity 2020.3.25f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.dll</HintPath>
</Reference>
......
......@@ -405,7 +405,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 0b4771b06a3a8614b822c760aaba2a18, type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0b4771b06a3a8614b822c760aaba2a18, type: 3}
......@@ -631,7 +631,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 0b4771b06a3a8614b822c760aaba2a18, type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0b4771b06a3a8614b822c760aaba2a18, type: 3}
......
......@@ -662,6 +662,7 @@ namespace URasterizer
input.TextureData = ro.texture.GetPixelData<URColor24>(0);
input.TextureWidth = ro.texture.width;
input.TextureHeight = ro.texture.height;
input.UseBilinear = _config.BilinearSample;
input.LocalNormal = normal_p;
input.WorldPos = worldPos_p;
input.WorldNormal = worldNormal_p;
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Collections;
using System.Runtime.CompilerServices;
namespace URasterizer
{
......@@ -30,6 +30,7 @@ namespace URasterizer
public NativeArray<URColor24> TextureData; //因为我们的纹理都是RGB格式的(24位),所以不能用Color32(32位)
public int TextureWidth;
public int TextureHeight;
public bool UseBilinear;
}
public struct ShaderUniforms
......@@ -54,36 +55,60 @@ namespace URasterizer
public static ShaderUniforms Uniforms;
public static RenderingConfig Config;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color FSVertexColor(FragmentShaderInputData input)
{
return input.Color;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Color GetTextureColor(NativeArray<URColor24> textureData, int w, int h, int x, int y)
{
int tidx = y*w + x;
URColor24 c = textureData[tidx];
return (Color)c;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color FSBlinnPhong(FragmentShaderInputData input)
{
Color textureColor;
int w = input.TextureWidth;
int h = input.TextureHeight;
int x = (int)(w * input.UV.x);
int y = (int)(h * input.UV.y);
int tidx = y*w + x;
URColor24 c = input.TextureData[tidx];
Color textureColor = (URColor24)c;
// if (input.Texture != null)
// {
// int w = input.Texture.width;
// int h = input.Texture.height;
// if (Config.BilinearSample)
// {
// textureColor = input.Texture.GetPixelBilinear(input.UV.x, input.UV.y);
// }
// else
// {
// textureColor = input.Texture.GetPixel((int)(w * input.UV.x), (int)(h * input.UV.y));
// }
// }
if(input.UseBilinear)
{
float u_img = input.UV.x * w;
int u_img_i = (int)(u_img);
int u0 = u_img < u_img_i + 0.5 ? u_img_i - 1 : u_img_i;
if(u0<0) u0 = 0;
int u1 = u0 + 1;
float s = u_img - (u0 + 0.5f);
float v_img = input.UV.y * h;
int v_img_i = (int)(v_img);
int v0 = v_img < v_img_i + 0.5 ? v_img_i-1 : v_img_i;
if(v0<0) v0 = 0;
int v1 = v0 + 1;
float t = v_img - (v0 + 0.5f);
var color_00 = GetTextureColor(input.TextureData, w, h, u0, v0);
var color_10 = GetTextureColor(input.TextureData, w, h, u1, v0);
var color_0 = Color.Lerp(color_00, color_10, s);
var color_01 = GetTextureColor(input.TextureData, w, h, u0, v1);
var color_11 = GetTextureColor(input.TextureData, w, h, u1, v1);
var color_1 = Color.Lerp(color_01, color_11, s);
textureColor = Color.Lerp(color_0, color_1, t);
}
else
{
int x = (int)(w * input.UV.x);
int y = (int)(h * input.UV.y);
textureColor = GetTextureColor(input.TextureData, w, h, x, y);
}
Color ambient = Uniforms.AmbientColor;
......@@ -104,6 +129,7 @@ namespace URasterizer
return ambient + diffuse + specular;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color FSNormalVisual(FragmentShaderInputData input)
{
Vector3 tmp = input.LocalNormal * 0.5f + new Vector3(0.5f,0.5f,0.5f);
......
......@@ -191,6 +191,7 @@ namespace URasterizer
triJob.TextureData = ro.texture.GetPixelData<URColor24>(0);
triJob.TextureWidth = ro.texture.width;
triJob.TextureHeight = ro.texture.height;
triJob.UseBilinear = _config.BilinearSample;
triJob.fsType = _config.FragmentShaderType;
JobHandle triHandle = triJob.Schedule(ro.jobData.trianglesData.Length, 1, vsHandle);
......
......@@ -25,7 +25,9 @@ namespace URasterizer
[ReadOnly]
public NativeArray<URColor24> TextureData;
public int TextureWidth;
public int TextureHeight;
public int TextureHeight;
public bool UseBilinear;
public ShaderType fsType;
......@@ -258,6 +260,7 @@ namespace URasterizer
input.TextureData = TextureData;
input.TextureWidth = TextureWidth;
input.TextureHeight = TextureHeight;
input.UseBilinear = UseBilinear;
input.LocalNormal = normal_p;
input.WorldPos = worldPos_p;
input.WorldNormal = worldNormal_p;
......
......@@ -14,7 +14,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
ClearColor: {r: 0.4716981, g: 0.4716981, b: 0.4716981, a: 0.72156864}
AmbientColor: {r: 0.0754717, g: 0.0754717, b: 0.0754717, a: 1}
RasterizerType: 0
RasterizerType: 1
UseUnityNativeRendering: 0
WireframeMode: 0
FrustumCulling: 1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册