add texture to frag shader. fix weird macro name collision bug
This commit is contained in:
		
							parent
							
								
									a1b9e3a7a5
								
							
						
					
					
						commit
						8a10c06ad5
					
				@ -11,6 +11,7 @@ Here is the current list of planned features. All items are sorted in approximat
 | 
			
		||||
    * Skeletal animation
 | 
			
		||||
    * Macro to produce vertex buffer attributes (and maybe descriptors) from structs
 | 
			
		||||
    * Add runtime type safety to uniform bindings (and maybe compile time)
 | 
			
		||||
    * Inject layout set/bindings into shader source so they don't need to be defined in-shader
 | 
			
		||||
* Error Handling
 | 
			
		||||
    * Custom error type?
 | 
			
		||||
    * Remove as many panics / unwraps as possible
 | 
			
		||||
 | 
			
		||||
@ -166,7 +166,7 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
 | 
			
		||||
 | 
			
		||||
                Some(potential_shader_defs.drain(..)
 | 
			
		||||
                    .filter(|(f, shader_def)| shader_def.is_some())
 | 
			
		||||
                    .map(|(f, shader_def)| format!("{}{}", f, shader_def.unwrap()))
 | 
			
		||||
                    .map(|(f, shader_def)| format!("{}_{}{}", #struct_name_screaming_snake, f, shader_def.unwrap()))
 | 
			
		||||
                    .collect::<Vec<String>>())
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								docs/debugging.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								docs/debugging.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
# Debugging
 | 
			
		||||
 | 
			
		||||
## Macro Debugging
 | 
			
		||||
 | 
			
		||||
* Print the final output of a macro using ```cargo rustc --profile=check -- -Zunstable-options --pretty=expanded```
 | 
			
		||||
* Print output during macro compilation using ```eprintln!("hi");```
 | 
			
		||||
@ -60,7 +60,7 @@ fn main() {
 | 
			
		||||
                                void main() {
 | 
			
		||||
                                    o_Target = color;
 | 
			
		||||
 | 
			
		||||
                                # ifdef always_red
 | 
			
		||||
                                # ifdef MY_MATERIAL_always_red
 | 
			
		||||
                                    o_Target = vec4(0.8, 0.0, 0.0, 1.0);
 | 
			
		||||
                                # endif
 | 
			
		||||
                                }
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@ fn setup(world: &mut World) {
 | 
			
		||||
        mesh_storage.add(Mesh::load(MeshType::Cube))
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let _texture_handle = {
 | 
			
		||||
    let texture_handle = {
 | 
			
		||||
        let mut texture_storage = world.resources.get_mut::<AssetStorage<Texture>>().unwrap();
 | 
			
		||||
        let texture = Texture::load(TextureType::Data(asset::create_texels(256)));
 | 
			
		||||
        texture_storage.add(texture)
 | 
			
		||||
@ -22,7 +22,7 @@ fn setup(world: &mut World) {
 | 
			
		||||
        .add_archetype(MeshEntity {
 | 
			
		||||
            mesh: cube_handle.clone(),
 | 
			
		||||
            material: StandardMaterial {
 | 
			
		||||
                albedo: math::vec4(0.5, 0.3, 0.3, 1.0).into(),
 | 
			
		||||
                albedo: texture_handle.into(),
 | 
			
		||||
            },
 | 
			
		||||
            translation: Translation::new(0.0, 0.0, 1.0),
 | 
			
		||||
            ..Default::default()
 | 
			
		||||
 | 
			
		||||
@ -15,6 +15,12 @@ impl From<Vec4> for ColorSource {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl From<Handle<Texture>> for ColorSource {
 | 
			
		||||
    fn from(texture: Handle<Texture>) -> Self {
 | 
			
		||||
        ColorSource::Texture(texture)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl ShaderDefSuffixProvider for ColorSource {
 | 
			
		||||
    fn get_shader_def(&self) -> Option<&'static str> {
 | 
			
		||||
        match *self {
 | 
			
		||||
 | 
			
		||||
@ -23,12 +23,21 @@ layout(set = 0, binding = 1) uniform Lights {
 | 
			
		||||
    Light SceneLights[MAX_LIGHTS];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
# ifdef STANDARD_MATERIAL_albedo_texture
 | 
			
		||||
layout(set = 1, binding = 1) uniform texture2D StandardMaterial_albedo_texture;
 | 
			
		||||
layout(set = 1, binding = 2) uniform sampler StandardMaterial_albedo_sampler;
 | 
			
		||||
# else
 | 
			
		||||
layout(set = 1, binding = 1) uniform StandardMaterial_albedo {
 | 
			
		||||
    vec4 Albedo;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
# endif
 | 
			
		||||
 | 
			
		||||
void main() {
 | 
			
		||||
# ifdef STANDARD_MATERIAL_albedo_texture
 | 
			
		||||
    vec4 Albedo = texture(
 | 
			
		||||
        sampler2D(StandardMaterial_albedo_texture, StandardMaterial_albedo_sampler),
 | 
			
		||||
        v_Uv);
 | 
			
		||||
# endif
 | 
			
		||||
    vec3 normal = normalize(v_Normal);
 | 
			
		||||
    vec3 ambient = vec3(0.05, 0.05, 0.05);
 | 
			
		||||
    // accumulate color
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user